[AdgDim] Invalidate also the quote value text
[adg.git] / src / adg / adg-canvas.c
blob5cbdd69590debd7eb925d3ba64d0d34230e341c3
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-canvas
23 * @short_description: The drawing container
25 * This container represents the object where the rendering process draws. All
26 * the drawing must have a canvas, and only one, as master parent (as all the
27 * #GtkWidget must have a #GtkWindow).
29 * Internally, the target is mantained as a #cairo_t context pointer.
32 /**
33 * AdgCanvas:
35 * All fields are private and should not be used directly.
36 * Use its public methods instead.
37 **/
40 #include "adg-internal.h"
41 #include "adg-canvas.h"
42 #include "adg-canvas-private.h"
43 #include "adg-dress-builtins.h"
44 #include "adg-color-style.h"
46 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_canvas_parent_class)
49 enum {
50 PROP_0,
51 PROP_BACKGROUND_DRESS
54 static void _adg_get_property (GObject *object,
55 guint param_id,
56 GValue *value,
57 GParamSpec *pspec);
58 static void _adg_set_property (GObject *object,
59 guint param_id,
60 const GValue *value,
61 GParamSpec *pspec);
62 static void _adg_render (AdgEntity *entity,
63 cairo_t *cr);
66 G_DEFINE_TYPE(AdgCanvas, adg_canvas, ADG_TYPE_CONTAINER);
69 static void
70 adg_canvas_class_init(AdgCanvasClass *klass)
72 GObjectClass *gobject_class;
73 AdgEntityClass *entity_class;
74 GParamSpec *param;
76 gobject_class = (GObjectClass *) klass;
77 entity_class = (AdgEntityClass *) klass;
79 g_type_class_add_private(klass, sizeof(AdgCanvasPrivate));
81 gobject_class->get_property = _adg_get_property;
82 gobject_class->set_property = _adg_set_property;
84 entity_class->render = _adg_render;
86 param = adg_param_spec_dress("background-dress",
87 P_("Background Dress"),
88 P_("The color dress to use for the canvas background"),
89 ADG_DRESS_COLOR_BACKGROUND,
90 G_PARAM_READWRITE);
91 g_object_class_install_property(gobject_class, PROP_BACKGROUND_DRESS, param);
94 static void
95 adg_canvas_init(AdgCanvas *canvas)
97 AdgCanvasPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(canvas,
98 ADG_TYPE_CANVAS,
99 AdgCanvasPrivate);
101 data->background_dress = ADG_DRESS_COLOR_BACKGROUND;
103 canvas->data = data;
106 static void
107 _adg_get_property(GObject *object, guint prop_id,
108 GValue *value, GParamSpec *pspec)
110 AdgCanvasPrivate *data = ((AdgCanvas *) object)->data;
112 switch (prop_id) {
113 case PROP_BACKGROUND_DRESS:
114 g_value_set_int(value, data->background_dress);
115 break;
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
118 break;
122 static void
123 _adg_set_property(GObject *object, guint prop_id,
124 const GValue *value, GParamSpec *pspec)
126 AdgCanvas *canvas;
127 AdgCanvasPrivate *data;
129 canvas = (AdgCanvas *) object;
130 data = canvas->data;
132 switch (prop_id) {
133 case PROP_BACKGROUND_DRESS:
134 data->background_dress = g_value_get_int(value);
135 break;
136 default:
137 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
138 break;
144 * adg_canvas_new:
146 * Creates a new empty canvas object.
148 * Returns: the canvas
150 AdgCanvas *
151 adg_canvas_new(void)
153 return g_object_new(ADG_TYPE_CANVAS, NULL);
157 * adg_canvas_set_background_dress:
158 * @canvas: an #AdgCanvas
159 * @dress: the new #AdgDress to use
161 * Sets a new background dress for rendering @canvas: the new
162 * dress must be a color dress.
164 void
165 adg_canvas_set_background_dress(AdgCanvas *canvas, AdgDress dress)
167 g_return_if_fail(ADG_IS_CANVAS(canvas));
168 g_object_set((GObject *) canvas, "background-dress", dress, NULL);
172 * adg_canvas_get_background_dress:
173 * @canvas: an #AdgCanvas
175 * Gets the background dress to be used in rendering @canvas.
177 * Returns: the current background dress
179 AdgDress
180 adg_canvas_get_background_dress(AdgCanvas *canvas)
182 AdgCanvasPrivate *data;
184 g_return_val_if_fail(ADG_IS_CANVAS(canvas), ADG_DRESS_UNDEFINED);
186 data = canvas->data;
188 return data->background_dress;
191 static void
192 _adg_render(AdgEntity *entity, cairo_t *cr)
194 AdgCanvasPrivate *data = ((AdgCanvas *) entity)->data;
196 adg_entity_apply_dress(entity, data->background_dress, cr);
197 cairo_paint(cr);
199 if (PARENT_ENTITY_CLASS->render)
200 PARENT_ENTITY_CLASS->render(entity, cr);