[cairo-commit] goocanvas/src goocanvasimage.c, 1.8, 1.9 goocanvasitemsimple.c, 1.15, 1.16 goocanvasitemsimple.h, 1.11, 1.12 goocanvaspolyline.c, 1.7, 1.8 goocanvastext.c, 1.7, 1.8

Damon Chaplin commit at pdx.freedesktop.org
Thu Nov 30 06:35:09 PST 2006


Committed by: damon

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

Modified Files:
	goocanvasimage.c goocanvasitemsimple.c goocanvasitemsimple.h 
	goocanvaspolyline.c goocanvastext.c 
Log Message:
2006-11-30  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasitemsimple.h (struct _GooCanvasItemSimpleClass): added
	new update/paint/get_item_at methods that subclasses can override.
	If items use these methods GooCanvasItemSimple will perform all the
	standard stuff before passing control to them. This makes it much
	easier to create simple canvas items.

	* demo/demo-item.c: 
	* src/goocanvaspolyline.c: 
	* src/goocanvastext.c: 
	* src/goocanvasimage.c: use the above methods, so we can get rid of
	all the boilerplate code.



Index: goocanvasimage.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasimage.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- goocanvasimage.c	29 Nov 2006 18:40:53 -0000	1.8
+++ goocanvasimage.c	30 Nov 2006 14:35:05 -0000	1.9
@@ -117,20 +117,6 @@
 
 
 static void
-goo_canvas_image_class_init (GooCanvasImageClass *klass)
-{
-  GObjectClass *gobject_class = (GObjectClass*) klass;
-
-  gobject_class->finalize = goo_canvas_image_finalize;
-
-  gobject_class->get_property = goo_canvas_image_get_property;
-  gobject_class->set_property = goo_canvas_image_set_property;
-
-  goo_canvas_image_install_common_properties (gobject_class);
-}
-
-
-static void
 goo_canvas_image_init (GooCanvasImage *image)
 {
   image->image_data = g_slice_new0 (GooCanvasImageData);
@@ -330,105 +316,45 @@
 
 
 static GooCanvasItem*
-goo_canvas_image_get_item_at (GooCanvasItem  *item,
-			      gdouble         x,
-			      gdouble         y,
-			      cairo_t        *cr,
-			      gboolean        is_pointer_event,
-			      gboolean        parent_visible)
+goo_canvas_image_get_item_at (GooCanvasItemSimple *simple,
+			      gdouble              x,
+			      gdouble              y,
+			      cairo_t             *cr,
+			      gboolean             is_pointer_event)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
   GooCanvasImage *image = (GooCanvasImage*) simple;
   GooCanvasImageData *image_data = image->image_data;
-  GooCanvasItem *found_item = item;
-  double user_x = x, user_y = y;
-
-  if (simple->need_update)
-    goo_canvas_item_ensure_updated (item);
-
-  /* Check if the item should receive events. Note that we don't take
-     image transparency into account here at present. */
-  if (is_pointer_event)
-    {
-      if (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE)
-	return NULL;
-      if (simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK
-	  && (!parent_visible
-	      || simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-	      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-		  && simple->canvas->scale < simple_data->visibility_threshold)))
-	return NULL;
-    }
-
-  cairo_save (cr);
-
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
-  cairo_device_to_user (cr, &user_x, &user_y);
-
-  if (user_x < image_data->x || (user_x > image_data->x + image_data->width)
-      || user_y < image_data->y || (user_y > image_data->y + image_data->height))
-    found_item = NULL;
 
-  cairo_restore (cr);
+  if (x < image_data->x || (x > image_data->x + image_data->width)
+      || y < image_data->y || (y > image_data->y + image_data->height))
+    return NULL;
 
-  return found_item;
+  return (GooCanvasItem*) simple;
 }
 
 
 static void
-goo_canvas_image_update  (GooCanvasItem      *item,
-			  gboolean            entire_tree,
-			  cairo_t            *cr,
-			  GooCanvasBounds    *bounds)
+goo_canvas_image_update  (GooCanvasItemSimple  *simple,
+			  cairo_t              *cr)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasImage *image = (GooCanvasImage*) item;
+  GooCanvasImage *image = (GooCanvasImage*) simple;
   GooCanvasImageData *image_data = image->image_data;
 
