[docs] Updated TODO.xml
[adg.git] / adg / adg-stroke.c
blob2d122495c72997f5072f7301682d0937fa8b7a76
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 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-stroke
23 * @short_description: A stroked entity
25 * The #AdgStroke object is a stroked representation of an #AdgPath model.
26 **/
28 /**
29 * AdgStroke:
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
33 **/
36 #include "adg-stroke.h"
37 #include "adg-stroke-private.h"
38 #include "adg-line-style.h"
39 #include "adg-intl.h"
42 enum {
43 PROP_0,
44 PROP_PATH
47 static void get_property (GObject *object,
48 guint param_id,
49 GValue *value,
50 GParamSpec *pspec);
51 static void set_property (GObject *object,
52 guint param_id,
53 const GValue *value,
54 GParamSpec *pspec);
55 static void set_path (AdgStroke *stroke,
56 AdgPath *path);
57 static gboolean render (AdgEntity *entity,
58 cairo_t *cr);
61 G_DEFINE_TYPE(AdgStroke, adg_stroke, ADG_TYPE_ENTITY)
64 static void
65 adg_stroke_class_init(AdgStrokeClass *klass)
67 GObjectClass *gobject_class;
68 AdgEntityClass *entity_class;
69 GParamSpec *param;
71 gobject_class = (GObjectClass *) klass;
72 entity_class = (AdgEntityClass *) klass;
74 g_type_class_add_private(klass, sizeof(AdgStrokePrivate));
76 gobject_class->get_property = get_property;
77 gobject_class->set_property = set_property;
79 entity_class->render = render;
81 param = g_param_spec_object("path",
82 P_("Path"),
83 P_("The path to be stroked"),
84 ADG_TYPE_PATH,
85 G_PARAM_CONSTRUCT|G_PARAM_READWRITE);
86 g_object_class_install_property(gobject_class, PROP_PATH, param);
89 static void
90 adg_stroke_init(AdgStroke *stroke)
92 AdgStrokePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(stroke,
93 ADG_TYPE_STROKE,
94 AdgStrokePrivate);
96 data->path = NULL;
98 stroke->data = data;
101 static void
102 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
104 AdgStrokePrivate *data = ((AdgStroke *) object)->data;
106 switch (prop_id) {
107 case PROP_PATH:
108 g_value_set_object(value, &data->path);
109 break;
110 default:
111 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
112 break;
116 static void
117 set_property(GObject *object, guint prop_id,
118 const GValue *value, GParamSpec *pspec)
120 AdgStroke *stroke = (AdgStroke *) object;
122 switch (prop_id) {
123 case PROP_PATH:
124 set_path(stroke, (AdgPath *) g_value_get_object(value));
125 break;
126 default:
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
128 break;
134 * adg_stroke_new:
135 * @path: the #AdgPath to stroke
137 * Creates a new stroke entity.
139 * Return value: the newly created entity
141 AdgEntity *
142 adg_stroke_new(AdgPath *path)
144 g_return_val_if_fail(ADG_IS_PATH(path), NULL);
146 return (AdgEntity *) g_object_new(ADG_TYPE_STROKE, "path", path, NULL);
151 * adg_stroke_get_path:
152 * @stroke: an #AdgStroke
154 * Gets the #AdgPath binded to this @stroke entity.
156 * Return value: the requested #AdgPath or %NULL on errors
158 AdgPath *
159 adg_stroke_get_path(AdgStroke *stroke)
161 AdgStrokePrivate *data;
163 g_return_val_if_fail(ADG_IS_STROKE(stroke), NULL);
165 data = stroke->data;
167 return data->path;
171 * adg_stroke_set_path:
172 * @stroke: an #AdgStroke
173 * @path: the new #AdgPath to bind
175 * Sets @path as the new path to be stroked by @stroke.
177 * <important>
178 * <title>TODO</title>
179 * <itemizedlist>
180 * <listitem>Actually the #AdgPath is disjointed from #AdgStroke (or any
181 * other #AdgEntity). When the model-entity dependency will be
182 * in place, make sure to destroy this entity when its binded
183 * path is destroyed.</listitem>
184 * </itemizedlist>
185 * </important>
187 void
188 adg_stroke_set_path(AdgStroke *stroke, AdgPath *path)
190 g_return_if_fail(ADG_IS_STROKE(stroke));
192 set_path(stroke, path);
194 g_object_notify((GObject *) stroke, "path");
198 static void
199 set_path(AdgStroke *stroke, AdgPath *path)
201 AdgStrokePrivate *data = stroke->data;
203 data->path = path;
206 static gboolean
207 render(AdgEntity *entity, cairo_t *cr)
209 AdgStroke *stroke;
210 AdgStrokePrivate *data;
211 const cairo_path_t *cairo_path;
213 stroke = (AdgStroke *) entity;
214 data = stroke->data;
215 cairo_path = adg_path_get_cairo_path(data->path);
217 if (cairo_path != NULL) {
218 AdgMatrix local, ctm;
220 adg_entity_get_local_matrix(entity, &local);
222 cairo_save(cr);
224 /* Apply the local matrix BEFORE the global one */
225 cairo_get_matrix(cr, &ctm);
226 cairo_matrix_multiply(&ctm, &ctm, &local);
227 cairo_set_matrix(cr, &ctm);
229 cairo_append_path(cr, cairo_path);
231 cairo_restore(cr);
233 adg_entity_apply(entity, ADG_SLOT_LINE_STYLE, cr);
234 cairo_stroke(cr);
237 return TRUE;