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"
42 #define PARENT_CLASS ((AdgEntityClass *) adg_stroke_parent_class)
50 static void get_property (GObject
*object
,
54 static void set_property (GObject
*object
,
58 static void set_path (AdgStroke
*stroke
,
60 static void render (AdgEntity
*entity
,
64 G_DEFINE_TYPE(AdgStroke
, adg_stroke
, ADG_TYPE_ENTITY
)
68 adg_stroke_class_init(AdgStrokeClass
*klass
)
70 GObjectClass
*gobject_class
;
71 AdgEntityClass
*entity_class
;
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",
86 P_("The path to be stroked"),
88 G_PARAM_CONSTRUCT
|G_PARAM_READWRITE
);
89 g_object_class_install_property(gobject_class
, PROP_PATH
, param
);
93 adg_stroke_init(AdgStroke
*stroke
)
95 AdgStrokePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE(stroke
,
105 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
107 AdgStroke
*stroke
= (AdgStroke
*) object
;
111 g_value_set_object(value
, &stroke
->priv
->path
);
114 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
120 set_property(GObject
*object
, guint prop_id
,
121 const GValue
*value
, GParamSpec
*pspec
)
123 AdgStroke
*stroke
= (AdgStroke
*) object
;
127 set_path(stroke
, (AdgPath
*) g_value_get_object(value
));
130 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
138 * @path: the #AdgPath to stroke
140 * Creates a new stroke entity.
142 * Return value: the newly created entity
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
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.
177 * <title>TODO</title>
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>
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");
198 set_path(AdgStroke
*stroke
, AdgPath
*path
)
200 stroke
->priv
->path
= path
;
204 render(AdgEntity
*entity
, cairo_t
*cr
)
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
);
218 PARENT_CLASS
->render(entity
, cr
);