-  if (entire_tree || simple->need_update)
-    {
-      simple->need_update = FALSE;
-
-      goo_canvas_item_simple_check_style (simple);
-
-      cairo_save (cr);
-      if (simple_data->transform)
-	cairo_transform (cr, simple_data->transform);
-
-      /* Request a redraw of the existing bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      /* Compute the new bounds. */
-      simple->bounds.x1 = image_data->x;
-      simple->bounds.y1 = image_data->y;
-      simple->bounds.x2 = image_data->x + image_data->width;
-      simple->bounds.y2 = image_data->y + image_data->height;
-
-      goo_canvas_item_simple_user_bounds_to_device (simple, cr,
-						    &simple->bounds);
-
-      /* Request a redraw of the new bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      cairo_restore (cr);
-    }
+  /* Compute the new bounds. */
+  simple->bounds.x1 = image_data->x;
+  simple->bounds.y1 = image_data->y;
+  simple->bounds.x2 = image_data->x + image_data->width;
+  simple->bounds.y2 = image_data->y + image_data->height;
 
-  *bounds = simple->bounds;
+  goo_canvas_item_simple_user_bounds_to_device (simple, cr, &simple->bounds);
 }
 
 
 static void
-goo_canvas_image_paint (GooCanvasItem     *item,
-			cairo_t           *cr,
-			GooCanvasBounds   *bounds,
-			gdouble            scale)
+goo_canvas_image_paint (GooCanvasItemSimple *simple,
+			cairo_t             *cr,
+			GooCanvasBounds     *bounds)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
   GooCanvasImage *image = (GooCanvasImage*) simple;
   GooCanvasImageData *image_data = image->image_data;
   cairo_matrix_t matrix;
@@ -436,17 +362,7 @@
   if (!image_data->pattern)
     return;
 
-  /* Check if the item should be visible. */
-  if (simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-	  && scale < simple_data->visibility_threshold))
-    return;
-
-  cairo_save (cr);
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
-  goo_canvas_style_set_fill_options (simple_data->style, cr);
+  goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
   cairo_set_source (cr, image_data->pattern);
   cairo_matrix_init_translate (&matrix, -image_data->x, -image_data->y);
   cairo_pattern_set_matrix (image_data->pattern, &matrix);
@@ -456,8 +372,6 @@
 
   /* Using cairo_paint() is much slower, so I guess we shouldn't. */
   /*cairo_paint (cr);*/
-
-  cairo_restore (cr);
 }
 
 
@@ -489,13 +403,29 @@
 static void
 canvas_item_interface_init (GooCanvasItemIface *iface)
 {
-  iface->get_item_at = goo_canvas_image_get_item_at;
-  iface->update      = goo_canvas_image_update;
-  iface->paint       = goo_canvas_image_paint;
   iface->set_model   = goo_canvas_image_set_model;
 }
 
 
+static void
+goo_canvas_image_class_init (GooCanvasImageClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass*) klass;
+  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
+
+  gobject_class->finalize = goo_canvas_image_finalize;
+
+  gobject_class->get_property = goo_canvas_image_get_property;
+  gobject_class->set_property = goo_canvas_image_set_property;
+
+  simple_class->update        = goo_canvas_image_update;
+  simple_class->paint         = goo_canvas_image_paint;
+  simple_class->get_item_at   = goo_canvas_image_get_item_at;
+
+  goo_canvas_image_install_common_properties (gobject_class);
+}
+
+
 
 /*
  * GooCanvasImageModel.

Index: goocanvasitemsimple.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemsimple.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- goocanvasitemsimple.c	29 Nov 2006 18:40:53 -0000	1.15
+++ goocanvasitemsimple.c	30 Nov 2006 14:35:05 -0000	1.16
@@ -863,6 +863,7 @@
 				    gboolean        is_pointer_event,
 				    gboolean        parent_visible)
 {
+  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item);
   GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
   GooCanvasItem *found = NULL;
@@ -894,17 +895,25 @@
 
   cairo_device_to_user (cr, &user_x, &user_y);
 
-  /* Remove any current translation, to avoid the 16-bit cairo limit. */
-  cairo_get_matrix (cr, &matrix);
-  matrix.x0 = matrix.y0 = 0.0;
-  cairo_set_matrix (cr, &matrix);
+  if (class->get_item_at)
+    {
+      found = class->get_item_at (simple, user_x, user_y, cr,
+				  is_pointer_event);
+    }
+  else
+    {
+      /* Remove any current translation, to avoid the 16-bit cairo limit. */
+      cairo_get_matrix (cr, &matrix);
+      matrix.x0 = matrix.y0 = 0.0;
+      cairo_set_matrix (cr, &matrix);
 
-  /* Use the virtual method subclasses define to create the path. */
-  GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item)->create_path (simple, cr);
+      /* Use the virtual method subclasses define to create the path. */
+      class->create_path (simple, cr);
 
