[cairo-commit] goocanvas/demo demo-paths.c, 1.3, 1.4 mv-demo-paths.c, 1.1, 1.2
Damon Chaplin
commit at pdx.freedesktop.org
Sun May 13 04:43:15 PDT 2007
Committed by: damon
Update of /cvs/cairo/goocanvas/demo
In directory kemper:/tmp/cvs-serv13841/demo
Modified Files:
demo-paths.c mv-demo-paths.c
Log Message:
2007-05-13 Damon Chaplin <damon at gnome.org>
* src/goocanvaspath.c: use a common GooCanvasPathData like the other
standard items. This fixes a crash where the model's path_commands
GArray was updated but the view still pointed to the old GArray
which had been freed.
* demo/mv-demo-paths.c:
* demo/demo-paths.c: added a button to test changing the path data
dynamically.
Index: demo-paths.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo-paths.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- demo-paths.c 29 Nov 2006 18:47:02 -0000 1.3
+++ demo-paths.c 13 May 2007 11:43:04 -0000 1.4
@@ -4,6 +4,8 @@
#include <goocanvas.h>
+static GooCanvasItem *path1;
+
static void
setup_canvas (GtkWidget *canvas)
{
@@ -12,7 +14,7 @@
root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
/* Test the simple commands like moveto and lineto: MmZzLlHhVv. */
- path = goo_canvas_path_new (root, "M 20 20 L 40 40", NULL);
+ path1 = goo_canvas_path_new (root, "M 20 20 L 40 40", NULL);
path = goo_canvas_path_new (root, "M30 20 l20, 20", NULL);
path = goo_canvas_path_new (root, "M 60 20 H 80", NULL);
path = goo_canvas_path_new (root, "M60 40 h20", NULL);
@@ -96,15 +98,41 @@
}
+static void
+move_path_clicked (GtkWidget *button, GooCanvas *canvas)
+{
+ static gint count = 0;
+
+ gchar *data;
+
+ if (count == 0)
+ data = "M130,70 L317,70";
+ else if (count == 1)
+ data = "M130,170 L317,170";
+ else
+ data = "M130,270 L317,270";
+
+ g_object_set (path1,
+ "data", data,
+ NULL);
+
+ count = (count + 1) % 3;
+}
+
+
GtkWidget *
create_paths_page (void)
{
- GtkWidget *vbox, *scrolled_win, *canvas;
+ GtkWidget *vbox, *hbox, *w, *scrolled_win, *canvas;
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_widget_show (vbox);
+ hbox = gtk_hbox_new (FALSE, 4);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_SHADOW_IN);
@@ -119,5 +147,11 @@
setup_canvas (canvas);
+ w = gtk_button_new_with_label ("Move Path");
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+ g_signal_connect (w, "clicked",
+ (GtkSignalFunc) move_path_clicked, canvas);
+
return vbox;
}
Index: mv-demo-paths.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/mv-demo-paths.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mv-demo-paths.c 29 Nov 2006 18:27:06 -0000 1.1
+++ mv-demo-paths.c 13 May 2007 11:43:05 -0000 1.2
@@ -4,6 +4,8 @@
#include <goocanvas.h>
+static GooCanvasItemModel *path1;
+
static GooCanvasItemModel*
create_canvas_model (void)
{
@@ -12,7 +14,7 @@
root = goo_canvas_group_model_new (NULL, NULL);
/* Test the simple commands like moveto and lineto: MmZzLlHhVv. */
- path = goo_canvas_path_model_new (root, "M 20 20 L 40 40", NULL);
+ path1 = goo_canvas_path_model_new (root, "M 20 20 L 40 40", NULL);
path = goo_canvas_path_model_new (root, "M30 20 l20, 20", NULL);
path = goo_canvas_path_model_new (root, "M 60 20 H 80", NULL);
path = goo_canvas_path_model_new (root, "M60 40 h20", NULL);
@@ -98,16 +100,42 @@
}
+static void
+move_path_clicked (GtkWidget *button, GooCanvas *canvas)
+{
+ static gint count = 0;
+
+ gchar *data;
+
+ if (count == 0)
+ data = "M130,70 L317,70";
+ else if (count == 1)
+ data = "M130,170 L317,170";
+ else
+ data = "M130,270 L317,270";
+
+ g_object_set (path1,
+ "data", data,
+ NULL);
+
+ count = (count + 1) % 3;
+}
+
+
GtkWidget *
create_paths_page (void)
{
- GtkWidget *vbox, *scrolled_win, *canvas;
+ GtkWidget *vbox, *hbox, *w, *scrolled_win, *canvas;
GooCanvasItemModel *root;
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_widget_show (vbox);
+ hbox = gtk_hbox_new (FALSE, 4);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_SHADOW_IN);
@@ -124,5 +152,11 @@
goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
g_object_unref (root);
+ w = gtk_button_new_with_label ("Move Path");
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+ g_signal_connect (w, "clicked",
+ (GtkSignalFunc) move_path_clicked, canvas);
+
return vbox;
}
More information about the cairo-commit
mailing list