[libchamplain] Merge ChamplainLayer and ChamplainPolygon



commit 51528c331fe8c96aa030e207ffb02e073d4c3463
Author: JiÅ?í Techet <techet gmail com>
Date:   Wed Jan 26 00:08:46 2011 +0100

    Merge ChamplainLayer and ChamplainPolygon
    
    In principle, ChamplainLayer and ChamplainPolygon do the same thing.
    They both contain a list of points on the map (ChamplainMarker or
    ChamplainPoint) which in the case of ChamplainPolygon are defining the
    polygon. By merging both concept, we can reuse a lot of code, such as
    marker/polygon node moving, all point manipulation and so on.

 champlain/Makefile.am         |    2 -
 champlain/champlain-layer.c   |  632 ++++++++++++++++++++++++++++--
 champlain/champlain-layer.h   |   20 +
 champlain/champlain-polygon.c |  866 -----------------------------------------
 champlain/champlain-polygon.h |  112 ------
 champlain/champlain-view.c    |  151 -------
 champlain/champlain-view.h    |    6 -
 demos/launcher-gtk.c          |   12 +-
 demos/markers.c               |    2 +-
 demos/polygons.c              |   12 +-
 10 files changed, 633 insertions(+), 1182 deletions(-)
---
diff --git a/champlain/Makefile.am b/champlain/Makefile.am
index e82c64a..5a31e64 100644
--- a/champlain/Makefile.am
+++ b/champlain/Makefile.am
@@ -29,7 +29,6 @@ libchamplain_headers_public = 				\
 	$(srcdir)/champlain-file-cache.h		\
 	$(srcdir)/champlain-map-source-factory.h	\
 	$(srcdir)/champlain-map-source-desc.h		\
-	$(srcdir)/champlain-polygon.h			\
 	$(srcdir)/champlain-renderer.h			\
 	$(srcdir)/champlain-image-renderer.h		\
 	$(srcdir)/champlain-error-tile-renderer.h	\
@@ -66,7 +65,6 @@ libchamplain_sources =					\
 	$(srcdir)/champlain-map-source-factory.c	\
 	$(srcdir)/champlain-map-source-desc.c		\
 	$(srcdir)/champlain-point.c			\
-	$(srcdir)/champlain-polygon.c			\
 	$(srcdir)/champlain-renderer.c			\
 	$(srcdir)/champlain-image-renderer.c		\
 	$(srcdir)/champlain-error-tile-renderer.c	\
diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c
index 82fe7f1..0a0fa18 100644
--- a/champlain/champlain-layer.c
+++ b/champlain/champlain-layer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc pierlux com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc pierlux com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -54,15 +54,34 @@ enum
 enum
 {
   PROP_0,
-  PROP_SELECTION_MODE
+  PROP_SELECTION_MODE,
+  PROP_CLOSED_PATH,
+  PROP_STROKE_WIDTH,
+  PROP_STROKE_COLOR,
+  PROP_FILL,
+  PROP_FILL_COLOR,
+  PROP_STROKE,
+  PROP_VISIBLE,
 };
 
+static ClutterColor DEFAULT_FILL_COLOR = { 0xcc, 0x00, 0x00, 0xaa };
+static ClutterColor DEFAULT_STROKE_COLOR = { 0xa4, 0x00, 0x00, 0xff };
+
 static guint signals[LAST_SIGNAL] = { 0, };
 
 struct _ChamplainLayerPrivate
 {
   ChamplainSelectionMode mode;
   ChamplainView *view;
+  
+  ClutterActor *polygon_actor;
+  gboolean closed_path;
+  ClutterColor *stroke_color;
+  gboolean fill;
+  ClutterColor *fill_color;
+  gboolean stroke;
+  gdouble stroke_width;
+  gboolean visible;
 };
 
 
