[AdgArrowStyle] Hidden private struct
[adg.git] / adg / adg-stroke.c
bloba6ce364d46191588db491459f492ab9d6b9e2350
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"
43 enum {
44 PROP_0,
45 PROP_PATH
48 static void get_property (GObject *object,
49 guint param_id,
50 GValue *value,
51 GParamSpec *pspec);
52 static void set_property (GObject *object,
53 guint param_id,
54 const GValue *value,
55 GParamSpec *pspec);
56 static void set_path (AdgStroke *stroke,
57 AdgPath *path);
58 static void render (AdgEntity *entity,
59 cairo_t *cr);
62 G_DEFINE_TYPE(AdgStroke, adg_stroke, ADG_TYPE_ENTITY)
65 static void
66 adg_stroke_class_init(AdgStrokeClass *klass)
68 GObjectClass *gobject_class;
69 AdgEntityClass *entity_class;
70 GParamSpec *param;
72 gobject_class = (GObjectClass *) klass;
73 entity_class = (AdgEntityClass *) klass;
75 g_type_class_add_private(klass, sizeof(AdgStrokePrivate));
77 gobject_class->get_property = get_property;
78 gobject_class->set_property = set_property;
80 entity_class->render = render;
82 param = g_param_spec_object("path",
83 P_("Path"),
84 P_("The path to be stroked"),
85 ADG_TYPE_PATH,
86 G_PARAM_CONSTRUCT|G_PARAM_READWRITE);
87 g_object_class_install_property(gobject_class, PROP_PATH, param);
90 static void
91 adg_stroke_init(AdgStroke *stroke)
93 AdgStrokePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(stroke,
94 ADG_TYPE_STROKE,
95 AdgStrokePrivate);
97 priv->path = NULL;
99 stroke->priv = priv;
102 static void
103 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
105 AdgStroke *stroke = (AdgStroke *) object;
107 switch (prop_id) {
108 case PROP_PATH:
109 g_value_set_object(value, &stroke->priv->path);
110 break;
111 default:
112 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
113 break;
117 static void
118 set_property(GObject *object, guint prop_id,
119 const GValue *value, GParamSpec *pspec)
121 AdgStroke *stroke = (AdgStroke *) object;
123 switch (prop_id) {
124 case PROP_PATH:
125 set_path(stroke, (AdgPath *) g_value_get_object(value));
126 break;
127 default:
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
129 break;
135 * adg_stroke_new:
136 * @path: the #AdgPath to stroke
138 * Creates a new stroke entity.
140 * Return value: the newly created entity
142 AdgEntity *
143 adg_stroke_new(AdgPath *path)
145 g_return_val_if_fail(ADG_IS_PATH(path), NULL);
147 return (AdgEntity *) g_object_new(ADG_TYPE_STROKE, "path", path, NULL);
152 * adg_stroke_get_path:
153 * @stroke: an #AdgStroke
155 * Gets the #AdgPath binded to this @stroke entity.
157 * Return value: the requested #AdgPath or %NULL on errors
159 AdgPath *
160 adg_stroke_get_path(AdgStroke *stroke)
162 g_return_val_if_fail(ADG_IS_STROKE(stroke), NULL);
164 return stroke->priv->path;
168 * adg_stroke_set_path:
169 * @stroke: an #AdgStroke
170 * @path: the new #AdgPath to bind
172 * Sets @path as the new path to be stroked by @stroke.
174 * <important>
175 * <title>TODO</title>
176 * <itemizedlist>
177 * <listitem>Actually the #AdgPath is disjointed from #AdgStroke (or any
178 * other #AdgEntity). When the model-entity dependency will be
179 * in place, make sure to destroy this entity when its binded
180 * path is destroyed.</listitem>
181 * </itemizedlist>
182 * </important>
184 void
185 adg_stroke_set_path(AdgStroke *stroke, AdgPath *path)
187 g_return_if_fail(ADG_IS_STROKE(stroke));
189 set_path(stroke, path);
191 g_object_notify((GObject *) stroke, "path");
195 static void
196 set_path(AdgStroke *stroke, AdgPath *path)
198 stroke->priv->path = path;
201 static void
202 render(AdgEntity *entity, cairo_t *cr)
204 AdgStroke *stroke;
205 AdgEntityClass *entity_class;
206 const cairo_path_t *cairo_path;
208 stroke = (AdgStroke *) entity;
209 entity_class = (AdgEntityClass *) adg_stroke_parent_class;
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 if (entity_class->render != NULL)
219 entity_class->render(entity, cr);