doc: updated italian translations
[adg.git] / src / adg / adg-hatch.c
blobc02e8ab65f1eb8cb17d5ed8ee4cf2e9849068367
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012 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:adg-hatch
23 * @short_description: A hatched region
25 * The #AdgHatch object is used to fill a closed #AdgTrail model
26 * with some sort of pattern.
28 * Since: 1.0
29 **/
31 /**
32 * AdgHatch:
34 * All fields are private and should not be used directly.
35 * Use its public methods instead.
37 * Since: 1.0
38 **/
41 #include "adg-internal.h"
42 #include "adg-model.h"
43 #include "adg-trail.h"
44 #include "adg-stroke.h"
45 #include "adg-pattern.h"
46 #include "adg-style.h"
47 #include "adg-fill-style.h"
48 #include "adg-dress.h"
49 #include "adg-dress-builtins.h"
51 #include "adg-hatch.h"
52 #include "adg-hatch-private.h"
55 G_DEFINE_TYPE(AdgHatch, adg_hatch, ADG_TYPE_STROKE)
57 enum {
58 PROP_0,
59 PROP_FILL_DRESS
63 static void _adg_get_property (GObject *object,
64 guint param_id,
65 GValue *value,
66 GParamSpec *pspec);
67 static void _adg_set_property (GObject *object,
68 guint param_id,
69 const GValue *value,
70 GParamSpec *pspec);
71 static void _adg_render (AdgEntity *entity,
72 cairo_t *cr);
75 static void
76 adg_hatch_class_init(AdgHatchClass *klass)
78 GObjectClass *gobject_class;
79 AdgEntityClass *entity_class;
80 GParamSpec *param;
82 gobject_class = (GObjectClass *) klass;
83 entity_class = (AdgEntityClass *) klass;
85 g_type_class_add_private(klass, sizeof(AdgHatchPrivate));
87 gobject_class->get_property = _adg_get_property;
88 gobject_class->set_property = _adg_set_property;
90 entity_class->render = _adg_render;
92 param = adg_param_spec_dress("fill-dress",
93 P_("Fill Dress"),
94 P_("The dress to use for filling this entity"),
95 ADG_DRESS_FILL_HATCH,
96 G_PARAM_READWRITE);
97 g_object_class_install_property(gobject_class, PROP_FILL_DRESS, param);
100 static void
101 adg_hatch_init(AdgHatch *hatch)
103 AdgHatchPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(hatch, ADG_TYPE_HATCH,
104 AdgHatchPrivate);
106 data->fill_dress = ADG_DRESS_FILL_HATCH;
108 hatch->data = data;
111 static void
112 _adg_get_property(GObject *object, guint prop_id,
113 GValue *value, GParamSpec *pspec)
115 AdgHatchPrivate *data = ((AdgHatch *) object)->data;
117 switch (prop_id) {
118 case PROP_FILL_DRESS:
119 g_value_set_int(value, data->fill_dress);
120 break;
121 default:
122 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
123 break;
127 static void
128 _adg_set_property(GObject *object, guint prop_id,
129 const GValue *value, GParamSpec *pspec)
131 AdgHatch *hatch;
132 AdgHatchPrivate *data;
134 hatch = (AdgHatch *) object;
135 data = hatch->data;
137 switch (prop_id) {
138 case PROP_FILL_DRESS:
139 data->fill_dress = g_value_get_int(value);
140 break;
141 default:
142 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
143 break;
149 * adg_hatch_new:
150 * @trail: the #AdgTrail to hatch
152 * Creates a new hatch entity.
153 * @trail can be %NULL, in which case an empty hatch is created.
155 * Returns: the newly created hatch entity
157 * Since: 1.0
159 AdgHatch *
160 adg_hatch_new(AdgTrail *trail)
162 return g_object_new(ADG_TYPE_HATCH, "trail", trail, NULL);
166 * adg_hatch_set_fill_dress:
167 * @hatch: an #AdgHatch
168 * @dress: the new #AdgDress to use
170 * Sets a new line dress for rendering @hatch. The new dress
171 * must be related to the original dress for this property:
172 * you cannot set a dress used for line styles to a dress
173 * managing fonts.
175 * The check is done by calling adg_dress_are_related() with
176 * @dress and the previous dress as arguments. Check out its
177 * documentation for details on what is a related dress.
179 * Since: 1.0
181 void
182 adg_hatch_set_fill_dress(AdgHatch *hatch, AdgDress dress)
184 g_return_if_fail(ADG_IS_HATCH(hatch));
185 g_object_set(hatch, "fill-dress", dress, NULL);
189 * adg_hatch_get_fill_dress:
190 * @hatch: an #AdgHatch
192 * Gets the line dress to be used in rendering @hatch.
194 * Returns: (transfer none): the current line dress.
196 * Since: 1.0
198 AdgDress
199 adg_hatch_get_fill_dress(AdgHatch *hatch)
201 AdgHatchPrivate *data;
203 g_return_val_if_fail(ADG_IS_HATCH(hatch), ADG_DRESS_UNDEFINED);
205 data = hatch->data;
207 return data->fill_dress;
211 static void
212 _adg_render(AdgEntity *entity, cairo_t *cr)
214 AdgHatch *hatch;
215 AdgStroke *stroke;
216 AdgHatchPrivate *data;
217 const cairo_path_t *cairo_path;
219 hatch = (AdgHatch *) entity;
220 stroke = (AdgStroke *) entity;
221 data = hatch->data;
222 cairo_path = adg_trail_get_cairo_path(adg_stroke_get_trail(stroke));
224 if (cairo_path != NULL) {
225 AdgFillStyle *fill_style = (AdgFillStyle *)
226 adg_entity_style(entity, data->fill_dress);
228 adg_fill_style_set_extents(fill_style, adg_entity_get_extents(entity));
230 cairo_save(cr);
231 cairo_transform(cr, adg_entity_get_global_matrix(entity));
232 cairo_transform(cr, adg_entity_get_local_matrix(entity));
233 cairo_append_path(cr, cairo_path);
234 cairo_restore(cr);
236 adg_style_apply((AdgStyle *) fill_style, entity, cr);
237 cairo_fill(cr);