@@ -84,6 +103,35 @@ champlain_layer_get_property (GObject *object,
     case PROP_SELECTION_MODE:
       g_value_set_enum (value, priv->mode);
       break;
+      
+    case PROP_CLOSED_PATH:
+      g_value_set_boolean (value, priv->closed_path);
+      break;
+
+    case PROP_FILL:
+      g_value_set_boolean (value, priv->fill);
+      break;
+
+    case PROP_STROKE:
+      g_value_set_boolean (value, priv->stroke);
+      break;
+
+    case PROP_FILL_COLOR:
+      clutter_value_set_color (value, priv->fill_color);
+      break;
+
+    case PROP_STROKE_COLOR:
+      clutter_value_set_color (value, priv->stroke_color);
+      break;
+
+    case PROP_STROKE_WIDTH:
+      g_value_set_double (value, priv->stroke_width);
+      break;
+
+    case PROP_VISIBLE:
+      g_value_set_boolean (value, priv->visible);
+      break;
+      
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -97,12 +145,50 @@ champlain_layer_set_property (GObject *object,
     GParamSpec *pspec)
 {
   ChamplainLayer *self = CHAMPLAIN_LAYER (object);
+  ChamplainLayerPrivate *priv = self->priv;
   
   switch (property_id)
     {
     case PROP_SELECTION_MODE:
       champlain_layer_set_selection_mode (self, g_value_get_enum (value));
       break;
+      
+    case PROP_CLOSED_PATH:
+      priv->closed_path = g_value_get_boolean (value);
+      break;
+
+    case PROP_FILL:
+      champlain_layer_set_polygon_fill (CHAMPLAIN_LAYER (object),
+          g_value_get_boolean (value));
+      break;
+
+    case PROP_STROKE:
+      champlain_layer_set_polygon_stroke (CHAMPLAIN_LAYER (object),
+          g_value_get_boolean (value));
+      break;
+
+    case PROP_FILL_COLOR:
+      champlain_layer_set_polygon_fill_color (CHAMPLAIN_LAYER (object),
+          clutter_value_get_color (value));
+      break;
+
+    case PROP_STROKE_COLOR:
+      champlain_layer_set_polygon_stroke_color (CHAMPLAIN_LAYER (object),
+          clutter_value_get_color (value));
+      break;
+
+    case PROP_STROKE_WIDTH:
+      champlain_layer_set_polygon_stroke_width (CHAMPLAIN_LAYER (object),
+          g_value_get_double (value));
+      break;
+
+    case PROP_VISIBLE:
+      if (g_value_get_boolean (value))
+        champlain_layer_show_polygon (CHAMPLAIN_LAYER (object));
+      else
+        champlain_layer_hide_polygon (CHAMPLAIN_LAYER (object));
+      break;
+      
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -127,6 +213,12 @@ champlain_layer_dispose (GObject *object)
 static void
 champlain_layer_finalize (GObject *object)
 {
+  ChamplainLayer *self = CHAMPLAIN_LAYER (object);
+  ChamplainLayerPrivate *priv = self->priv;
+  
+  clutter_color_free (priv->stroke_color);
+  clutter_color_free (priv->fill_color);
+
   G_OBJECT_CLASS (champlain_layer_parent_class)->finalize (object);
 }
 
@@ -160,6 +252,109 @@ champlain_layer_class_init (ChamplainLayerClass *klass)
           CHAMPLAIN_PARAM_READWRITE));
 
   /**
+   * ChamplainPolygon:close-path:
+   *
+   * The shape is a closed path
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_CLOSED_PATH,
+      g_param_spec_boolean ("closed-path",
+          "Closed Path",
+          "The Path is Closed",
+          FALSE, CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:fill:
+   *
+   * The shape should be filled
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_FILL,
+      g_param_spec_boolean ("fill",
+          "Fill",
+          "The shape is filled",
+          FALSE, CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:stroke:
+   *
+   * The shape should be stroked
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_STROKE,
+      g_param_spec_boolean ("stroke",
+          "Stroke",
+          "The shape is stroked",
+          TRUE, CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:stroke-color:
+   *
+   * The polygon's stroke color
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_STROKE_COLOR,
+      clutter_param_spec_color ("stroke-color",
+          "Stroke Color",
+          "The polygon's stroke color",
+          &DEFAULT_STROKE_COLOR,
+          CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:text-color:
+   *
+   * The polygon's fill color
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_FILL_COLOR,
+      clutter_param_spec_color ("fill-color",
+          "Fill Color",
+          "The polygon's fill color",
+          &DEFAULT_FILL_COLOR,
+          CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:stroke-width:
+   *
+   * The polygon's stroke width (in pixels)
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_STROKE_WIDTH,
+      g_param_spec_double ("stroke-width",
+          "Stroke Width",
+          "The polygon's stroke width",
+          0, 100.0,
+          2.0,
+          CHAMPLAIN_PARAM_READWRITE));
+
+  /**
+   * ChamplainPolygon:visible:
+   *
+   * Wether the polygon is visible
+   *
+   * Since: 0.4
+   */
+  g_object_class_install_property (object_class,
+      PROP_VISIBLE,
+      g_param_spec_boolean ("visible",
+          "Visible",
+          "The polygon's visibility",
+          TRUE,
+          CHAMPLAIN_PARAM_READWRITE));
+
+  /**
    * ChamplainLayer::changed
    *
    * The changed signal is emitted when the selected marker(s) change.
@@ -191,9 +386,25 @@ button_release_cb (G_GNUC_UNUSED ClutterActor *actor,
 static void
 champlain_layer_init (ChamplainLayer *self)
 {
+  ChamplainLayerPrivate *priv;
+  
   self->priv = GET_PRIVATE (self);
-  self->priv->mode = CHAMPLAIN_SELECTION_NONE;
-  self->priv->view = NULL;
+  priv = self->priv;
+  priv->mode = CHAMPLAIN_SELECTION_NONE;
+  priv->view = NULL;
+
+  priv->visible = TRUE;
+  priv->fill = FALSE;
+  priv->stroke = TRUE;
+  priv->stroke_width = 2.0;
+
+  priv->fill_color = clutter_color_copy (&DEFAULT_FILL_COLOR);
+  priv->stroke_color = clutter_color_copy (&DEFAULT_STROKE_COLOR);
+  
+  //TODO destroy + ref()
+  priv->polygon_actor = clutter_group_new ();
+  clutter_container_add_actor (CLUTTER_CONTAINER (self), priv->polygon_actor);
+  
   
   clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
   g_signal_connect (self, "button-release-event",
@@ -227,20 +438,24 @@ set_highlighted_all_but_one (ChamplainLayer *layer,
   
   for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
     {
-      ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
-      
-      if (marker != not_highlighted)
-        {
-          g_signal_handlers_block_by_func (marker, 
-              G_CALLBACK (marker_highlighted_cb), 
-              layer);
-
-          champlain_base_marker_set_highlighted (marker, highlight);
-          champlain_base_marker_set_selectable (marker, layer->priv->mode != CHAMPLAIN_SELECTION_NONE);
-
-          g_signal_handlers_unblock_by_func (marker, 
-              G_CALLBACK (marker_highlighted_cb), 
-              layer);
+      ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+      if (CHAMPLAIN_IS_BASE_MARKER (actor))
+        {    
+          ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
+          
+          if (marker != not_highlighted)
+            {
+              g_signal_handlers_block_by_func (marker, 
+                  G_CALLBACK (marker_highlighted_cb), 
+                  layer);
+
+              champlain_base_marker_set_highlighted (marker, highlight);
+              champlain_base_marker_set_selectable (marker, layer->priv->mode != CHAMPLAIN_SELECTION_NONE);
+
+              g_signal_handlers_unblock_by_func (marker, 
+                  G_CALLBACK (marker_highlighted_cb), 
+                  layer);
+            }
         }
     }
 }
@@ -325,10 +540,14 @@ champlain_layer_animate_in_all_markers (ChamplainLayer *layer)
 
   for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
     {
-      ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+      ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+      if (CHAMPLAIN_IS_BASE_MARKER (actor))
+        {    
+          ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
 
-      champlain_base_marker_animate_in_with_delay (marker, delay);
-      delay += 50;
+          champlain_base_marker_animate_in_with_delay (marker, delay);
+          delay += 50;
+        }
     }
 }
 
@@ -351,10 +570,14 @@ champlain_layer_animate_out_all_markers (ChamplainLayer *layer)
 
   for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
     {
-      ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+      ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+      if (CHAMPLAIN_IS_BASE_MARKER (actor))
+        {    
+          ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
 
-      champlain_base_marker_animate_out_with_delay (marker, delay);
-      delay += 50;
+          champlain_base_marker_animate_out_with_delay (marker, delay);
+          delay += 50;
+        }
     }
 }
 
@@ -540,15 +763,18 @@ relocate (ChamplainLayer *layer)
   for (i = 0; i < n_children; i++)
     {
       ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
-      ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
-      gint x, y;
+      if (CHAMPLAIN_IS_BASE_MARKER (actor))
+        {    
+          ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
+          gint x, y;
 
-      x = champlain_view_longitude_to_layer_x (priv->view, 
-        champlain_base_marker_get_longitude (marker));
-      y = champlain_view_latitude_to_layer_y (priv->view, 
-        champlain_base_marker_get_latitude (marker));
+          x = champlain_view_longitude_to_layer_x (priv->view, 
+            champlain_base_marker_get_longitude (marker));
+          y = champlain_view_latitude_to_layer_y (priv->view, 
+            champlain_base_marker_get_latitude (marker));
 
-      clutter_actor_set_position (CLUTTER_ACTOR (marker), x, y);
+          clutter_actor_set_position (CLUTTER_ACTOR (marker), x, y);
+        }
     }
 }
 
@@ -562,6 +788,94 @@ relocate_cb (G_GNUC_UNUSED GObject *gobject,
 }
 
 
+
+static void
+redraw_polygon (ChamplainLayer *layer)
+{
+  ChamplainLayerPrivate *priv = layer->priv;
+  ClutterActor *cairo_texture;
+  cairo_t *cr;
+  gfloat width, height;
+  int i, n_children;
+  ChamplainView *view = priv->view;
+  gdouble lon, lat;
+  gdouble x, y;
+  
+  clutter_actor_get_size (CLUTTER_ACTOR (view), &width, &height);
+
+  if (!priv->visible || width == 0.0 || height == 0.0)
+    return;
+
+  clutter_group_remove_all (CLUTTER_GROUP (priv->polygon_actor));
+  cairo_texture = clutter_cairo_texture_new (width, height);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->polygon_actor), cairo_texture);
+  
+  lon = champlain_view_x_to_longitude (view, 0);
+  lat = champlain_view_y_to_latitude (view, 0);
+  x = champlain_view_longitude_to_layer_x (view, lon);
+  y = champlain_view_latitude_to_layer_y (view, lat);
+  clutter_actor_set_position (priv->polygon_actor, x, y);
+
+  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (cairo_texture));
+
+  /* Clear the drawing area */
+  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
+
+  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+  n_children = clutter_group_get_n_children (CLUTTER_GROUP (layer));
+  for (i = 0; i < n_children; i++)
+    {
+      ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+      if (CHAMPLAIN_IS_BASE_MARKER (actor))
+        {    
+          ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
+          gfloat x, y;
+
+          x = champlain_view_longitude_to_x (view, champlain_base_marker_get_longitude (marker));
+          y = champlain_view_latitude_to_y (view, champlain_base_marker_get_latitude (marker));
+
+          cairo_line_to (cr, x, y);
+        }
+    }
+
+  if (priv->closed_path)
+    cairo_close_path (cr);
+
+  cairo_set_source_rgba (cr,
+      priv->fill_color->red / 255.0,
+      priv->fill_color->green / 255.0,
+      priv->fill_color->blue / 255.0,
+      priv->fill_color->alpha / 255.0);
+
+  if (priv->fill)
+    cairo_fill_preserve (cr);
+
+  cairo_set_source_rgba (cr,
+      priv->stroke_color->red / 255.0,
+      priv->stroke_color->green / 255.0,
+      priv->stroke_color->blue / 255.0,
+      priv->stroke_color->alpha / 255.0);
+
+  cairo_set_line_width (cr, priv->stroke_width);
+
+  if (priv->stroke)
+    cairo_stroke (cr);
+
+  cairo_destroy (cr);
+}
+
+
+static void
+redraw_polygon_cb (G_GNUC_UNUSED GObject *gobject,
+    G_GNUC_UNUSED GParamSpec *arg1,
+    ChamplainLayer *layer)
+{
+  redraw_polygon (layer);
+}
+
+
 void champlain_layer_set_view (ChamplainLayer *layer,
     ChamplainView *view)
 {
@@ -582,8 +896,12 @@ void champlain_layer_set_view (ChamplainLayer *layer,
   
       g_signal_connect (view, "layer-relocated",
         G_CALLBACK (relocate_cb), layer);
+
+      g_signal_connect (view, "notify::latitude",
+        G_CALLBACK (redraw_polygon_cb), layer);
         
-      relocate (layer);          
+      relocate (layer);
+      redraw_polygon (layer);
     }
 }
 
