[cairo-commit] goocanvas/src goocanvas.c, 1.22, 1.23 goocanvas.h, 1.14, 1.15

Damon Chaplin commit at pdx.freedesktop.org
Wed Jun 20 06:00:02 PDT 2007


Committed by: damon

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

Modified Files:
	goocanvas.c goocanvas.h 
Log Message:
2007-06-20  Damon Chaplin  <damon at gnome.org>

	* src/goocanvas.c: added "automatic-bounds", "bounds-from-origin" and
	"bounds-padding" properties, used to calculate the canvas bounds
	automatically.

	* demo/demo.c (change_bounds_clicked): 
	* demo/mv-demo.c (change_bounds_clicked): test the above.



Index: goocanvas.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvas.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- goocanvas.c	19 Jun 2007 11:22:53 -0000	1.22
+++ goocanvas.c	20 Jun 2007 12:59:48 -0000	1.23
@@ -116,6 +116,9 @@
   PROP_Y1,
   PROP_X2,
   PROP_Y2,
+  PROP_AUTOMATIC_BOUNDS,
+  PROP_BOUNDS_FROM_ORIGIN,
+  PROP_BOUNDS_PADDING,
   PROP_UNITS,
   PROP_RESOLUTION_X,
   PROP_RESOLUTION_Y,
@@ -195,6 +198,7 @@
 					    GdkEvent         *event);
 static void     reconfigure_canvas	   (GooCanvas        *canvas,
 					    gboolean          redraw_if_needed);
+static void	goo_canvas_update_automatic_bounds (GooCanvas       *canvas);
 
 
 G_DEFINE_TYPE (GooCanvas, goo_canvas, GTK_TYPE_CONTAINER)
@@ -202,6 +206,9 @@
 /* This evaluates to TRUE if an item is still in the canvas. */
 #define ITEM_IS_VALID(item) (goo_canvas_item_get_canvas (item))
 
+#define GOO_CANVAS_DEFAULT_WIDTH	1000.0
+#define GOO_CANVAS_DEFAULT_HEIGHT	1000.0
+
 static void
 goo_canvas_class_init (GooCanvasClass *klass)
 {
@@ -297,7 +304,8 @@
 							_("X2"),
 							_("The x coordinate of the right edge of the canvas bounds, in canvas units"),
 							-G_MAXDOUBLE,
-							G_MAXDOUBLE, 1000.0,
+							G_MAXDOUBLE,
+							GOO_CANVAS_DEFAULT_WIDTH,
 							G_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class, PROP_Y2,
@@ -305,10 +313,32 @@
 							_("Y2"),
 							_("The y coordinate of the bottom edge of the canvas bounds, in canvas units"),
 							-G_MAXDOUBLE,
-							G_MAXDOUBLE, 1000.0,
+							G_MAXDOUBLE,
+							GOO_CANVAS_DEFAULT_HEIGHT,
 							G_PARAM_READWRITE));
 
 
