Top |
GooCanvasAnchorType | anchor | Read / Write |
gboolean | automatic-bounds | Read / Write |
gchar * | background-color | Write |
GdkRGBA * | background-color-gdk-rgba | Write |
guint | background-color-rgb | Write |
gboolean | bounds-from-origin | Read / Write |
gdouble | bounds-padding | Read / Write |
gboolean | clear-background | Read / Write |
gboolean | integer-layout | Read / Write |
gboolean | redraw-when-scrolled | Read / Write |
gdouble | resolution-x | Read / Write |
gdouble | resolution-y | Read / Write |
gdouble | scale | Read / Write |
gdouble | scale-x | Read / Write |
gdouble | scale-y | Read / Write |
GtkUnit | units | Read / Write |
gdouble | x1 | Read / Write |
gdouble | x2 | Read / Write |
gdouble | y1 | Read / Write |
gdouble | y2 | Read / Write |
GooCanvas is the main widget containing a number of canvas items.
Here is a simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
#include <goocanvas.h> 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; /* Initialize GTK+. */ 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", 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 (); 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, GOO_CANVAS_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", G_CALLBACK (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; } |
A GooCanvas widget is usually placed inside a GtkScrolledWindow widget and can be scrolled with the scrollbar or with the scroll wheel on a mouse. To disable mouse wheel scrolling, do this:
1 |
g_signal_connect (canvas, "scroll-event", G_CALLBACK (gtk_true), NULL); |
GtkWidget *
goo_canvas_new (void
);
Creates a new GooCanvas widget.
A GooCanvasGroup is created automatically as the root item of the canvas,
though this can be overriden with goo_canvas_set_root_item()
or
goo_canvas_set_root_item_model()
.
GooCanvasItem *
goo_canvas_get_root_item (GooCanvas *canvas
);
Gets the root item of the canvas, usually a GooCanvasGroup.
void goo_canvas_set_root_item (GooCanvas *canvas
,GooCanvasItem *item
);
Sets the root item of the canvas. Any existing canvas items are removed.
GooCanvasItemModel *
goo_canvas_get_root_item_model (GooCanvas *canvas
);
Gets the root item model of the canvas.
void goo_canvas_set_root_item_model (GooCanvas *canvas
,GooCanvasItemModel *model
);
Sets the root item model of the canvas.
A hierarchy of canvas items will be created, corresponding to the hierarchy of items in the model. Any current canvas items will be removed.
GooCanvasItem *
goo_canvas_get_static_root_item (GooCanvas *canvas
);
Gets the static root item of the canvas.
Static items are exactly the same as ordinary canvas items, except that they do not move or change size when the canvas is scrolled or the scale changes.
Static items are added to the static root item in exactly the same way that ordinary items are added to the root item.
void goo_canvas_set_static_root_item (GooCanvas *canvas
,GooCanvasItem *item
);
Sets the static root item. Any existing static items are removed.
Static items are exactly the same as ordinary canvas items, except that they do not move or change size when the canvas is scrolled or the scale changes.
Static items are added to the static root item in exactly the same way that ordinary items are added to the root item.
GooCanvasItemModel *
goo_canvas_get_static_root_item_model (GooCanvas *canvas
);
Gets the static root item model of the canvas.
Static item models are exactly the same as ordinary item models, except that the corresponding items do not move or change size when the canvas is scrolled or the scale changes.
Static items models are added to the static root item model in exactly the same way that ordinary item models are added to the root item model.
void goo_canvas_set_static_root_item_model (GooCanvas *canvas
,GooCanvasItemModel *model
);
Sets the static root item model. Any existing static item models are removed.
Static item models are exactly the same as ordinary item models, except that the corresponding items do not move or change size when the canvas is scrolled or the scale changes.
Static items models are added to the static root item model in exactly the same way that ordinary item models are added to the root item model.
void goo_canvas_get_bounds (GooCanvas *canvas
,gdouble *left
,gdouble *top
,gdouble *right
,gdouble *bottom
);
Gets the bounds of the canvas, in canvas units.
By default, canvas units are pixels, though the “units” property can be used to change the units to points, inches or millimeters.
canvas |
a GooCanvas. |
|
left |
a pointer to a gdouble to return the left edge, or |
[out][allow-none] |
top |
a pointer to a gdouble to return the top edge, or |
[out][allow-none] |
right |
a pointer to a gdouble to return the right edge, or |
[out][allow-none] |
bottom |
a pointer to a gdouble to return the bottom edge, or |
[out][allow-none] |
void goo_canvas_set_bounds (GooCanvas *canvas
,gdouble left
,gdouble top
,gdouble right
,gdouble bottom
);
Sets the bounds of the GooCanvas, in canvas units.
By default, canvas units are pixels, though the “units” property can be used to change the units to points, inches or millimeters.
canvas |
a GooCanvas. |
|
left |
the left edge. |
|
top |
the top edge. |
|
right |
the right edge. |
|
bottom |
the bottom edge. |
gdouble
goo_canvas_get_scale (GooCanvas *canvas
);
Gets the current scale of the canvas.
The scale specifies the magnification factor of the canvas, e.g. if an item has a width of 2 pixels and the scale is set to 3, it will be displayed with a width of 2 x 3 = 6 pixels.
void goo_canvas_set_scale (GooCanvas *canvas
,gdouble scale
);
Sets the scale of the canvas.
The scale specifies the magnification factor of the canvas, e.g. if an item has a width of 2 pixels and the scale is set to 3, it will be displayed with a width of 2 x 3 = 6 pixels.
GooCanvasItem * goo_canvas_get_item (GooCanvas *canvas
,GooCanvasItemModel *model
);
Gets the canvas item associated with the given GooCanvasItemModel.
This is only useful when goo_canvas_set_root_item_model()
has been used to
set a model for the canvas.
For simple applications you can use goo_canvas_get_item()
to set up
signal handlers for your items, e.g.
1 2 3 |
item = goo_canvas_get_item (GOO_CANVAS (canvas), my_item); g_signal_connect (item, "button_press_event", (GtkSignalFunc) on_my_item_button_press, NULL); |
More complex applications may want to use the “item-created” signal to hook up their signal handlers.
the canvas item corresponding to the given
GooCanvasItemModel, or NULL
if no canvas item has been created for it yet.
[transfer none]
GooCanvasItem * goo_canvas_get_item_at (GooCanvas *canvas
,gdouble x
,gdouble y
,gboolean is_pointer_event
);
Gets the item at the given point.
canvas |
a GooCanvas. |
|
x |
the x coordinate of the point. |
|
y |
the y coordinate of the point |
|
is_pointer_event |
|
GList * goo_canvas_get_items_at (GooCanvas *canvas
,gdouble x
,gdouble y
,gboolean is_pointer_event
);
Gets all items at the given point.
canvas |
a GooCanvas. |
|
x |
the x coordinate of the point. |
|
y |
the y coordinate of the point |
|
is_pointer_event |
|
GList * goo_canvas_get_items_in_area (GooCanvas *canvas
,const GooCanvasBounds *area
,gboolean inside_area
,gboolean allow_overlaps
,gboolean include_containers
);
Gets a list of items inside or outside a given area.
canvas |
a GooCanvas. |
|
area |
the area to compare with each item's bounds. |
|
inside_area |
|
|
allow_overlaps |
|
|
include_containers |
|
void goo_canvas_scroll_to (GooCanvas *canvas
,gdouble left
,gdouble top
);
Scrolls the canvas, placing the given point as close to the top-left of the view as possible.
canvas |
a GooCanvas. |
|
left |
the x coordinate to scroll to. |
|
top |
the y coordinate to scroll to. |
void goo_canvas_render (GooCanvas *canvas
,cairo_t *cr
,const GooCanvasBounds *bounds
,gdouble scale
);
Renders all or part of a canvas to the given cairo context.
This example code could be used in a GtkPrintOperation
“draw-page” callback to print each page in a multi-page
document (assuming the pages appear one after the other vertically in the
canvas). Note the call to cairo_translate()
to translate the output to
the correct position on the printed page.
1 2 3 4 5 6 7 8 9 |
GooCanvasBounds bounds; bounds.x1 = 0; bounds.x2 = A4_PAGE_WIDTH; bounds.y1 = A4_PAGE_HEIGHT * page_num; bounds.y2 = A4_PAGE_HEIGHT * (page_num + 1); cr = gtk_print_context_get_cairo_context (print_context); cairo_translate (cr, 0, -A4_PAGE_HEIGHT * page_num); goo_canvas_render (GOO_CANVAS (canvas), cr, &bounds, 0.0); |
canvas |
a GooCanvas. |
|
cr |
a cairo context. |
|
bounds |
the area to render, or |
[allow-none] |
scale |
the scale to compare with each item's visibility
threshold to see if they should be rendered. This only affects items that
have their visibility set to |
void goo_canvas_convert_to_pixels (GooCanvas *canvas
,gdouble *x
,gdouble *y
);
Converts a coordinate from the canvas coordinate space to pixels.
The canvas coordinate space is specified in the call to
goo_canvas_set_bounds()
.
The pixel coordinate space specifies pixels from the top-left of the entire
canvas window, according to the current scale setting.
See goo_canvas_set_scale()
.
canvas |
a GooCanvas. |
|
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
void goo_canvas_convert_from_pixels (GooCanvas *canvas
,gdouble *x
,gdouble *y
);
Converts a coordinate from pixels to the canvas coordinate space.
The pixel coordinate space specifies pixels from the top-left of the entire
canvas window, according to the current scale setting.
See goo_canvas_set_scale()
.
The canvas coordinate space is specified in the call to
goo_canvas_set_bounds()
.
canvas |
a GooCanvas. |
|
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
void goo_canvas_convert_to_item_space (GooCanvas *canvas
,GooCanvasItem *item
,gdouble *x
,gdouble *y
);
Converts a coordinate from the canvas coordinate space to the given item's coordinate space, applying all transformation matrices including the item's own transformation matrix, if it has one.
canvas |
a GooCanvas. |
|
item |
||
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
void goo_canvas_convert_from_item_space (GooCanvas *canvas
,GooCanvasItem *item
,gdouble *x
,gdouble *y
);
Converts a coordinate from the given item's coordinate space to the canvas coordinate space, applying all transformation matrices including the item's own transformation matrix, if it has one.
canvas |
a GooCanvas. |
|
item |
||
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
void goo_canvas_convert_bounds_to_item_space (GooCanvas *canvas
,GooCanvasItem *item
,GooCanvasBounds *bounds
);
Converts the given bounds in the canvas coordinate space to a bounding box
in item space. This is useful in the item paint()
methods to convert the
bounds to be painted to the item's coordinate space.
void goo_canvas_convert_units_to_pixels (GooCanvas *canvas
,gdouble *x
,gdouble *y
);
Converts a coordinate from the canvas's units to pixels,
ignoring scaling and ignoring the coordinate space specified
in the call to goo_canvas_set_bounds()
.
canvas |
a GooCanvas. |
|
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
Since: 2.0.1
void goo_canvas_convert_units_from_pixels (GooCanvas *canvas
,gdouble *x
,gdouble *y
);
Converts a coordinate from pixels to the canvas's units,
ignoring scaling and ignoring the coordinate space specified
in the call to goo_canvas_set_bounds()
.
canvas |
a GooCanvas. |
|
x |
a pointer to the x coordinate to convert. |
[inout] |
y |
a pointer to the y coordinate to convert. |
[inout] |
Since: 2.0.1
GdkGrabStatus goo_canvas_pointer_grab (GooCanvas *canvas
,GooCanvasItem *item
,GdkEventMask event_mask
,GdkCursor *cursor
,guint32 time
);
Attempts to grab the pointer for the given item.
canvas |
a GooCanvas. |
|
item |
the item to grab the pointer for. |
|
event_mask |
the events to receive during the grab. |
|
cursor |
the cursor to display during the grab, or NULL. |
|
time |
the time of the event that lead to the pointer grab. This should come from the relevant GdkEvent. |
void goo_canvas_pointer_ungrab (GooCanvas *canvas
,GooCanvasItem *item
,guint32 time
);
Ungrabs the pointer, if the given item has the pointer grab.
canvas |
a GooCanvas. |
|
item |
the item that has the grab. |
|
time |
the time of the event that lead to the pointer ungrab. This should come from the relevant GdkEvent. |
void goo_canvas_grab_focus (GooCanvas *canvas
,GooCanvasItem *item
);
Grabs the keyboard focus for the given item.
GdkGrabStatus goo_canvas_keyboard_grab (GooCanvas *canvas
,GooCanvasItem *item
,gboolean owner_events
,guint32 time
);
Attempts to grab the keyboard for the given item.
canvas |
a GooCanvas. |
|
item |
the item to grab the keyboard for. |
|
owner_events |
|
|
time |
the time of the event that lead to the keyboard grab. This should come from the relevant GdkEvent. |
void goo_canvas_keyboard_ungrab (GooCanvas *canvas
,GooCanvasItem *item
,guint32 time
);
Ungrabs the keyboard, if the given item has the keyboard grab.
canvas |
a GooCanvas. |
|
item |
the item that has the keyboard grab. |
|
time |
the time of the event that lead to the keyboard ungrab. This should come from the relevant GdkEvent. |
cairo_t *
goo_canvas_create_cairo_context (GooCanvas *canvas
);
Creates a cairo context, initialized with the default canvas settings. Note that this context should not be used for drawing. It should only be used for calculating bounds of items.
GooCanvasItem * goo_canvas_create_item (GooCanvas *canvas
,GooCanvasItemModel *model
);
This function is only intended to be used when implementing new canvas items, typically container items such as GooCanvasGroup.
It creates a new canvas item for the given item model, and recursively creates items for any children.
It uses the create_item()
virtual method if it has been set.
Subclasses of GooCanvas can define this method if they want to use
custom views for items.
It emits the “item-created” signal after creating the view, so application code can connect signal handlers to the new view if desired.
void goo_canvas_unregister_item (GooCanvas *canvas
,GooCanvasItemModel *model
);
This function is only intended to be used when implementing new canvas items.
It should be called in the finalize method of GooCanvasItem objects, to remove the canvas item from the GooCanvas's hash table.
void goo_canvas_register_widget_item (GooCanvas *canvas
,GooCanvasWidget *witem
);
This function should only be used by GooCanvasWidget and subclass implementations.
It registers a widget item with the canvas, so that the canvas can do the necessary actions to move and resize the widget as needed.
void goo_canvas_unregister_widget_item (GooCanvas *canvas
,GooCanvasWidget *witem
);
This function should only be used by GooCanvasWidget and subclass implementations.
It unregisters a widget item from the canvas, when the item is no longer in the canvas.
void
goo_canvas_update (GooCanvas *canvas
);
This function is only intended to be used by subclasses of GooCanvas or GooCanvasItem implementations.
It updates any items that need updating.
If the bounds of items change, they will request a redraw of the old and new bounds so the display is updated correctly.
void
goo_canvas_request_update (GooCanvas *canvas
);
This function is only intended to be used by subclasses of GooCanvas or GooCanvasItem implementations.
It schedules an update of the GooCanvas. This will be performed in the idle loop, after all pending events have been handled, but before the canvas has been repainted.
void goo_canvas_request_redraw (GooCanvas *canvas
,const GooCanvasBounds *bounds
);
This function is only intended to be used by subclasses of GooCanvas or GooCanvasItem implementations.
Requests that the given bounds be redrawn. The bounds must be in the canvas coordinate space.
void goo_canvas_request_item_redraw (GooCanvas *canvas
,const GooCanvasBounds *bounds
,gboolean is_static
);
This function is only intended to be used by subclasses of GooCanvas or GooCanvasItem implementations.
Requests that the given bounds be redrawn. If is_static
is TRUE
the bounds
are assumed to be in the static item coordinate space, otherwise they are
assumed to be in the canvas coordinate space.
If is_static
is FALSE
this function behaves the same as
goo_canvas_request_redraw()
.
canvas |
a GooCanvas. |
|
bounds |
the bounds of the item to redraw. |
|
is_static |
if the item is static. |
struct GooCanvasClass { GooCanvasItem* (* create_item) (GooCanvas *canvas, GooCanvasItemModel *model); /* Signals. */ void (* item_created) (GooCanvas *canvas, GooCanvasItem *item, GooCanvasItemModel *model); };
The GooCanvasClass struct contains one virtual method that subclasses may override.
“anchor”
property“anchor” GooCanvasAnchorType
Where to place the canvas when it is smaller than the widget's allocated area.
Flags: Read / Write
Default value: GOO_CANVAS_ANCHOR_NORTH_WEST
“automatic-bounds”
property “automatic-bounds” gboolean
If the bounds are automatically calculated based on the bounds of all the items in the canvas.
Flags: Read / Write
Default value: FALSE
“background-color”
property “background-color” gchar *
The color to use for the canvas background.
Flags: Write
Default value: NULL
“background-color-gdk-rgba”
property “background-color-gdk-rgba” GdkRGBA *
The color to use for the canvas background, specified as a GdkRGBA.
Flags: Write
Since: 2.0.1
“background-color-rgb”
property “background-color-rgb” guint
The color to use for the canvas background, specified as a 24-bit integer value, 0xRRGGBB.
Flags: Write
Default value: 0
“bounds-from-origin”
property “bounds-from-origin” gboolean
If the automatic bounds are calculated from the origin.
Flags: Read / Write
Default value: TRUE
“bounds-padding”
property “bounds-padding” gdouble
The padding added to the automatic bounds.
Flags: Read / Write
Allowed values: >= 0
Default value: 0
“clear-background”
property “clear-background” gboolean
If the background is cleared before the canvas is painted.
Flags: Read / Write
Default value: TRUE
“integer-layout”
property “integer-layout” gboolean
If all item layout is done to the nearest integer.
Flags: Read / Write
Default value: FALSE
“redraw-when-scrolled”
property “redraw-when-scrolled” gboolean
If the canvas is completely redrawn when scrolled, to reduce the flicker of static items. Note that since GTK+ 3.0 the canvas is always redrawn when scrolled, so this option has no effect.
Flags: Read / Write
Default value: FALSE
“resolution-x”
property “resolution-x” gdouble
The horizontal resolution of the display, in dots per inch.
Flags: Read / Write
Allowed values: >= 0
Default value: 96
“resolution-y”
property “resolution-y” gdouble
The vertical resolution of the display, in dots per inch.
Flags: Read / Write
Allowed values: >= 0
Default value: 96
“scale”
property “scale” gdouble
The magnification factor of the canvas.
Flags: Read / Write
Allowed values: >= 0
Default value: 1
“scale-x”
property “scale-x” gdouble
The horizontal magnification factor of the canvas.
Flags: Read / Write
Allowed values: >= 0
Default value: 1
“scale-y”
property “scale-y” gdouble
The vertical magnification factor of the canvas.
Flags: Read / Write
Allowed values: >= 0
Default value: 1
“units”
property “units” GtkUnit
The units to use for the canvas.
Flags: Read / Write
Default value: GTK_UNIT_NONE
“x1”
property “x1” gdouble
The x coordinate of the left edge of the canvas bounds, in canvas units.
Flags: Read / Write
Default value: 0
“x2”
property “x2” gdouble
The x coordinate of the right edge of the canvas bounds, in canvas units.
Flags: Read / Write
Default value: 1000
“y1”
property “y1” gdouble
The y coordinate of the top edge of the canvas bounds, in canvas units.
Flags: Read / Write
Default value: 0
“item-created”
signalvoid user_function (GooCanvas *canvas, GooCanvasItem *item, GooCanvasItemModel *model, gpointer user_data)
This is emitted when a new canvas item is created, in model/view mode.
Applications can set up signal handlers for the new items here.
canvas |
the canvas. |
|
item |
the new item. |
|
model |
the item's model. |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last