[cairo-commit] goocanvas/demo Makefile.am, 1.12, 1.13 demo-table.c, NONE, 1.1 demo.c, 1.17, 1.18 mv-demo-table.c, NONE, 1.1 mv-demo.c, 1.4, 1.5 table-demo.c, 1.5, NONE

Damon Chaplin commit at pdx.freedesktop.org
Tue Feb 20 15:53:23 PST 2007


Committed by: damon

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

Modified Files:
	Makefile.am demo.c mv-demo.c 
Added Files:
	demo-table.c mv-demo-table.c 
Removed Files:
	table-demo.c 
Log Message:
2007-02-20  Damon Chaplin  <damon at gnome.org>

	* demo/demo-table.c: 
	* demo/mv-demo-table.c: moved table-demo.c into main demo app, and
	made a model-view version.



Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- Makefile.am	19 Feb 2007 13:22:35 -0000	1.12
+++ Makefile.am	20 Feb 2007 23:53:17 -0000	1.13
@@ -7,20 +7,21 @@
 	-I$(top_srcdir)/src \
 	@PACKAGE_CFLAGS@
 
-noinst_PROGRAMS = demo simple-demo scalability-demo units-demo widgets-demo table-demo mv-demo mv-simple-demo mv-scalability-demo
+noinst_PROGRAMS = demo simple-demo scalability-demo units-demo widgets-demo mv-demo mv-simple-demo mv-scalability-demo
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
 	demo-arrowhead.c demo-features.c demo-events.c \
 	demo-paths.c demo-focus.c demo-item.h demo-item.c demo-animation.c \
-	demo-clipping.c
+	demo-clipping.c demo-table.c
 
 demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
 mv_demo_SOURCES = \
 	mv-demo.c mv-demo-fifteen.c mv-demo-scalability.c mv-demo-grabs.c \
 	mv-demo-arrowhead.c mv-demo-features.c mv-demo-events.c \
-	mv-demo-paths.c mv-demo-focus.c mv-demo-animation.c mv-demo-clipping.c
+	mv-demo-paths.c mv-demo-focus.c mv-demo-animation.c \
+	mv-demo-clipping.c mv-demo-table.c
 
 mv_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
@@ -54,10 +55,5 @@
 
 widgets_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
-table_demo_SOURCES = \
-	table-demo.c
-
-table_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
-
 EXTRA_DIST = flower.png toroid.png
 

--- NEW FILE: demo-table.c ---
#include <config.h>
#include <stdlib.h>
#include <goocanvas.h>


#define DEMO_RECT_ITEM 0
#define DEMO_TEXT_ITEM 1
#define DEMO_WIDGET_ITEM 2


static gboolean
on_button_press (GooCanvasItem *item,
		 GooCanvasItem *target,
		 GdkEventButton *event,
		 gpointer data)
{
  gchar *id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received 'button-press' signal at %g, %g (root: %g, %g)\n",
	   id ? id : "unknown", event->x, event->y,
	   event->x_root, event->y_root);

  return TRUE;
}


static void
create_demo_item (GooCanvasItem *table,
		  gint           demo_item_type,
		  gint           row,
		  gint           column,
		  gint           rows,
		  gint           columns,
		  gchar         *text)
{
  GooCanvasItem *item;
  GtkWidget *widget;

  switch (demo_item_type)
    {
    case DEMO_RECT_ITEM:
      item = goo_canvas_rect_new (table, 0, 0, 38, 19,
				  "fill-color", "red",
				  NULL);
      break;
    case DEMO_TEXT_ITEM:
      item = goo_canvas_text_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
      break;
    case DEMO_WIDGET_ITEM:
      widget = gtk_button_new_with_label (text);
      item = goo_canvas_widget_new (table, widget, 0, 0, -1, -1, NULL);
      break;
    }

  goo_canvas_item_set_child_properties (table, item,
					"row", row,
					"column", column,
					"rows", rows,
					"columns", columns,
#if 1
					"x-expand", TRUE,
					"x-fill", TRUE,
					"y-expand", TRUE,
					"y-fill", TRUE,
#endif
					NULL);

  g_object_set_data (G_OBJECT (item), "id", text);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);
}


