[goocanvas/group-manipulation] show example of group clipping and child move
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/group-manipulation] show example of group clipping and child move
- Date: Thu, 11 Feb 2021 01:30:34 +0000 (UTC)
commit 6d4637026e910976e72f5506ab8560d9bfe88303
Author: Alberto Fanjul <albertofanjul gmail com>
Date: Thu Feb 11 02:28:34 2021 +0100
show example of group clipping and child move
demo/generic-position-demo.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/demo/generic-position-demo.c b/demo/generic-position-demo.c
index 89686e4..b5cc593 100644
--- a/demo/generic-position-demo.c
+++ b/demo/generic-position-demo.c
@@ -77,9 +77,13 @@ on_motion_notify_event_cb (GooCanvasItem *item,
gdouble rel_x = event->x - drag_x;
gdouble rel_y = event->y - drag_y;
+ GooCanvasGroup *group;
+ group = g_object_get_data (G_OBJECT (item), "group");
if (drag_mode == MODE_MOVE)
{
g_object_set (G_OBJECT (item), "x", item_x + rel_x, "y", item_y + rel_y, NULL);
+ if (group)
+ g_object_set (G_OBJECT (group), "x", item_x + rel_x, "y", item_y + rel_y, NULL);
}
else
{
@@ -87,6 +91,8 @@ on_motion_notify_event_cb (GooCanvasItem *item,
gdouble new_height = MAX (item_height + rel_y, 5.0);
g_object_set (G_OBJECT (item), "width", new_width, "height", new_height, NULL);
+ if (group)
+ g_object_set (G_OBJECT (group), "width", new_width, "height", new_height, NULL);
}
return TRUE;
@@ -110,6 +116,7 @@ void
setup_canvas (GtkWidget *canvas)
{
GooCanvasItem *root;
+ GooCanvasGroup *group;
GooCanvasItem *item;
GdkPixbuf *pixbuf;
GtkWidget *button;
@@ -119,33 +126,38 @@ setup_canvas (GtkWidget *canvas)
/* Test clipping of GooCanvasGroup: We put the rectangle and the ellipse into
* a group with width=200 and height=200. */
- item = goo_canvas_group_new (root, "x", 50.0, "y", 350.0, "width", 200.0, "height", 200.0, NULL);
- /*goo_canvas_item_rotate(item, 45.0, 150.0, 450.0);*/
+ group = goo_canvas_group_new (root, "x", 50.0, "y", 350.0, "width", 200.0, "height", 200.0, NULL);
+ setup_dnd_handlers (GOO_CANVAS (canvas), group);
+ goo_canvas_item_rotate(group, 45.0, 150.0, 450.0);
+ item = goo_canvas_rect_new (root, 50.0, 350.0, 200.0, 200.0, "stroke-color", "black", "line-width", 2.0,
NULL);
+ g_object_set_data (G_OBJECT (item), "group", group);
+ setup_dnd_handlers (GOO_CANVAS (canvas), item);
+ goo_canvas_item_rotate(item, 45.0, 150.0, 450.0);
- child = goo_canvas_rect_new (item, 0.0, 0.0, 100, 100, "fill-color", "blue", NULL);
+ child = goo_canvas_rect_new (group, 0.0, 0.0, 100, 100, "fill-color", "blue", NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), child);
goo_canvas_item_rotate(child, 45.0, 50.0, 50.0);
- child = goo_canvas_ellipse_new (item, 150, 00, 50, 50, "fill-color", "red", NULL);
+ child = goo_canvas_ellipse_new (group, 150, 00, 50, 50, "fill-color", "red", NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), child);
- item = goo_canvas_polyline_new (root, FALSE, 5.0, 250.0, 350.0, 275.0, 400.0, 300.0, 350.0, 325.0, 400.0,
350.0, 350.0, "stroke-color", "cyan", "line-width", 5.0, NULL);
+ item = goo_canvas_polyline_new (group, FALSE, 5.0, 250.0, 350.0, 275.0, 400.0, 300.0, 350.0, 325.0, 400.0,
350.0, 350.0, "stroke-color", "cyan", "line-width", 5.0, NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
- item = goo_canvas_path_new (root, "M20,500 C20,450 100,450 100,500", "stroke-color", "green",
"line-width", 5.0, NULL);
+ item = goo_canvas_path_new (group, "M20,500 C20,450 100,450 100,500", "stroke-color", "green",
"line-width", 5.0, NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"dialog-warning", 48, 0, NULL);
- item = goo_canvas_image_new (root, pixbuf, 150, 450, /*"fill-color", "yellow", */NULL);
+ item = goo_canvas_image_new (group, pixbuf, 50, 50, /*"fill-color", "yellow", */NULL);
g_object_unref (pixbuf);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
- item = goo_canvas_text_new (root, "Hello, World!", 250, 450, -1, GOO_CANVAS_ANCHOR_NW, "fill-color",
"magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
+ item = goo_canvas_text_new (group, "Hello, World!", 75, 75, -1, GOO_CANVAS_ANCHOR_NW, "fill-color",
"magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
button = gtk_label_new ("GtkLabel");
- item = goo_canvas_widget_new (root, button, 50, 550, -1, -1, NULL);
+ item = goo_canvas_widget_new (group, button, 50, 550, -1, -1, NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
item = goo_canvas_table_new (root, "horz-grid-line-width", 2.0, "vert-grid-line-width", 2.0,
"row-spacing", 2.0, "column-spacing", 2.0, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]