goocanvas r20 - in trunk: . demo src



Author: damon
Date: Wed Oct 15 10:59:41 2008
New Revision: 20
URL: http://svn.gnome.org/viewvc/goocanvas?rev=20&view=rev

Log:

2008-10-15  Damon Chaplin  <damon gnome org>

	    * src/goocanvaspolyline.c (goo_canvas_polyline_is_item_at): only check
	    the fill if the polyline path is closed. Otherwise if we call
	    cairo_in_fill() it will automatically close the path which is not what
	    we want.

	    * src/goocanvaspath.c (goo_canvas_path_is_item_at): only check the fill
	    if a fill color/pattern has been set, for similar reasons.



Modified:
   trunk/ChangeLog
   trunk/demo/demo-paths.c
   trunk/demo/demo.c
   trunk/src/goocanvaspath.c
   trunk/src/goocanvaspolyline.c

Modified: trunk/demo/demo-paths.c
==============================================================================
--- trunk/demo/demo-paths.c	(original)
+++ trunk/demo/demo-paths.c	Wed Oct 15 10:59:41 2008
@@ -6,12 +6,36 @@
 
 static GooCanvasItem *path1;
 
+static gboolean
+on_background_button_press (GooCanvasItem *item,
+			    GooCanvasItem *target,
+			    GdkEventButton *event,
+			    gpointer data)
+{
+  GooCanvas *canvas;
+  GList *items, *elem;
+
+  g_print ("Button Press Item: %p\n", target);
+
+  canvas = goo_canvas_item_get_canvas (item);
+  items = goo_canvas_get_items_at (canvas, event->x_root, event->y_root,
+				   FALSE);
+  for (elem = items; elem; elem = elem->next)
+    g_print ("  clicked items: %p\n", elem->data);
+  g_list_free (items);
+
+  return TRUE;
+}
+
+
 static void
 setup_canvas (GtkWidget *canvas)
 {
   GooCanvasItem *root, *path;
 
   root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
+  g_signal_connect (root, "button_press_event",
+		    G_CALLBACK (on_background_button_press), NULL);
 
   /* Test the simple commands like moveto and lineto: MmZzLlHhVv. */
   path1 = goo_canvas_path_new (root, "M 20 20 L 40 40", NULL);

Modified: trunk/demo/demo.c
==============================================================================
--- trunk/demo/demo.c	(original)
+++ trunk/demo/demo.c	Wed Oct 15 10:59:41 2008
@@ -412,6 +412,7 @@
 			    gpointer data)
 {
   GooCanvas *canvas;
+  GList *items, *elem;
 
 #if 1
   g_print ("background received 'button-press' signal\n");
@@ -420,6 +421,12 @@
   canvas = goo_canvas_item_get_canvas (item);
   output_items_in_area (canvas, event->x_root, event->y_root);
 
+  items = goo_canvas_get_items_at (canvas, event->x_root, event->y_root,
+				   FALSE);
+  for (elem = items; elem; elem = elem->next)
+    g_print ("  clicked items: %p\n", elem->data);
+  g_list_free (items);
+
   return TRUE;
 }
 

Modified: trunk/src/goocanvaspath.c
==============================================================================
--- trunk/src/goocanvaspath.c	(original)
+++ trunk/src/goocanvaspath.c	Wed Oct 15 10:59:41 2008
@@ -42,17 +42,6 @@
 };
 
 static void canvas_item_interface_init   (GooCanvasItemIface  *iface);
