[cairo-commit] goocanvas/demo mv-table-demo.c, 1.1, 1.2 table-demo.c, 1.7, 1.8

Damon Chaplin commit at pdx.freedesktop.org
Sun Apr 6 08:55:56 PDT 2008


Committed by: damon

Update of /cvs/cairo/goocanvas/demo
In directory kemper:/tmp/cvs-serv17357/demo

Modified Files:
	mv-table-demo.c table-demo.c 
Log Message:
2008-04-06  Armin Burgmeier  <armin at openismus.com>

	    * src/goocanvastable.c: Implemented grid lines between table items by
	    adding"row-grid-line-width", "column-grid-line-width",
	    "row-border-spacing" and "column-border-spacing" properties.
	    (Patch applied by Damon with a few changes.)

	    * demo/mv-table-demo.c: 
	    * demo/table-demo.c: added tests for the gridlines.



Index: mv-table-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/mv-table-demo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mv-table-demo.c	19 Jun 2007 11:22:53 -0000	1.1
+++ mv-table-demo.c	6 Apr 2008 16:00:14 -0000	1.2
@@ -55,7 +55,8 @@
 	       gdouble             x,
 	       gdouble             y,
 	       gdouble             width,
-	       gdouble             height)
+	       gdouble             height,
+	       gboolean            with_grid_lines)
 {
   GooCanvasItemModel *table, *items[9];
   GooCanvasItem *item;
@@ -68,6 +69,18 @@
 				      NULL);
   goo_canvas_item_model_translate (table, x, y);
 