-  if (goo_canvas_item_simple_check_in_path (simple, user_x, user_y, cr,
-					    pointer_events))
-    found = item;
+      if (goo_canvas_item_simple_check_in_path (simple, user_x, user_y, cr,
+						pointer_events))
+	found = item;
+    }
 
   cairo_restore (cr);
 
@@ -966,6 +975,7 @@
 				cairo_t         *cr,
 				GooCanvasBounds *bounds)
 {
+  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item);
   GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
   cairo_matrix_t matrix;
@@ -991,11 +1001,15 @@
       /* Request a redraw of the existing bounds. */
       goo_canvas_request_redraw (simple->canvas, &simple->bounds);
 
-      /* Use the virtual method subclasses define to create the path. */
-      GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item)->create_path (simple, cr);
-
-      /* Compute the new bounds. */
-      goo_canvas_item_simple_get_path_bounds (simple, cr, &simple->bounds);
+      if (class->update)
+	{
+	  class->update (simple, cr);
+	}
+      else
+	{
+	  class->create_path (simple, cr);
+	  goo_canvas_item_simple_get_path_bounds (simple, cr, &simple->bounds);
+	}
 
       /* Add the translation back to the bounds. */
       simple->bounds.x1 += x_offset;
@@ -1019,6 +1033,7 @@
 			      GooCanvasBounds   *bounds,
 			      gdouble            scale)
 {
+  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item);
   GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
 
@@ -1032,10 +1047,15 @@
   if (simple_data->transform)
     cairo_transform (cr, simple_data->transform);
 
-  /* Use the virtual method subclasses define to create the path. */
-  GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item)->create_path (simple, cr);
-
-  goo_canvas_item_simple_paint_path (simple, cr);
+  if (class->paint)
+    {
+      class->paint (simple, cr, bounds);
+    }
+  else
+    {
+      class->create_path (simple, cr);
+      goo_canvas_item_simple_paint_path (simple, cr);
+    }
 
   cairo_restore (cr);
 }

Index: goocanvasitemsimple.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemsimple.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- goocanvasitemsimple.h	29 Nov 2006 18:40:53 -0000	1.11
+++ goocanvasitemsimple.h	30 Nov 2006 14:35:05 -0000	1.12
@@ -93,8 +93,26 @@
   GObjectClass parent_class;
 
   /* Virtual methods. */
-  void		(* create_path)			   (GooCanvasItemSimple *item,
-						    cairo_t             *cr);
+
+  /* This is for very simple items that just create a path, such as the
+     GooCanvasRect, GooCanvasEllipse and GooCanvasPath items. They don't
+     need to override the update(), paint() & get_item_at() methods. */
+  void		 (* create_path)      (GooCanvasItemSimple *simple,
+				       cairo_t             *cr);
+
+  /* This is for more complicated items that do their own updates, hit
+     detection and drawing. */
+  void           (* update)	      (GooCanvasItemSimple *simple,
+				       cairo_t             *cr);
+  void           (* paint)	      (GooCanvasItemSimple *simple,
+				       cairo_t             *cr,
+				       GooCanvasBounds     *bounds);
+  GooCanvasItem* (* get_item_at)      (GooCanvasItemSimple *simple,
+				       gdouble              x,
+				       gdouble              y,
+				       cairo_t             *cr,
+				       gboolean             is_pointer_event);
+
 };
 
 

