1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010 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.
36 #include "adg-internal.h"
38 #include "adg-logo-private.h"
39 #include "adg-line-style.h"
40 #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_set_symbol_dress:
202 * @dress: the new #AdgDress to use
204 * Sets a new line dress for rendering the symbol of @logo. The
205 * new dress must be a line dress: the check is done by calling
206 * adg_dress_are_related() with @dress and the old dress as
207 * arguments. Check out its documentation for further details.
209 * The default dress is a transparent line dress: the rendering
210 * callback will stroke the symbol using the default color with
211 * a predefined thickness.
214 adg_logo_set_symbol_dress(AdgLogo
*logo
, AdgDress dress
)
216 AdgLogoPrivate
*data
;
218 g_return_if_fail(ADG_IS_LOGO(logo
));
222 if (adg_dress_set(&data
->symbol_dress
, dress
))
223 g_object_notify((GObject
*) logo
, "symbol-dress");
227 * adg_logo_get_symbol_dress:
230 * Gets the line dress to be used in stroking the symbol of @logo.
232 * Returns: the requested line dress
235 adg_logo_get_symbol_dress(AdgLogo
*logo
)
237 AdgLogoPrivate
*data
;
239 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
243 return data
->symbol_dress
;
247 * adg_logo_set_screen_dress:
249 * @dress: the new #AdgDress to use
251 * Sets a new line dress for rendering the screen of @logo.
252 * The new dress must be a line dress: the check is done by
253 * calling adg_dress_are_related() with @dress and the old
254 * dress as arguments. Check out its documentation for
257 * The default dress is a transparent line dress: the rendering
258 * callback will stroke the screen using the default color with
259 * a predefined thickness.
262 adg_logo_set_screen_dress(AdgLogo
*logo
, AdgDress dress
)
264 AdgLogoPrivate
*data
;
266 g_return_if_fail(ADG_IS_LOGO(logo
));
270 if (adg_dress_set(&data
->screen_dress
, dress
))
271 g_object_notify((GObject
*) logo
, "screen-dress");
275 * adg_logo_get_screen_dress:
278 * Gets the line dress to be used in stroking the screen shape of @logo.
280 * Returns: the requested line dress
283 adg_logo_get_screen_dress(AdgLogo
*logo
)
285 AdgLogoPrivate
*data
;
287 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
291 return data
->screen_dress
;
295 * adg_logo_set_frame_dress:
297 * @dress: the new #AdgDress to use
299 * Sets a new line dress for rendering the frame of @logo.
300 * The new dress must be a line dress: the check is done by
301 * calling adg_dress_are_related() with @dress and the old
302 * dress as arguments. Check out its documentation for
305 * The default dress is a transparent line dress: the rendering
306 * callback will stroke the frame using the default color with
307 * a predefined thickness.
310 adg_logo_set_frame_dress(AdgLogo
*logo
, AdgDress dress
)
312 AdgLogoPrivate
*data
;
314 g_return_if_fail(ADG_IS_LOGO(logo
));
318 if (adg_dress_set(&data
->frame_dress
, dress
))
319 g_object_notify((GObject
*) logo
, "frame-dress");
323 * adg_logo_get_frame_dress:
326 * Gets the line dress to be used in stroking the frame of @logo.
328 * Returns: the requested line dress
331 adg_logo_get_frame_dress(AdgLogo
*logo
)
333 AdgLogoPrivate
*data
;
335 g_return_val_if_fail(ADG_IS_LOGO(logo
), ADG_DRESS_UNDEFINED
);
339 return data
->frame_dress
;
344 arrange(AdgEntity
*entity
)
346 AdgLogoClass
*logo_class
;
347 AdgLogoClassPrivate
*data_class
;
350 logo_class
= ADG_LOGO_GET_CLASS(entity
);
351 data_class
= logo_class
->data_class
;
353 arrange_class(logo_class
);
354 cpml_extents_copy(&extents
, &data_class
->extents
);
356 cpml_extents_transform(&extents
, adg_entity_get_local_matrix(entity
));
357 cpml_extents_transform(&extents
, adg_entity_get_global_matrix(entity
));
358 adg_entity_set_extents(entity
, &extents
);
362 arrange_class(AdgLogoClass
*logo_class
)
364 AdgLogoClassPrivate
*data_class
;
365 CpmlExtents
*extents
;
367 data_class
= logo_class
->data_class
;
368 extents
= &data_class
->extents
;
370 if (data_class
->symbol
== NULL
) {
371 AdgPath
*path
= adg_path_new();
373 adg_path_move_to_explicit(path
, 3, 13);
374 adg_path_line_to_explicit(path
, 11, 5);
375 adg_path_arc_to_explicit(path
, 15, 9, 11, 13);
376 adg_path_line_to_explicit(path
, 11, 5.5);
378 adg_path_move_to_explicit(path
, 19, 5);
379 adg_path_arc_to_explicit(path
, 15, 9, 19, 13);
380 adg_path_line_to_explicit(path
, 19, 11);
381 adg_path_line_to_explicit(path
, 18, 11);
383 adg_path_move_to_explicit(path
, 10.5, 11);
384 adg_path_line_to_explicit(path
, 7, 11);
386 data_class
->symbol
= path
;
387 extents
->is_defined
= FALSE
;
390 if (data_class
->screen
== NULL
) {
391 AdgPath
*path
= adg_path_new();
393 adg_path_move_to_explicit(path
, 2, 2);
394 adg_path_line_to_explicit(path
, 23, 2);
395 adg_path_fillet(path
, 5);
396 adg_path_line_to_explicit(path
, 23, 16);
397 adg_path_fillet(path
, 5);
398 adg_path_line_to_explicit(path
, 2, 16);
399 adg_path_fillet(path
, 5);
400 adg_path_close(path
);
401 adg_path_fillet(path
, 5);
403 data_class
->screen
= path
;
404 extents
->is_defined
= FALSE
;
407 if (data_class
->frame
== NULL
) {
408 AdgPath
*path
= adg_path_new();
410 adg_path_move_to_explicit(path
, 0, 0);
411 adg_path_line_to_explicit(path
, 25, 0);
412 adg_path_line_to_explicit(path
, 25, 18);
413 adg_path_line_to_explicit(path
, 0, 18);
414 adg_path_close(path
);
416 data_class
->frame
= path
;
417 extents
->is_defined
= FALSE
;
420 if (!data_class
->extents
.is_defined
) {
421 cpml_extents_add(extents
,
422 adg_trail_get_extents((AdgTrail
*) data_class
->symbol
));
423 cpml_extents_add(extents
,
424 adg_trail_get_extents((AdgTrail
*) data_class
->screen
));
425 cpml_extents_add(extents
,
426 adg_trail_get_extents((AdgTrail
*) data_class
->frame
));
431 render(AdgEntity
*entity
, cairo_t
*cr
)
433 AdgLogoClassPrivate
*data_class
;
434 AdgLogoPrivate
*data
;
435 const cairo_path_t
*cairo_path
;
437 data_class
= ADG_LOGO_GET_CLASS(entity
)->data_class
;
438 data
= ((AdgLogo
*) entity
)->data
;
440 cairo_set_line_cap(cr
, CAIRO_LINE_CAP_ROUND
);
442 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->symbol
);
443 if (cairo_path
!= NULL
) {
445 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
446 cairo_append_path(cr
, cairo_path
);
449 cairo_set_line_width(cr
, 2.25);
450 adg_entity_apply_dress(entity
, data
->symbol_dress
, cr
);
455 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->screen
);
456 if (cairo_path
!= NULL
) {
458 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
459 cairo_append_path(cr
, cairo_path
);
462 cairo_set_line_width(cr
, 1.5);
463 adg_entity_apply_dress(entity
, data
->screen_dress
, cr
);
468 cairo_path
= adg_trail_get_cairo_path((AdgTrail
*) data_class
->frame
);
469 if (cairo_path
!= NULL
) {
471 cairo_transform(cr
, adg_entity_get_local_matrix(entity
));
472 cairo_append_path(cr
, cairo_path
);
475 cairo_set_line_width(cr
, 1.5);
476 adg_entity_apply_dress(entity
, data
->frame_dress
, cr
);