[cairo-commit] goocanvas/demo Makefile.am, 1.9, 1.10 demo-clipping.c, NONE, 1.1 demo.c, 1.14, 1.15 mv-demo-clipping.c, NONE, 1.1 mv-demo.c, 1.2, 1.3

Damon Chaplin commit at pdx.freedesktop.org
Thu Feb 15 06:18:56 PST 2007


Committed by: damon

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

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

	* src/goocanvasutils.c: 
	* src/goocanvaspath.c: moved data structures and code for parsing and
	creating SVG paths from goocanvaspath.[hc] to goocanvasutils.[hc].
	Added goo_canvas_parse_path_data() and goo_canvas_create_path() public
	functions.

	* src/goocanvasitemsimple.c: added "clip-path" and "clip-fill-rule"
	properties to specify the clip path and fill rule, and used these
	to calculate bounds, paint, and do hit testing.

	* src/goocanvasitemsimple.h (struct _GooCanvasItemSimpleData): added
	clip_path_commands and clip_fill_rule.

	* src/goocanvastext.c (goo_canvas_text_set_model): 
	* src/goocanvasrect.c (goo_canvas_rect_set_model): 
	* src/goocanvaspolyline.c (goo_canvas_polyline_set_model): 
	* src/goocanvaspath.c (goo_canvas_path_set_model): 
	* src/goocanvasimage.c (goo_canvas_image_set_model): 
	* src/goocanvasgroup.c (goo_canvas_group_set_model): 
	* src/goocanvasellipse.c (goo_canvas_ellipse_set_model): use
	goo_canvas_item_simple_set_model() rather than getting parent iface.
	(For GooCanvasTable this actually caused a crash as when it called
	the GooCanvasGroup function that got the parent iface which pointed to
	itself so it got into an infinite loop.)

	* demo/mv-demo-clipping.c: 
	* demo/demo-clipping.c: new files for clipping demo pages.

	* demo/Makefile.am: 
	* demo/mv-demo.c: 
	* demo/demo.c: added clipping pages.



Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.am	13 Feb 2007 12:32:44 -0000	1.9
+++ Makefile.am	15 Feb 2007 14:18:50 -0000	1.10
@@ -12,14 +12,14 @@
 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.c demo-animation.c
+	demo-paths.c demo-focus.c demo-item.c demo-animation.c demo-clipping.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-paths.c mv-demo-focus.c mv-demo-animation.c mv-demo-clipping.c
 
 mv_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 

--- NEW FILE: demo-clipping.c ---
#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include <goocanvas.h>


static gboolean
on_button_press (GooCanvasItem *item,
		 GooCanvasItem *target,
		 GdkEventButton *event,
		 gchar *id)
{
  g_print ("%s received 'button-press' signal at %g, %g (root: %g, %g)\n",
	   id, event->x, event->y, event->x_root, event->y_root);

  return TRUE;
}


static void
setup_canvas (GtkWidget *canvas)
{
  GooCanvasItem *root, *item, *table;

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  /* Plain items without clip path. */
  item = goo_canvas_ellipse_new (root, 0, 0, 50, 30,
				 "fill-color", "blue",
				 NULL);
  goo_canvas_item_translate (item, 100, 100);
  goo_canvas_item_rotate (item, 30, 0, 0);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse (unclipped)");

  item = goo_canvas_rect_new (root, 200, 50, 100, 100,
			      "fill-color", "red",
			      "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
			      NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle (unclipped)");

  item = goo_canvas_rect_new (root, 380, 50, 100, 100,
			      "fill-color", "yellow",
			      NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle (unclipped)");



  /* Clipped items. */
  item = goo_canvas_ellipse_new (root, 0, 0, 50, 30,
				 "fill-color", "blue",
				 "clip-path", "M 0 0 h 100 v 100 h -100 Z",
				 NULL);
  goo_canvas_item_translate (item, 100, 300);
  goo_canvas_item_rotate (item, 30, 0, 0);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse");

  item = goo_canvas_rect_new (root, 200, 250, 100, 100,
			      "fill-color", "red",
			      "clip-path", "M 250 300 h 100 v 100 h -100 Z",
			      "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
			      NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle");

  item = goo_canvas_rect_new (root, 380, 250, 100, 100,
			      "fill-color", "yellow",
			      "clip-path", "M480,230 l40,100 l-80 0 z",
			      NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle");


  /* Table with clipped items. */
  table = goo_canvas_table_new (root, NULL);
  goo_canvas_item_translate (table, 200, 400);
  goo_canvas_item_rotate (table, 30, 0, 0);

  item = goo_canvas_ellipse_new (table, 0, 0, 50, 30,
				 "fill-color", "blue",
				 "clip-path", "M 0 0 h 100 v 100 h -100 Z",
				 NULL);
  goo_canvas_item_translate (item, 100, 300);
  goo_canvas_item_rotate (item, 30, 0, 0);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse");

  item = goo_canvas_rect_new (table, 200, 250, 100, 100,
			      "fill-color", "red",
			      "clip-path", "M 250 300 h 100 v 100 h -100 Z",
			      "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
			      NULL);
  goo_canvas_item_set_child_properties (table, item,
					"column", 1,
					NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle");

  item = goo_canvas_rect_new (table, 380, 250, 100, 100,
			      "fill-color", "yellow",
			      "clip-path", "M480,230 l40,100 l-80 0 z",
			      NULL);
  goo_canvas_item_set_child_properties (table, item,
					"column", 2,
					NULL);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle");
}


GtkWidget *
create_clipping_page (void)
{
  GtkWidget *vbox, *scrolled_win, *canvas;

  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_container_add (GTK_CONTAINER (vbox), scrolled_win);

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

  setup_canvas (canvas);

  return vbox;
}

Index: demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- demo.c	13 Feb 2007 12:32:44 -0000	1.14
+++ demo.c	15 Feb 2007 14:18:50 -0000	1.15
@@ -32,6 +32,7 @@
 GtkWidget *create_paths_page (void);
 GtkWidget *create_focus_page (void);
 GtkWidget *create_animation_page (void);
+GtkWidget *create_clipping_page (void);
 
 #if CAIRO_HAS_PDF_SURFACE
 static void
@@ -1216,7 +1217,7 @@
 #if 1
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
 			    create_canvas_features (),
-			    gtk_label_new ("Features"));
+			    gtk_label_new ("Reparent"));
 #endif
 #if 1
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
@@ -1248,6 +1249,11 @@
 			    create_animation_page (),
 			    gtk_label_new ("Animation"));
 #endif
+#if 1
+  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+			    create_clipping_page (),
+			    gtk_label_new ("Clipping"));
+#endif
 
   return window;
 }

