[cairo-commit] goocanvas/src goocanvasitemsimple.c,1.36,1.37

Damon Chaplin commit at pdx.freedesktop.org
Sun Mar 23 16:30:07 PDT 2008


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv31360/src

Modified Files:
	goocanvasitemsimple.c 
Log Message:
2008-03-23  Damon Chaplin  <damon at gnome.org>

	    * src/goocanvasitemsimple.c: made "stroke-color-rgba" and
	    "fill-color-rgba" properties read/write.

	    * configure.in (pkg_modules): depend on cairo >= 1.4.0 for
	    cairo_pattern_get_rgba().

	    * demo/demo.c (test_color_properties): added some test code.



Index: goocanvasitemsimple.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemsimple.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- goocanvasitemsimple.c	25 Feb 2008 15:34:59 -0000	1.36
+++ goocanvasitemsimple.c	23 Mar 2008 23:33:41 -0000	1.37
@@ -22,7 +22,7 @@
  * method. (#GooCanvasEllipse, #GooCanvasRect and #GooCanvasPath do this.)
  *
  * More complicated items need to implement the update(), paint() and
- * is_item_at() methods. (#GooCanvasImage, #GooCanvasPolyline,
+ * is_item_at() methods instead. (#GooCanvasImage, #GooCanvasPolyline,
  * #GooCanvasText and #GooCanvasWidget do this.) They may also need to
  * override some of the other GooCanvasItem methods such as set_canvas(),
  * set_parent() or allocate_area() if special code is needed. (#GooCanvasWidget
@@ -232,7 +232,7 @@
 						      _("Stroke Color RGBA"),
 						      _("The color to use for the item's perimeter, specified as a 32-bit integer value. To disable painting set the 'stroke-pattern' property to NULL"),
 						      0, G_MAXUINT, 0,
-						      G_PARAM_WRITABLE));
+						      G_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class, PROP_STROKE_PIXBUF,
                                    g_param_spec_object ("stroke-pixbuf",
@@ -253,7 +253,7 @@
 						      _("Fill Color RGBA"),
 						      _("The color to use to paint the interior of the item, specified as a 32-bit integer value. To disable painting set the 'fill-pattern' property to NULL"),
 						      0, G_MAXUINT, 0,
-						      G_PARAM_WRITABLE));
+						      G_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class, PROP_FILL_PIXBUF,
                                    g_param_spec_object ("fill-pixbuf",
@@ -432,6 +432,27 @@
 }
 
 
+static guint
+convert_color (double red, double green, double blue, double alpha)
+{
+  guint red_byte, green_byte, blue_byte, alpha_byte;
+
+  red_byte = red * 256;
+  red_byte -= red_byte >> 8;
+
+  green_byte = green * 256;
+  green_byte -= green_byte >> 8;
+
+  blue_byte = blue * 256;
+  blue_byte -= blue_byte >> 8;
+
+  alpha_byte = alpha * 256;
+  alpha_byte -= alpha_byte >> 8;
+
+  return (red_byte << 24) + (green_byte << 16) + (blue_byte << 8) + alpha_byte;
+}
+
+
 static void
 goo_canvas_item_simple_get_common_property (GObject                 *object,
 					    GooCanvasItemSimpleData *simple_data,
@@ -444,6 +465,9 @@
   GValue *svalue;
   gdouble line_width = 2.0;
   gchar *font = NULL;
+  cairo_pattern_t *pattern;
+  double red, green, blue, alpha;
+  guint rgba = 0;
 
   switch (prop_id)
     {
@@ -512,6 +536,34 @@
       g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_HINT_METRICS_OFF);
       break;
 
+      /* Convenience properties. */
+    case PROP_STROKE_COLOR_RGBA:
+      svalue = goo_canvas_style_get_property (style, goo_canvas_style_stroke_pattern_id);
+      if (svalue && svalue->data[0].v_pointer)
+	{
+	  pattern = svalue->data[0].v_pointer;
+	  if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SOLID)
+	    {
+	      cairo_pattern_get_rgba (pattern, &red, &green, &blue, &alpha);
+	      rgba = convert_color (red, green, blue, alpha);
+	    }
+	}
+      g_value_set_uint (value, rgba);
+      break;
+    case PROP_FILL_COLOR_RGBA:
+      svalue = goo_canvas_style_get_property (style, goo_canvas_style_fill_pattern_id);
+      if (svalue && svalue->data[0].v_pointer)
+	{
+	  pattern = svalue->data[0].v_pointer;
+	  if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SOLID)
+	    {
+	      cairo_pattern_get_rgba (pattern, &red, &green, &blue, &alpha);
+	      rgba = convert_color (red, green, blue, alpha);
+	    }
+	}
+      g_value_set_uint (value, rgba);
+      break;
+
       /* Other properties. */
     case PROP_TRANSFORM:
       g_value_set_boxed (value, simple_data->transform);



More information about the cairo-commit mailing list