@@ -639,3 +957,253 @@ champlain_view_ensure_markers_visible (ChamplainView *view,
 }*/
 
 
+/**
+ * champlain_polygon_set_fill_color:
+ * @polygon: The polygon
+ * @color: (allow-none): The polygon's fill color or NULL to reset to the
+ *         default color. The color parameter is copied.
+ *
+ * Set the polygon's fill color.
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_set_polygon_fill_color (ChamplainLayer *layer,
+    const ClutterColor *color)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  ChamplainLayerPrivate *priv = layer->priv;
+
+  if (priv->fill_color != NULL)
+    clutter_color_free (priv->fill_color);
+
+  if (color == NULL)
+    color = &DEFAULT_FILL_COLOR;
+
+  priv->fill_color = clutter_color_copy (color);
+  g_object_notify (G_OBJECT (layer), "fill-color");
+}
+
+
+/**
+ * champlain_polygon_set_stroke_color:
+ * @polygon: The polygon
+ * @color: (allow-none): The polygon's stroke color or NULL to reset to the
+ *         default color. The color parameter is copied.
+ *
+ * Set the polygon's stroke color.
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_set_polygon_stroke_color (ChamplainLayer *layer,
+    const ClutterColor *color)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  ChamplainLayerPrivate *priv = layer->priv;
+
+  if (priv->stroke_color != NULL)
+    clutter_color_free (priv->stroke_color);
+
+  if (color == NULL)
+    color = &DEFAULT_STROKE_COLOR;
+
+  priv->stroke_color = clutter_color_copy (color);
+  g_object_notify (G_OBJECT (layer), "stroke-color");
+}
+
+
+/**
+ * champlain_polygon_get_fill_color:
+ * @polygon: The polygon
+ *
+ * Gets the polygon's fill color.
+ *
+ * Returns: the polygon's fill color.
+ *
+ * Since: 0.4
+ */
+ClutterColor *
+champlain_layer_get_polygon_fill_color (ChamplainLayer *layer)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LAYER (layer), NULL);
+
+  return layer->priv->fill_color;
+}
+
+
+/**
+ * champlain_polygon_get_stroke_color:
+ * @polygon: The polygon
+ *
+ * Gets the polygon's stroke color.
+ *
+ * Returns: the polygon's stroke color.
+ *
+ * Since: 0.4
+ */
+ClutterColor *
+champlain_layer_get_polygon_stroke_color (ChamplainLayer *layer)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LAYER (layer), NULL);
+
+  return layer->priv->stroke_color;
+}
+
+
+/**
+ * champlain_polygon_set_stroke:
+ * @polygon: The polygon
+ * @value: if the polygon is stroked
+ *
+ * Sets the polygon to have a stroke
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_set_polygon_stroke (ChamplainLayer *layer,
+    gboolean value)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  layer->priv->stroke = value;
+  g_object_notify (G_OBJECT (layer), "stroke");
+}
+
+
+/**
+ * champlain_polygon_get_stroke:
+ * @polygon: The polygon
+ *
+ * Checks whether the polygon has a stroke.
+ *
+ * Returns: TRUE if the polygon has a stroke, FALSE otherwise.
+ *
+ * Since: 0.4
+ */
+gboolean
+champlain_layer_get_polygon_stroke (ChamplainLayer *layer)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LAYER (layer), FALSE);
+
+  return layer->priv->stroke;
+}
+
+
+/**
+ * champlain_polygon_set_fill:
+ * @polygon: The polygon
+ * @value: if the polygon is filled
+ *
+ * Sets the polygon to have be filled
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_set_polygon_fill (ChamplainLayer *layer,
+    gboolean value)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  layer->priv->fill = value;
+  g_object_notify (G_OBJECT (layer), "fill");
+}
+
+
+/**
+ * champlain_polygon_get_fill:
+ * @polygon: The polygon
+ *
+ * Checks whether the polygon is filled.
+ *
+ * Returns: TRUE if the polygon is filled, FALSE otherwise.
+ *
+ * Since: 0.4
+ */
+gboolean
+champlain_layer_get_polygon_fill (ChamplainLayer *layer)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LAYER (layer), FALSE);
+
+  return layer->priv->fill;
+}
+
+
+/**
+ * champlain_polygon_set_stroke_width:
+ * @polygon: The polygon
+ * @value: the width of the stroke (in pixels)
+ *
+ * Sets the width of the stroke
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_set_polygon_stroke_width (ChamplainLayer *layer,
+    gdouble value)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  layer->priv->stroke_width = value;
+  g_object_notify (G_OBJECT (layer), "stroke-width");
+}
+
+
+/**
+ * champlain_polygon_get_stroke_width:
+ * @polygon: The polygon
+ *
+ * Gets the width of the stroke.
+ *
+ * Returns: the width of the stroke
+ *
+ * Since: 0.4
+ */
+gdouble
+champlain_layer_get_polygon_stroke_width (ChamplainLayer *layer)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LAYER (layer), 0);
+
+  return layer->priv->stroke_width;
+}
+
+
+/**
+ * champlain_polygon_show:
+ * @polygon: The polygon
+ *
+ * Makes the polygon visible
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_show_polygon (ChamplainLayer *layer)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  layer->priv->visible = TRUE;
+  clutter_actor_show (CLUTTER_ACTOR (layer->priv->polygon_actor));
+  g_object_notify (G_OBJECT (layer->priv->polygon_actor), "visible");
+}
+
+
+/**
+ * champlain_polygon_hide:
+ * @polygon: The polygon
+ *
+ * Hides the polygon
+ *
+ * Since: 0.4
+ */
+void
+champlain_layer_hide_polygon (ChamplainLayer *layer)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
+
+  layer->priv->visible = FALSE;
+  clutter_actor_hide (CLUTTER_ACTOR (layer->priv->polygon_actor));
+  g_object_notify (G_OBJECT (layer->priv->polygon_actor), "visible");
+}
+
diff --git a/champlain/champlain-layer.h b/champlain/champlain-layer.h
index 6e702a2..ca58fdd 100644
--- a/champlain/champlain-layer.h
+++ b/champlain/champlain-layer.h
@@ -113,6 +113,26 @@ ChamplainSelectionMode champlain_layer_get_selection_mode (
 //    ChamplainBaseMarker *markers[],
 //    gboolean animate);
 
+void champlain_layer_set_polygon_fill_color (ChamplainLayer *layer,
+    const ClutterColor *color);
+void champlain_layer_set_polygon_stroke_color (ChamplainLayer *layer,
+    const ClutterColor *color);
+ClutterColor *champlain_layer_get_polygon_fill_color (ChamplainLayer *layer);
+ClutterColor *champlain_layer_get_polygon_stroke_color (ChamplainLayer *layer);
+
+gboolean champlain_layer_get_polygon_fill (ChamplainLayer *layer);
+void champlain_layer_set_polygon_fill (ChamplainLayer *layer,
+    gboolean value);
+gboolean champlain_layer_get_polygon_stroke (ChamplainLayer *layer);
+void champlain_layer_set_polygon_stroke (ChamplainLayer *layer,
+    gboolean value);
+void champlain_layer_set_polygon_stroke_width (ChamplainLayer *layer,
+    gdouble value);
+gdouble champlain_layer_get_polygon_stroke_width (ChamplainLayer *layer);
+
+void champlain_layer_show_polygon (ChamplainLayer *layer);
+void champlain_layer_hide_polygon (ChamplainLayer *layer);
+
 G_END_DECLS
 
 #endif
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 275af73..f0172db 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -59,7 +59,6 @@
 #include "champlain-marshal.h"
 #include "champlain-map-source.h"
 #include "champlain-map-source-factory.h"
-#include "champlain-polygon.h"
 #include "champlain-private.h"
 #include "champlain-tile.h"
 
@@ -136,11 +135,6 @@ typedef struct
   gdouble from_longitude;
 } GoToContext;
 
