[cairo-commit] goocanvas/src goocanvasview.c,1.11,1.12

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


Committed by: damon

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

Modified Files:
	goocanvasview.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: goocanvasview.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasview.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- goocanvasview.c	16 Apr 2006 13:20:05 -0000	1.11
+++ goocanvasview.c	16 Apr 2006 21:00:54 -0000	1.12
@@ -11,6 +11,114 @@
  * @Short_Description: the main canvas widget.
  *
  * #GooCanvasView is the main widget containing the view of the canvas model.
+ *
+ *
+ * Here is a simple example:
+ *
+ * <informalexample><programlisting>
+ *  &num;include &lt;goocanvas.h&gt;
+ *  
+ *  int
+ *  main (int argc, char *argv[])
+ *  {
+ *    GtkWidget *window, *scrolled_win, *canvas;
+ *    GooCanvasModelSimple *canvas_model;
+ *  
+ *    /&ast; Initialize GTK+. &ast;/
+ *    gtk_set_locale ();
+ *    gtk_init (&amp;argc, &amp;argv);
+ *  
+ *    /&ast; Create the window and widgets. &ast;/
+ *    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ *    gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
+ *    gtk_widget_show (window);
+ *  
+ *    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&nbsp;();
+ *    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);
+ *  
+ *    /&ast; Connect to the "item-view-created" signal so we can connect signal
+ *       handlers to the item views. &ast;/
+ *    g_signal_connect (canvas, "item_view_created",
+ *                      (GtkSignalFunc) on_item_view_created,
+ *                      NULL);
+ *  
+ *    /&ast; Create the canvas model &ast;/
+ *    canvas_model = create_canvas_model ();
+ *    goo_canvas_view_set_model (GOO_CANVAS_VIEW (canvas),
+ *                               GOO_CANVAS_MODEL (canvas_model));
+ *    g_object_unref (canvas_model);
+ *  
+ *    gtk_main ();
+ *    return 0;
+ *  }
+ *  
+ *  
+ *  /&ast; The creates &amp; returns a simple canvas model with a few simple items. &ast;/
+ *  static GooCanvasModelSimple*
+ *  create_canvas_model (void)
+ *  {
+ *    GooCanvasModelSimple *canvas_model;
+ *    GooCanvasItem *root, *item;
+ *  
+ *    canvas_model = goo_canvas_model_simple_new&nbsp;();
+ *  
+ *    root = goo_canvas_model_get_root_item (GOO_CANVAS_MODEL (canvas_model));
+ *  
+ *    /&ast; Add a few simple items. &ast;/
+ *    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;
+ *  }
+ *  
+ *  
+ *  /&ast; 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. &ast;/
+ *  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);
+ *  }
+ *  
+ *  
+ *  /&ast; This handles button presses in item views. We simply output a message to
+ *     the console. &ast;/
+ *  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;
+ *  }
+ * </programlisting></informalexample>
+ *
  */
 #include <config.h>
 #include <gtk/gtk.h>



More information about the cairo-commit mailing list