+  g_object_class_install_property (gobject_class, PROP_AUTOMATIC_BOUNDS,
+                                   g_param_spec_boolean ("automatic-bounds",
+							 _("Automatic Bounds"),
+							 _("If the bounds are automatically calculated based on the bounds of all the items in the canvas"),
+							 FALSE,
+							 G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_BOUNDS_FROM_ORIGIN,
+                                   g_param_spec_boolean ("bounds-from-origin",
+							 _("Bounds From Origin"),
+							 _("If the automatic bounds are calculated from the origin"),
+							 TRUE,
+							 G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_BOUNDS_PADDING,
+				   g_param_spec_double ("bounds-padding",
+							_("Bounds Padding"),
+							_("The padding added to the automatic bounds"),
+							0.0, G_MAXDOUBLE, 0.0,
+							G_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class, PROP_UNITS,
 				   g_param_spec_enum ("units",
 						      _("Units"),
@@ -420,8 +450,11 @@
   /* Set the default bounds to a reasonable size. */
   canvas->bounds.x1 = 0.0;
   canvas->bounds.y1 = 0.0;
-  canvas->bounds.x2 = 1000.0;
-  canvas->bounds.y2 = 1000.0;
+  canvas->bounds.x2 = GOO_CANVAS_DEFAULT_WIDTH;
+  canvas->bounds.y2 = GOO_CANVAS_DEFAULT_HEIGHT;
+  canvas->automatic_bounds = FALSE;
+  canvas->bounds_from_origin = TRUE;
+  canvas->bounds_padding = 0.0;
 
   canvas->units = GTK_UNIT_PIXEL;
   canvas->resolution_x = 96.0;
@@ -634,6 +667,15 @@
     case PROP_Y2:
       g_value_set_double (value, canvas->bounds.y2);
       break;
+    case PROP_AUTOMATIC_BOUNDS:
+      g_value_set_boolean (value, canvas->automatic_bounds);
+      break;
+    case PROP_BOUNDS_FROM_ORIGIN:
+      g_value_set_boolean (value, canvas->bounds_from_origin);
+      break;
+    case PROP_BOUNDS_PADDING:
+      g_value_set_double (value, canvas->bounds_padding);
+      break;
     case PROP_UNITS:
       g_value_set_enum (value, canvas->units);
       break;
@@ -663,6 +705,7 @@
   GooCanvas *canvas = (GooCanvas*) object;
   GdkColor color = { 0, 0, 0, 0, };
   gboolean need_reconfigure = FALSE;
+  gboolean need_update_automatic_bounds = FALSE;
   guint rgb;
 
   switch (prop_id)
@@ -698,6 +741,21 @@
       canvas->bounds.y2 = g_value_get_double (value);
       need_reconfigure = TRUE;
       break;
+    case PROP_AUTOMATIC_BOUNDS:
+      canvas->automatic_bounds = g_value_get_boolean (value);
+      if (canvas->automatic_bounds)
+	need_update_automatic_bounds = TRUE;
+      break;
+    case PROP_BOUNDS_FROM_ORIGIN:
+      canvas->bounds_from_origin = g_value_get_boolean (value);
+      if (canvas->automatic_bounds)
+	need_update_automatic_bounds = TRUE;
+      break;
+    case PROP_BOUNDS_PADDING:
+      canvas->bounds_padding = g_value_get_double (value);
+      if (canvas->automatic_bounds)
+	need_update_automatic_bounds = TRUE;
+      break;
     case PROP_UNITS:
       canvas->units = g_value_get_enum (value);
       need_reconfigure = TRUE;
@@ -736,6 +794,11 @@
       break;
   }
 
+  if (need_update_automatic_bounds)
+    {
+      goo_canvas_update_automatic_bounds (canvas);
+    }
+
   if (need_reconfigure)
     {
       reconfigure_canvas (canvas, FALSE);
@@ -1965,6 +2028,52 @@
 
 
 static void
+goo_canvas_update_automatic_bounds (GooCanvas       *canvas)
+{
+  GooCanvasBounds bounds = { 0.0, 0.0, GOO_CANVAS_DEFAULT_WIDTH,
+			     GOO_CANVAS_DEFAULT_HEIGHT };
+
+  if (canvas->root_item)
+    goo_canvas_item_get_bounds (canvas->root_item, &bounds);
+
+  /* Calculate the new automatic bounds, which is the bounds of all the items
+     in the canvas plus any specified padding. If bounds_from_origin is set
+     x1 and y1 are set to 0.0. */
+  if (canvas->bounds_from_origin)
+    {
+      bounds.x1 = 0.0;
+      bounds.y1 = 0.0;
+      bounds.x2 += canvas->bounds_padding;
+      bounds.y2 += canvas->bounds_padding;
+    }
+  else
+    {
+      bounds.x1 -= canvas->bounds_padding;
+      bounds.y1 -= canvas->bounds_padding;
+      bounds.x2 += canvas->bounds_padding;
+      bounds.y2 += canvas->bounds_padding;
+    }
+
+  /* Make sure the bounds are sane. */
+  if (bounds.x2 < bounds.x1)
+    bounds.x2 = bounds.x1;
+  if (bounds.y2 < bounds.y1)
+    bounds.y2 = bounds.y1;
+
+  /* If the bounds have changed, reconfigure the canvas and redraw. */
+  if (bounds.x1 != canvas->bounds.x1
+      || bounds.y1 != canvas->bounds.y1
+      || bounds.x2 != canvas->bounds.x2
+      || bounds.y2 != canvas->bounds.y2)
+    {
+      canvas->bounds = bounds;
+      reconfigure_canvas (canvas, FALSE);
+      gtk_widget_queue_draw (GTK_WIDGET (canvas));
+    }
+}
+
+
+static void
 goo_canvas_update_internal (GooCanvas *canvas,
 			    cairo_t   *cr)
 {
@@ -1983,6 +2092,10 @@
 	goo_canvas_item_update (canvas->root_item, entire_tree, cr, &bounds);
     }
 
+  /* If the bounds are automatically-calculated, update them now. */
+  if (canvas->root_item && canvas->automatic_bounds)
+    goo_canvas_update_automatic_bounds (canvas);
+
   /* Check which item is under the pointer. */
   update_pointer_item (canvas, NULL);
 }

Index: goocanvas.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvas.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- goocanvas.h	19 Jun 2007 11:22:53 -0000	1.14
+++ goocanvas.h	20 Jun 2007 12:59:48 -0000	1.15
@@ -73,6 +73,16 @@
   /* This is TRUE if all layout should be done to the nearest integer. */
   guint integer_layout : 1;
 
+  /* This is TRUE if the bounds are calculated automatically, using the bounds
+     of all the items in the canvas. */
+  guint automatic_bounds : 1;
+
+  /* This is TRUE if the automatic bounds are calculated from the origin. */
+  guint bounds_from_origin : 1;
+
+  /* This is the padding around the automatic bounds. */
+  gdouble bounds_padding;
+
   /* The item that the mouse is over. */
   GooCanvasItem *pointer_item;
 



More information about the cairo-commit mailing list