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 base class for renderable objects
25 * This abstract class provides the base for all renderable objects.
27 * To provide a proper #AdgEntity derived type, you must at least
28 * implement its arrange() and render() virtual methods. Also, if
29 * you are using some sort of caching, ensure to clear it in the
30 * invalidate() method.
36 * All fields are private and should not be used directly.
37 * Use its public methods instead.
42 * @parent_set: called after the parent has changed
43 * @invalidate: invalidating callback, used to clear the cache
44 * @arrange: prepare the layout and fill the extents struct
45 * @render: rendering callback, it must be implemented
47 * Any entity (if not abstract) must implement at least the @render method.
51 #include "adg-entity.h"
52 #include "adg-entity-private.h"
53 #include "adg-canvas.h"
54 #include "adg-font-style.h"
55 #include "adg-dim-style.h"
56 #include "adg-marshal.h"
59 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_entity_parent_class)
81 static void dispose (GObject
*object
);
82 static void get_property (GObject
*object
,
86 static void set_property (GObject
*object
,
90 static gboolean
set_parent (AdgEntity
*entity
,
92 static void global_changed (AdgEntity
*entity
);
93 static void local_changed (AdgEntity
*entity
);
94 static gboolean
set_global_map (AdgEntity
*entity
,
95 const AdgMatrix
*map
);
96 static gboolean
set_local_map (AdgEntity
*entity
,
97 const AdgMatrix
*map
);
98 static gboolean
set_local_mode (AdgEntity
*entity
,
99 AdgTransformationMode mode
);
100 static void real_invalidate (AdgEntity
*entity
);
101 static void real_arrange (AdgEntity
*entity
);
102 static void real_render (AdgEntity
*entity
,
105 static guint signals
[LAST_SIGNAL
] = { 0 };
108 G_DEFINE_ABSTRACT_TYPE(AdgEntity
, adg_entity
, G_TYPE_INITIALLY_UNOWNED
);
112 adg_entity_class_init(AdgEntityClass
*klass
)
114 GObjectClass
*gobject_class
;
117 GType param_types
[1];
119 gobject_class
= (GObjectClass
*) klass
;
121 g_type_class_add_private(klass
, sizeof(AdgEntityPrivate
));
123 gobject_class
->dispose
= dispose
;
124 gobject_class
->get_property
= get_property
;
125 gobject_class
->set_property
= set_property
;
127 klass
->parent_set
= NULL
;
128 klass
->global_changed
= global_changed
;
129 klass
->local_changed
= local_changed
;
130 klass
->invalidate
= NULL
;
131 klass
->arrange
= NULL
;
132 klass
->render
= NULL
;
134 param
= g_param_spec_object("parent",
136 P_("The parent entity of this entity or NULL if this is a top-level entity"),
139 g_object_class_install_property(gobject_class
, PROP_PARENT
, param
);
141 param
= g_param_spec_boxed("global-map",
143 P_("The transformation to be combined with the parent ones to get the global matrix"),
146 g_object_class_install_property(gobject_class
, PROP_GLOBAL_MAP
, param
);
148 param
= g_param_spec_boxed("local-map",
150 P_("The transformation to be combined with the parent ones to get the local matrix"),
153 g_object_class_install_property(gobject_class
, PROP_LOCAL_MAP
, param
);
155 param
= g_param_spec_enum("local-mode",
157 P_("How the local matrix should be combined with the global matrix to get the current transformation matrix (ctm)"),
158 ADG_TYPE_TRANSFORMATION_MODE
,
161 g_object_class_install_property(gobject_class
, PROP_LOCAL_MODE
, param
);
164 * AdgEntity::parent-set:
165 * @entity: an #AdgEntity
166 * @old_parent: the old parent
168 * Emitted after the parent entity has changed. The new parent
169 * can be inspected using adg_entity_get_parent().
171 * It is allowed for both old and new parent to be %NULL.
173 signals
[PARENT_SET
] = g_signal_new("parent-set",
174 G_OBJECT_CLASS_TYPE(gobject_class
),
176 G_STRUCT_OFFSET(AdgEntityClass
, parent_set
),
178 adg_marshal_VOID__OBJECT
,
179 G_TYPE_NONE
, 1, ADG_TYPE_ENTITY
);
182 * AdgEntity::global-changed
183 * @entity: an #AdgEntity
185 * Emitted when the global map of @entity or any of its parent
186 * has changed. The default handler will compute the new global
187 * matrix, updating the internal cache.
189 signals
[GLOBAL_CHANGED
] = g_signal_new("global-changed",
190 G_OBJECT_CLASS_TYPE(gobject_class
),
192 G_STRUCT_OFFSET(AdgEntityClass
, global_changed
),
194 adg_marshal_VOID__VOID
,
198 * AdgEntity::local-changed
199 * @entity: an #AdgEntity
201 * Emitted when the local map of @entity or any of its parent
202 * has changed. The default handler will compute the new local
203 * matrix, updating the internal cache.
205 signals
[LOCAL_CHANGED
] = g_signal_new("local-changed",
206 G_OBJECT_CLASS_TYPE(gobject_class
),
208 G_STRUCT_OFFSET(AdgEntityClass
, local_changed
),
210 adg_marshal_VOID__VOID
,
214 * AdgEntity::invalidate:
215 * @entity: an #AdgEntity
217 * Invalidates the whole @entity, that is resets all the cache
218 * (if present) built during the #AdgEntity::arrange signal.
219 * The resulting state is a clean entity, similar to what you
220 * have just before the first rendering.
222 closure
= g_cclosure_new(G_CALLBACK(real_invalidate
), NULL
, NULL
);
223 signals
[INVALIDATE
] = g_signal_newv("invalidate", ADG_TYPE_ENTITY
,
224 G_SIGNAL_RUN_LAST
, closure
, NULL
, NULL
,
225 adg_marshal_VOID__VOID
,
226 G_TYPE_NONE
, 0, param_types
);
229 * AdgEntity::arrange:
230 * @entity: an #AdgEntity
232 * Arranges the layout of @entity, updating the cache if necessary,
233 * and computes the extents of @entity.
235 closure
= g_cclosure_new(G_CALLBACK(real_arrange
), NULL
, NULL
);
236 signals
[ARRANGE
] = g_signal_newv("arrange", ADG_TYPE_ENTITY
,
237 G_SIGNAL_RUN_LAST
, closure
, NULL
, NULL
,
238 adg_marshal_VOID__VOID
,
239 G_TYPE_NONE
, 0, param_types
);
242 * @entity: an #AdgEntity
243 * @cr: a #cairo_t drawing context
245 * Causes the rendering of @entity on @cr. A render signal will
246 * automatically emit #AdgEntity::arrange just before the real
247 * rendering on the cairo context.
249 closure
= g_cclosure_new(G_CALLBACK(real_render
), NULL
, NULL
);
250 param_types
[0] = G_TYPE_POINTER
;
251 signals
[RENDER
] = g_signal_newv("render", ADG_TYPE_ENTITY
,
252 G_SIGNAL_RUN_LAST
, closure
, NULL
, NULL
,
253 adg_marshal_VOID__POINTER
,
254 G_TYPE_NONE
, 1, param_types
);
258 adg_entity_init(AdgEntity
*entity
)
260 AdgEntityPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(entity
,
264 cairo_matrix_init_identity(&data
->global_map
);
265 cairo_matrix_init_identity(&data
->local_map
);
266 data
->local_mode
= ADG_TRANSFORM_NONE
;
267 data
->hash_styles
= NULL
;
268 cairo_matrix_init_identity(&data
->global_matrix
);
269 cairo_matrix_init_identity(&data
->local_matrix
);
270 data
->extents
.is_defined
= FALSE
;
276 dispose(GObject
*object
)
279 AdgEntityPrivate
*data
;
281 entity
= (AdgEntity
*) object
;
284 /* This call will emit a "notify" signal for parent.
285 * Consequentially, the references to the old parent is dropped. */
286 adg_entity_set_parent(entity
, NULL
);
288 if (data
->hash_styles
!= NULL
) {
289 g_hash_table_destroy(data
->hash_styles
);
290 data
->hash_styles
= NULL
;
293 if (PARENT_OBJECT_CLASS
->dispose
!= NULL
)
294 PARENT_OBJECT_CLASS
->dispose(object
);
299 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
302 AdgEntityPrivate
*data
;
304 entity
= (AdgEntity
*) object
;
309 g_value_set_object(value
, data
->parent
);
311 case PROP_GLOBAL_MAP
:
312 g_value_set_boxed(value
, &data
->global_map
);
315 g_value_set_boxed(value
, &data
->local_map
);
317 case PROP_LOCAL_MODE
:
318 g_value_set_enum(value
, data
->local_mode
);
321 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
327 set_property(GObject
*object
,
328 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
330 AdgEntity
*entity
= (AdgEntity
*) object
;
334 set_parent(entity
, g_value_get_object(value
));
336 case PROP_GLOBAL_MAP
:
337 set_global_map(entity
, g_value_get_boxed(value
));
340 set_local_map(entity
, g_value_get_boxed(value
));
342 case PROP_LOCAL_MODE
:
343 set_local_mode(entity
, g_value_get_enum(value
));
346 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
353 * adg_entity_get_parent:
354 * @entity: an #AdgEntity
356 * Gets the parent of @entity.
358 * Returns: the parent entity or %NULL on errors or if @entity is a toplevel
361 adg_entity_get_parent(AdgEntity
*entity
)
363 AdgEntityPrivate
*data
;
365 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
373 * adg_entity_set_parent:
374 * @entity: an #AdgEntity
375 * @parent: the parent entity
378 * This function is only useful in entity implementations.
381 * Sets a new parent on @entity.
384 adg_entity_set_parent(AdgEntity
*entity
, AdgEntity
*parent
)
386 g_return_if_fail(ADG_IS_ENTITY(entity
));
388 if (set_parent(entity
, parent
))
389 g_object_notify((GObject
*) entity
, "parent");
393 * adg_entity_get_canvas:
394 * @entity: an #AdgEntity
396 * Walks on the @entity hierarchy and gets the first parent of @entity that is
397 * of #AdgCanvas derived type.
399 * Returns: the requested canvas or %NULL on errors or if there is
400 * no #AdgCanvas in the @entity hierarchy
403 adg_entity_get_canvas(AdgEntity
*entity
)
405 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
408 if (ADG_IS_CANVAS(entity
))
409 return (AdgCanvas
*) entity
;
411 entity
= (AdgEntity
*) adg_entity_get_parent(entity
);
418 * adg_entity_get_global_map:
419 * @entity: an #AdgEntity object
420 * @map: where to store the global map
422 * Gets the transformation to be used to compute the global matrix
423 * of @entity and store it in @map.
426 adg_entity_get_global_map(AdgEntity
*entity
, AdgMatrix
*map
)
428 AdgEntityPrivate
*data
;
430 g_return_if_fail(ADG_IS_ENTITY(entity
));
431 g_return_if_fail(map
!= NULL
);
434 adg_matrix_copy(map
, &data
->global_map
);
438 * adg_entity_set_global_map:
439 * @entity: an #AdgEntity object
442 * Sets the new global transformation of @entity to @map:
443 * the old map is discarded. If @map is %NULL an identity
447 adg_entity_set_global_map(AdgEntity
*entity
, const AdgMatrix
*map
)
449 g_return_if_fail(ADG_IS_ENTITY(entity
));
451 if (set_global_map(entity
, map
))
452 g_object_notify((GObject
*) entity
, "global-map");
456 * adg_entity_transform_global_map:
457 * @entity: an #AdgEntity object
458 * @transformation: the transformation to apply
459 * @mode: how @transformation should be applied
461 * Convenient function to change the global map of @entity by
462 * applying @tranformation using the @mode operator. This is
463 * logically equivalent to the following:
467 * adg_entity_get_global_map(entity, &tmp_map);
468 * adg_matrix_transform(&tmp_map, transformation, mode);
469 * adg_entity_set_global_map(entity, &tmp_map);
473 adg_entity_transform_global_map(AdgEntity
*entity
,
474 const AdgMatrix
*transformation
,
475 AdgTransformationMode mode
)
477 AdgEntityPrivate
*data
;
480 g_return_if_fail(ADG_IS_ENTITY(entity
));
481 g_return_if_fail(transformation
!= NULL
);
485 adg_matrix_copy(&map
, &data
->global_map
);
486 adg_matrix_transform(&map
, transformation
, mode
);
488 if (set_global_map(entity
, &map
))
489 g_object_notify((GObject
*) entity
, "global-map");
493 * adg_entity_get_local_map:
494 * @entity: an #AdgEntity object
495 * @map: where to store the local map
497 * Gets the transformation to be used to compute the local matrix
498 * of @entity and store it in @map.
501 adg_entity_get_local_map(AdgEntity
*entity
, AdgMatrix
*map
)
503 AdgEntityPrivate
*data
;
505 g_return_if_fail(ADG_IS_ENTITY(entity
));
506 g_return_if_fail(map
!= NULL
);
510 adg_matrix_copy(map
, &data
->local_map
);
514 * adg_entity_set_local_map:
515 * @entity: an #AdgEntity object
518 * Sets the new local transformation of @entity to @map:
519 * the old map is discarded. If @map is %NULL an identity
523 adg_entity_set_local_map(AdgEntity
*entity
, const AdgMatrix
*map
)
525 g_return_if_fail(ADG_IS_ENTITY(entity
));
527 if (set_local_map(entity
, map
))
528 g_object_notify((GObject
*) entity
, "local-map");
532 * adg_entity_transform_local_map:
533 * @entity: an #AdgEntity object
534 * @transformation: the transformation to apply
535 * @mode: how @transformation should be applied
537 * Convenient function to change the local map of @entity by
538 * applying @tranformation using the @mode operator. This is
539 * logically equivalent to the following:
543 * adg_entity_get_local_map(entity, &tmp_map);
544 * adg_matrix_transform(&tmp_map, transformation, mode);
545 * adg_entity_set_local_map(entity, &tmp_map);
549 adg_entity_transform_local_map(AdgEntity
*entity
,
550 const AdgMatrix
*transformation
,
551 AdgTransformationMode mode
)
553 AdgEntityPrivate
*data
;
556 g_return_if_fail(ADG_IS_ENTITY(entity
));
557 g_return_if_fail(transformation
!= NULL
);
561 adg_matrix_copy(&map
, &data
->local_map
);
562 adg_matrix_transform(&map
, transformation
, mode
);
564 if (set_local_map(entity
, &map
))
565 g_object_notify((GObject
*) entity
, "local-map");
569 * adg_entity_get_local_mode:
570 * @entity: an #AdgEntity object
572 * Gets the transformation mode to be used while applying the
573 * local matrix over the global matrix. It is internally used
574 * by adg_entity_get_ctm().
576 * Returns: the current transformation mode
578 AdgTransformationMode
579 adg_entity_get_local_mode(AdgEntity
*entity
)
581 AdgEntityPrivate
*data
;
583 g_return_val_if_fail(ADG_IS_ENTITY(entity
), ADG_TRANSFORM_NONE
);
587 return data
->local_mode
;
591 * adg_entity_set_local_mode:
592 * @entity: an #AdgEntity object
593 * @mode: the new mode
595 * Sets a new transformation mode to be used while combining
596 * global and local matrices.
597 * Sets a new transformation mode to be used while applying
598 * the local matrix over the global matrix. It is internally
599 * used by adg_entity_get_ctm().
602 adg_entity_set_local_mode(AdgEntity
*entity
, AdgTransformationMode mode
)
604 g_return_if_fail(ADG_IS_ENTITY(entity
));
606 if (set_local_mode(entity
, mode
))
607 g_object_notify((GObject
*) entity
, "local-mode");
611 * adg_entity_get_extents:
612 * @entity: an #AdgEntity
613 * @extents: where to store the extents
615 * Stores a copy of the bounding box of @entity in @extents.
616 * This struct specifies the surface portion (in global space)
617 * occupied by the entity without taking into account line
618 * thickness and caps.
620 * The #AdgEntity::arrange signal will be emitted in order to
621 * update the entity layout before computing the extents.
624 adg_entity_get_extents(AdgEntity
*entity
, CpmlExtents
*extents
)
626 AdgEntityPrivate
*data
;
628 g_return_if_fail(ADG_IS_ENTITY(entity
));
632 g_signal_emit(entity
, signals
[ARRANGE
], 0);
635 cpml_extents_copy(extents
, &data
->extents
);
639 * adg_entity_set_extents:
640 * @entity: an #AdgEntity
641 * @extents: the new extents
644 * This function is only useful in entity implementations.
647 * Sets a new bounding box for @entity.
650 adg_entity_set_extents(AdgEntity
*entity
, const CpmlExtents
*extents
)
652 AdgEntityPrivate
*data
;
654 g_return_if_fail(ADG_IS_ENTITY(entity
));
658 cpml_extents_copy(&data
->extents
, extents
);
663 * @entity: an #AdgEntity
664 * @dress: the dress of the style to get
666 * Gets the style to be used for @entity. @dress specifies the "type"
669 * This method is supposed to always return a valid style instance,
670 * specifically the most appropriate one for this entity. The following
671 * sequence of checks is performed to get the proper @dress style,
672 * stopping at the first succesfull result:
675 * <listitem>check if the style is defined directly by this entity type,
676 * as returned by adg_entity_get_style();</listitem>
677 * <listitem>check if @entity has a parent, in which case returns the
678 * adg_entity_style() of the parent;</listitem>
679 * <listitem>returns the main style with adg_dress_get_style().</listitem>
682 * Returns: the requested style or %NULL on errors
685 adg_entity_style(AdgEntity
*entity
, AdgDress dress
)
689 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
690 g_return_val_if_fail(dress
!= ADG_DRESS_UNDEFINED
, NULL
);
692 style
= adg_entity_get_style(entity
, dress
);
695 AdgEntityPrivate
*data
= entity
->data
;
697 if (data
->parent
!= NULL
)
698 style
= adg_entity_style(data
->parent
, dress
);
700 style
= adg_dress_get_style(dress
);
707 * adg_entity_get_style:
708 * @entity: an #AdgEntity
709 * @dress: the dress of the style to get
711 * Gets the overriden @dress style from @entity. This is a kind
712 * of accessor function: to get the style to be used for rendering
713 * purpose, consider adg_entity_style().
715 * Returns: the requested style or %NULL if the @dress style
719 adg_entity_get_style(AdgEntity
*entity
, AdgDress dress
)
721 AdgEntityPrivate
*data
;
723 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
724 g_return_val_if_fail(dress
!= ADG_DRESS_UNDEFINED
, NULL
);
728 if (data
->hash_styles
== NULL
)
731 return g_hash_table_lookup(data
->hash_styles
, GINT_TO_POINTER(dress
));
735 * adg_entity_set_style:
736 * @entity: an #AdgEntity
737 * @dress: a dress style
738 * @style: the new style to use
740 * Overrides the style of @dress for @entity and its children.
741 * If @style is %NULL, any previous override is removed.
744 adg_entity_set_style(AdgEntity
*entity
, AdgDress dress
, AdgStyle
*style
)
746 AdgEntityPrivate
*data
;
750 g_return_if_fail(ADG_IS_ENTITY(entity
));
754 if (data
->hash_styles
== NULL
&& style
== NULL
)
757 if (data
->hash_styles
== NULL
)
758 data
->hash_styles
= g_hash_table_new_full(NULL
, NULL
,
759 NULL
, g_object_unref
);
761 p_dress
= GINT_TO_POINTER(dress
);
762 old_style
= g_hash_table_lookup(data
->hash_styles
, p_dress
);
764 if (style
== old_style
)
768 g_hash_table_remove(data
->hash_styles
, p_dress
);
771 g_hash_table_replace(data
->hash_styles
, p_dress
, style
);
776 * adg_entity_apply_dress:
777 * @entity: an #AdgEntity
778 * @dress: the dress style to apply
779 * @cr: a #cairo_t drawing context
781 * Convenient function to apply a @dress style (as returned by
782 * adg_entity_style()) to the @cr cairo context.
785 adg_entity_apply_dress(AdgEntity
*entity
, AdgDress dress
, cairo_t
*cr
)
787 g_return_if_fail(ADG_IS_ENTITY(entity
));
788 g_return_if_fail(cr
!= NULL
);
790 adg_style_apply(adg_entity_style(entity
, dress
), cr
);
794 * adg_entity_global_changed:
795 * @entity: an #AdgEntity
797 * Emits the #AdgEntity::global-changed signal on @entity and on all of
798 * its children, if any.
801 adg_entity_global_changed(AdgEntity
*entity
)
803 g_return_if_fail(ADG_IS_ENTITY(entity
));
805 g_signal_emit(entity
, signals
[GLOBAL_CHANGED
], 0);
809 * adg_entity_local_changed:
810 * @entity: an #AdgEntity
812 * Emits the #AdgEntity::local-changed signal on @entity and on all of
813 * its children, if any.
816 adg_entity_local_changed(AdgEntity
*entity
)
818 g_return_if_fail(ADG_IS_ENTITY(entity
));
820 g_signal_emit(entity
, signals
[LOCAL_CHANGED
], 0);
824 * adg_entity_global_matrix:
825 * @entity: an #AdgEntity object
827 * Gets the global matrix by combining all the global maps of the
828 * @entity hierarchy. The returned value is owned by @entity and
829 * should not be changed or freed.
831 * This method is only useful after the #AdgEntity::arrange default
832 * handler has been called, that is at the rendering stage or while
833 * arranging the entity after the parent method has been chained up.
835 * Returns: the global matrix or %NULL on errors
838 adg_entity_global_matrix(AdgEntity
*entity
)
840 AdgEntityPrivate
*data
;
842 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
846 return &data
->global_matrix
;
850 * adg_entity_local_matrix:
851 * @entity: an #AdgEntity object
852 * @matrix: where to store the local matrix
854 * Gets the local matrix by combining all the local maps of the
855 * @entity hierarchy. The returned value is owned by @entity and
856 * should not be changed or freed.
858 * This method is only useful after the #AdgEntity::arrange default
859 * handler has been called, that is at the rendering stage or while
860 * arranging the entity after the parent method has been chained up.
862 * Returns: the global matrix or %NULL on errors
865 adg_entity_local_matrix(AdgEntity
*entity
)
867 AdgEntityPrivate
*data
;
869 g_return_val_if_fail(ADG_IS_ENTITY(entity
), NULL
);
873 return &data
->local_matrix
;
877 * adg_entity_get_ctm:
878 * @entity: an #AdgEntity object
879 * @ctm: where to store the current transformation matrix
881 * Gets the current transformation matrix (ctm) of @entity
882 * by combining global and local matrices in the way specified
883 * by the #AdgEntity:local-mode property. The result is stored
886 * This method is only useful after the #AdgEntity::arrange default
887 * handler has been called, that is at the rendering stage or while
888 * arranging the entity after the parent method has been chained up.
891 adg_entity_get_ctm(AdgEntity
*entity
, AdgMatrix
*ctm
)
893 AdgEntityPrivate
*data
;
895 g_return_if_fail(ADG_IS_ENTITY(entity
));
896 g_return_if_fail(ctm
!= NULL
);
900 adg_matrix_copy(ctm
, &data
->global_matrix
);
901 adg_matrix_transform(ctm
, &data
->local_matrix
, data
->local_mode
);
905 * adg_entity_invalidate:
906 * @entity: an #AdgEntity
908 * Emits the #AdgEntity::invalidate signal on @entity and on all of
909 * its children, if any, clearing the eventual cache stored by the
910 * #AdgEntity::arrange signal and setting the entity state similary
911 * to the just initialized entity.
914 adg_entity_invalidate(AdgEntity
*entity
)
916 g_return_if_fail(ADG_IS_ENTITY(entity
));
918 g_signal_emit(entity
, signals
[INVALIDATE
], 0);
922 * adg_entity_arrange:
923 * @entity: an #AdgEntity
926 * This function is only useful in entity implementations.
929 * Emits the #AdgEntity::arrange signal on @entity and all its children,
930 * if any. This function is rarely needed as the arrange call is usually
931 * managed by the #AdgEntity::render signal or indirectly by a call to
932 * adg_entity_get_extents().
935 adg_entity_arrange(AdgEntity
*entity
)
937 g_return_if_fail(ADG_IS_ENTITY(entity
));
939 g_signal_emit(entity
, signals
[ARRANGE
], 0);
944 * @entity: an #AdgEntity
945 * @cr: a #cairo_t drawing context
947 * Emits the #AdgEntity::render signal on @entity and on all of its
948 * children, if any, causing the rendering to the @cr cairo context.
951 adg_entity_render(AdgEntity
*entity
, cairo_t
*cr
)
953 g_return_if_fail(ADG_IS_ENTITY(entity
));
955 g_signal_emit(entity
, signals
[RENDER
], 0, cr
);
960 set_parent(AdgEntity
*entity
, AdgEntity
*parent
)
962 AdgEntityPrivate
*data
;
963 AdgEntity
*old_parent
;
966 old_parent
= data
->parent
;
968 /* Check if parent has changed */
969 if (parent
== old_parent
)
973 g_object_ref(parent
);
975 data
->parent
= parent
;
976 g_signal_emit(entity
, signals
[PARENT_SET
], 0, old_parent
);
978 if (old_parent
!= NULL
)
979 g_object_unref(old_parent
);
985 global_changed(AdgEntity
*entity
)
987 AdgEntityPrivate
*data
;
991 matrix
= &data
->global_matrix
;
993 if (data
->parent
== NULL
) {
994 adg_matrix_copy(matrix
, &data
->global_map
);
996 adg_matrix_copy(matrix
, adg_entity_global_matrix(data
->parent
));
997 cairo_matrix_multiply(matrix
, &data
->global_map
, matrix
);
1002 local_changed(AdgEntity
*entity
)
1004 AdgEntityPrivate
*data
;
1007 data
= entity
->data
;
1008 matrix
= &data
->local_matrix
;
1010 if (data
->parent
== NULL
) {
1011 adg_matrix_copy(matrix
, &data
->local_map
);
1013 adg_matrix_copy(matrix
, adg_entity_local_matrix(data
->parent
));
1014 cairo_matrix_multiply(matrix
, &data
->local_map
, matrix
);
1019 set_global_map(AdgEntity
*entity
, const AdgMatrix
*map
)
1021 AdgEntityPrivate
*data
= entity
->data
;
1023 if (map
!= NULL
&& adg_matrix_equal(&data
->global_map
, map
))
1027 cairo_matrix_init_identity(&data
->global_map
);
1029 adg_matrix_copy(&data
->global_map
, map
);
1031 g_signal_emit(entity
, signals
[GLOBAL_CHANGED
], 0, &data
->global_matrix
);
1036 set_local_map(AdgEntity
*entity
, const AdgMatrix
*map
)
1038 AdgEntityPrivate
*data
= entity
->data
;
1040 if (map
!= NULL
&& adg_matrix_equal(&data
->local_map
, map
))
1044 cairo_matrix_init_identity(&data
->local_map
);
1046 adg_matrix_copy(&data
->local_map
, map
);
1048 g_signal_emit(entity
, signals
[LOCAL_CHANGED
], 0, &data
->local_matrix
);
1053 set_local_mode(AdgEntity
*entity
, AdgTransformationMode mode
)
1055 AdgEntityPrivate
*data
= entity
->data
;
1057 if (mode
== data
->local_mode
)
1060 data
->local_mode
= mode
;
1066 real_invalidate(AdgEntity
*entity
)
1068 AdgEntityPrivate
*data
= entity
->data
;
1069 AdgEntityClass
*klass
= ADG_ENTITY_GET_CLASS(entity
);
1071 if (klass
->invalidate
== NULL
) {
1072 /* Do not raise any warning if invalidate() is not defined,
1073 * assuming entity does not have cache to be cleared */
1075 klass
->invalidate(entity
);
1078 data
->extents
.is_defined
= FALSE
;
1082 real_arrange(AdgEntity
*entity
)
1084 AdgEntityClass
*klass
= ADG_ENTITY_GET_CLASS(entity
);
1086 if (klass
->arrange
== NULL
) {
1087 /* The arrange() method must be defined */
1088 g_warning("%s: `arrange' method not implemented for type `%s'",
1089 G_STRLOC
, g_type_name(G_OBJECT_TYPE(entity
)));
1091 klass
->arrange(entity
);
1096 real_render(AdgEntity
*entity
, cairo_t
*cr
)
1098 AdgEntityPrivate
*data
= entity
->data
;
1099 AdgEntityClass
*klass
= ADG_ENTITY_GET_CLASS(entity
);
1101 if (klass
->render
== NULL
) {
1102 /* The render method must be defined */
1103 g_warning("%s: `render' method not implemented for type `%s'",
1104 G_STRLOC
, g_type_name(G_OBJECT_TYPE(entity
)));
1106 /* Before the rendering, the entity should be arranged */
1107 g_signal_emit(entity
, signals
[ARRANGE
], 0);
1110 cairo_set_matrix(cr
, &data
->global_matrix
);
1111 klass
->render(entity
, cr
);