-typedef struct
-{
-  ChamplainView *view;
-  ChamplainPolygon *polygon;
-} PolygonRedrawContext;
 
 typedef struct
 {
@@ -198,12 +192,6 @@ struct _ChamplainViewPrivate
   /* champlain_view_go_to's context, kept for stop_go_to */
   GoToContext *goto_context;
 
-  /* notify_polygon_cb's context, kept for idle cb */
-  guint polygon_redraw_id;
-
-  /* Lines and shapes */
-  ClutterActor *polygon_layer;  /* Contains the polygons */
-
   gint tiles_loading;
 };
 
@@ -245,7 +233,6 @@ static gboolean view_set_zoom_level_at (ChamplainView *view,
 static void tile_state_notify (ChamplainTile *tile,
     G_GNUC_UNUSED GParamSpec *pspec,
     ChamplainView *view);
-static void view_update_polygons (ChamplainView *view);
 static gboolean finger_scroll_key_press_cb (ClutterActor *actor,
     ClutterKeyEvent *event,
     ChamplainView *view);
@@ -297,7 +284,6 @@ update_viewport (ChamplainView *view,
       y);
 
   view_load_visible_tiles (view);
-  view_update_polygons (view);
   update_scale (view);
 
   g_object_notify (G_OBJECT (view), "longitude");
@@ -344,47 +330,6 @@ scroll_event (G_GNUC_UNUSED ClutterActor *actor,
 }
 
 
-static gboolean
-redraw_polygon_on_idle (PolygonRedrawContext *ctx)
-{
-  DEBUG_LOG ()
-
-  ChamplainViewPrivate *priv = ctx->view->priv;
-
-  if (ctx->polygon)
-    champlain_polygon_draw_polygon (ctx->polygon, ctx->view);
-
-  priv->polygon_redraw_id = 0;
-
-  g_object_unref (ctx->view);
-  g_object_unref (ctx->polygon);
-  /* ctx is freed by g_idle_add_full */
-  return FALSE;
-}
-
-
-static void
-notify_polygon_cb (ChamplainPolygon *polygon,
-    G_GNUC_UNUSED GParamSpec *arg1,
-    ChamplainView *view)
-{
-  DEBUG_LOG ()
-
-  ChamplainViewPrivate *priv = view->priv;
-  PolygonRedrawContext *ctx;
-
-  if (priv->polygon_redraw_id != 0)
-    return;
-
-  ctx = g_new0 (PolygonRedrawContext, 1);
-  ctx->view = g_object_ref (view);
-  ctx->polygon = g_object_ref (polygon);
-
-  priv->polygon_redraw_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
-        (GSourceFunc) redraw_polygon_on_idle, ctx, g_free);
-}
-
-
 static void
 resize_viewport (ChamplainView *view)
 {
@@ -665,12 +610,6 @@ champlain_view_dispose (GObject *object)
       priv->user_layers = NULL;
     }
 
