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 hatched region
25 * The #AdgHatch object is used to fill a closed #AdgTrail model
26 * with some sort of pattern.
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
37 #include "adg-hatch.h"
38 #include "adg-hatch-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-fill-style.h"
43 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_hatch_parent_class)
51 static void get_property (GObject
*object
,
55 static void set_property (GObject
*object
,
59 static void render (AdgEntity
*entity
,
63 G_DEFINE_TYPE(AdgHatch
, adg_hatch
, ADG_TYPE_STROKE
);
67 adg_hatch_class_init(AdgHatchClass
*klass
)
69 GObjectClass
*gobject_class
;
70 AdgEntityClass
*entity_class
;
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",
85 P_("The dress to use for filling this entity"),
88 g_object_class_install_property(gobject_class
, PROP_FILL_DRESS
, param
);
92 adg_hatch_init(AdgHatch
*hatch
)
94 AdgHatchPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(hatch
, ADG_TYPE_HATCH
,
97 data
->fill_dress
= ADG_DRESS_FILL_HATCH
;
103 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
105 AdgHatchPrivate
*data
= ((AdgHatch
*) object
)->data
;
108 case PROP_FILL_DRESS
:
109 g_value_set_int(value
, data
->fill_dress
);
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
)
122 AdgHatchPrivate
*data
;
124 hatch
= (AdgHatch
*) object
;
128 case PROP_FILL_DRESS
:
129 adg_dress_set(&data
->fill_dress
, g_value_get_int(value
));
132 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
140 * @trail: the #AdgTrail to hatch
142 * Creates a new hatch entity.
144 * Returns: the newly created hatch entity
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
163 adg_hatch_get_fill_dress(AdgHatch
*hatch
)
165 AdgHatchPrivate
*data
;
167 g_return_val_if_fail(ADG_IS_HATCH(hatch
), ADG_DRESS_UNDEFINED
);
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
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.
189 adg_hatch_set_fill_dress(AdgHatch
*hatch
, AdgDress dress
)
191 AdgHatchPrivate
*data
;
193 g_return_if_fail(ADG_IS_HATCH(hatch
));
197 if (adg_dress_set(&data
->fill_dress
, dress
))
198 g_object_notify((GObject
*) hatch
, "fill-dress");
203 render(AdgEntity
*entity
, cairo_t
*cr
)
207 AdgHatchPrivate
*data
;
208 const cairo_path_t
*cairo_path
;
210 hatch
= (AdgHatch
*) entity
;
211 stroke
= (AdgStroke
*) entity
;
213 cairo_path
= adg_trail_get_cairo_path(adg_stroke_get_trail(stroke
));
215 if (cairo_path
!= NULL
) {
216 AdgFillStyle
*fill_style
;
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
);
225 cairo_set_matrix(cr
, adg_entity_ctm(entity
));
226 cairo_append_path(cr
, cairo_path
);
229 adg_style_apply((AdgStyle
*) fill_style
, entity
, cr
);