Index: goocanvaspolyline.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspolyline.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvaspolyline.c	29 Nov 2006 18:40:53 -0000	1.7
+++ goocanvaspolyline.c	30 Nov 2006 14:35:05 -0000	1.8
@@ -196,20 +196,6 @@
 
 
 static void
-goo_canvas_polyline_class_init (GooCanvasPolylineClass *klass)
-{
-  GObjectClass *gobject_class = (GObjectClass*) klass;
-
-  gobject_class->finalize = goo_canvas_polyline_finalize;
-
-  gobject_class->get_property = goo_canvas_polyline_get_property;
-  gobject_class->set_property = goo_canvas_polyline_set_property;
-
-  goo_canvas_polyline_install_common_properties (gobject_class);
-}
-
-
-static void
 goo_canvas_polyline_init (GooCanvasPolyline *polyline)
 {
   polyline->polyline_data = g_slice_new0 (GooCanvasPolylineData);
@@ -779,49 +765,26 @@
 
 
 static GooCanvasItem*
-goo_canvas_polyline_get_item_at (GooCanvasItem      *item,
-				 gdouble             x,
-				 gdouble             y,
-				 cairo_t            *cr,
-				 gboolean            is_pointer_event,
-				 gboolean            parent_visible)
+goo_canvas_polyline_get_item_at (GooCanvasItemSimple *simple,
+				 gdouble              x,
+				 gdouble              y,
+				 cairo_t             *cr,
+				 gboolean             is_pointer_event)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
   GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
   GooCanvasPolylineData *polyline_data = polyline->polyline_data;
   GooCanvasItem *found_item = NULL;
-  double user_x = x, user_y = y;
   GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
   gboolean do_stroke;
   cairo_matrix_t matrix;
 
-  if (simple->need_update)
-    goo_canvas_item_ensure_updated (item);
-
   if (polyline_data->num_points == 0)
     return NULL;
 
   /* Check if the item should receive events. */
   if (is_pointer_event)
-    {
-      if (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE)
-	return NULL;
-      if (simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK
-	  && (!parent_visible
-	      || simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-	      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-		  && simple->canvas->scale < simple_data->visibility_threshold)))
-	return NULL;
-
-      pointer_events = simple_data->pointer_events;
-    }
-
-  cairo_save (cr);
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
-  cairo_device_to_user (cr, &user_x, &user_y);
+    pointer_events = simple_data->pointer_events;
 
   /* Remove any current translation, to avoid the 16-bit cairo limit. */
   cairo_get_matrix (cr, &matrix);
@@ -829,9 +792,8 @@
   cairo_set_matrix (cr, &matrix);
 
   goo_canvas_polyline_create_path (polyline, cr);
-  if (goo_canvas_item_simple_check_in_path (simple, user_x, user_y, cr,
-					    pointer_events))
-    found_item = item;
+  if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events))
+    found_item = (GooCanvasItem*) simple;
 
   /* Check the arrows, if the polyline has them. */
   if (!found_item && (polyline_data->start_arrow || polyline_data->end_arrow)
@@ -845,21 +807,19 @@
 	  if (polyline_data->start_arrow)
 	    {
 	      goo_canvas_polyline_create_start_arrow_path (polyline, cr);
-	      if (cairo_in_fill (cr, user_x, user_y))
-		found_item = item;
+	      if (cairo_in_fill (cr, x, y))
+		found_item = (GooCanvasItem*) simple;
 	    }
 
 	  if (!found_item && polyline_data->end_arrow)
 	    {
 	      goo_canvas_polyline_create_end_arrow_path (polyline, cr);
-	      if (cairo_in_fill (cr, user_x, user_y))
-		found_item = item;
+	      if (cairo_in_fill (cr, x, y))
+		found_item = (GooCanvasItem*) simple;
 	    }
 	}
     }
 
-  cairo_restore (cr);
-
   return found_item;
 }
 
@@ -920,84 +880,32 @@
 
 
 static void
-goo_canvas_polyline_update  (GooCanvasItem      *item,
-			     gboolean            entire_tree,
-			     cairo_t            *cr,
-			     GooCanvasBounds    *bounds)
+goo_canvas_polyline_update  (GooCanvasItemSimple *simple,
+			     cairo_t             *cr)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasPolyline *polyline = (GooCanvasPolyline*) item;
+  GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
   GooCanvasPolylineData *polyline_data = polyline->polyline_data;