-  if (priv->polygon_layer != NULL)
-    {
-      g_object_unref (CLUTTER_ACTOR (priv->polygon_layer));
-      priv->polygon_layer = NULL;
-    }
-
   if (priv->goto_context != NULL)
     champlain_view_stop_go_to (view);
 
@@ -1367,7 +1306,6 @@ champlain_view_init (ChamplainView *view)
   priv->latitude = 0.0f;
   priv->longitude = 0.0f;
   priv->goto_context = NULL;
-  priv->polygon_redraw_id = 0;
   priv->show_scale = FALSE;
   priv->scale_unit = CHAMPLAIN_UNIT_KM;
   priv->max_scale_width = 100;
@@ -1378,10 +1316,6 @@ champlain_view_init (ChamplainView *view)
   priv->map_layer = g_object_ref (clutter_group_new ());
   clutter_actor_show (priv->map_layer);
 
-  /* Setup polygon layer */
-  priv->polygon_layer = g_object_ref (clutter_group_new ());
-  clutter_actor_show (priv->polygon_layer);
-
   /* Setup user_layers */
   priv->user_layers = g_object_ref (clutter_group_new ());
   clutter_actor_show (priv->user_layers);
@@ -1391,8 +1325,6 @@ champlain_view_init (ChamplainView *view)
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport_container),
       priv->map_layer);
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport_container),
-      priv->polygon_layer);
-  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport_container),
       priv->user_layers);
 
   clutter_actor_show (priv->viewport_container);
