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.
24 * @short_description: A stroked entity
26 * The #AdgStroke object is a stroked representation of an #AdgPath model.
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
37 #include "adg-stroke.h"
38 #include "adg-stroke-private.h"
39 #include "adg-line-style.h"
48 static void get_property (GObject
*object
,
52 static void set_property (GObject
*object
,
56 static void set_path (AdgStroke
*stroke
,
58 static void render (AdgEntity
*entity
,
62 G_DEFINE_TYPE(AdgStroke
, adg_stroke
, ADG_TYPE_ENTITY
)
66 adg_stroke_class_init(AdgStrokeClass
*klass
)
68 GObjectClass
*gobject_class
;
69 AdgEntityClass
*entity_class
;
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",
84 P_("The path to be stroked"),
86 G_PARAM_CONSTRUCT
|G_PARAM_READWRITE
);
87 g_object_class_install_property(gobject_class
, PROP_PATH
, param
);
91 adg_stroke_init(AdgStroke
*stroke
)
93 AdgStrokePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE(stroke
,
103 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
105 AdgStroke
*stroke
= (AdgStroke
*) object
;
109 g_value_set_object(value
, &stroke
->priv
->path
);
112 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
118 set_property(GObject
*object
, guint prop_id
,
119 const GValue
*value
, GParamSpec
*pspec
)
121 AdgStroke
*stroke
= (AdgStroke
*) object
;
125 set_path(stroke
, (AdgPath
*) g_value_get_object(value
));
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
136 * @path: the #AdgPath to stroke
138 * Creates a new stroke entity.
140 * Return value: the newly created entity
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
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.
175 * <title>TODO</title>
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>
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");
196 set_path(AdgStroke
*stroke
, AdgPath
*path
)
198 stroke
->priv
->path
= path
;
202 render(AdgEntity
*entity
, cairo_t
*cr
)
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
);
218 if (entity_class
->render
!= NULL
)
219 entity_class
->render(entity
, cr
);