static GooCanvasItem*
create_table (GooCanvasItem *parent,
	      gint           row,
	      gint           column,
	      gint           embedding_level,
	      gdouble        x,
	      gdouble        y,
	      gdouble        rotation,
	      gdouble        scale,
	      gint           demo_item_type)
{
  GooCanvasItem *table;

  /* Add a few simple items. */
  table = goo_canvas_table_new (parent,
				"row-spacing", 4.0,
				"column-spacing", 4.0,
				NULL);
  goo_canvas_item_translate (table, x, y);
#if 1
  goo_canvas_item_rotate (table, rotation, 0, 0);
#endif
#if 1
  goo_canvas_item_scale (table, scale, scale);
#endif

  if (row != -1)
    goo_canvas_item_set_child_properties (parent, table,
					  "row", row,
					  "column", column,
#if 1
					  "x-expand", TRUE,
					  "x-fill", TRUE,
#endif
#if 0
					  "y-expand", TRUE,
					  "y-fill", TRUE,
#endif
					  NULL);

  if (embedding_level)
    {
      gint level = embedding_level - 1;
      create_table (table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type);
      create_table (table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type);
      create_table (table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type);
      create_table (table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type);
      create_table (table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type);
      create_table (table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type);
      create_table (table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type);
      create_table (table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type);
      create_table (table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type);
    }
  else
    {
      create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0,0)");
      create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(1,0)");
      create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(2,0)");
      create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0,1)");
      create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(1,1)");
      create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(2,1)");
      create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(0,2)");
      create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,2)");
      create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(2,2)");
    }

  return table;
}


static void
create_demo_table (GooCanvasItem *root,
		   gdouble        x,
		   gdouble        y,
		   gdouble        width,
		   gdouble        height)
{
  GooCanvasItem *table, *square, *circle, *triangle;

  table = goo_canvas_table_new (root,
                                "row-spacing", 4.0,
                                "column-spacing", 4.0,
				"width", width,
				"height", height,
                                NULL);
  goo_canvas_item_translate (table, x, y);

  square = goo_canvas_rect_new (table, 0.0, 0.0, 50.0, 50.0,
				"fill-color", "red",
				NULL);
  goo_canvas_item_set_child_properties (table, square,
					"row", 0,
					"column", 0,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (square), "id", "Red square");
  g_signal_connect (square, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);

  circle = goo_canvas_ellipse_new (table, 0.0, 0.0, 25.0, 25.0,
				   "fill-color", "blue",
				   NULL);
  goo_canvas_item_set_child_properties (table, circle,
					"row", 0,
					"column", 1,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (circle), "id", "Blue circle");
  g_signal_connect (circle, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);

  triangle = goo_canvas_polyline_new (table, TRUE, 3,
				      25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
				      "fill-color", "yellow",
				      NULL);
  goo_canvas_item_set_child_properties (table, triangle,
					"row", 0,
					"column", 2,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (triangle), "id", "Yellow triangle");
  g_signal_connect (triangle, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);
}


GtkWidget *
create_table_page (void)
{
  GtkWidget *vbox, *scrolled_win, *canvas;
  GooCanvasItem *root, *table;

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_widget_show (vbox);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
				       GTK_SHADOW_IN);
  gtk_widget_show (scrolled_win);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);

  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

#if 1
  create_demo_table (root, 400, 200, -1, -1);
  create_demo_table (root, 400, 260, 100, -1);
#endif

#if 1
  create_table (root, -1, -1, 0, 10, 10, 0, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 180, 10, 30, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 350, 10, 60, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 500, 10, 90, 1.0, DEMO_TEXT_ITEM);
#endif

#if 1
  table = create_table (root, -1, -1, 0, 30, 150, 0, 1.0, DEMO_TEXT_ITEM);
  g_object_set (table, "width", 300.0, "height", 100.0, NULL);
#endif

#if 1
  create_table (root, -1, -1, 1, 200, 200, 30, 0.8, DEMO_TEXT_ITEM);
#endif

#if 1
  table = create_table (root, -1, -1, 0, 10, 700, 0, 1.0, DEMO_WIDGET_ITEM);
  g_object_set (table, "width", 300.0, "height", 200.0, NULL);
#endif

  gtk_widget_show (canvas);

  return vbox;
}