-static void goo_canvas_path_finalize     (GObject             *object);
-static void goo_canvas_path_get_property (GObject             *object,
-					  guint                param_id,
-					  GValue              *value,
-					  GParamSpec          *pspec);
-static void goo_canvas_path_set_property (GObject             *object,
-					  guint                param_id,
-					  const GValue        *value,
-					  GParamSpec          *pspec);
-static void goo_canvas_path_create_path  (GooCanvasItemSimple *simple,
-					  cairo_t             *cr);
 
 G_DEFINE_TYPE_WITH_CODE (GooCanvasPath, goo_canvas_path,
 			 GOO_TYPE_CANVAS_ITEM_SIMPLE,
@@ -80,23 +69,6 @@
 
 
 static void
-goo_canvas_path_class_init (GooCanvasPathClass *klass)
-{
-  GObjectClass *gobject_class = (GObjectClass*) klass;
-  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
-
-  gobject_class->finalize     = goo_canvas_path_finalize;
-
-  gobject_class->get_property = goo_canvas_path_get_property;
-  gobject_class->set_property = goo_canvas_path_set_property;
-
-  simple_class->simple_create_path = goo_canvas_path_create_path;
-
-  goo_canvas_path_install_common_properties (gobject_class);
-}
-
-
-static void
 goo_canvas_path_init (GooCanvasPath *path)
 {
   path->path_data = g_slice_new0 (GooCanvasPathData);
@@ -282,6 +254,34 @@
 }
 
 
+static gboolean
+goo_canvas_path_is_item_at (GooCanvasItemSimple *simple,
+			    gdouble              x,
+			    gdouble              y,
+			    cairo_t             *cr,
+			    gboolean             is_pointer_event)
+{
+  GooCanvasItemSimpleData *simple_data = simple->simple_data;
+  GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
+  gboolean do_fill;
+
+  /* By default only check the fill if a fill color/pattern is specified. */
+  do_fill = goo_canvas_style_set_fill_options (simple_data->style, cr);
+  if (!do_fill)
+    pointer_events &= ~GOO_CANVAS_EVENTS_FILL_MASK;
+
+  /* If is_pointer_event is set use the pointer_events property instead. */
+  if (is_pointer_event)
+    pointer_events = simple_data->pointer_events;
+
+  goo_canvas_path_create_path (simple, cr);
+  if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events))
+    return TRUE;
+
+  return FALSE;
+}
+
+
 static void
 goo_canvas_path_set_model    (GooCanvasItem      *item,
 			      GooCanvasItemModel *model)
@@ -313,6 +313,24 @@
 }
 
 
+static void
+goo_canvas_path_class_init (GooCanvasPathClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass*) klass;
+  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
+
+  gobject_class->finalize     = goo_canvas_path_finalize;
+
+  gobject_class->get_property = goo_canvas_path_get_property;
+  gobject_class->set_property = goo_canvas_path_set_property;
+
+  simple_class->simple_create_path = goo_canvas_path_create_path;
+  simple_class->simple_is_item_at  = goo_canvas_path_is_item_at;
+
+  goo_canvas_path_install_common_properties (gobject_class);
+}
+
+
 /**
  * SECTION:goocanvaspathmodel
  * @Title: GooCanvasPathModel

Modified: trunk/src/goocanvaspolyline.c
==============================================================================
--- trunk/src/goocanvaspolyline.c	(original)
+++ trunk/src/goocanvaspolyline.c	Wed Oct 15 10:59:41 2008
@@ -121,16 +121,7 @@
 };
 
 
-static void goo_canvas_polyline_finalize     (GObject            *object);
 static void canvas_item_interface_init       (GooCanvasItemIface *iface);
-static void goo_canvas_polyline_get_property (GObject            *object,
-					      guint               param_id,
-					      GValue             *value,
-					      GParamSpec         *pspec);
-static void goo_canvas_polyline_set_property (GObject            *object,
-					      guint               param_id,
-					      const GValue       *value,
-					      GParamSpec         *pspec);
 
 G_DEFINE_TYPE_WITH_CODE (GooCanvasPolyline, goo_canvas_polyline,
 			 GOO_TYPE_CANVAS_ITEM_SIMPLE,
@@ -769,6 +760,10 @@
   if (is_pointer_event)
     pointer_events = simple_data->pointer_events;
 
+  /* If the path isn't closed, we never check the fill. */
+  if (!(polyline_data->close_path && polyline_data->num_points > 2))
+    pointer_events &= ~GOO_CANVAS_EVENTS_FILL_MASK;
+
   goo_canvas_polyline_create_path (polyline, cr);
   if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events))
     return TRUE;



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