[AdgEntity] Changed "local-mode" to "normalized"
[adg.git] / adg / adg-hatch.c
blobe26be544b04a804a9fe28e6c4e55601d5ad7592d
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: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.
27 **/
29 /**
30 * AdgHatch:
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
34 **/
37 #include "adg-hatch.h"
38 #include "adg-hatch-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-fill-style.h"
41 #include "adg-intl.h"
43 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_hatch_parent_class)
46 enum {
47 PROP_0,
48 PROP_FILL_DRESS
51 static void get_property (GObject *object,
52 guint param_id,
53 GValue *value,
54 GParamSpec *pspec);
55 static void set_property (GObject *object,
56 guint param_id,
57 const GValue *value,
58 GParamSpec *pspec);
59 static void render (AdgEntity *entity,
60 cairo_t *cr);
63 G_DEFINE_TYPE(AdgHatch, adg_hatch, ADG_TYPE_STROKE);
66 static void
67 adg_hatch_class_init(AdgHatchClass *klass)
69 GObjectClass *gobject_class;
70 AdgEntityClass *entity_class;
71 GParamSpec *param;
73 gobject_class = (GObjectClass *) klass;
74 entity_class = (AdgEntityClass *) klass;
76 g_type_class_add_private(klass, sizeof(AdgHatchPrivate));
78 gobject_class->get_property = get_property;
79 gobject_class->set_property = set_property;
81 entity_class->render = render;
83 param = adg_param_spec_dress("fill-dress",
84 P_("Fill Dress"),
85 P_("The dress to use for filling this entity"),
86 ADG_DRESS_FILL_HATCH,
87 G_PARAM_READWRITE);
88 g_object_class_install_property(gobject_class, PROP_FILL_DRESS, param);
91 static void
92 adg_hatch_init(AdgHatch *hatch)
94 AdgHatchPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(hatch, ADG_TYPE_HATCH,
95 AdgHatchPrivate);
97 data->fill_dress = ADG_DRESS_FILL_HATCH;
99 hatch->data = data;
102 static void
103 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
105 AdgHatchPrivate *data = ((AdgHatch *) object)->data;
107 switch (prop_id) {
108 case PROP_FILL_DRESS:
109 g_value_set_int(value, data->fill_dress);
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 AdgHatch *hatch;
122 AdgHatchPrivate *data;
124 hatch = (AdgHatch *) object;
125 data = hatch->data;
127 switch (prop_id) {
128 case PROP_FILL_DRESS:
129 adg_dress_set(&data->fill_dress, g_value_get_int(value));
130 break;
131 default:
132 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
133 break;
139 * adg_hatch_new:
140 * @trail: the #AdgTrail to hatch
142 * Creates a new hatch entity.
144 * Returns: the newly created hatch entity
146 AdgHatch *
147 adg_hatch_new(AdgTrail *trail)
149 g_return_val_if_fail(ADG_IS_TRAIL(trail), NULL);
151 return g_object_new(ADG_TYPE_HATCH, "trail", trail, NULL);
155 * adg_hatch_get_fill_dress:
156 * @hatch: an #AdgHatch
158 * Gets the line dress to be used in rendering @hatch.
160 * Returns: the current line dress
162 AdgDress
163 adg_hatch_get_fill_dress(AdgHatch *hatch)
165 AdgHatchPrivate *data;
167 g_return_val_if_fail(ADG_IS_HATCH(hatch), ADG_DRESS_UNDEFINED);
169 data = hatch->data;
171 return data->fill_dress;
175 * adg_hatch_set_fill_dress:
176 * @hatch: an #AdgHatch
177 * @dress: the new #AdgDress to use
179 * Sets a new line dress for rendering @hatch. The new dress
180 * must be related to the original dress for this property:
181 * you cannot set a dress used for line styles to a dress
182 * managing fonts.
184 * The check is done by calling adg_dress_are_related() with
185 * @dress and the previous dress as arguments. Check out its
186 * documentation for details on what is a related dress.
188 void
189 adg_hatch_set_fill_dress(AdgHatch *hatch, AdgDress dress)
191 AdgHatchPrivate *data;
193 g_return_if_fail(ADG_IS_HATCH(hatch));
195 data = hatch->data;
197 if (adg_dress_set(&data->fill_dress, dress))
198 g_object_notify((GObject *) hatch, "fill-dress");
202 static void
203 render(AdgEntity *entity, cairo_t *cr)
205 AdgHatch *hatch;
206 AdgStroke *stroke;
207 AdgHatchPrivate *data;
208 const cairo_path_t *cairo_path;
210 hatch = (AdgHatch *) entity;
211 stroke = (AdgStroke *) entity;
212 data = hatch->data;
213 cairo_path = adg_trail_get_cairo_path(adg_stroke_get_trail(stroke));
215 if (cairo_path != NULL) {
216 AdgFillStyle *fill_style;
217 CpmlExtents extents;
219 fill_style = (AdgFillStyle *) adg_entity_style(entity, data->fill_dress);
220 adg_entity_get_extents(entity, &extents);
222 adg_fill_style_set_extents(fill_style, &extents);
224 cairo_save(cr);
225 cairo_set_matrix(cr, adg_entity_ctm(entity));
226 cairo_append_path(cr, cairo_path);
227 cairo_restore(cr);
229 adg_style_apply((AdgStyle *) fill_style, entity, cr);
230 cairo_fill(cr);