[cairo-commit] goocanvas/docs creating-items.xml, 1.1,
1.2 goocanvas-sections.txt, 1.20, 1.21 model-view-canvas.xml,
1.1, 1.2 simple-canvas.xml, 1.1, 1.2
Damon Chaplin
commit at pdx.freedesktop.org
Fri Feb 9 05:41:08 PST 2007
- Previous message: [cairo-commit] goocanvas/demo demo-item.c,1.2,1.3
- Next message: [cairo-commit] goocanvas/src Makefile.am, 1.12, 1.13 goocanvas.h,
1.5, 1.6 goocanvasellipse.h, 1.3, 1.4 goocanvasgroup.h, 1.9,
1.10 goocanvasimage.h, 1.3, 1.4 goocanvasitem.h, 1.11,
1.12 goocanvasitemmodel.h, 1.4, 1.5 goocanvasitemsimple.h,
1.15, 1.16 goocanvaspath.h, 1.6, 1.7 goocanvaspolyline.h, 1.5,
1.6 goocanvasrect.h, 1.3, 1.4 goocanvasstyle.h, 1.3,
1.4 goocanvastable.h, 1.3, 1.4 goocanvastext.h, 1.4,
1.5 goocanvaswidget.h, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: damon
Update of /cvs/cairo/goocanvas/docs
In directory kemper:/tmp/cvs-serv1492/docs
Modified Files:
creating-items.xml goocanvas-sections.txt
model-view-canvas.xml simple-canvas.xml
Log Message:
2007-02-09 Damon Chaplin <damon at gnome.org>
* demo/demo-item.c (goo_demo_item_update): don't convert bounds to
device space.
* src/*.h: added padding to all *Class structs, to allow a bit of
expansion without breaking backwards compatibility.
* docs/*.xml: added example code to the introductory sections.
Needs more explanation at some point.
* configure.in:
* src/Makefile.am: added libtool version numbers.
Index: creating-items.xml
===================================================================
RCS file: /cvs/cairo/goocanvas/docs/creating-items.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- creating-items.xml 8 Feb 2007 22:56:45 -0000 1.1
+++ creating-items.xml 9 Feb 2007 13:41:03 -0000 1.2
@@ -16,7 +16,215 @@
<refsect1 id="new-items-overview">
<title>How to Create New Canvas Items</title>
<para>
- ... unfinished ...
+ Here's an example of how to create a new simple canvas item. (Note that
+ this item doesn't have a model-view split.)
+ </para>
+ <para>
+ Here's the header file - a fairly standard GObject header file.
+ Our item derives from #GooCanvasItemSimple and just has its own
+ x, y, width and height variables:
</para>
+
+<informalexample><programlisting>
+ /*
+ * GooCanvas Demo. Copyright (C) 2006 Damon Chaplin.
+ * Released under the GNU LGPL license. See COPYING for details.
+ *
+ * demo-item.c - a simple demo item.
+ */
+ #ifndef __GOO_DEMO_ITEM_H__
+ #define __GOO_DEMO_ITEM_H__
+
+ #include <gtk/gtk.h>
+ #include "goocanvasitemsimple.h"
+
+ G_BEGIN_DECLS
+
+
+ #define GOO_TYPE_DEMO_ITEM (goo_demo_item_get_type ())
+ #define GOO_DEMO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_DEMO_ITEM, GooDemoItem))
+ #define GOO_DEMO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_DEMO_ITEM, GooDemoItemClass))
+ #define GOO_IS_DEMO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_DEMO_ITEM))
+ #define GOO_IS_DEMO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_DEMO_ITEM))
+ #define GOO_DEMO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_DEMO_ITEM, GooDemoItemClass))
+
+
+ typedef struct _GooDemoItem GooDemoItem;
+ typedef struct _GooDemoItemClass GooDemoItemClass;
+
+ struct _GooDemoItem
+ {
+ GooCanvasItemSimple parent_object;
+
+ gdouble x, y, width, height;
+ };
+
+ struct _GooDemoItemClass
+ {
+ GooCanvasItemSimpleClass parent_class;
+ };
+
+
+ GType goo_demo_item_get_type (void) G_GNUC_CONST;
+
+ GooCanvasItem* goo_demo_item_new (GooCanvasItem *parent,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ ...);
+
+
+ G_END_DECLS
+
+ #endif /* __GOO_DEMO_ITEM_H__ */
+ </programlisting></informalexample>
+
+<para>
+And here's the source file:
+</para>
+
+<informalexample><programlisting>
+ /*
+ * GooCanvas Demo. Copyright (C) 2006 Damon Chaplin.
+ * Released under the GNU LGPL license. See COPYING for details.
+ *
+ * demo-item.c - a simple demo item.
+ */
+ #include <config.h>
+ #include "goocanvas.h"
+ #include "demo-item.h"
+
+
+ /* Use the GLib convenience macro to define the type. GooDemoItem is the
+ class struct, goo_demo_item is the function prefix, and our class is a
+ subclass of GOO_TYPE_CANVAS_ITEM_SIMPLE. */
+ G_DEFINE_TYPE (GooDemoItem, goo_demo_item, GOO_TYPE_CANVAS_ITEM_SIMPLE)
+
+
+ /* The standard object initialization function. */
+ static void
+ goo_demo_item_init (GooDemoItem *demo_item)
+ {
+ demo_item->x = 0.0;
+ demo_item->y = 0.0;
+ demo_item->width = 0.0;
+ demo_item->height = 0.0;
+ }
+
+
+ /* The convenience function to create new items. This should start with a
+ parent argument and end with a variable list of object properties to fit
+ in with the standard canvas items. */
+ GooCanvasItem*
+ goo_demo_item_new (GooCanvasItem *parent,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ ...)
+ {
+ GooCanvasItem *item;
+ GooDemoItem *demo_item;
+ const char *first_property;
+ va_list var_args;
+
+ item = g_object_new (GOO_TYPE_DEMO_ITEM, NULL);
+
+ demo_item = (GooDemoItem*) item;
+ demo_item->x = x;
+ demo_item->y = y;
+ demo_item->width = width;
+ demo_item->height = height;
+
+ va_start (var_args, height);
+ first_property = va_arg (var_args, char*);
+ if (first_property)
+ g_object_set_valist ((GObject*) item, first_property, var_args);
+ va_end (var_args);
+
+ if (parent)
+ {
+ goo_canvas_item_add_child (parent, item, -1);
+ g_object_unref (item);
+ }
+
+ return item;
+ }
+
+
+ /* The update method. This is called when the canvas is initially shown and
+ also whenever the object is updated and needs to change its size and/or
+ shape. It should calculate its new bounds in its own coordinate space,
+ storing them in simple->bounds. */
+ static void
+ goo_demo_item_update (GooCanvasItemSimple *simple,
+ cairo_t *cr)
+ {
+ GooDemoItem *demo_item = (GooDemoItem*) simple;
+
+ /* Compute the new bounds. */
+ simple->bounds.x1 = demo_item->x;
+ simple->bounds.y1 = demo_item->y;
+ simple->bounds.x2 = demo_item->x + demo_item->width;
+ simple->bounds.y2 = demo_item->y + demo_item->height;
+ }
+
+
+ /* The paint method. This should draw the item on the given cairo_t, using
+ the item's own coordinate space. */
+ static void
+ goo_demo_item_paint (GooCanvasItemSimple *simple,
+ cairo_t *cr,
+ GooCanvasBounds *bounds)
+ {
+ GooDemoItem *demo_item = (GooDemoItem*) simple;
+
+ cairo_move_to (cr, demo_item->x, demo_item->y);
+ cairo_line_to (cr, demo_item->x, demo_item->y + demo_item->height);
+ cairo_line_to (cr, demo_item->x + demo_item->width,
+ demo_item->y + demo_item->height);
+ cairo_line_to (cr, demo_item->x + demo_item->width, demo_item->y);
+ cairo_close_path (cr);
+ goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
+ cairo_fill (cr);
+ }
+
+
+ /* Hit detection. This should check if the given coordinate (in the item's
+ coordinate space) is within the item. If it is it should return the item,
+ otherwise it should return NULL. */
+ static GooCanvasItem*
+ goo_demo_item_get_item_at (GooCanvasItemSimple *simple,
+ gdouble x,
+ gdouble y,
+ cairo_t *cr,
+ gboolean is_pointer_event)
+ {
+ GooDemoItem *demo_item = (GooDemoItem*) simple;
+
+ if (x < demo_item->x || (x > demo_item->x + demo_item->width)
+ || y < demo_item->y || (y > demo_item->y + demo_item->height))
+ return NULL;
+
+ return (GooCanvasItem*) simple;
+ }
+
+
+ /* The class initialization function. Here we set the class' update(), paint()
+ and get_item_at() methods. */
+ static void
+ goo_demo_item_class_init (GooDemoItemClass *klass)
+ {
+ GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
+
+ simple_class->update = goo_demo_item_update;
+ simple_class->paint = goo_demo_item_paint;
+ simple_class->get_item_at = goo_demo_item_get_item_at;
+ }
+
+
+ </programlisting></informalexample>
+
</refsect1>
</refentry>
Index: goocanvas-sections.txt
===================================================================
RCS file: /cvs/cairo/goocanvas/docs/goocanvas-sections.txt,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- goocanvas-sections.txt 8 Feb 2007 17:54:25 -0000 1.20
+++ goocanvas-sections.txt 9 Feb 2007 13:41:03 -0000 1.21
@@ -112,6 +112,7 @@
<SUBSECTION>
goo_canvas_item_get_transform
goo_canvas_item_set_transform
+goo_canvas_item_set_simple_transform
goo_canvas_item_translate
goo_canvas_item_scale
goo_canvas_item_rotate
@@ -182,6 +183,7 @@
<SUBSECTION>
goo_canvas_item_model_get_transform
goo_canvas_item_model_set_transform
+goo_canvas_item_model_set_simple_transform
goo_canvas_item_model_translate
goo_canvas_item_model_scale
goo_canvas_item_model_rotate
Index: model-view-canvas.xml
===================================================================
RCS file: /cvs/cairo/goocanvas/docs/model-view-canvas.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- model-view-canvas.xml 8 Feb 2007 22:56:45 -0000 1.1
+++ model-view-canvas.xml 9 Feb 2007 13:41:03 -0000 1.2
@@ -16,7 +16,108 @@
<refsect1 id="model-view-overview">
<title>Model View Canvas Example</title>
<para>
- ... unfinished ...
+ Here's a complete example application that creates a model-view #GooCanvas
+ with a rectangle and a text item in it.
</para>
+
+<informalexample><programlisting>
+ #include <stdlib.h>
+ #include <goocanvas.h>
+
+
+ static gboolean on_rect_button_press (GooCanvasItem *view,
+ GooCanvasItem *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;
+ GooCanvasItemModel *root, *rect_model, *text_model;
+ GooCanvasItem *rect_item;
+
+ /* 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_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);
+
+ root = goo_canvas_group_model_new (NULL, NULL);
+
+ /* Add a few simple items. */
+ rect_model = goo_canvas_rect_model_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);
+
+ text_model = goo_canvas_text_model_new (root, "Hello World", 300, 300, -1,
+ GTK_ANCHOR_CENTER,
+ "font", "Sans 24",
+ NULL);
+ goo_canvas_item_model_rotate (text_model, 45, 300, 300);
+
+ goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root);
+
+ /* Connect a signal handler for the rectangle item. */
+ rect_item = goo_canvas_get_item (GOO_CANVAS (canvas), rect_model);
+ g_signal_connect (rect_item, "button_press_event",
+ (GtkSignalFunc) on_rect_button_press, NULL);
+
+ /* Pass control to the GTK+ main event loop. */
+ gtk_main ();
+
+ return 0;
+ }
+
+
+ /* This handles button presses in item views. We simply output a message to
+ the console. */
+ static gboolean
+ on_rect_button_press (GooCanvasItem *item,
+ GooCanvasItem *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);
+ }
+ </programlisting></informalexample>
</refsect1>
</refentry>
Index: simple-canvas.xml
===================================================================
RCS file: /cvs/cairo/goocanvas/docs/simple-canvas.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- simple-canvas.xml 8 Feb 2007 22:56:45 -0000 1.1
+++ simple-canvas.xml 9 Feb 2007 13:41:03 -0000 1.2
@@ -16,7 +16,106 @@
<refsect1 id="simple-canvas-example">
<title>Simple Canvas Example</title>
<para>
- ... unfinished ...
+ Here's a complete example application that creates a #GooCanvas with a
+ rectangle and a text item in it:
</para>
+
+<informalexample><programlisting>
+ #include <stdlib.h>
+ #include <goocanvas.h>
+
+
+ static gboolean on_rect_button_press (GooCanvasItem *view,
+ GooCanvasItem *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;
+ GooCanvasItem *root, *rect_item, *text_item;
+
+ /* 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_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);
+
+ root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
+
+ /* Add a few simple items. */
+ rect_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);
+
+ text_item = goo_canvas_text_new (root, "Hello World", 300, 300, -1,
+ GTK_ANCHOR_CENTER,
+ "font", "Sans 24",
+ NULL);
+ goo_canvas_item_rotate (text_item, 45, 300, 300);
+
+ /* Connect a signal handler for the rectangle item. */
+ g_signal_connect (rect_item, "button_press_event",
+ (GtkSignalFunc) on_rect_button_press, NULL);
+
+ /* Pass control to the GTK+ main event loop. */
+ gtk_main ();
+
+ return 0;
+ }
+
+
+ /* This handles button presses in item views. We simply output a message to
+ the console. */
+ static gboolean
+ on_rect_button_press (GooCanvasItem *item,
+ GooCanvasItem *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);
+ }
+ </programlisting></informalexample>
+
+
</refsect1>
</refentry>
- Previous message: [cairo-commit] goocanvas/demo demo-item.c,1.2,1.3
- Next message: [cairo-commit] goocanvas/src Makefile.am, 1.12, 1.13 goocanvas.h,
1.5, 1.6 goocanvasellipse.h, 1.3, 1.4 goocanvasgroup.h, 1.9,
1.10 goocanvasimage.h, 1.3, 1.4 goocanvasitem.h, 1.11,
1.12 goocanvasitemmodel.h, 1.4, 1.5 goocanvasitemsimple.h,
1.15, 1.16 goocanvaspath.h, 1.6, 1.7 goocanvaspolyline.h, 1.5,
1.6 goocanvasrect.h, 1.3, 1.4 goocanvasstyle.h, 1.3,
1.4 goocanvastable.h, 1.3, 1.4 goocanvastext.h, 1.4,
1.5 goocanvaswidget.h, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list