-  cairo_matrix_t matrix;
-  double x_offset, y_offset;
-
-  if (entire_tree || simple->need_update)
-    {
-      simple->need_update = FALSE;
-
-      goo_canvas_item_simple_check_style (simple);
-
-      if (polyline_data->reconfigure_arrows)
-	goo_canvas_polyline_reconfigure_arrows (polyline);
-
-      cairo_save (cr);
-      if (simple_data->transform)
-	cairo_transform (cr, simple_data->transform);
-
-      /* Remove any current translation, to avoid the 16-bit cairo limit. */
-      cairo_get_matrix (cr, &matrix);
-      x_offset = matrix.x0;
-      y_offset = matrix.y0;
-      matrix.x0 = matrix.y0 = 0.0;
-      cairo_set_matrix (cr, &matrix);
-
-      /* Request a redraw of the existing bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      /* Compute the new bounds. */
-      goo_canvas_polyline_compute_bounds (polyline, cr, &simple->bounds);
 
-      /* Add the translation back to the bounds. */
-      simple->bounds.x1 += x_offset;
-      simple->bounds.y1 += y_offset;
-      simple->bounds.x2 += x_offset;
-      simple->bounds.y2 += y_offset;
-
-      /* Request a redraw of the new bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      cairo_restore (cr);
-    }
+  if (polyline_data->reconfigure_arrows)
+    goo_canvas_polyline_reconfigure_arrows (polyline);
 
-  *bounds = simple->bounds;
+  /* Compute the new bounds. */
+  goo_canvas_polyline_compute_bounds (polyline, cr, &simple->bounds);
 }
 
 
 static void
-goo_canvas_polyline_paint (GooCanvasItem     *item,
-			   cairo_t           *cr,
-			   GooCanvasBounds   *bounds,
-			   gdouble            scale)
+goo_canvas_polyline_paint (GooCanvasItemSimple *simple,
+			   cairo_t             *cr,
+			   GooCanvasBounds     *bounds)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasPolyline *polyline = (GooCanvasPolyline*) item;
+  GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
   GooCanvasPolylineData *polyline_data = polyline->polyline_data;
 
   if (polyline_data->num_points == 0)
     return;
 
-  /* Check if the item should be visible. */
-  if (simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-	  && scale < simple_data->visibility_threshold))
-    return;
-
-  cairo_save (cr);
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
   goo_canvas_polyline_create_path (polyline, cr);
   goo_canvas_item_simple_paint_path (simple, cr);
 
@@ -1020,8 +928,6 @@
 	  cairo_fill (cr);
 	}
     }
-
-  cairo_restore (cr);
 }
 
 
@@ -1050,13 +956,29 @@
 static void
 canvas_item_interface_init (GooCanvasItemIface *iface)
 {
-  iface->get_item_at = goo_canvas_polyline_get_item_at;
-  iface->update      = goo_canvas_polyline_update;
-  iface->paint       = goo_canvas_polyline_paint;
   iface->set_model   = goo_canvas_polyline_set_model;
 }
 
 
+static void
+goo_canvas_polyline_class_init (GooCanvasPolylineClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass*) klass;
+  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
+
+  gobject_class->finalize = goo_canvas_polyline_finalize;
+
+  gobject_class->get_property = goo_canvas_polyline_get_property;
+  gobject_class->set_property = goo_canvas_polyline_set_property;
+
+  simple_class->update        = goo_canvas_polyline_update;
+  simple_class->paint         = goo_canvas_polyline_paint;
+  simple_class->get_item_at   = goo_canvas_polyline_get_item_at;
+
+  goo_canvas_polyline_install_common_properties (gobject_class);
+}
+
+
 /*
  * GooCanvasPolylineModel.
  */

Index: goocanvastext.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastext.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- goocanvastext.c	29 Nov 2006 18:40:53 -0000	1.7
+++ goocanvastext.c	30 Nov 2006 14:35:05 -0000	1.8
@@ -126,27 +126,6 @@
 
 
 static void
