[cairo-commit] goocanvas/demo .cvsignore, 1.6, 1.7 Makefile.am, 1.11, 1.12 mv-scalability-demo.c, NONE, 1.1 scalability-demo.c, 1.4, 1.5

Damon Chaplin commit at pdx.freedesktop.org
Mon Feb 19 05:22:41 PST 2007


Committed by: damon

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

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

	* demo/scalability-demo.c (setup_canvas): set the font on the root
	group so we don't need to set it on all the text items.
	Also output the time to the first expose.

	* demo/mv-scalability-demo.c: new demo based on scalability-demo.c.



Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/.cvsignore,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- .cvsignore	9 Dec 2006 12:08:38 -0000	1.6
+++ .cvsignore	19 Feb 2007 13:22:35 -0000	1.7
@@ -13,3 +13,4 @@
 widgets-demo
 mv-demo
 mv-simple-demo
+mv-scalability-demo

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Makefile.am	17 Feb 2007 13:54:36 -0000	1.11
+++ Makefile.am	19 Feb 2007 13:22:35 -0000	1.12
@@ -7,7 +7,7 @@
 	-I$(top_srcdir)/src \
 	@PACKAGE_CFLAGS@
 
-noinst_PROGRAMS = demo simple-demo scalability-demo units-demo widgets-demo table-demo mv-demo mv-simple-demo
+noinst_PROGRAMS = demo simple-demo scalability-demo units-demo widgets-demo table-demo mv-demo mv-simple-demo mv-scalability-demo
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
@@ -39,6 +39,11 @@
 
 scalability_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
+mv_scalability_demo_SOURCES = \
+	mv-scalability-demo.c
+
+mv_scalability_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
+
 units_demo_SOURCES = \
 	units-demo.c
 

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

#if 0
#define N_GROUP_COLS 5
#define N_GROUP_ROWS 5
#else
#define N_GROUP_COLS 25
#define N_GROUP_ROWS 20
#endif
#define N_COLS 10
#define N_ROWS 10
#define N_TOTAL_ID_ITEMS (N_GROUP_COLS * N_GROUP_ROWS) * (N_COLS * N_ROWS)

/* The maximum length of a string identifying an item (i.e. its coords). */
#define MAX_ID_LEN 20

#define PADDING 10

#if 0
#define USE_PIXMAP 
#endif

#if 0
#define ONLY_ONE
#endif

double total_width, total_height;
double left_offset, top_offset;
char ids[N_TOTAL_ID_ITEMS][MAX_ID_LEN];

static clock_t start;

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

  g_print ("%s item received 'motion-notify' signal\n", id ? id : "Unknown");

  return FALSE;
}


