goocanvas r29 - in trunk: . demo src



Author: damon
Date: Mon Nov 17 11:05:45 2008
New Revision: 29
URL: http://svn.gnome.org/viewvc/goocanvas?rev=29&view=rev

Log:

2008-11-17  Damon Chaplin  <damon gnome org>

	    * src/goocanvas.c (redraw_static_items_at_position): redraw each
	    group of static items separately, to stop GTK+ merging the redraw
	    rect into one massive one.

	    * demo/mv-demo.c (create_static_model): 
	    * demo/demo.c (setup_static_items): use a group for all the static
	    items.



Modified:
   trunk/ChangeLog
   trunk/demo/demo.c
   trunk/demo/mv-demo.c
   trunk/src/goocanvas.c

Modified: trunk/demo/demo.c
==============================================================================
--- trunk/demo/demo.c	(original)
+++ trunk/demo/demo.c	Mon Nov 17 11:05:45 2008
@@ -1332,11 +1332,15 @@
 static void
 setup_static_items (GooCanvas *canvas)
 {
-  GooCanvasItem *static_root, *item;
+  GooCanvasItem *static_root, *group, *item;
 
   static_root = goo_canvas_get_static_root_item (canvas);
 
-  item = goo_canvas_polyline_new_line (static_root,
+  /* All static items in one place in the canvas should be placed in the same
+     group. */
+  group = goo_canvas_group_new (static_root, NULL);
+
+  item = goo_canvas_polyline_new_line (group,
 				       40.0, 410.0,
 				       40.0, 330.0,
 				       "stroke-color", "midnightblue",
@@ -1348,7 +1352,7 @@
 				       NULL);
   setup_item_signals (item);
 
-  item = goo_canvas_polyline_new_line (static_root,
+  item = goo_canvas_polyline_new_line (group,
 				       32.0, 370.0,
 				       48.0, 370.0,
 				       "stroke-color", "midnightblue",
@@ -1356,7 +1360,7 @@
 				       NULL);
   setup_item_signals (item);
 
-  item = goo_canvas_text_new (static_root, "N", 40, 320, -1, GTK_ANCHOR_S,
+  item = goo_canvas_text_new (group, "N", 40, 320, -1, GTK_ANCHOR_S,
 			      "font", "Sans 12",
 			      NULL);
   setup_item_signals (item);

Modified: trunk/demo/mv-demo.c
==============================================================================
--- trunk/demo/mv-demo.c	(original)
+++ trunk/demo/mv-demo.c	Mon Nov 17 11:05:45 2008
@@ -415,6 +415,9 @@
 		      "bounds-from-origin", FALSE,
 		      "bounds-padding", 4.0,
 		      "background-color-rgb", 0xC3C3FF,
+#if 0
+		      "redraw-when-scrolled", TRUE,
+#endif
 		      NULL);
 	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 604, 454);
 
@@ -1217,11 +1220,13 @@
 static GooCanvasItemModel*
 create_static_model ()
 {
-  GooCanvasItemModel *static_root, *item;
+  GooCanvasItemModel *static_root, *group, *item;
 
   static_root = goo_canvas_group_model_new (NULL, NULL);
 
-  item = goo_canvas_polyline_model_new_line (static_root,
+  group = goo_canvas_group_model_new (static_root, NULL);
+
+  item = goo_canvas_polyline_model_new_line (group,
 					     40.0, 410.0,
 					     40.0, 330.0,
 					     "stroke-color", "midnightblue",
@@ -1232,14 +1237,14 @@
 					     "arrow-width", 3.5,
 					     NULL);
 
-  item = goo_canvas_polyline_model_new_line (static_root,
+  item = goo_canvas_polyline_model_new_line (group,
 					     32.0, 370.0,
 					     48.0, 370.0,
 					     "stroke-color", "midnightblue",
 					     "line-width", 3.0,
 					     NULL);
 
-  item = goo_canvas_text_model_new (static_root, "N", 40, 320, -1, GTK_ANCHOR_S,
+  item = goo_canvas_text_model_new (group, "N", 40, 320, -1, GTK_ANCHOR_S,
 				    "font", "Sans 12",
 				    NULL);
 

Modified: trunk/src/goocanvas.c
==============================================================================
--- trunk/src/goocanvas.c	(original)
+++ trunk/src/goocanvas.c	Mon Nov 17 11:05:45 2008
@@ -1682,20 +1682,47 @@
 }
 
 
+/* This requests a redraw of all the toplevel static items at their current
+   position, but redraws them at their given new position.
+   We redraw one item at a time to avoid GTK+ merging the rectangles into
+   one big one. */
 static void
-request_all_static_redraws (GooCanvas *canvas)
+redraw_static_items_at_position (GooCanvas *canvas,
+				 gint       x,
+				 gint       y)
 {
   GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
   GooCanvasBounds bounds;
+  GooCanvasItem *item;
+  gint n_children, i, window_x_copy, window_y_copy;
 
   if (!priv->static_root_item)
     return;
 
-  /* Get the bounds of all the static items, relative to the window. */
-  goo_canvas_item_get_bounds (priv->static_root_item, &bounds);
+  window_x_copy = priv->window_x;
+  window_y_copy = priv->window_y;
 
-  /* Request a redraw of the old position. */
-  request_static_redraw (canvas, &bounds);
+  n_children = goo_canvas_item_get_n_children (priv->static_root_item);
+  for (i = 0; i < n_children; i++)
+    {
+      item = goo_canvas_item_get_child (priv->static_root_item, i);
+
+      /* Get the bounds of all the static items, relative to the window. */
+      goo_canvas_item_get_bounds (item, &bounds);
+
+      /* Request a redraw of the old position. */
+      request_static_redraw (canvas, &bounds);
+
+      /* Redraw the item in its new position. */
+      priv->window_x = x;
+      priv->window_y = y;
+
+      gdk_window_process_updates (canvas->canvas_window, TRUE);
+
+      /* Now reset the window position. */
+      priv->window_x = window_x_copy;
+      priv->window_y = window_y_copy;
+    }
 }
 
 
@@ -1921,17 +1948,16 @@
 	}
       else
 	{
-	  /* Request a redraw of the bounds of the static items. */
-	  request_all_static_redraws (canvas);
+	  /* Redraw the area currently occupied by the static items. But
+	     draw the static items in their new position. This stops them
+	     from being "dragged" when the window is scrolled. */
+	  redraw_static_items_at_position (canvas,
+					   -canvas->hadjustment->value,
+					   -canvas->hadjustment->value);
 
 	  /* Move the static items to the new position. */
 	  priv->window_x = -canvas->hadjustment->value;
 	  priv->window_y = -canvas->vadjustment->value;
-
-	  /* Now do the redraw. This makes sure the static items don't get
-	     dragged when the rest of the window is scrolled. */
-	  if (adjustment)
-	    gdk_window_process_updates (canvas->canvas_window, TRUE);
 	}
 
       gdk_window_move (canvas->canvas_window,
@@ -1947,16 +1973,12 @@
 	}
       else
 	{
-	  /* If this is callback from a signal for one of the scrollbars,
-	     process updates here for smoother scrolling. */
-	  if (adjustment)
-	    gdk_window_process_updates (canvas->canvas_window, TRUE);
+	  /* Process updates here for smoother scrolling. */
+	  gdk_window_process_updates (canvas->canvas_window, TRUE);
 
 	  /* Now ensure the static items are redrawn in their new position. */
-	  request_all_static_redraws (canvas);
-
-	  if (adjustment)
-	    gdk_window_process_updates (canvas->canvas_window, TRUE);
+	  redraw_static_items_at_position (canvas, priv->window_x,
+					   priv->window_y);
 	}
 
       /* Notify any accessibility modules that the view has changed. */



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