--- NEW FILE: mv-demo-clipping.c ---
#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include <goocanvas.h>


static gboolean
on_button_press (GooCanvasItem *item,
		 GooCanvasItem *target,
		 GdkEventButton *event,
		 gchar *id)
{
  g_print ("%s received 'button-press' signal at %g, %g (root: %g, %g)\n",
	   id, event->x, event->y, event->x_root, event->y_root);

  return TRUE;
}


static void
setup_canvas (GooCanvas *canvas)
{
  GooCanvasItemModel *root, *model, *table;
  GooCanvasItem *item;

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

  /* Plain items without clip path. */
  model = goo_canvas_ellipse_model_new (root, 0, 0, 50, 30,
					"fill-color", "blue",
					NULL);
  goo_canvas_item_model_translate (model, 100, 100);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse (unclipped)");

  model = goo_canvas_rect_model_new (root, 200, 50, 100, 100,
				     "fill-color", "red",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle (unclipped)");

  model = goo_canvas_rect_model_new (root, 380, 50, 100, 100,
				     "fill-color", "yellow",
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle (unclipped)");



  /* Clipped items. */
  model = goo_canvas_ellipse_model_new (root, 0, 0, 50, 30,
					"fill-color", "blue",
					"clip-path", "M 0 0 h 100 v 100 h -100 Z",
					NULL);
  goo_canvas_item_model_translate (model, 100, 300);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse");

  model = goo_canvas_rect_model_new (root, 200, 250, 100, 100,
				     "fill-color", "red",
				     "clip-path", "M 250 300 h 100 v 100 h -100 Z",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle");

  model = goo_canvas_rect_model_new (root, 380, 250, 100, 100,
				     "fill-color", "yellow",
				     "clip-path", "M480,230 l40,100 l-80 0 z",
				     NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle");


  /* Table with clipped items. */
  table = goo_canvas_table_model_new (root, NULL);

  goo_canvas_item_model_translate (table, 200, 400);
  goo_canvas_item_model_rotate (table, 30, 0, 0);

  model = goo_canvas_ellipse_model_new (table, 0, 0, 50, 30,
					"fill-color", "blue",
					"clip-path", "M 0 0 h 100 v 100 h -100 Z",
					NULL);
  goo_canvas_item_model_translate (model, 100, 300);
  goo_canvas_item_model_rotate (model, 30, 0, 0);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Blue ellipse");

  model = goo_canvas_rect_model_new (table, 200, 250, 100, 100,
				     "fill-color", "red",
				     "clip-path", "M 250 300 h 100 v 100 h -100 Z",
				     "clip-fill-rule", CAIRO_FILL_RULE_EVEN_ODD,
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "column", 1,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Red rectangle");

  model = goo_canvas_rect_model_new (table, 380, 250, 100, 100,
				     "fill-color", "yellow",
				     "clip-path", "M480,230 l40,100 l-80 0 z",
				     NULL);
  goo_canvas_item_model_set_child_properties (table, model,
					      "column", 2,
					      NULL);
  item = goo_canvas_get_item (canvas, model);
  g_signal_connect (item, "button_press_event",
		    (GtkSignalFunc) on_button_press, "Yellow rectangle");
}


GtkWidget *
create_clipping_page (void)
{
  GtkWidget *vbox, *scrolled_win, *canvas;

  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_container_add (GTK_CONTAINER (vbox), scrolled_win);

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

  setup_canvas (GOO_CANVAS (canvas));

  return vbox;
}

Index: mv-demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/mv-demo.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mv-demo.c	13 Feb 2007 12:32:44 -0000	1.2
+++ mv-demo.c	15 Feb 2007 14:18:50 -0000	1.3
@@ -30,6 +30,7 @@
 GtkWidget *create_paths_page (void);
 GtkWidget *create_focus_page (void);
 GtkWidget *create_animation_page (void);
+GtkWidget *create_clipping_page (void);
 
 #if CAIRO_HAS_PDF_SURFACE
 static void
@@ -1228,6 +1229,11 @@
 			    create_animation_page (),
 			    gtk_label_new ("Animation"));
 #endif
+#if 1
+  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+			    create_clipping_page (),
+			    gtk_label_new ("Clipping"));
+#endif
 
   return window;
 }



More information about the cairo-commit mailing list