Index: demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- demo.c	20 Feb 2007 14:22:03 -0000	1.17
+++ demo.c	20 Feb 2007 23:53:17 -0000	1.18
@@ -33,6 +33,7 @@
 GtkWidget *create_focus_page (void);
 GtkWidget *create_animation_page (void);
 GtkWidget *create_clipping_page (void);
+GtkWidget *create_table_page (void);
 
 #if CAIRO_HAS_PDF_SURFACE
 static void
@@ -1264,6 +1265,11 @@
 			    create_clipping_page (),
 			    gtk_label_new ("Clipping"));
 #endif
+#if 1
+  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+			    create_table_page (),
+			    gtk_label_new ("Table"));
+#endif
 
   return window;
 }

--- NEW FILE: mv-demo-table.c ---
#include <config.h>
#include <stdlib.h>
#include <goocanvas.h>


#define DEMO_RECT_ITEM 0
#define DEMO_TEXT_ITEM 1

static GooCanvas *canvas;

static gboolean
on_button_press (GooCanvasItem *item,
		 GooCanvasItem *target,
		 GdkEventButton *event,
		 gpointer data)
{
  gchar *id = g_object_get_data (G_OBJECT (item), "id");

  g_print ("%s received 'button-press' signal at %g, %g (root: %g, %g)\n",
	   id ? id : "unknown", event->x, event->y,
	   event->x_root, event->y_root);

  return TRUE;
}


static void
create_demo_item (GooCanvasItemModel *table,
		  gint           demo_item_type,
		  gint           row,
		  gint           column,
		  gint           rows,
		  gint           columns,
		  gchar         *text)
{
  GooCanvasItemModel *model;
  GooCanvasItem *item;

  switch (demo_item_type)
    {
    case DEMO_RECT_ITEM:
      model = goo_canvas_rect_model_new (table, 0, 0, 38, 19,
					 "fill-color", "red",
					 NULL);
      break;
    case DEMO_TEXT_ITEM:
      model = goo_canvas_text_model_new (table, text, 0, 0, -1, GTK_ANCHOR_NW,
					 NULL);
      break;
    }

  goo_canvas_item_model_set_child_properties (table, model,
					      "row", row,
					      "column", column,
					      "rows", rows,
					      "columns", columns,
#if 1
					      "x-expand", TRUE,
					      "x-fill", TRUE,
					      "y-expand", TRUE,
					      "y-fill", TRUE,
#endif
					      NULL);

  item = goo_canvas_get_item (canvas, model);
  g_object_set_data (G_OBJECT (item), "id", text);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);
}


static GooCanvasItemModel*
create_table (GooCanvasItemModel *parent,
	      gint           row,
	      gint           column,
	      gint           embedding_level,
	      gdouble        x,
	      gdouble        y,
	      gdouble        rotation,
	      gdouble        scale,
	      gint           demo_item_type)
{
  GooCanvasItemModel *table;

  /* Add a few simple items. */
  table = goo_canvas_table_model_new (parent,
				      "row-spacing", 4.0,
				      "column-spacing", 4.0,
				      NULL);
  goo_canvas_item_model_translate (table, x, y);
#if 1
  goo_canvas_item_model_rotate (table, rotation, 0, 0);
#endif
#if 1
  goo_canvas_item_model_scale (table, scale, scale);
#endif

  if (row != -1)
    goo_canvas_item_model_set_child_properties (parent, table,
						"row", row,
						"column", column,
#if 1
						"x-expand", TRUE,
						"x-fill", TRUE,
#endif
#if 0
						"y-expand", TRUE,
						"y-fill", TRUE,
#endif
					  NULL);

  if (embedding_level)
    {
      gint level = embedding_level - 1;
      create_table (table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type);
      create_table (table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type);
      create_table (table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type);
      create_table (table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type);
      create_table (table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type);
      create_table (table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type);
      create_table (table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type);
      create_table (table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type);
      create_table (table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type);
    }
  else
    {
      create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0,0)");
      create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(1,0)");
      create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(2,0)");
      create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0,1)");
      create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(1,1)");
      create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(2,1)");
      create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(0,2)");
      create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,2)");
      create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(2,2)");
    }

  return table;
}