@@ -1408,7 +1340,6 @@ champlain_view_init (ChamplainView *view)
   g_signal_connect (priv->viewport, "notify::y-origin",
       G_CALLBACK (viewport_pos_changed_cb), view);
 
-  clutter_actor_raise (priv->polygon_layer, priv->map_layer);
   clutter_actor_raise (priv->user_layers, priv->map_layer);
 
   /* Setup finger scroll */
@@ -3240,85 +3171,3 @@ champlain_view_get_zoom_on_double_click (ChamplainView *view)
 
   return view->priv->zoom_on_double_click;
 }
-
-
-static void
-view_update_polygons (ChamplainView *view)
-{
-  DEBUG_LOG ()
-
-  ChamplainViewPrivate *priv = view->priv;
-  ClutterGroup *polygon_layer_group = CLUTTER_GROUP (priv->polygon_layer);
-  guint polygon_num, i;
-  gfloat x, y;
-
-  polygon_num = clutter_group_get_n_children (polygon_layer_group);
-
-  if (polygon_num == 0)
-    return;
-
-  for (i = 0; i < polygon_num; i++)
-    {
-      ChamplainPolygon *polygon = CHAMPLAIN_POLYGON (clutter_group_get_nth_child (polygon_layer_group, i));
-
-      champlain_polygon_draw_polygon (polygon, view);
-    }
-
-  /* Position the layer in the viewport */
-  x = priv->viewport_size.x;
-  y = priv->viewport_size.y;
-
-  clutter_actor_set_position (priv->polygon_layer, x, y);
-}
-
-
-/**
- * champlain_view_add_polygon:
- * @view: a #ChamplainView
- * @polygon: a #ChamplainPolygon
- *
- * Adds a #ChamplainPolygon to the #ChamplainView
- *
- * Since: 0.4
- */
-void
-champlain_view_add_polygon (ChamplainView *view,
-    ChamplainPolygon *polygon)
-{
-  DEBUG_LOG ()
-
-  g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
-  g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
-
-  ChamplainViewPrivate *priv = view->priv;
-
-  g_signal_connect (polygon, "notify",
-      G_CALLBACK (notify_polygon_cb), view);
-
-  clutter_actor_set_position (CLUTTER_ACTOR (polygon), 0, 0);
-  clutter_container_add_actor (CLUTTER_CONTAINER (priv->polygon_layer),
-      CLUTTER_ACTOR (polygon));
-}
-
-
-/**
- * champlain_view_remove_polygon:
- * @view: a #ChamplainView
- * @polygon: a #ChamplainPolygon
- *
- * Removes a #ChamplainPolygon from #ChamplainView
- *
- * Since: 0.4
- */
-void
-champlain_view_remove_polygon (ChamplainView *view,
-    ChamplainPolygon *polygon)
-{
-  DEBUG_LOG ()
-
-  g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
-  g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
-
-  clutter_container_remove_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
-      CLUTTER_ACTOR (polygon));
-}
diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h
index d6fd729..9baf324 100644
--- a/champlain/champlain-view.h
+++ b/champlain/champlain-view.h
@@ -27,7 +27,6 @@
 #include <champlain/champlain-defines.h>
 #include <champlain/champlain-base-marker.h>
 #include <champlain/champlain-layer.h>
