[cairo-commit] goocanvas/demo .cvsignore, 1.1, 1.2 Makefile.am, 1.1, 1.2 demo-paths.c, 1.1, 1.2 simple-demo.c, NONE, 1.1

Damon Chaplin commit at pdx.freedesktop.org
Sun Apr 16 14:00:56 PDT 2006


Committed by: damon

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

Modified Files:
	.cvsignore Makefile.am demo-paths.c 
Added Files:
	simple-demo.c 
Log Message:
2006-04-16  Damon Chaplin  <damon at gnome.org>

	* demo/simple-demo.c: new very simple demo, also used in docs.



Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- .cvsignore	12 Apr 2006 10:46:32 -0000	1.1
+++ .cvsignore	16 Apr 2006 21:00:54 -0000	1.2
@@ -6,3 +6,4 @@
 *.lo
 *.loT
 demo
+simple-demo

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	12 Apr 2006 10:45:52 -0000	1.1
+++ Makefile.am	16 Apr 2006 21:00:54 -0000	1.2
@@ -7,7 +7,7 @@
 	-I$(top_srcdir)/src \
 	@PACKAGE_CFLAGS@
 
-noinst_PROGRAMS = demo
+noinst_PROGRAMS = demo simple-demo
 
 demo_SOURCES = \
 	demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
@@ -15,5 +15,10 @@
 
 demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
 
+simple_demo_SOURCES = \
+	simple-demo.c
+
+simple_demo_LDADD = $(top_builddir)/src/libgoocanvas.la @PACKAGE_LIBS@ $(INTLLIBS)
+
 EXTRA_DIST = flower.png toroid.png
 

Index: demo-paths.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo-paths.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- demo-paths.c	12 Apr 2006 10:45:52 -0000	1.1
+++ demo-paths.c	16 Apr 2006 21:00:54 -0000	1.2
@@ -4,11 +4,14 @@
 #include <goocanvas.h>
 
 
-static void
-create_paths (GooCanvasModelSimple   *canvas_model)
+static GooCanvasModelSimple*
+create_canvas_model (void)
 {
+  GooCanvasModelSimple *canvas_model;
   GooCanvasItem *root, *path;
 
+  canvas_model = goo_canvas_model_simple_new ();
+
   root = goo_canvas_model_get_root_item (GOO_CANVAS_MODEL (canvas_model));
 
   /* Test the simple commands like moveto and lineto: MmZzLlHhVv. */
@@ -93,55 +96,34 @@
 			      "stroke-color", "red",
 			      "line-width", 5.0,
 			      NULL);
+
+  return canvas_model;
 }
 
 
 GtkWidget *
 create_paths_page (void)
 {
-  GtkWidget *vbox, *alignment, *frame, *label, *canvas, *scrolled_win;
+  GtkWidget *vbox, *scrolled_win, *canvas;
   GooCanvasModelSimple *canvas_model;
-  GtkAdjustment *hadj, *vadj;
 
   vbox = gtk_vbox_new (FALSE, 4);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
   gtk_widget_show (vbox);
 
-  /* Instructions */
-
-  label = gtk_label_new ("Demo Paths");
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-  /*gtk_widget_show (label);*/
-
-  /* Frame and canvas */
-
-  alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-  gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
-  gtk_widget_show (alignment);
-
-  frame = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  gtk_container_add (GTK_CONTAINER (alignment), frame);
-  gtk_widget_show (frame);
+  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_view_new ();
-
-  canvas_model = goo_canvas_model_simple_new ();
-
   gtk_widget_set_size_request (canvas, 600, 450);
   goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (canvas), 0, 0, 1000, 1000);
   gtk_widget_show (canvas);
-
-  hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1000, 10, 100, 100));
-  vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1000, 10, 100, 100));
-  scrolled_win = gtk_scrolled_window_new (hadj, vadj);
-  gtk_widget_show (scrolled_win);
-  gtk_container_add (GTK_CONTAINER (frame), scrolled_win);
-
   gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);
 
-  create_paths (canvas_model);
-
+  canvas_model = create_canvas_model ();
   goo_canvas_view_set_model (GOO_CANVAS_VIEW (canvas),
 			     GOO_CANVAS_MODEL (canvas_model));
   g_object_unref (canvas_model);

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


static GooCanvasModelSimple* create_canvas_model (void);
static void on_item_view_created (GooCanvasView     *view,
				  GooCanvasItemView *item_view,
				  GooCanvasItem     *item,
				  gpointer           data);
static gboolean on_rect_button_press (GooCanvasItemView *view,
				      GooCanvasItemView *target,
				      GdkEventButton    *event,
				      gpointer           data);
static gboolean on_delete_event  (GtkWidget         *window,
				  GdkEvent          *event,
				  gpointer           unused_data);


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

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

  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 (window), scrolled_win);

  canvas = goo_canvas_view_new ();
  gtk_widget_set_size_request (canvas, 600, 450);
  goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);

  /* Connect to the "item-view-created" signal so we can connect signal
     handlers to the item views. */
  g_signal_connect (canvas, "item_view_created",
		    (GtkSignalFunc) on_item_view_created,
		    NULL);

  /* Create the canvas model */
  canvas_model = create_canvas_model ();
  goo_canvas_view_set_model (GOO_CANVAS_VIEW (canvas),
			     GOO_CANVAS_MODEL (canvas_model));
  g_object_unref (canvas_model);

  /* Pass control to the GTK+ main event loop. */
  gtk_main ();

  return 0;
}


/* The creates & returns a simple canvas model with a few simple items. */
static GooCanvasModelSimple*
create_canvas_model (void)
{
  GooCanvasModelSimple *canvas_model;
  GooCanvasItem *root, *item;

  canvas_model = goo_canvas_model_simple_new ();

  root = goo_canvas_model_get_root_item (GOO_CANVAS_MODEL (canvas_model));

  /* Add a few simple items. */
  item = goo_canvas_rect_new (root, 100, 100, 400, 400,
			      "line-width", 10.0,
			      "radius-x", 20.0,
			      "radius-y", 10.0,
			      "stroke-color", "yellow",
			      "fill-color", "red",
			      NULL);

  item = goo_canvas_text_new (root, "Hello World", 300, 300, -1,
			      GTK_ANCHOR_CENTER,
			      "font", "Sans 24",
			      NULL);
  goo_canvas_item_rotate (item, 45, 300, 300);

  return canvas_model;
}


/* This is our handler for the "item-view-created" signal of the GooCanvasView.
   We connect to the "button-press-event" signal of new rect views. */
static void
on_item_view_created (GooCanvasView     *view,
		      GooCanvasItemView *item_view,
		      GooCanvasItem     *item,
		      gpointer           data)
{
  if (GOO_IS_CANVAS_RECT (item))
    g_signal_connect (item_view, "button_press_event",
		      (GtkSignalFunc) on_rect_button_press, NULL);
}


/* This handles button presses in item views. We simply output a message to
   the console. */
static gboolean
on_rect_button_press (GooCanvasItemView *view,
		      GooCanvasItemView *target,
		      GdkEventButton *event,
		      gpointer data)
{
  g_print ("rect item received button press event\n");
  return TRUE;
}


/* This is our handler for the "delete-event" signal of the window, which
   is emitted when the 'x' close button is clicked. We just exit here. */
static gboolean
on_delete_event (GtkWidget *window,
		 GdkEvent  *event,
		 gpointer   unused_data)
{
  exit (0);
}



More information about the cairo-commit mailing list