static void
create_demo_table (GooCanvasItemModel *root,
		   gdouble        x,
		   gdouble        y,
		   gdouble        width,
		   gdouble        height)
{
  GooCanvasItemModel *table, *square, *circle, *triangle;
  GooCanvasItem *item;

  table = goo_canvas_table_model_new (root,
				      "row-spacing", 4.0,
				      "column-spacing", 4.0,
				      "width", width,
				      "height", height,
				      NULL);
  goo_canvas_item_model_translate (table, x, y);

  square = goo_canvas_rect_model_new (table, 0.0, 0.0, 50.0, 50.0,
				      "fill-color", "red",
				      NULL);
  goo_canvas_item_model_set_child_properties (table, square,
					      "row", 0,
					      "column", 0,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, square);
  g_object_set_data (G_OBJECT (item), "id", "Red square");
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);

  circle = goo_canvas_ellipse_model_new (table, 0.0, 0.0, 25.0, 25.0,
					 "fill-color", "blue",
					 NULL);
  goo_canvas_item_model_set_child_properties (table, circle,
					      "row", 0,
					      "column", 1,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, circle);
  g_object_set_data (G_OBJECT (item), "id", "Blue circle");
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);

  triangle = goo_canvas_polyline_model_new (table, TRUE, 3,
					    25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
					    "fill-color", "yellow",
					    NULL);
  goo_canvas_item_model_set_child_properties (table, triangle,
					      "row", 0,
					      "column", 2,
					      "x-shrink", TRUE,
					      NULL);
  item = goo_canvas_get_item (canvas, triangle);
  g_object_set_data (G_OBJECT (item), "id", "Yellow triangle");
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, NULL);
}


GtkWidget *
create_table_page (void)
{
  GtkWidget *vbox, *scrolled_win;
  GooCanvasItemModel *root, *table;

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_widget_show (vbox);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
				       GTK_SHADOW_IN);
  gtk_widget_show (scrolled_win);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);

  canvas = (GooCanvas*) goo_canvas_new ();
  gtk_widget_set_size_request ((GtkWidget*) canvas, 600, 450);
  goo_canvas_set_bounds (canvas, 0, 0, 1000, 1000);
  gtk_container_add (GTK_CONTAINER (scrolled_win), (GtkWidget*) canvas);

  root = goo_canvas_group_model_new (NULL, NULL);
  goo_canvas_set_root_item_model (canvas, root);
  g_object_unref (root);

#if 1
  create_demo_table (root, 400, 200, -1, -1);
  create_demo_table (root, 400, 260, 100, -1);
#endif

#if 1
  create_table (root, -1, -1, 0, 10, 10, 0, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 180, 10, 30, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 350, 10, 60, 1.0, DEMO_TEXT_ITEM);
  create_table (root, -1, -1, 0, 500, 10, 90, 1.0, DEMO_TEXT_ITEM);
#endif

#if 1
  table = create_table (root, -1, -1, 0, 30, 150, 0, 1.0, DEMO_TEXT_ITEM);
  g_object_set (table, "width", 300.0, "height", 100.0, NULL);
#endif

#if 1
  create_table (root, -1, -1, 1, 200, 200, 30, 0.8, DEMO_TEXT_ITEM);
#endif

#if 0
  table = create_table (root, -1, -1, 0, 10, 700, 0, 1.0, DEMO_WIDGET_ITEM);
  g_object_set (table, "width", 300.0, "height", 200.0, NULL);
#endif

  gtk_widget_show ((GtkWidget*) canvas);

  return vbox;
}



Index: mv-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/mv-demo.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mv-demo.c	19 Feb 2007 11:43:36 -0000	1.4
+++ mv-demo.c	20 Feb 2007 23:53:17 -0000	1.5
@@ -31,6 +31,7 @@
 GtkWidget *create_focus_page (void);
 GtkWidget *create_animation_page (void);
 GtkWidget *create_clipping_page (void);
+GtkWidget *create_table_page (void);
 
 #if CAIRO_HAS_PDF_SURFACE
 static void
@@ -1259,6 +1260,11 @@
 			    create_clipping_page (),
 			    gtk_label_new ("Clipping"));
 #endif
+#if 1
+  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+			    create_table_page (),
+			    gtk_label_new ("Table"));
+#endif
 
   return window;
 }

--- table-demo.c DELETED ---



More information about the cairo-commit mailing list