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.
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.
35 * All fields are private and should not be used directly.
36 * Use its public methods instead.
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)
54 static void _adg_get_property (GObject
*object
,
58 static void _adg_set_property (GObject
*object
,
62 static void _adg_render (AdgEntity
*entity
,
66 G_DEFINE_TYPE(AdgCanvas
, adg_canvas
, ADG_TYPE_CONTAINER
);
70 adg_canvas_class_init(AdgCanvasClass
*klass
)
72 GObjectClass
*gobject_class
;
73 AdgEntityClass
*entity_class
;
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
,
91 g_object_class_install_property(gobject_class
, PROP_BACKGROUND_DRESS
, param
);
95 adg_canvas_init(AdgCanvas
*canvas
)
97 AdgCanvasPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(canvas
,
101 data
->background_dress
= ADG_DRESS_COLOR_BACKGROUND
;
107 _adg_get_property(GObject
*object
, guint prop_id
,
108 GValue
*value
, GParamSpec
*pspec
)
110 AdgCanvasPrivate
*data
= ((AdgCanvas
*) object
)->data
;
113 case PROP_BACKGROUND_DRESS
:
114 g_value_set_int(value
, data
->background_dress
);
117 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
123 _adg_set_property(GObject
*object
, guint prop_id
,
124 const GValue
*value
, GParamSpec
*pspec
)
127 AdgCanvasPrivate
*data
;
129 canvas
= (AdgCanvas
*) object
;
133 case PROP_BACKGROUND_DRESS
:
134 data
->background_dress
= g_value_get_int(value
);
137 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
146 * Creates a new empty canvas object.
148 * Returns: the canvas
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.
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
180 adg_canvas_get_background_dress(AdgCanvas
*canvas
)
182 AdgCanvasPrivate
*data
;
184 g_return_val_if_fail(ADG_IS_CANVAS(canvas
), ADG_DRESS_UNDEFINED
);
188 return data
->background_dress
;
192 _adg_render(AdgEntity
*entity
, cairo_t
*cr
)
194 AdgCanvasPrivate
*data
= ((AdgCanvas
*) entity
)->data
;
196 adg_entity_apply_dress(entity
, data
->background_dress
, cr
);
199 if (PARENT_ENTITY_CLASS
->render
)
200 PARENT_ENTITY_CLASS
->render(entity
, cr
);