+  if (with_grid_lines)
+    {
+      g_object_set (G_OBJECT (table),
+		    "row-spacing",  2.0,
+		    "column-spacing", 2.0,
+		    "x-border-spacing", 1.0,
+		    "y-border-spacing", 1.0,
+		    "horz-grid-line-width", 1.0,
+		    "vert-grid-line-width", 2.0,
+		    NULL);
+    }
+
   items[i++] = create_item (table, 17.3, 12.9, 0, 0, 1, 1,
 			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
   items[i++] = create_item (table, 33.1, 17.2, 1, 0, 1, 1,
@@ -100,6 +113,70 @@
 }
 
 
+/* Creates a table with items spanning multiple cells */
+void
+create_table2 (GtkWidget          *canvas,
+	       GooCanvasItemModel *parent,
+	       gdouble             x,
+	       gdouble             y,
+	       gdouble             width,
+	       gdouble             height,
+	       gboolean            with_grid_lines)
+{
+  GooCanvasItemModel *table, *items[9];
+  GooCanvasItem *item;
+  GooCanvasBounds bounds;
+  gint i = 0;
+
+  table = goo_canvas_table_model_new (parent,
+				      "width", width,
+				      "height", height,
+				      NULL);
+  goo_canvas_item_model_translate (table, x, y);
+
+  if (with_grid_lines)
+    {
+      g_object_set (G_OBJECT (table),
+		    "row-spacing",  2.0,
+		    "column-spacing", 2.0,
+		    "x-border-spacing", 1.0,
+		    "y-border-spacing", 1.0,
+		    "horz-grid-line-width", 1.0,
+		    "vert-grid-line-width", 2.0,
+		    NULL);
+    }
+
+  items[i++] = create_item (table, 17.3, 12.9, 0, 0, 2, 2,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 33.1, 17.2, 0, 2, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 41.6, 23.9, 1, 2, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  items[i++] = create_item (table, 7.1, 5.7, 0, 3, 2, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 13.5, 18.2, 2, 0, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 25.2, 22.1, 2, 1, 1, 3,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  items[i++] = create_item (table, 11.3, 11.7, 3, 0, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 21.7, 18.8, 3, 1, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 22.2, 13.8, 3, 2, 1, 2,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  for (i = 0; i < 9; i++)
+    {
+      item = goo_canvas_get_item (GOO_CANVAS (canvas), items[i]);
+      goo_canvas_item_get_bounds (item, &bounds);
+      g_print ("Item %i: %g,%g - %g,%g\n", i,
+	       bounds.x1 - x, bounds.y1 - y,
+	       bounds.x2 - x, bounds.y2 - y);
+    }
+}
+
 void
 setup_canvas (GtkWidget *canvas)
 {
@@ -109,13 +186,31 @@
   goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
 
   g_print ("\nTable at default size...\n");
-  create_table1 (canvas, root, 50, 50, -1, -1);
+  create_table1 (canvas, root, 50, 50, -1, -1, FALSE);
 
   g_print ("\nTable at reduced size...\n");
-  create_table1 (canvas, root, 250, 50, 30, 30);
+  create_table1 (canvas, root, 250, 50, 30, 30, FALSE);
 
   g_print ("\nTable at enlarged size...\n");
-  create_table1 (canvas, root, 450, 50, 100, 100);
+  create_table1 (canvas, root, 450, 50, 100, 100, FALSE);
+
+  g_print ("\nTable with grid lines at default size...\n");
+  create_table1 (canvas, root, 50, 250, -1, -1, TRUE);
+
+  g_print ("\nTable with grid lines at reduced size...\n");
+  create_table1 (canvas, root, 250, 250, 30, 30, TRUE);
+
+  g_print ("\nTable with grid lines at enlarged size...\n");
+  create_table1 (canvas, root, 450, 250, 150, 150, TRUE);
+
+  g_print ("Multispanning table with grid lines at default size...\n");
+  create_table2 (canvas, root, 50, 450, -1, -1, TRUE);
+
+  g_print ("Multispanning table with grid lines at reduced size...\n");
+  create_table2 (canvas, root, 250, 450, 30, 30, TRUE);
+
+  g_print ("Multispanning table with grid lines at enlarged size...\n");
+  create_table2 (canvas, root, 450, 450, 150, 150, TRUE);
 }
 
 

Index: table-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/table-demo.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- table-demo.c	19 Jun 2007 11:22:53 -0000	1.7
+++ table-demo.c	6 Apr 2008 16:00:14 -0000	1.8
@@ -54,7 +54,8 @@
 	       gdouble        x,
 	       gdouble        y,
 	       gdouble        width,
-	       gdouble        height)
+	       gdouble        height,
+	       gboolean       with_grid_lines)
 {
   GooCanvasItem *table, *items[9];
   GooCanvasBounds bounds;
@@ -66,6 +67,18 @@
 				NULL);
   goo_canvas_item_translate (table, x, y);
 
+  if (with_grid_lines)
+    {
+      g_object_set (G_OBJECT (table),
+		    "row-spacing",  2.0,
+		    "column-spacing", 2.0,
+		    "x-border-spacing", 1.0,
+		    "y-border-spacing", 1.0,
+		    "horz-grid-line-width", 1.0,
+		    "vert-grid-line-width", 2.0,
+		    NULL);
+    }
+
   items[i++] = create_item (table, 17.3, 12.9, 0, 0, 1, 1,
 			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
   items[i++] = create_item (table, 33.1, 17.2, 1, 0, 1, 1,
@@ -96,6 +109,66 @@
     }
 }
 
+/* Creates a table with items spanning multiple cells */
+void
+create_table2 (GooCanvasItem *parent,
+	       gdouble        x,
+	       gdouble        y,
+	       gdouble        width,
+	       gdouble        height,
+	       gboolean       with_grid_lines)
+{
+  GooCanvasItem *table, *items[9];
+  GooCanvasBounds bounds;
+  gint i = 0;
+
+  table = goo_canvas_table_new (parent,
+				"width", width,
+				"height", height,
+				NULL);
+  goo_canvas_item_translate (table, x, y);
+
+  if (with_grid_lines)
+    {
+      g_object_set (G_OBJECT (table),
+		    "row-spacing",  2.0,
+		    "column-spacing", 2.0,
+		    "x-border-spacing", 1.0,
+		    "y-border-spacing", 1.0,
+		    "horz-grid-line-width", 1.0,
+		    "vert-grid-line-width", 2.0,
+		    NULL);
+    }
+
+  items[i++] = create_item (table, 17.3, 12.9, 0, 0, 2, 2,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 33.1, 17.2, 0, 2, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 41.6, 23.9, 1, 2, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  items[i++] = create_item (table, 7.1, 5.7, 0, 3, 2, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 13.5, 18.2, 2, 0, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 25.2, 22.1, 2, 1, 1, 3,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  items[i++] = create_item (table, 11.3, 11.7, 3, 0, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 21.7, 18.8, 3, 1, 1, 1,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+  items[i++] = create_item (table, 22.2, 13.8, 3, 2, 1, 2,
+			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
+
+  for (i = 0; i < 9; i++)
+    {
+      goo_canvas_item_get_bounds (items[i], &bounds);
+      g_print ("Item %i: %g,%g - %g,%g\n", i,
+	       bounds.x1 - x, bounds.y1 - y,
+	       bounds.x2 - x, bounds.y2 - y);
+    }
+}
 
 void
 setup_canvas (GtkWidget *canvas)
@@ -105,13 +178,31 @@
   root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
 
   g_print ("\nTable at default size...\n");
-  create_table1 (root, 50, 50, -1, -1);
+  create_table1 (root, 50, 50, -1, -1, FALSE);
 
   g_print ("\nTable at reduced size...\n");
-  create_table1 (root, 250, 50, 30, 30);
+  create_table1 (root, 250, 50, 30, 30, FALSE);
 
   g_print ("\nTable at enlarged size...\n");
-  create_table1 (root, 450, 50, 100, 100);
+  create_table1 (root, 450, 50, 100, 100, FALSE);
+
+  g_print ("\nTable with grid lines at default size...\n");
+  create_table1 (root, 50, 250, -1, -1, TRUE);
+
+  g_print ("\nTable with grid lines at reduced size...\n");
+  create_table1 (root, 250, 250, 30, 30, TRUE);
+
+  g_print ("\nTable with grid lines at enlarged size...\n");
+  create_table1 (root, 450, 250, 150, 150, TRUE);
+
+  g_print ("Multispanning table with grid lines at default size...\n");
+  create_table2 (root, 50, 450, -1, -1, TRUE);
+
+  g_print ("Multispanning table with grid lines at reduced size...\n");
+  create_table2 (root, 250, 450, 30, 30, TRUE);
+
+  g_print ("Multispanning table with grid lines at enlarged size...\n");
+  create_table2 (root, 450, 450, 150, 150, TRUE);
 }
 
 



More information about the cairo-commit mailing list