-goo_canvas_text_class_init (GooCanvasTextClass *klass)
-{
-  GObjectClass *gobject_class = (GObjectClass*) klass;
-
-  gobject_class->finalize = goo_canvas_text_finalize;
-
-  gobject_class->get_property = goo_canvas_text_get_property;
-  gobject_class->set_property = goo_canvas_text_set_property;
-
-  goo_canvas_text_install_common_properties (gobject_class);
-
-  /* Create the font options once and reuse it. */
-  klass->font_options = cairo_font_options_create ();
-  cairo_font_options_set_hint_metrics (klass->font_options,
-				       CAIRO_HINT_METRICS_OFF);
-  cairo_font_options_set_hint_style (klass->font_options,
-				     CAIRO_HINT_STYLE_NONE);
-}
-
-
-static void
 goo_canvas_text_init (GooCanvasText *text)
 {
   text->text_data = g_slice_new0 (GooCanvasTextData);
@@ -487,104 +466,53 @@
 
 
 static void
-goo_canvas_text_update  (GooCanvasItem      *item,
-			 gboolean            entire_tree,
-			 cairo_t            *cr,
-			 GooCanvasBounds    *bounds)
+goo_canvas_text_update  (GooCanvasItemSimple *simple,
+			 cairo_t             *cr)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasText *text = (GooCanvasText*) item;
+  GooCanvasText *text = (GooCanvasText*) simple;
   PangoLayout *layout;
 
-  if (entire_tree || simple->need_update)
-    {
-      simple->need_update = FALSE;
-
-      goo_canvas_item_simple_check_style (simple);
-
-      cairo_save (cr);
-      if (simple_data->transform)
-	cairo_transform (cr, simple_data->transform);
-
-      /* Request a redraw of the existing bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      /* Compute the new bounds. */
-      layout = goo_canvas_text_create_layout (text, cr, &simple->bounds,
-					      NULL, NULL);
-      g_object_unref (layout);
-
-      goo_canvas_item_simple_user_bounds_to_device (simple, cr,
-						    &simple->bounds);
-
-      /* Request a redraw of the new bounds. */
-      goo_canvas_request_redraw (simple->canvas, &simple->bounds);
-
-      cairo_restore (cr);
-    }
+  /* Compute the new bounds. */
+  layout = goo_canvas_text_create_layout (text, cr, &simple->bounds,
+					  NULL, NULL);
+  g_object_unref (layout);
 
-  *bounds = simple->bounds;
+  goo_canvas_item_simple_user_bounds_to_device (simple, cr, &simple->bounds);
 }
 
 
 static GooCanvasItem*
-goo_canvas_text_get_item_at (GooCanvasItem      *item,
-			     gdouble             x,
-			     gdouble             y,
-			     cairo_t            *cr,
-			     gboolean            is_pointer_event,
-			     gboolean            parent_visible)
+goo_canvas_text_get_item_at (GooCanvasItemSimple *simple,
+			     gdouble              x,
+			     gdouble              y,
+			     cairo_t             *cr,
+			     gboolean             is_pointer_event)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
   GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasText *text = (GooCanvasText*) item;
+  GooCanvasText *text = (GooCanvasText*) simple;
   GooCanvasItem *found_item = NULL;
   PangoLayout *layout;
   GooCanvasBounds bounds;
   PangoLayoutIter *iter;
   PangoRectangle log_rect;
   int px, py;
-  double user_x = x, user_y = y;
   gdouble origin_x, origin_y;
 
   /* If there is no text just return. */
   if (!text->text_data->text || !text->text_data->text[0])
     return NULL;
 
-  if (simple->need_update)
-    goo_canvas_item_ensure_updated (item);
-
-  /* Check if the item should receive events. */
-  if (is_pointer_event)
-    {
-      if (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE)
-	return NULL;
-      if (simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK
-	  && (!parent_visible
-	      || simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-	      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-		  && simple->canvas->scale < simple_data->visibility_threshold)))
-	return NULL;
-      if (simple_data->pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK)
-	{
-	  if (!goo_canvas_style_set_fill_options (simple_data->style, cr))
-	    return NULL;
-	}
-    }
-
-  cairo_save (cr);
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
-  cairo_device_to_user (cr, &user_x, &user_y);
+  if (is_pointer_event
+      && simple_data->pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK
+      && !goo_canvas_style_set_fill_options (simple_data->style, cr))
+    return NULL;
 
   layout = goo_canvas_text_create_layout (text, cr, &bounds,
 					  &origin_x, &origin_y);
 
   /* Convert the coordinates into Pango units. */
