[goocanvas/new-api] 2010-06-30 Damon Chaplin <damon gnome org>
- From: Damon Chaplin <damon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/new-api] 2010-06-30 Damon Chaplin <damon gnome org>
- Date: Thu, 1 Jul 2010 11:49:21 +0000 (UTC)
commit b27d6438d17384ea2b2276c08cc29a9b19416a7b
Author: Damon Chaplin <damon gnome org>
Date: Wed Jun 30 15:42:25 2010 +0100
2010-06-30 Damon Chaplin <damon gnome org>
* src/goocanvas.c (goo_canvas_update_items_using_style): new function
to update items when they are using a shared style.
* demo/demo.c: added "Change Style" button to test the above.
ChangeLog | 7 ++++++
demo/demo.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++-------
src/goocanvas.c | 46 +++++++++++++++++++++++++++++++++++++++++++
src/goocanvas.h | 5 ++++
4 files changed, 108 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b68dd22..a74450f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-06-30 Damon Chaplin <damon gnome org>
+ * src/goocanvas.c (goo_canvas_update_items_using_style): new function
+ to update items when they are using a shared style.
+
+ * demo/demo.c: added "Change Style" button to test the above.
+
+2010-06-30 Damon Chaplin <damon gnome org>
+
* demo/scalability-demo.c: fixed the USE_PIXMAP test.
2010-06-30 Damon Chaplin <damon gnome org>
diff --git a/demo/demo.c b/demo/demo.c
index 0e55bcb..70879bb 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -22,6 +22,8 @@ static GooCanvasItem *ellipse2, *textitem;
static gboolean dragging = FALSE;
static double drag_x, drag_y;
+static GooCanvasStyle *diamond_style = NULL;
+
static void setup_canvas (GooCanvas *canvas);
GtkWidget *create_canvas_fifteen (void);
GtkWidget *create_canvas_features (void);
@@ -196,6 +198,41 @@ change_bounds_clicked (GtkWidget *button, GooCanvas *canvas)
static void
+change_style_clicked (GtkWidget *button, GooCanvas *canvas)
+{
+ static gint last_state = 0;
+
+ if (last_state == 0)
+ {
+ g_object_set (diamond_style,
+ "line-width", 3.0,
+ "stroke-color", "orange",
+ NULL);
+ goo_canvas_update_items_using_style (canvas, diamond_style, TRUE);
+ last_state = 1;
+ }
+ else if (last_state == 1)
+ {
+ g_object_set (diamond_style,
+ "line-width", 1.0,
+ "stroke-color", "red",
+ NULL);
+ goo_canvas_update_items_using_style (canvas, diamond_style, TRUE);
+ last_state = 2;
+ }
+ else
+ {
+ g_object_set (diamond_style,
+ "stroke-color", "black",
+ "line-width", 1.0,
+ NULL);
+ goo_canvas_update_items_using_style (canvas, diamond_style, FALSE);
+ last_state = 0;
+ }
+}
+
+
+static void
move_ellipse_clicked (GtkWidget *button, GooCanvas *canvas)
{
static int last_state = 0;
@@ -609,6 +646,13 @@ create_canvas_primitives ()
G_CALLBACK (change_bounds_clicked),
canvas);
+ w = gtk_button_new_with_label("Change Style");
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+ g_signal_connect (w, "clicked",
+ G_CALLBACK (change_style_clicked),
+ canvas);
+
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
@@ -988,7 +1032,6 @@ static void
polish_diamond (GooCanvasItem *root)
{
GooCanvasItem *group, *item;
- GooCanvasStyle *style;
int i, j;
double a, x1, y1, x2, y2;
@@ -996,10 +1039,10 @@ polish_diamond (GooCanvasItem *root)
goo_canvas_item_translate (group, 270, 230);
setup_item_signals (group);
- style = g_object_new (GOO_TYPE_CANVAS_STYLE,
- "line-width", 1.0,
- "line-cap", CAIRO_LINE_CAP_ROUND,
- NULL);
+ diamond_style = g_object_new (GOO_TYPE_CANVAS_STYLE,
+ "line-width", 1.0,
+ "line-cap", CAIRO_LINE_CAP_ROUND,
+ NULL);
for (i = 0; i < VERTICES; i++) {
a = 2.0 * M_PI * i / VERTICES;
@@ -1011,11 +1054,10 @@ polish_diamond (GooCanvasItem *root)
x2 = RADIUS * cos (a);
y2 = RADIUS * sin (a);
item = goo_canvas_polyline_new_line (group, x1, y1, x2, y2, NULL);
- goo_canvas_item_simple_set_style ((GooCanvasItemSimple*) item, style);
+ goo_canvas_item_simple_set_style ((GooCanvasItemSimple*) item,
+ diamond_style);
}
}
-
- g_object_unref (style);
}
diff --git a/src/goocanvas.c b/src/goocanvas.c
index 923ab55..759da94 100644
--- a/src/goocanvas.c
+++ b/src/goocanvas.c
@@ -4013,3 +4013,49 @@ goo_canvas_query_tooltip (GtkWidget *widget,
return GTK_WIDGET_CLASS (goo_canvas_parent_class)->query_tooltip (widget, x, y, keyboard_tip, tooltip);
}
+
+static void
+goo_canvas_update_items_using_style_recurse (GooCanvasItem *item,
+ GooCanvasStyle *style,
+ gboolean recompute_bounds)
+{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
+ gint n_children, i;
+
+ if (GOO_IS_CANVAS_ITEM_SIMPLE (item) && simple->style == style)
+ goo_canvas_item_simple_changed (simple, TRUE);
+
+ n_children = goo_canvas_item_get_n_children (item);
+ for (i = 0; i < n_children; i++)
+ {
+ GooCanvasItem *child = goo_canvas_item_get_child (item, i);
+ goo_canvas_update_items_using_style_recurse (child, style,
+ recompute_bounds);
+ }
+}
+
+
+/**
+ * goo_canvas_update_items_using_style:
+ * @canvas: a #GooCanvas.
+ * @style: a #GooCanvasStyle.
+ * @recompute_bounds: %TRUE if the bounds of the items should be recomputed,
+ * e.g. if the line width has been changed.
+ *
+ * Requests an update of all canvas items using the given style.
+ * This function must be called when many items are using a shared
+ * #GooCanvasStyle which has been changed.
+ **/
+void
+goo_canvas_update_items_using_style (GooCanvas *canvas,
+ GooCanvasStyle *style,
+ gboolean recompute_bounds)
+{
+ if (canvas->root_item)
+ goo_canvas_update_items_using_style_recurse (canvas->root_item,
+ style, recompute_bounds);
+
+ if (canvas->static_root_item)
+ goo_canvas_update_items_using_style_recurse (canvas->static_root_item,
+ style, recompute_bounds);
+}
diff --git a/src/goocanvas.h b/src/goocanvas.h
index a5d060f..7a9d48e 100644
--- a/src/goocanvas.h
+++ b/src/goocanvas.h
@@ -236,6 +236,11 @@ void goo_canvas_render (GooCanvas *canvas,
const GooCanvasBounds *bounds,
gdouble scale);
+void goo_canvas_update_items_using_style (GooCanvas *canvas,
+ GooCanvasStyle *style,
+ gboolean recompute_bounds);
+
+
/*
* Coordinate conversion.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]