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.
23 * @short_description: A stroked entity
25 * The #AdgStroke object is a stroked representation of an #AdgPath model.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
36 #include "adg-stroke.h"
37 #include "adg-stroke-private.h"
38 #include "adg-line-style.h"
47 static void get_property (GObject
*object
,
51 static void set_property (GObject
*object
,
55 static void set_path (AdgStroke
*stroke
,
57 static void render (AdgEntity
*entity
,
61 G_DEFINE_TYPE(AdgStroke
, adg_stroke
, ADG_TYPE_ENTITY
)
65 adg_stroke_class_init(AdgStrokeClass
*klass
)
67 GObjectClass
*gobject_class
;
68 AdgEntityClass
*entity_class
;
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",
83 P_("The path to be stroked"),
85 G_PARAM_CONSTRUCT
|G_PARAM_READWRITE
);
86 g_object_class_install_property(gobject_class
, PROP_PATH
, param
);
90 adg_stroke_init(AdgStroke
*stroke
)
92 AdgStrokePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(stroke
,
102 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
104 AdgStrokePrivate
*data
= ((AdgStroke
*) object
)->data
;
108 g_value_set_object(value
, &data
->path
);
111 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
117 set_property(GObject
*object
, guint prop_id
,
118 const GValue
*value
, GParamSpec
*pspec
)
120 AdgStroke
*stroke
= (AdgStroke
*) object
;
124 set_path(stroke
, (AdgPath
*) g_value_get_object(value
));
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
135 * @path: the #AdgPath to stroke
137 * Creates a new stroke entity.
139 * Return value: the newly created entity
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
159 adg_stroke_get_path(AdgStroke
*stroke
)
161 AdgStrokePrivate
*data
;
163 g_return_val_if_fail(ADG_IS_STROKE(stroke
), NULL
);
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.
178 * <title>TODO</title>
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>
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");
199 set_path(AdgStroke
*stroke
, AdgPath
*path
)
201 AdgStrokePrivate
*data
= stroke
->data
;
207 render(AdgEntity
*entity
, cairo_t
*cr
)
210 AdgStrokePrivate
*data
;
211 AdgEntityClass
*entity_class
;
212 const cairo_path_t
*cairo_path
;
214 stroke
= (AdgStroke
*) entity
;
216 entity_class
= (AdgEntityClass
*) adg_stroke_parent_class
;
217 cairo_path
= adg_path_get_cairo_path(data
->path
);
219 if (cairo_path
!= NULL
) {
220 cairo_append_path(cr
, cairo_path
);
221 adg_entity_apply(entity
, ADG_SLOT_LINE_STYLE
, cr
);
225 if (entity_class
->render
!= NULL
)
226 entity_class
->render(entity
, cr
);