]> err.no Git - libchamplain/commitdiff
Add default stroke and fill colors
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Mon, 25 May 2009 23:22:03 +0000 (19: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-line.h
champlain/champlain-private.h
champlain/champlain-view.c

index 8612fe9b31d265816bd10e9637ca34530ea0b4a1..2ac1c4d26c09cf1fa22e6aa65a15f25f09f095f9 100644 (file)
 
 /**
  * SECTION:champlain-line
- * @short_description: A container for #ChamplainMarker
+ * @short_description: A container for #ChamplainLine
  *
  * A ChamplainLine is little more than a #ClutterContainer. It keeps the
- * markers ordered so that they display correctly.
+ * lines ordered so that they display correctly.
  *
- * Use #clutter_container_add to add markers to the line and
+ * Use #clutter_container_add to add lines to the line and
  * #clutter_container_remove to remove them.
  */
 
@@ -37,6 +37,9 @@
 #include <clutter/clutter.h>
 #include <glib.h>
 
+static ClutterColor DEFAULT_FILL_COLOR = {0xcc, 0x00, 0x00, 0xaa};
+static ClutterColor DEFAULT_STROKE_COLOR = {0xa4, 0x00, 0x00, 0xff};
+
 G_DEFINE_TYPE (ChamplainLine, champlain_line, G_TYPE_OBJECT)
 
 #define GET_PRIVATE(o) \
@@ -46,8 +49,8 @@ enum
 {
   PROP_0,
   PROP_CLOSED_PATH,
-  PROP_LINE_WIDTH,
-  PROP_LINE_COLOR,
+  PROP_STROKE_WIDTH,
+  PROP_STROKE_COLOR,
   PROP_FILL,
   PROP_FILL_COLOR,
   PROP_STROKE,
@@ -75,8 +78,8 @@ champlain_line_get_property (GObject *object,
       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);
+      case PROP_STROKE_COLOR:
+        clutter_value_set_color (value, priv->stroke_color);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -103,12 +106,10 @@ champlain_line_set_property (GObject *object,
         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));
+        champlain_line_set_fill_color (CHAMPLAIN_LINE (object), 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));
+      case PROP_STROKE_COLOR:
+        champlain_line_set_stroke_color (CHAMPLAIN_LINE (object), clutter_value_get_color (value));
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -181,7 +182,7 @@ champlain_line_class_init (ChamplainLineClass *klass)
       g_param_spec_boolean ("stroke",
          "Stroke",
          "The shape is stroked",
-         FALSE, CHAMPLAIN_PARAM_READWRITE));
+         TRUE, CHAMPLAIN_PARAM_READWRITE));
 }
 
 static void
@@ -192,6 +193,9 @@ champlain_line_init (ChamplainLine *self)
   self->priv->points = NULL;
   self->priv->fill = FALSE;
   self->priv->stroke = TRUE;
+
+  self->priv->fill_color = clutter_color_copy (&DEFAULT_FILL_COLOR);
+  self->priv->stroke_color = clutter_color_copy (&DEFAULT_STROKE_COLOR);
 }
 
 /**
@@ -235,3 +239,90 @@ champlain_line_clear_points (ChamplainLine *self)
   g_list_free (self->priv->points);
 }
 
+/**
+ * champlain_line_set_fill_color:
+ * @line: The line
+ * @color: The line's fill color or NULL to reset to the
+ *         default color. The color parameter is copied.
+ *
+ * Set the line's fill color.
+ *
+ * Since: 0.4
+ */
+void
+champlain_line_set_fill_color (ChamplainLine *line,
+    const ClutterColor *color)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LINE (line));
+
+  ChamplainLinePrivate *priv = line->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 (line), "fill-color");
+}
+
+/**
+ * champlain_line_set_stoke_color:
+ * @line: The line
+ * @color: The line's stroke color or NULL to reset to the
+ *         default color. The color parameter is copied.
+ *
+ * Set the line's stroke color.
+ *
+ * Since: 0.4
+ */
+void
+champlain_line_set_stroke_color (ChamplainLine *line,
+    const ClutterColor *color)
+{
+  g_return_if_fail (CHAMPLAIN_IS_LINE (line));
+
+  ChamplainLinePrivate *priv = line->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 (line), "stroke-color");
+}
+
+/**
+ * champlain_line_get_color:
+ * @line: The line
+ *
+ * Returns the line's fill color.
+ *
+ * Since: 0.4
+ */
+ClutterColor *
+champlain_line_get_fill_color (ChamplainLine *line)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LINE (line), NULL);
+
+  return line->priv->fill_color;
+}
+
+/**
+ * champlain_line_get_stroke_color:
+ * @line: The line
+ *
+ * Returns the line's stroke color.
+ *
+ * Since: 0.4
+ */
+ClutterColor *
+champlain_line_get_stroke_color (ChamplainLine *line)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_LINE (line), NULL);
+
+  return line->priv->stroke_color;
+}
index a2879eac4af9ce1dd1ab868d4202b1e2d0622c30..081073e2a7a7280dbebd9347c8749ba5dff9dc1d 100644 (file)
@@ -26,6 +26,7 @@
 #include <champlain/champlain-defines.h>
 
 #include <glib-object.h>
+#include <clutter/clutter.h>
 
 G_BEGIN_DECLS
 
@@ -66,6 +67,12 @@ void champlain_line_add_point (ChamplainLine *line,
     gdouble lon);
 
 void champlain_line_clear_points (ChamplainLine *line);
+void champlain_line_set_fill_color (ChamplainLine *line,
+    const ClutterColor *color);
+void champlain_line_set_stroke_color (ChamplainLine *line,
+    const ClutterColor *color);
+ClutterColor * champlain_line_get_fill_color (ChamplainLine *line);
+ClutterColor * champlain_line_get_stroke_color (ChamplainLine *line);
 
 G_END_DECLS
 
index a1c107005251ec650b89a3fb83acff8c72737b19..2576d0285f802678e407af4fc7840e42dca39dff 100644 (file)
@@ -40,7 +40,7 @@ struct _ChamplainBaseMarkerPrivate
 struct _ChamplainLinePrivate {
   GList *points;
   gboolean closed_path;
-  ClutterColor *line_color;
+  ClutterColor *stroke_color;
   gboolean fill;
   ClutterColor *fill_color;
   gboolean stroke;
index 8172be42cacf2954800dd4c5f688b2bb58b6f9ff..eae2cc701ab8029ccde325ebd34a8388e3740776 100644 (file)
@@ -2204,9 +2204,21 @@ draw_line (ChamplainView *view, cairo_t *cr, ChamplainLine *line)
   if (line->priv->closed_path)
     cairo_close_path (cr);
 
+  cairo_set_source_rgba (cr,
+      line->priv->fill_color->red / 255.0,
+      line->priv->fill_color->green / 255.0,
+      line->priv->fill_color->blue / 255.0,
+      line->priv->fill_color->alpha / 255.0);
+
   if (line->priv->fill)
     cairo_fill_preserve (cr);
 
+  cairo_set_source_rgba (cr,
+      line->priv->stroke_color->red / 255.0,
+      line->priv->stroke_color->green / 255.0,
+      line->priv->stroke_color->blue / 255.0,
+      line->priv->stroke_color->alpha / 255.0);
+
   if (line->priv->stroke)
     cairo_stroke (cr);
 }