-  px = (user_x - origin_x) * PANGO_SCALE;
-  py = (user_y - origin_y) * PANGO_SCALE;
+  px = (x - origin_x) * PANGO_SCALE;
+  py = (y - origin_y) * PANGO_SCALE;
 
   /* We use line extents here. Note that SVG uses character cells to determine
      hits so we have slightly different behavior. */
@@ -596,7 +524,7 @@
       if (px >= log_rect.x && px < log_rect.x + log_rect.width 
 	  && py >= log_rect.y && py < log_rect.y + log_rect.height)
 	{
-	  found_item = item;
+	  found_item = (GooCanvasItem*) simple;
 	  break;
 	}
 
@@ -606,21 +534,16 @@
 
   g_object_unref (layout);
 
-  cairo_restore (cr);
-
   return found_item;
 }
 
 
 static void
-goo_canvas_text_paint (GooCanvasItem     *item,
-		       cairo_t           *cr,
-		       GooCanvasBounds   *bounds,
-		       gdouble            scale)
+goo_canvas_text_paint (GooCanvasItemSimple *simple,
+		       cairo_t             *cr,
+		       GooCanvasBounds     *bounds)
 {
-  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
-  GooCanvasItemSimpleData *simple_data = simple->simple_data;
-  GooCanvasText *text = (GooCanvasText*) item;
+  GooCanvasText *text = (GooCanvasText*) simple;
   PangoLayout *layout;
   GooCanvasBounds layout_bounds;
   gdouble origin_x, origin_y;
@@ -629,17 +552,7 @@
   if (!text->text_data->text || !text->text_data->text[0])
     return;
 
-  /* Check if the item should be visible. */
-  if (simple_data->visibility == GOO_CANVAS_ITEM_INVISIBLE
-      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
-	  && scale < simple_data->visibility_threshold))
-    return;
-
-  cairo_save (cr);
-  if (simple_data->transform)
-    cairo_transform (cr, simple_data->transform);
-
-  goo_canvas_style_set_fill_options (simple_data->style, cr);
+  goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
 
   cairo_new_path (cr);
   layout = goo_canvas_text_create_layout (text, cr, &layout_bounds,
@@ -647,8 +560,6 @@
   cairo_move_to (cr, origin_x, origin_y);
   pango_cairo_show_layout (cr, layout);
   g_object_unref (layout);
-
-  cairo_restore (cr);
 }
 
 
@@ -677,13 +588,36 @@
 static void
 canvas_item_interface_init (GooCanvasItemIface *iface)
 {
-  iface->get_item_at = goo_canvas_text_get_item_at;
-  iface->update      = goo_canvas_text_update;
-  iface->paint       = goo_canvas_text_paint;
   iface->set_model   = goo_canvas_text_set_model;
 }
 
 
+static void
+goo_canvas_text_class_init (GooCanvasTextClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass*) klass;
+  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
+
+  gobject_class->finalize = goo_canvas_text_finalize;
+
+  gobject_class->get_property = goo_canvas_text_get_property;
+  gobject_class->set_property = goo_canvas_text_set_property;
+
+  simple_class->update        = goo_canvas_text_update;
+  simple_class->paint         = goo_canvas_text_paint;
+  simple_class->get_item_at   = goo_canvas_text_get_item_at;
+
+  goo_canvas_text_install_common_properties (gobject_class);
+
+  /* Create the font options once and reuse it. */
+  klass->font_options = cairo_font_options_create ();
+  cairo_font_options_set_hint_metrics (klass->font_options,
+				       CAIRO_HINT_METRICS_OFF);
+  cairo_font_options_set_hint_style (klass->font_options,
+				     CAIRO_HINT_STYLE_NONE);
+}
+
+
 
 /*
  * GooCanvasTextModel.



More information about the cairo-commit mailing list