-#include <champlain/champlain-polygon.h>
 #include <champlain/champlain-map-source.h>
 
 #include <glib.h>
@@ -168,11 +167,6 @@ guint champlain_view_get_max_scale_width (ChamplainView *view);
 ChamplainUnit champlain_view_get_scale_unit (ChamplainView *view);
 gboolean champlain_view_get_zoom_on_double_click (ChamplainView *view);
 
-void champlain_view_add_polygon (ChamplainView *view,
-    ChamplainPolygon *polygon);
-void champlain_view_remove_polygon (ChamplainView *view,
-    ChamplainPolygon *polygon);
-
 void champlain_view_reload_tiles (ChamplainView *view);
 
 
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c
index 897e148..8a2aba7 100644
--- a/demos/launcher-gtk.c
+++ b/demos/launcher-gtk.c
@@ -28,7 +28,7 @@
 #define COL_ID 0
 #define COL_NAME 1
 
-static ChamplainPolygon *polygon;
+//static ChamplainPolygon *polygon;
 static gboolean destroying = FALSE;
 
 /*
@@ -48,12 +48,12 @@ toggle_layer (GtkToggleButton *widget,
 {
   if (gtk_toggle_button_get_active (widget))
     {
-      champlain_polygon_show (polygon);
+//      champlain_polygon_show (polygon);
       champlain_layer_animate_in_all_markers (CHAMPLAIN_LAYER (layer));
     }
   else
     {
-      champlain_polygon_hide (polygon);
+//      champlain_polygon_hide (polygon);
       champlain_layer_animate_out_all_markers (CHAMPLAIN_LAYER (layer));
     }
 }
@@ -246,9 +246,9 @@ main (int argc,
   champlain_view_add_layer (view, layer);
   champlain_layer_hide_all_markers (CHAMPLAIN_LAYER (layer));
 
-  polygon = champlain_polygon_new ();
+//  polygon = champlain_polygon_new ();
   /* Cheap approx of Highway 10 */
