[docs] Updated TODO.xml
[adg.git] / adg / adg-logo.c
blob422cfc36947aa1a8012a7e476c10aa6e8e2680e1
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-logo
23 * @short_description: The ADG default logo
25 * The #AdgLogo is an entity representing the default ADG logo.
26 **/
28 /**
29 * AdgLogo:
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
33 **/
36 #include "adg-logo.h"
37 #include "adg-logo-private.h"
38 #include "adg-line-style.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-intl.h"
42 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_logo_parent_class)
45 enum {
46 PROP_0,
47 PROP_SYMBOL_DRESS,
48 PROP_SCREEN_DRESS,
49 PROP_FRAME_DRESS
53 static void get_property (GObject *object,
54 guint param_id,
55 GValue *value,
56 GParamSpec *pspec);
57 static void set_property (GObject *object,
58 guint param_id,
59 const GValue *value,
60 GParamSpec *pspec);
61 static void arrange (AdgEntity *entity);
62 static void render (AdgEntity *entity,
63 cairo_t *cr);
64 static void arrange_class (AdgLogoClass *logo_class);
67 G_DEFINE_TYPE(AdgLogo, adg_logo, ADG_TYPE_ENTITY);
70 static void
71 adg_logo_class_init(AdgLogoClass *klass)
73 GObjectClass *gobject_class;
74 AdgEntityClass *entity_class;
75 GParamSpec *param;
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",
90 P_("Symbol Dress"),
91 P_("The line dress to use for rendering the symbol of the logo"),
92 ADG_DRESS_LINE,
93 G_PARAM_READWRITE);
94 g_object_class_install_property(gobject_class, PROP_SYMBOL_DRESS, param);
96 param = adg_param_spec_dress("screen-dress",
97 P_("Screen Dress"),
98 P_("The line dress to use for rendering the screen shape around the logo"),
99 ADG_DRESS_LINE,
100 G_PARAM_READWRITE);
101 g_object_class_install_property(gobject_class, PROP_SCREEN_DRESS, param);
103 param = adg_param_spec_dress("frame-dress",
104 P_("Frame Dress"),
105 P_("The line dress to use for rendering the frame"),
106 ADG_DRESS_LINE,
107 G_PARAM_READWRITE);
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;
125 static void
126 adg_logo_init(AdgLogo *logo)
128 AdgLogoPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(logo, ADG_TYPE_LOGO,
129 AdgLogoPrivate);
131 data->symbol_dress = ADG_DRESS_LINE;
132 data->screen_dress = ADG_DRESS_LINE;
133 data->frame_dress = ADG_DRESS_LINE;
135 logo->data = data;
138 static void
139 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
141 AdgLogoPrivate *data = ((AdgLogo *) object)->data;
143 switch (prop_id) {
144 case PROP_SYMBOL_DRESS:
145 g_value_set_int(value, data->symbol_dress);
146 break;
147 case PROP_SCREEN_DRESS:
148 g_value_set_int(value, data->screen_dress);
149 break;
150 case PROP_FRAME_DRESS:
151 g_value_set_int(value, data->frame_dress);
152 break;
153 default:
154 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
155 break;
159 static void
160 set_property(GObject *object, guint prop_id,
161 const GValue *value, GParamSpec *pspec)
163 AdgLogo *logo;
164 AdgLogoPrivate *data;
166 logo = (AdgLogo *) object;
167 data = logo->data;
169 switch (prop_id) {
170 case PROP_SYMBOL_DRESS:
171 adg_dress_set(&data->symbol_dress, g_value_get_int(value));
172 break;
173 case PROP_SCREEN_DRESS:
174 adg_dress_set(&data->screen_dress, g_value_get_int(value));
175 break;
176 case PROP_FRAME_DRESS:
177 adg_dress_set(&data->frame_dress, g_value_get_int(value));
178 break;
179 default:
180 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
181 break;
187 * adg_logo_new:
189 * Creates a new logo entity.
191 * Returns: the newly created logo entity
193 AdgLogo *
194 adg_logo_new(void)
196 return g_object_new(ADG_TYPE_LOGO, NULL);
200 * adg_logo_set_symbol_dress:
201 * @logo: an #AdgLogo
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.
213 void
214 adg_logo_set_symbol_dress(AdgLogo *logo, AdgDress dress)
216 AdgLogoPrivate *data;
218 g_return_if_fail(ADG_IS_LOGO(logo));
220 data = logo->data;
222 if (adg_dress_set(&data->symbol_dress, dress))
223 g_object_notify((GObject *) logo, "symbol-dress");
227 * adg_logo_get_symbol_dress:
228 * @logo: an #AdgLogo
230 * Gets the line dress to be used in stroking the symbol of @logo.
232 * Returns: the requested line dress
234 AdgDress
235 adg_logo_get_symbol_dress(AdgLogo *logo)
237 AdgLogoPrivate *data;
239 g_return_val_if_fail(ADG_IS_LOGO(logo), ADG_DRESS_UNDEFINED);
241 data = logo->data;
243 return data->symbol_dress;
247 * adg_logo_set_screen_dress:
248 * @logo: an #AdgLogo
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
255 * further details.
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.
261 void
262 adg_logo_set_screen_dress(AdgLogo *logo, AdgDress dress)
264 AdgLogoPrivate *data;
266 g_return_if_fail(ADG_IS_LOGO(logo));
268 data = logo->data;
270 if (adg_dress_set(&data->screen_dress, dress))
271 g_object_notify((GObject *) logo, "screen-dress");
275 * adg_logo_get_screen_dress:
276 * @logo: an #AdgLogo
278 * Gets the line dress to be used in stroking the screen shape of @logo.
280 * Returns: the requested line dress
282 AdgDress
283 adg_logo_get_screen_dress(AdgLogo *logo)
285 AdgLogoPrivate *data;
287 g_return_val_if_fail(ADG_IS_LOGO(logo), ADG_DRESS_UNDEFINED);
289 data = logo->data;
291 return data->screen_dress;
295 * adg_logo_set_frame_dress:
296 * @logo: an #AdgLogo
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
303 * further details.
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.
309 void
310 adg_logo_set_frame_dress(AdgLogo *logo, AdgDress dress)
312 AdgLogoPrivate *data;
314 g_return_if_fail(ADG_IS_LOGO(logo));
316 data = logo->data;
318 if (adg_dress_set(&data->frame_dress, dress))
319 g_object_notify((GObject *) logo, "frame-dress");
323 * adg_logo_get_frame_dress:
324 * @logo: an #AdgLogo
326 * Gets the line dress to be used in stroking the frame of @logo.
328 * Returns: the requested line dress
330 AdgDress
331 adg_logo_get_frame_dress(AdgLogo *logo)
333 AdgLogoPrivate *data;
335 g_return_val_if_fail(ADG_IS_LOGO(logo), ADG_DRESS_UNDEFINED);
337 data = logo->data;
339 return data->frame_dress;
343 static void
344 arrange(AdgEntity *entity)
346 AdgLogoClass *logo_class;
347 AdgLogoClassPrivate *data_class;
348 CpmlExtents extents;
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);
361 static void
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));
430 static void
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) {
444 cairo_save(cr);
445 cairo_transform(cr, adg_entity_get_local_matrix(entity));
446 cairo_append_path(cr, cairo_path);
447 cairo_restore(cr);
449 cairo_set_line_width(cr, 2.25);
450 adg_entity_apply_dress(entity, data->symbol_dress, cr);
452 cairo_stroke(cr);
455 cairo_path = adg_trail_get_cairo_path((AdgTrail *) data_class->screen);
456 if (cairo_path != NULL) {
457 cairo_save(cr);
458 cairo_transform(cr, adg_entity_get_local_matrix(entity));
459 cairo_append_path(cr, cairo_path);
460 cairo_restore(cr);
462 cairo_set_line_width(cr, 1.5);
463 adg_entity_apply_dress(entity, data->screen_dress, cr);
465 cairo_stroke(cr);
468 cairo_path = adg_trail_get_cairo_path((AdgTrail *) data_class->frame);
469 if (cairo_path != NULL) {
470 cairo_save(cr);
471 cairo_transform(cr, adg_entity_get_local_matrix(entity));
472 cairo_append_path(cr, cairo_path);
473 cairo_restore(cr);
475 cairo_set_line_width(cr, 1.5);
476 adg_entity_apply_dress(entity, data->frame_dress, cr);
478 cairo_stroke(cr);