1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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.
34 * All fields are private and should not be used directly.
35 * Use its public methods instead.
41 #include "adg-internal.h"
42 #include "adg-model.h"
43 #include "adg-trail.h"
44 #include "adg-stroke.h"
45 #include "adg-style.h"
46 #include "adg-fill-style.h"
47 #include "adg-dress.h"
48 #include "adg-dress-builtins.h"
50 #include "adg-hatch.h"
51 #include "adg-hatch-private.h"
54 G_DEFINE_TYPE(AdgHatch
, adg_hatch
, ADG_TYPE_STROKE
)
62 static void _adg_get_property (GObject
*object
,
66 static void _adg_set_property (GObject
*object
,
70 static void _adg_render (AdgEntity
*entity
,
75 adg_hatch_class_init(AdgHatchClass
*klass
)
77 GObjectClass
*gobject_class
;
78 AdgEntityClass
*entity_class
;
81 gobject_class
= (GObjectClass
*) klass
;
82 entity_class
= (AdgEntityClass
*) klass
;
84 g_type_class_add_private(klass
, sizeof(AdgHatchPrivate
));
86 gobject_class
->get_property
= _adg_get_property
;
87 gobject_class
->set_property
= _adg_set_property
;
89 entity_class
->render
= _adg_render
;
91 param
= adg_param_spec_dress("fill-dress",
93 P_("The dress to use for filling this entity"),
96 g_object_class_install_property(gobject_class
, PROP_FILL_DRESS
, param
);
100 adg_hatch_init(AdgHatch
*hatch
)
102 AdgHatchPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(hatch
, ADG_TYPE_HATCH
,
105 data
->fill_dress
= ADG_DRESS_FILL_HATCH
;
111 _adg_get_property(GObject
*object
, guint prop_id
,
112 GValue
*value
, GParamSpec
*pspec
)
114 AdgHatchPrivate
*data
= ((AdgHatch
*) object
)->data
;
117 case PROP_FILL_DRESS
:
118 g_value_set_int(value
, data
->fill_dress
);
121 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
127 _adg_set_property(GObject
*object
, guint prop_id
,
128 const GValue
*value
, GParamSpec
*pspec
)
131 AdgHatchPrivate
*data
;
133 hatch
= (AdgHatch
*) object
;
137 case PROP_FILL_DRESS
:
138 data
->fill_dress
= g_value_get_int(value
);
141 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
149 * @trail: the #AdgTrail to hatch
151 * Creates a new hatch entity.
152 * @trail can be %NULL, in which case an empty hatch is created.
154 * Returns: the newly created hatch entity
159 adg_hatch_new(AdgTrail
*trail
)
161 return g_object_new(ADG_TYPE_HATCH
, "trail", trail
, NULL
);
165 * adg_hatch_set_fill_dress:
166 * @hatch: an #AdgHatch
167 * @dress: the new #AdgDress to use
169 * Sets a new line dress for rendering @hatch. The new dress
170 * must be related to the original dress for this property:
171 * you cannot set a dress used for line styles to a dress
174 * The check is done by calling adg_dress_are_related() with
175 * @dress and the previous dress as arguments. Check out its
176 * documentation for details on what is a related dress.
181 adg_hatch_set_fill_dress(AdgHatch
*hatch
, AdgDress dress
)
183 g_return_if_fail(ADG_IS_HATCH(hatch
));
184 g_object_set(hatch
, "fill-dress", dress
, NULL
);
188 * adg_hatch_get_fill_dress:
189 * @hatch: an #AdgHatch
191 * Gets the line dress to be used in rendering @hatch.
193 * Returns: (transfer none): the current line dress.
198 adg_hatch_get_fill_dress(AdgHatch
*hatch
)
200 AdgHatchPrivate
*data
;
202 g_return_val_if_fail(ADG_IS_HATCH(hatch
), ADG_DRESS_UNDEFINED
);
206 return data
->fill_dress
;
211 _adg_render(AdgEntity
*entity
, cairo_t
*cr
)
215 AdgHatchPrivate
*data
;
216 const cairo_path_t
*cairo_path
;
218 hatch
= (AdgHatch
*) entity
;
219 stroke
= (AdgStroke
*) entity
;
221 cairo_path
= adg_trail_get_cairo_path(adg_stroke_get_trail(stroke
));
223 if (cairo_path
!= NULL
) {
224 AdgFillStyle
*fill_style
= (AdgFillStyle
*)
225 adg_entity_style(entity
, data
->fill_dress
);
227 adg_fill_style_set_extents(fill_style
, adg_entity_get_extents(entity
));
230 cairo_transform(cr
, adg_entity_get_global_matrix(entity
));
231 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
232 cairo_append_path(cr
, cairo_path
);
235 adg_style_apply((AdgStyle
*) fill_style
, entity
, cr
);