-  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
+/*  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
   champlain_polygon_append_point (polygon, 45.4104, -73.2846);
   champlain_polygon_append_point (polygon, 45.4178, -73.2239);
   champlain_polygon_append_point (polygon, 45.4176, -73.2181);
@@ -263,7 +263,7 @@ main (int argc,
       NULL);
   champlain_view_add_polygon (CHAMPLAIN_VIEW (view), polygon);
   champlain_polygon_hide (polygon);
-
+*/
   gtk_widget_set_size_request (widget, 640, 480);
 
   bbox = gtk_hbox_new (FALSE, 10);
diff --git a/demos/markers.c b/demos/markers.c
index 00bd1c1..53527fd 100644
--- a/demos/markers.c
+++ b/demos/markers.c
@@ -48,7 +48,7 @@ create_marker_layer (G_GNUC_UNUSED ChamplainView *view)
   ClutterActor *layer_actor;
   ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
 
-  layer = champlain_layer_new_full (CHAMPLAIN_SELECTION_SINGLE);
+  layer = champlain_layer_new_full (CHAMPLAIN_SELECTION_MULTIPLE);
   layer_actor = CLUTTER_ACTOR (layer);
 
   marker = champlain_marker_new_with_text ("Montréal\n<span size=\"xx-small\">Québec</span>",
diff --git a/demos/polygons.c b/demos/polygons.c
index 5d07bb3..fa5e638 100644
--- a/demos/polygons.c
+++ b/demos/polygons.c
@@ -71,7 +71,7 @@ main (int argc,
     char *argv[])
 {
   ClutterActor *actor, *stage, *buttons, *button;
-  ChamplainPolygon *polygon;
+//  ChamplainPolygon *polygon;
   gfloat width, total_width = 0;;
 
   g_thread_init (NULL);
@@ -110,9 +110,9 @@ main (int argc,
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), buttons);
 
   /* draw a line */
-  polygon = champlain_polygon_new ();
+//  polygon = champlain_polygon_new ();
   /* Cheap approx of Highway 10 */
-  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
+/*  champlain_polygon_append_point (polygon, 45.4095, -73.3197);
   champlain_polygon_append_point (polygon, 45.4104, -73.2846);
   champlain_polygon_append_point (polygon, 45.4178, -73.2239);
   champlain_polygon_append_point (polygon, 45.4176, -73.2181);
@@ -123,9 +123,9 @@ main (int argc,
   champlain_polygon_append_point (polygon, 45.4151, -73.1218);
   champlain_polygon_set_stroke_width (polygon, 5.0);
   champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
-
+*/
   /* draw a polygon */
-  polygon = champlain_polygon_new ();
+/*  polygon = champlain_polygon_new ();
   champlain_polygon_append_point (polygon, 45.1386, -73.9196);
   champlain_polygon_append_point (polygon, 45.1229, -73.8991);
   champlain_polygon_append_point (polygon, 45.0946, -73.9531);
@@ -134,7 +134,7 @@ main (int argc,
   g_object_set (polygon, "closed-path", TRUE, NULL);
   g_object_set (polygon, "fill", TRUE, NULL);
   champlain_view_add_polygon (CHAMPLAIN_VIEW (actor), polygon);
-
+*/
   /* Finish initialising the map view */
   g_object_set (G_OBJECT (actor), "zoom-level", 8,
       "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]