]> err.no Git - libchamplain/commitdiff
Implement shape filling and stroking
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Mon, 25 May 2009 04:22:40 +0000 (00:22 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 00:27:35 +0000 (20:27 -0400)
champlain/champlain-line.c
champlain/champlain-private.h
champlain/champlain-view.c
demos/lines.c

index e432dc3e529b0e33c58c95aed9a753ae8c06185f..8612fe9b31d265816bd10e9637ca34530ea0b4a1 100644 (file)
@@ -44,7 +44,13 @@ G_DEFINE_TYPE (ChamplainLine, champlain_line, G_TYPE_OBJECT)
 
 enum
 {
-  PROP_0
+  PROP_0,
+  PROP_CLOSED_PATH,
+  PROP_LINE_WIDTH,
+  PROP_LINE_COLOR,
+  PROP_FILL,
+  PROP_FILL_COLOR,
+  PROP_STROKE,
 };
 
 static void
@@ -53,9 +59,25 @@ champlain_line_get_property (GObject *object,
     GValue *value,
     GParamSpec *pspec)
 {
-  //ChamplainLine *self = CHAMPLAIN_LINE (object);
+  ChamplainLinePrivate *priv = GET_PRIVATE (object);
+
   switch (property_id)
     {
+      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_LINE_COLOR:
+        clutter_value_set_color (value, priv->line_color);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -67,9 +89,27 @@ champlain_line_set_property (GObject *object,
     const GValue *value,
     GParamSpec *pspec)
 {
-  //ChamplainLine *self = CHAMPLAIN_LINE (object);
+  ChamplainLinePrivate *priv = GET_PRIVATE (object);
+
   switch (property_id)
     {
+      case PROP_CLOSED_PATH:
+        priv->closed_path = g_value_get_boolean (value);
+        break;
+      case PROP_FILL:
+        priv->fill = g_value_get_boolean (value);
+        break;
+      case PROP_STROKE:
+        priv->stroke = g_value_get_boolean (value);
+        break;
+      case PROP_FILL_COLOR:
+        clutter_color_free (priv->fill_color);
+        priv->fill_color = clutter_color_copy (clutter_value_get_color (value));
+        break;
+      case PROP_LINE_COLOR:
+        clutter_color_free (priv->line_color);
+        priv->line_color = clutter_color_copy (clutter_value_get_color (value));
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -100,6 +140,48 @@ champlain_line_class_init (ChamplainLineClass *klass)
   object_class->set_property = champlain_line_set_property;
   object_class->dispose = champlain_line_dispose;
   object_class->finalize = champlain_line_finalize;
+
+  /**
+  * ChamplainLine: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));
+
+  /**
+  * ChamplainLine: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));
+
+  /**
+  * ChamplainLine: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",
+         FALSE, CHAMPLAIN_PARAM_READWRITE));
 }
 
 static void
@@ -108,6 +190,8 @@ champlain_line_init (ChamplainLine *self)
   self->priv = GET_PRIVATE (self);
 
   self->priv->points = NULL;
+  self->priv->fill = FALSE;
+  self->priv->stroke = TRUE;
 }
 
 /**
index e837afaf38f1144132444a91b4ad5479e7b19fc9..a1c107005251ec650b89a3fb83acff8c72737b19 100644 (file)
@@ -20,7 +20,7 @@
 #define CHAMPLAIN_PRIVATE_H
 
 #include <glib.h>
-
+#include <clutter/clutter.h>
 
 typedef struct _Map Map;
 
@@ -39,6 +39,11 @@ struct _ChamplainBaseMarkerPrivate
 
 struct _ChamplainLinePrivate {
   GList *points;
+  gboolean closed_path;
+  ClutterColor *line_color;
+  gboolean fill;
+  ClutterColor *fill_color;
+  gboolean stroke;
 };
 
 typedef struct
index 0cad84a4f7fafd5037b08499e319a618dac8685e..8172be42cacf2954800dd4c5f688b2bb58b6f9ff 100644 (file)
@@ -2200,7 +2200,15 @@ draw_line (ChamplainView *view, cairo_t *cr, ChamplainLine *line)
       cairo_line_to (cr, x, y);
       list = list->next;
     }
-  cairo_stroke (cr);
+
+  if (line->priv->closed_path)
+    cairo_close_path (cr);
+
+  if (line->priv->fill)
+    cairo_fill_preserve (cr);
+
+  if (line->priv->stroke)
+    cairo_stroke (cr);
 }
 
 static void
index e566c7b6bf8a3b237226aeb118aa02ec4c0aec9f..eacca131ee13e0a89210602b23f7ec63e025daac 100644 (file)
@@ -116,7 +116,10 @@ main (int argc,
   line = champlain_line_new ();
   champlain_line_add_point (line, 44, -75);
   champlain_line_add_point (line, 45, -74);
+  champlain_line_add_point (line, 46, -74);
   champlain_view_add_line (CHAMPLAIN_VIEW (actor), line);
+  g_object_set (line, "closed-path", TRUE, NULL);
+  g_object_set (line, "fill", TRUE, NULL);
 
   /* Finish initialising the map view */
   g_object_set (G_OBJECT (actor), "zoom-level", 12,