[AdgDim] Removed PARENT_CLASS define
[adg.git] / adg / adg-stroke.c
blob3cd17d462d0caeb15b91c2c35cfaf11e65c043f5
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:stroke
23 * @title: AdgStroke
24 * @short_description: A stroked entity
26 * The #AdgStroke object is a stroked representation of an #AdgPath model.
27 **/
29 /**
30 * AdgStroke:
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
34 **/
37 #include "adg-stroke.h"
38 #include "adg-stroke-private.h"
39 #include "adg-line-style.h"
40 #include "adg-intl.h"
42 #define PARENT_CLASS ((AdgEntityClass *) adg_stroke_parent_class)
45 enum {
46 PROP_0,
47 PROP_PATH
50 static void get_property (GObject *object,
51 guint param_id,
52 GValue *value,
53 GParamSpec *pspec);
54 static void set_property (GObject *object,
55 guint param_id,
56 const GValue *value,
57 GParamSpec *pspec);
58 static void set_path (AdgStroke *stroke,
59 AdgPath *path);
60 static void render (AdgEntity *entity,
61 cairo_t *cr);
64 G_DEFINE_TYPE(AdgStroke, adg_stroke, ADG_TYPE_ENTITY)
67 static void
68 adg_stroke_class_init(AdgStrokeClass *klass)
70 GObjectClass *gobject_class;
71 AdgEntityClass *entity_class;
72 GParamSpec *param;
74 gobject_class = (GObjectClass *) klass;
75 entity_class = (AdgEntityClass *) klass;
77 g_type_class_add_private(klass, sizeof(AdgStrokePrivate));
79 gobject_class->get_property = get_property;
80 gobject_class->set_property = set_property;
82 entity_class->render = render;
84 param = g_param_spec_object("path",
85 P_("Path"),
86 P_("The path to be stroked"),
87 ADG_TYPE_PATH,
88 G_PARAM_CONSTRUCT|G_PARAM_READWRITE);
89 g_object_class_install_property(gobject_class, PROP_PATH, param);
92 static void
93 adg_stroke_init(AdgStroke *stroke)
95 AdgStrokePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(stroke,
96 ADG_TYPE_STROKE,
97 AdgStrokePrivate);
99 priv->path = NULL;
101 stroke->priv = priv;
104 static void
105 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
107 AdgStroke *stroke = (AdgStroke *) object;
109 switch (prop_id) {
110 case PROP_PATH:
111 g_value_set_object(value, &stroke->priv->path);
112 break;
113 default:
114 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
115 break;
119 static void
120 set_property(GObject *object, guint prop_id,
121 const GValue *value, GParamSpec *pspec)
123 AdgStroke *stroke = (AdgStroke *) object;
125 switch (prop_id) {
126 case PROP_PATH:
127 set_path(stroke, (AdgPath *) g_value_get_object(value));
128 break;
129 default:
130 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
131 break;
137 * adg_stroke_new:
138 * @path: the #AdgPath to stroke
140 * Creates a new stroke entity.
142 * Return value: the newly created entity
144 AdgEntity *
145 adg_stroke_new(AdgPath *path)
147 g_return_val_if_fail(ADG_IS_PATH(path), NULL);
149 return (AdgEntity *) g_object_new(ADG_TYPE_STROKE, "path", path, NULL);
154 * adg_stroke_get_path:
155 * @stroke: an #AdgStroke
157 * Gets the #AdgPath binded to this @stroke entity.
159 * Return value: the requested #AdgPath or %NULL on errors
161 AdgPath *
162 adg_stroke_get_path(AdgStroke *stroke)
164 g_return_val_if_fail(ADG_IS_STROKE(stroke), NULL);
166 return stroke->priv->path;
170 * adg_stroke_set_path:
171 * @stroke: an #AdgStroke
172 * @path: the new #AdgPath to bind
174 * Sets @path as the new path to be stroked by @stroke.
176 * <important>
177 * <title>TODO</title>
178 * <itemizedlist>
179 * <listitem>Actually the #AdgPath is disjointed from #AdgStroke (or any
180 * other #AdgEntity). When the model-entity dependency will be
181 * in place, make sure to destroy this entity when its binded
182 * path is destroyed.</listitem>
183 * </itemizedlist>
184 * </important>
186 void
187 adg_stroke_set_path(AdgStroke *stroke, AdgPath *path)
189 g_return_if_fail(ADG_IS_STROKE(stroke));
191 set_path(stroke, path);
193 g_object_notify((GObject *) stroke, "path");
197 static void
198 set_path(AdgStroke *stroke, AdgPath *path)
200 stroke->priv->path = path;
203 static void
204 render(AdgEntity *entity, cairo_t *cr)
206 AdgStroke *stroke;
207 const cairo_path_t *cairo_path;
209 stroke = (AdgStroke *) entity;
210 cairo_path = adg_path_get_cairo_path(stroke->priv->path);
212 if (cairo_path != NULL) {
213 cairo_append_path(cr, cairo_path);
214 adg_entity_apply(entity, ADG_SLOT_LINE_STYLE, cr);
215 cairo_stroke(cr);
218 PARENT_CLASS->render(entity, cr);