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: The ADG default logo
25 * The #AdgLogo is an entity representing the default ADG logo.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
37 #include "adg-logo-private.h"
38 #include "adg-line-style.h"
39 #include "adg-dress-builtins.h"
42 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_logo_parent_class)
53 static void get_property (GObject
*object
,
57 static void set_property (GObject
*object
,
61 static void arrange (AdgEntity
*entity
);
62 static void render (AdgEntity
*entity
,
64 static void arrange_class (AdgLogoClass
*logo_class
);
67 G_DEFINE_TYPE(AdgLogo
, adg_logo
, ADG_TYPE_ENTITY
);
71 adg_logo_class_init(AdgLogoClass
*klass
)
73 GObjectClass
*gobject_class
;
74 AdgEntityClass
*entity_class
;
76 AdgLogoClassPrivate
*data_class
;
78 gobject_class
= (GObjectClass
*) klass
;
79 entity_class
= (AdgEntityClass
*) klass
;
81 g_type_class_add_private(klass
, sizeof(AdgLogoPrivate
));
83 gobject_class
->get_property
= get_property
;
84 gobject_class
->set_property
= set_property
;
86 entity_class
->arrange
= arrange
;
87 entity_class
->render
= render
;
89 param
= adg_param_spec_dress("symbol-dress",
91 P_("The line dress to use for rendering the symbol of the logo"),
94 g_object_class_install_property(gobject_class
, PROP_SYMBOL_DRESS
, param
);
96 param
= adg_param_spec_dress("screen-dress",
98 P_("The line dress to use for rendering the screen shape around the logo"),
101 g_object_class_install_property(gobject_class
, PROP_SCREEN_DRESS
, param
);
103 param
= adg_param_spec_dress("frame-dress",
105 P_("The line dress to use for rendering the frame"),
108 g_object_class_install_property(gobject_class
, PROP_FRAME_DRESS
, param
);
110 /* Initialize the private class data: the allocated struct is
111 * never freed as this type is registered statically, hence
112 * never destroyed. A better approach would be to use the old
113 * type initialization (no G_TYPE_DEFINE and friends) that
114 * allows to specify a custom class finalization method */
115 data_class
= g_new(AdgLogoClassPrivate
, 1);
117 data_class
->symbol
= NULL
;
118 data_class
->screen
= NULL
;
119 data_class
->frame
= NULL
;
120 data_class
->extents
.is_defined
= FALSE
;
122 klass
->data_class
= data_class
;
126 adg_logo_init(AdgLogo
*logo
)
128 AdgLogoPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(logo
, ADG_TYPE_LOGO
,
131 data
->symbol_dress
= ADG_DRESS_LINE
;
132 data
->screen_dress
= ADG_DRESS_LINE
;
133 data
->frame_dress
= ADG_DRESS_LINE
;
139 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
141 AdgLogoPrivate
*data
= ((AdgLogo
*) object
)->data
;
144 case PROP_SYMBOL_DRESS
:
145 g_value_set_int(value
, data
->symbol_dress
);
147 case PROP_SCREEN_DRESS
:
148 g_value_set_int(value
, data
->screen_dress
);
150 case PROP_FRAME_DRESS
:
151 g_value_set_int(value
, data
->frame_dress
);
154 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
160 set_property(GObject
*object
, guint prop_id
,
161 const GValue
*value
, GParamSpec
*pspec
)
164 AdgLogoPrivate
*data
;
166 logo
= (AdgLogo
*) object
;
170 case PROP_SYMBOL_DRESS
:
171 adg_dress_set(&data
->symbol_dress
, g_value_get_int(value
));
173 case PROP_SCREEN_DRESS
:
174 adg_dress_set(&data
->screen_dress
, g_value_get_int(value
));
176 case PROP_FRAME_DRESS
:
177 adg_dress_set(&data
->frame_dress
, g_value_get_int(value
));
180 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
189 * Creates a new logo entity.
191 * Returns: the newly created logo entity
196 return g_object_new(ADG_TYPE_LOGO
, NULL
);
200 * adg_logo_get_symbol_dress:
203 * Gets the line dress to be used in stroking the symbol of @logo.
205 * Returns: the requested line dress
208 adg_logo_get_symbol_dress(AdgLogo
*logo
)
210 AdgLogoPrivate
*data
;
212 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
216 return data
->symbol_dress
;
220 * adg_logo_set_symbol_dress:
222 * @dress: the new #AdgDress to use
224 * Sets a new line dress for rendering the symbol of @logo. The
225 * new dress must be a line dress: the check is done by calling
226 * adg_dress_are_related() with @dress and the old dress as
227 * arguments. Check out its documentation for further details.
229 * The default dress is a transparent line dress: the rendering
230 * callback will stroke the symbol using the default color with
231 * a predefined thickness.
234 adg_logo_set_symbol_dress(AdgLogo
*logo
, AdgDress dress
)
236 AdgLogoPrivate
*data
;
238 g_return_if_fail(ADG_IS_LOGO(logo
));
242 if (adg_dress_set(&data
->symbol_dress
, dress
))
243 g_object_notify((GObject
*) logo
, "symbol-dress");
247 * adg_logo_get_screen_dress:
250 * Gets the line dress to be used in stroking the screen shape of @logo.
252 * Returns: the requested line dress
255 adg_logo_get_screen_dress(AdgLogo
*logo
)
257 AdgLogoPrivate
*data
;
259 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
263 return data
->screen_dress
;
267 * adg_logo_set_screen_dress:
269 * @dress: the new #AdgDress to use
271 * Sets a new line dress for rendering the screen of @logo.
272 * The new dress must be a line dress: the check is done by
273 * calling adg_dress_are_related() with @dress and the old
274 * dress as arguments. Check out its documentation for
277 * The default dress is a transparent line dress: the rendering
278 * callback will stroke the screen using the default color with
279 * a predefined thickness.
282 adg_logo_set_screen_dress(AdgLogo
*logo
, AdgDress dress
)
284 AdgLogoPrivate
*data
;
286 g_return_if_fail(ADG_IS_LOGO(logo
));
290 if (adg_dress_set(&data
->screen_dress
, dress
))
291 g_object_notify((GObject
*) logo
, "screen-dress");
295 * adg_logo_get_frame_dress:
298 * Gets the line dress to be used in stroking the frame of @logo.
300 * Returns: the requested line dress
303 adg_logo_get_frame_dress(AdgLogo
*logo
)
305 AdgLogoPrivate
*data
;
307 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
311 return data
->frame_dress
;
315 * adg_logo_set_frame_dress:
317 * @dress: the new #AdgDress to use
319 * Sets a new line dress for rendering the frame of @logo.
320 * The new dress must be a line dress: the check is done by
321 * calling adg_dress_are_related() with @dress and the old
322 * dress as arguments. Check out its documentation for
325 * The default dress is a transparent line dress: the rendering
326 * callback will stroke the frame using the default color with
327 * a predefined thickness.
330 adg_logo_set_frame_dress(AdgLogo
*logo
, AdgDress dress
)
332 AdgLogoPrivate
*data
;
334 g_return_if_fail(ADG_IS_LOGO(logo
));
338 if (adg_dress_set(&data
->frame_dress
, dress
))
339 g_object_notify((GObject
*) logo
, "frame-dress");
344 arrange(AdgEntity
*entity
)
346 AdgLogoClass
*logo_class
;
347 AdgLogoClassPrivate
*data_class
;
348 CpmlExtents
*extents
;
349 const AdgMatrix
*local
;
351 logo_class
= ADG_LOGO_GET_CLASS(entity
);
352 data_class
= logo_class
->data_class
;
353 extents
= (CpmlExtents
*) adg_entity_extents(entity
);
354 local
= adg_entity_get_local_matrix(entity
);
356 arrange_class(logo_class
);
357 cpml_extents_copy(extents
, &data_class
->extents
);
359 /* Apply the local matrix to the extents of this logo instance */
360 cpml_pair_transform(&extents
->org
, local
);
361 cpml_vector_transform(&extents
->size
, local
);
365 arrange_class(AdgLogoClass
*logo_class
)
367 AdgLogoClassPrivate
*data_class
;
368 CpmlExtents
*extents
;
370 data_class
= logo_class
->data_class
;
371 extents
= &data_class
->extents
;
373 if (data_class
->symbol
== NULL
) {
374 AdgPath
*path
= adg_path_new();
376 adg_path_move_to_explicit(path
, 3, 13);
377 adg_path_line_to_explicit(path
, 11, 5);
378 adg_path_arc_to_explicit(path
, 15, 9, 11, 13);
379 adg_path_line_to_explicit(path
, 11, 5.5);
381 adg_path_move_to_explicit(path
, 19, 5);
382 adg_path_arc_to_explicit(path
, 15, 9, 19, 13);
383 adg_path_line_to_explicit(path
, 19, 11);
384 adg_path_line_to_explicit(path
, 18, 11);
386 adg_path_move_to_explicit(path
, 10.5, 11);
387 adg_path_line_to_explicit(path
, 7, 11);
389 data_class
->symbol
= path
;
390 extents
->is_defined
= FALSE
;
393 if (data_class
->screen
== NULL
) {
394 AdgPath
*path
= adg_path_new();
396 adg_path_move_to_explicit(path
, 2, 2);
397 adg_path_line_to_explicit(path
, 23, 2);
398 adg_path_fillet(path
, 5);
399 adg_path_line_to_explicit(path
, 23, 16);
400 adg_path_fillet(path
, 5);
401 adg_path_line_to_explicit(path
, 2, 16);
402 adg_path_fillet(path
, 5);
403 adg_path_close(path
);
404 adg_path_fillet(path
, 5);
406 data_class
->screen
= path
;
407 extents
->is_defined
= FALSE
;
410 if (data_class
->frame
== NULL
) {
411 AdgPath
*path
= adg_path_new();
413 adg_path_move_to_explicit(path
, 0, 0);
414 adg_path_line_to_explicit(path
, 25, 0);
415 adg_path_line_to_explicit(path
, 25, 18);
416 adg_path_line_to_explicit(path
, 0, 18);
417 adg_path_close(path
);
419 data_class
->frame
= path
;
420 extents
->is_defined
= FALSE
;
423 if (!data_class
->extents
.is_defined
) {
424 cpml_extents_add(extents
,
425 adg_trail_extents((AdgTrail
*) data_class
->symbol
));
426 cpml_extents_add(extents
,
427 adg_trail_extents((AdgTrail
*) data_class
->screen
));
428 cpml_extents_add(extents
,
429 adg_trail_extents((AdgTrail
*) data_class
->frame
));
434 render(AdgEntity
*entity
, cairo_t
*cr
)
436 AdgLogoClassPrivate
*data_class
;
437 AdgLogoPrivate
*data
;
438 const cairo_path_t
*cairo_path
;
440 data_class
= ADG_LOGO_GET_CLASS(entity
)->data_class
;
441 data
= ((AdgLogo
*) entity
)->data
;
443 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_ROUND
);
445 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->symbol
);
446 if (cairo_path
!= NULL
) {
448 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
449 cairo_append_path(cr
, cairo_path
);
452 cairo_set_line_width(cr
, 2.25);
453 adg_entity_apply_dress(entity
, data
->symbol_dress
, cr
);
458 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->screen
);
459 if (cairo_path
!= NULL
) {
461 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
462 cairo_append_path(cr
, cairo_path
);
465 cairo_set_line_width(cr
, 1.5);
466 adg_entity_apply_dress(entity
, data
->screen_dress
, cr
);
471 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->frame
);
472 if (cairo_path
!= NULL
) {
474 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
475 cairo_append_path(cr
, cairo_path
);
478 cairo_set_line_width(cr
, 1.5);
479 adg_entity_apply_dress(entity
, data
->frame_dress
, cr
);