static void
setup_canvas (GtkWidget *canvas)
{
  GooCanvasItemModel *root, *group, *model;
  GooCanvasItem *item;
  GdkPixbuf *pixbuf = NULL;
  cairo_pattern_t *pattern = NULL;
  int group_i, group_j, i, j;
  double item_width, item_height;
  double cell_width, cell_height;
  double group_width, group_height;
  int total_items = 0, id_item_num = 0;;
  GdkColor color = { 0, 0, 0, 0, };
  GooCanvasStyle *style, *style2;
  GValue tmpval = { 0 };

  root = goo_canvas_group_model_new (NULL,
				     "font", "Sans 8",
				     NULL);
  goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
  g_object_unref (root);

#ifdef USE_PIXMAP
  pixbuf = gdk_pixbuf_new_from_file("toroid.png", NULL);
  item_width = gdk_pixbuf_get_width (pixbuf);
  item_height = gdk_pixbuf_get_height (pixbuf);
  pattern = goo_canvas_cairo_pattern_from_pixbuf (pixbuf);
#else
  pixbuf = NULL;
  item_width = 400/*80*/;
  item_height = 19;
#endif
	
  cell_width = item_width + PADDING * 2;
  cell_height = item_height + PADDING * 2;

  group_width = N_COLS * cell_width;
  group_height = N_ROWS * cell_height;

  total_width = N_GROUP_COLS * group_width;
  total_height = N_GROUP_ROWS * group_height;

  /* We use -ve offsets to test if -ve coords are handled correctly. */
  left_offset = -total_width / 2;
  top_offset = -total_height / 2;

  style = goo_canvas_style_new ();
  gdk_color_parse ("mediumseagreen", &color);
  pattern = cairo_pattern_create_rgb (color.red / 65535.0,
				      color.green / 65535.0,
				      color.blue / 65535.0);
  g_value_init (&tmpval, GOO_TYPE_CAIRO_PATTERN);
  g_value_take_boxed (&tmpval, pattern);
  goo_canvas_style_set_property (style, goo_canvas_style_fill_pattern_id, &tmpval);
  g_value_unset (&tmpval);

  style2 = goo_canvas_style_new ();
  gdk_color_parse ("steelblue", &color);
  pattern = cairo_pattern_create_rgb (color.red / 65535.0,
				      color.green / 65535.0,
				      color.blue / 65535.0);
  g_value_init (&tmpval, GOO_TYPE_CAIRO_PATTERN);
  g_value_take_boxed (&tmpval, pattern);
  goo_canvas_style_set_property (style2, goo_canvas_style_fill_pattern_id, &tmpval);
  g_value_unset (&tmpval);

  for (group_i = 0; group_i < N_GROUP_COLS; group_i++)
    {
      for (group_j = 0; group_j < N_GROUP_ROWS; group_j++)
	{
	  double group_x = left_offset + (group_i * group_width);
	  double group_y = top_offset + (group_j * group_height);

	  group = goo_canvas_group_model_new (root, NULL);
	  total_items++;
	  goo_canvas_item_model_translate (group, group_x, group_y);

	  for (i = 0; i < N_COLS; i++)
	    {
	      for (j = 0; j < N_ROWS; j++)
		{
		  double item_x = (i * cell_width) + PADDING;
		  double item_y = (j * cell_height) + PADDING;
		  double rotation = i % 10 * 2;
		  double rotation_x = item_x + item_width / 2;
		  double rotation_y = item_y + item_height / 2;

		  sprintf (ids[id_item_num], "%g, %g",
			   group_x + item_x, group_y + item_y);

#ifdef USE_PIXMAP
		  model = goo_canvas_image_model_new (group, NULL,
						      item_x, item_y,
						      "pattern", pattern,
						      "width", item_width,
						      "height", item_height,
						      NULL);
#else
		  model = goo_canvas_rect_model_new (group, item_x, item_y,
						     item_width, item_height,
						     NULL);
		  goo_canvas_item_model_set_style (model, (j % 2) ? style : style2);
		  goo_canvas_item_model_rotate (model, rotation, rotation_x, rotation_y);
#endif

		  item = goo_canvas_get_item (GOO_CANVAS (canvas), model);
		  g_object_set_data (G_OBJECT (item), "id",
				     ids[id_item_num]);
		  g_signal_connect (item, "motion_notify_event",
				    (GtkSignalFunc) on_motion_notify, NULL);

		  model = goo_canvas_text_model_new (group, ids[id_item_num],
						     item_x + item_width / 2,
						     item_y + item_height / 2,
						     -1, GTK_ANCHOR_CENTER,
						     NULL);
		  goo_canvas_item_model_rotate (model, rotation, rotation_x,
						rotation_y);

		  id_item_num++;
		  total_items += 2;

#ifdef ONLY_ONE
		  break;
#endif
		}
#ifdef ONLY_ONE
	      break;
#endif
	    }
#ifdef ONLY_ONE
	  break;
#endif
	}
#ifdef ONLY_ONE
      break;
#endif
    }

  if (pattern)
    cairo_pattern_destroy (pattern);

  g_print ("Total items: %i\n", total_items);

}


