Canvas


Object Hierarchy:

Goo.Canvas Goo.Canvas Goo.Canvas Gtk.Container Gtk.Container Gtk.Container->Goo.Canvas Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Goo.Canvas Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Goo.Canvas Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget Gtk.Scrollable Gtk.Scrollable Gtk.Scrollable->Goo.Canvas

Description:

[ CCode ( type_id = "goo_canvas_get_type ()" ) ]
public class Canvas : Container, Implementor, Buildable, Scrollable

Canvas is the main widget containing a number of canvas items.

Here is a simple example:

<informalexample><programlisting> &num;include &lt;goocanvas.h&gt;

static gboolean on_rect_button_press (GooCanvasItem *view, GooCanvasItem *target, GdkEventButton *event, gpointer data);

int main (int argc, char *argv[]) { GtkWidget *window, *scrolled_win, *canvas; GooCanvasItem *root, *rect_item, *text_item;

/&ast; Initialize GTK+. &ast;/ 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); g_signal_connect (window, "delete_event", G_CALLBACK (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&nbsp;(); 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));

/&ast; Add a few simple items. &ast;/ 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, GOO_CANVAS_ANCHOR_CENTER, "font", "Sans 24", NULL); goo_canvas_item_rotate (text_item, 45, 300, 300);

/&ast; Connect a signal handler for the rectangle item. &ast;/ g_signal_connect (rect_item, "button_press_event", G_CALLBACK ( on_rect_button_press), NULL);

/&ast; Pass control to the GTK+ main event loop. &ast;/ gtk_main&nbsp;();

return 0; }

/&ast; This handles button presses in item views. We simply output a message to the console. &ast;/ 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; }

</programlisting></informalexample>

A Canvas widget is usually placed inside a ScrolledWindow widget and can be scrolled with the scrollbar or with the scroll wheel on a mouse. To disable mouse wheel scrolling, do this: <informalexample>< programlisting> g_signal_connect (canvas, "scroll-event", G_CALLBACK (gtk_true), NULL); </programlisting></informalexample >


Namespace: Goo
Package: goocanvas-2.0

Content:

Properties:

Static methods:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.Container
All known members inherited from class Gtk.Widget
All known members inherited from class GLib.Object
All known members inherited from interface Atk.Implementor
All known members inherited from interface Gtk.Buildable
All known members inherited from interface Gtk.Scrollable



2022 vala-language.org