[cairo-commit] goocanvas/demo .cvsignore, 1.7, 1.8 Makefile.am, 1.14, 1.15 mv-table-demo.c, NONE, 1.1 table-demo.c, 1.6, 1.7

Damon Chaplin commit at pdx.freedesktop.org
Tue Jun 19 04:23:07 PDT 2007


Committed by: damon

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

Modified Files:
	.cvsignore Makefile.am 
Added Files:
	mv-table-demo.c table-demo.c 
Log Message:
2007-06-19  Damon Chaplin  <damon at gnome.org>

	* src/goocanvas.c: added "integer-layout" boolean property, to specify
	that all layout in the canvas (i.e. in GooCanvasTable) is done to the
	nearest integer.

	* src/goocanvastable.c: implement integer layout.

	* demo/table-demo.c: 
	* demo/mv-table-demo.c: tests for integer layout.



Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/.cvsignore,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- .cvsignore	19 Feb 2007 13:22:35 -0000	1.7
+++ .cvsignore	19 Jun 2007 11:22:53 -0000	1.8
@@ -14,3 +14,4 @@
 mv-demo
 mv-simple-demo
 mv-scalability-demo
+mv-table-demo

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile.am	11 May 2007 16:30:47 -0000	1.14
+++ Makefile.am	19 Jun 2007 11:22:53 -0000	1.15
@@ -7,7 +7,7 @@
 	-I$(top_srcdir)/src \
 	@PACKAGE_CFLAGS@
 
-noinst_PROGRAMS = demo simple-demo scalability-demo units-demo widgets-demo mv-demo mv-simple-demo mv-scalability-demo
+noinst_PROGRAMS = demo table-demo simple-demo scalability-demo units-demo widgets-demo mv-demo mv-table-demo mv-simple-demo mv-scalability-demo
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
@@ -26,6 +26,16 @@
 
 mv_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)
+
+mv_table_demo_SOURCES = \
+	mv-table-demo.c
+
+mv_table_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
+
 simple_demo_SOURCES = \
 	simple-demo.c
 

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


static gboolean
on_delete_event (GtkWidget *window,
		 GdkEvent  *event,
		 gpointer   unused_data)
{
  exit (0);
}


static GooCanvasItemModel*
create_item (GooCanvasItemModel *table,
	     gdouble             width,
	     gdouble             height,
	     gint                row,
	     gint                column,
	     gint                rows,
	     gint                columns,
	     gboolean            x_expand,
	     gboolean            x_shrink,
	     gboolean            x_fill,
	     gboolean            y_expand,
	     gboolean            y_shrink,
	     gboolean            y_fill)
{
  GooCanvasItemModel *model;

  model = goo_canvas_rect_model_new (table, 0, 0, width, height,
				     "fill-color", "red",
				     NULL);

  goo_canvas_item_model_set_child_properties (table, model,
					      "row", row,
					      "column", column,
					      "rows", rows,
					      "columns", columns,
					      "x-expand", x_expand,
					      "x-fill", x_fill,
					      "x-shrink", x_shrink,
					      "y-expand", y_expand,
					      "y-fill", y_fill,
					      "y-shrink", y_shrink,
					      NULL);

  return model;
}


void
create_table1 (GtkWidget          *canvas,
	       GooCanvasItemModel *parent,
	       gdouble             x,
	       gdouble             y,
	       gdouble             width,
	       gdouble             height)
{
  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);

  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,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 41.6, 23.9, 2, 0, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

  items[i++] = create_item (table, 7.1, 5.7, 0, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 13.5, 18.2, 1, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 25.2, 22.1, 2, 1, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

  items[i++] = create_item (table, 11.3, 11.7, 0, 2, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 21.7, 18.8, 1, 2, 1, 1,
			    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  items[i++] = create_item (table, 22.2, 13.8, 2, 2, 1, 1,
			    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)
{
  GooCanvasItemModel *root;

  root = goo_canvas_group_model_new (NULL, NULL);
  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);

  g_print ("\nTable at reduced size...\n");
  create_table1 (canvas, root, 250, 50, 30, 30);

  g_print ("\nTable at enlarged size...\n");
  create_table1 (canvas, root, 450, 50, 100, 100);
}


int
main (int argc, char *argv[])
{
  GtkWidget *window, *vbox, *label, *scrolled_win, *canvas;

  /* Initialize GTK+. */
  gtk_set_locale ();
  gtk_init (&argc, &argv);

  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", (GtkSignalFunc) on_delete_event,
		    NULL);

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

  label = gtk_label_new ("Normal Layout");
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  /* Create top canvas. */
  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, FALSE, FALSE, 0);

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

  g_print ("\n\nNormal Canvas...\n");
  setup_canvas (canvas);

  label = gtk_label_new ("Integer Layout");
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  /* Create bottom canvas. */
  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, FALSE, FALSE, 0);

  canvas = goo_canvas_new ();
  g_object_set (canvas,
		"integer-layout", TRUE,
		NULL);
  gtk_widget_set_size_request (canvas, 600, 250);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  g_print ("\n\nInteger Layout Canvas...\n");
  setup_canvas (canvas);

  gtk_main ();

  return 0;
}






More information about the cairo-commit mailing list