static gboolean
on_expose_event (GtkWidget *canvas,
		 GdkEvent  *event,
		 gpointer   unused_data)
{
  static gboolean first_time = TRUE;

  if (first_time)
    {
      printf ("Update Canvas Time Used: %g\n",
	      (double) (clock() - start) / CLOCKS_PER_SEC);
      first_time = FALSE;
    }

  return FALSE;
}


GtkWidget *
create_canvas (void)
{
  GtkWidget *canvas;

  /* Create the canvas. */
  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 600, 450);

  start = clock();
  setup_canvas (canvas);
  printf ("Create Canvas Time Used: %g\n",
	  (double) (clock() - start) / CLOCKS_PER_SEC);

  start = clock();
  goo_canvas_set_bounds (GOO_CANVAS (canvas), left_offset, top_offset,
			 left_offset + total_width, top_offset + total_height);
  gtk_widget_show (canvas);

  g_signal_connect (canvas, "expose_event",
		    (GtkSignalFunc) on_expose_event, NULL);

  return canvas;
}


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


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

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  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);

  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolled_win);
  gtk_container_add (GTK_CONTAINER (window), scrolled_win);

  canvas = create_canvas ();
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  gtk_main ();

  return 0;
}



Index: scalability-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/scalability-demo.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- scalability-demo.c	29 Nov 2006 18:47:02 -0000	1.4
+++ scalability-demo.c	19 Feb 2007 13:22:35 -0000	1.5
@@ -29,6 +29,8 @@
 double left_offset, top_offset;
 char ids[N_TOTAL_ID_ITEMS][MAX_ID_LEN];
 
+static clock_t start;
+
 static gboolean
 on_motion_notify (GooCanvasItem *item,
 		  GooCanvasItem *target,
@@ -60,6 +62,10 @@
 
   root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
 
+  g_object_set (G_OBJECT (root),
+		"font", "Sans 8",
+		NULL);
+
 #ifdef USE_PIXMAP
   pixbuf = gdk_pixbuf_new_from_file("toroid.png", NULL);
   item_width = gdk_pixbuf_get_width (pixbuf);
@@ -144,14 +150,15 @@
 		  g_object_set_data (G_OBJECT (item), "id",
 				     ids[id_item_num]);
 
+#if 0
 		  g_signal_connect (item, "motion_notify_event",
 				    (GtkSignalFunc) on_motion_notify, NULL);
+#endif
 
 		  item = goo_canvas_text_new (group, ids[id_item_num],
 					      item_x + item_width / 2,
 					      item_y + item_height / 2,
 					      -1, GTK_ANCHOR_CENTER,
-					      "font", "Sans 8",
 					      NULL);
 		  goo_canvas_item_rotate (item, rotation, rotation_x,
 					  rotation_y);
@@ -183,11 +190,28 @@
 }
 
 
+static gboolean
+on_expose_event (GtkWidget *canvas,
+		 GdkEvent  *event,
+		 gpointer   unused_data)
+{
+  static gboolean first_time = TRUE;
+
+  if (first_time)
+    {
+      printf ("Update Canvas Time Used: %g\n",
+	      (double) (clock() - start) / CLOCKS_PER_SEC);
+      first_time = FALSE;
+    }
+
+  return FALSE;
+}
+
+
 GtkWidget *
 create_canvas (void)
 {
   GtkWidget *canvas;
-  clock_t start;
 
   /* Create the canvas. */
   canvas = goo_canvas_new ();
@@ -198,10 +222,14 @@
   printf ("Create Canvas Time Used: %g\n",
 	  (double) (clock() - start) / CLOCKS_PER_SEC);
 
+  start = clock();
   goo_canvas_set_bounds (GOO_CANVAS (canvas), left_offset, top_offset,
 			 left_offset + total_width, top_offset + total_height);
   gtk_widget_show (canvas);
 
+  g_signal_connect (canvas, "expose_event",
+		    (GtkSignalFunc) on_expose_event, NULL);
+
   return canvas;
 }
 



More information about the cairo-commit mailing list