[AdgEntity] -adg_entity_scale_to_{model,paper}()
[adg.git] / adg / adg-entity.c
blob5aa9f5d7264b002e15ea7ffe07447a5a5001006e
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-entity
23 * @title: AdgEntity
24 * @short_description: The base class for renderable objects
26 * This abstract class provides a base interface for all renderable objects
27 * (all the objects that can be printed or viewed).
28 **/
30 /**
31 * AdgEntity:
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
35 **/
38 #include "adg-entity.h"
39 #include "adg-entity-private.h"
40 #include "adg-canvas.h"
41 #include "adg-context.h"
42 #include "adg-util.h"
43 #include "adg-intl.h"
46 enum {
47 PROP_0,
48 PROP_PARENT,
49 PROP_CONTEXT
52 enum {
53 PARENT_SET,
54 MODEL_MATRIX_CHANGED,
55 PAPER_MATRIX_CHANGED,
56 INVALIDATE,
57 RENDER,
58 LAST_SIGNAL
62 static void get_property (GObject *object,
63 guint prop_id,
64 GValue *value,
65 GParamSpec *pspec);
66 static void set_property (GObject *object,
67 guint prop_id,
68 const GValue *value,
69 GParamSpec *pspec);
70 static void dispose (GObject *object);
71 static AdgContainer * get_parent (AdgEntity *entity);
72 static void set_parent (AdgEntity *entity,
73 AdgContainer *parent);
74 static void parent_set (AdgEntity *entity,
75 AdgContainer *old_parent);
76 static AdgContext * get_context (AdgEntity *entity);
77 static void set_context (AdgEntity *entity,
78 AdgContext *context);
79 static void model_matrix_changed (AdgEntity *entity,
80 AdgMatrix *parent_matrix);
81 static void paper_matrix_changed (AdgEntity *entity,
82 AdgMatrix *parent_matrix);
83 static void render (AdgEntity *entity,
84 cairo_t *cr);
85 static const AdgMatrix *get_model_matrix (AdgEntity *entity);
86 static const AdgMatrix *get_paper_matrix (AdgEntity *entity);
88 static guint signals[LAST_SIGNAL] = { 0 };
91 G_DEFINE_ABSTRACT_TYPE(AdgEntity, adg_entity, G_TYPE_INITIALLY_UNOWNED);
94 static void
95 adg_entity_class_init(AdgEntityClass *klass)
97 GObjectClass *gobject_class;
98 GParamSpec *param;
100 gobject_class = (GObjectClass *) klass;
102 g_type_class_add_private(klass, sizeof(AdgEntityPrivate));
104 gobject_class->get_property = get_property;
105 gobject_class->set_property = set_property;
106 gobject_class->dispose = dispose;
108 klass->get_parent = get_parent;
109 klass->set_parent = set_parent;
110 klass->parent_set = parent_set;
111 klass->get_context = get_context;
112 klass->model_matrix_changed = model_matrix_changed;
113 klass->paper_matrix_changed = paper_matrix_changed;
114 klass->invalidate = NULL;
115 klass->render = render;
116 klass->get_model_matrix = get_model_matrix;
117 klass->get_paper_matrix = get_paper_matrix;
119 param = g_param_spec_object("parent",
120 P_("Parent Container"),
121 P_("The parent AdgContainer of this entity or NULL if this is a top-level entity"),
122 ADG_TYPE_CONTAINER, G_PARAM_READWRITE);
123 g_object_class_install_property(gobject_class, PROP_PARENT, param);
125 param = g_param_spec_object("context",
126 P_("Context"),
127 P_("The context associated to this entity or NULL to inherit the parent context"),
128 ADG_TYPE_CONTEXT, G_PARAM_READWRITE);
129 g_object_class_install_property(gobject_class, PROP_CONTEXT, param);
132 * AdgEntity::parent-set:
133 * @entity: an #AdgEntity
134 * @parent: the #AdgContainer parent of @entity
136 * Emitted after the parent container has changed.
138 signals[PARENT_SET] =
139 g_signal_new("parent-set",
140 G_OBJECT_CLASS_TYPE(gobject_class),
141 G_SIGNAL_RUN_FIRST,
142 G_STRUCT_OFFSET(AdgEntityClass, parent_set),
143 NULL, NULL,
144 g_cclosure_marshal_VOID__OBJECT,
145 G_TYPE_NONE, 1, ADG_TYPE_CONTAINER);
148 * AdgEntity::model-matrix-changed:
149 * @entity: an #AdgEntity
150 * @parent_matrix: the parent model matrix
152 * Emitted after the current model matrix has changed.
154 signals[MODEL_MATRIX_CHANGED] =
155 g_signal_new("model-matrix-changed",
156 G_OBJECT_CLASS_TYPE(gobject_class),
157 G_SIGNAL_RUN_FIRST,
158 G_STRUCT_OFFSET(AdgEntityClass, model_matrix_changed),
159 NULL, NULL,
160 g_cclosure_marshal_VOID__BOXED,
161 G_TYPE_NONE, 1,
162 ADG_TYPE_MATRIX | G_SIGNAL_TYPE_STATIC_SCOPE);
165 * AdgEntity::paper-matrix-changed:
166 * @entity: an #AdgEntity
167 * @parent_matrix: the parent paper matrix
169 * Emitted after the current paper matrix has changed.
171 signals[PAPER_MATRIX_CHANGED] =
172 g_signal_new("paper-matrix-changed",
173 G_OBJECT_CLASS_TYPE(gobject_class),
174 G_SIGNAL_RUN_FIRST,
175 G_STRUCT_OFFSET(AdgEntityClass, paper_matrix_changed),
176 NULL, NULL,
177 g_cclosure_marshal_VOID__BOXED,
178 G_TYPE_NONE, 1,
179 ADG_TYPE_MATRIX | G_SIGNAL_TYPE_STATIC_SCOPE);
182 * AdgEntity::invalidate:
183 * @entity: an #AdgEntity
185 * Clears the cached data of @entity.
187 signals[INVALIDATE] =
188 g_signal_new("invalidate",
189 G_OBJECT_CLASS_TYPE(gobject_class),
190 G_SIGNAL_RUN_FIRST,
191 G_STRUCT_OFFSET(AdgEntityClass, invalidate),
192 NULL, NULL,
193 g_cclosure_marshal_VOID__BOOLEAN,
194 G_TYPE_NONE, 0);
197 * AdgEntity::render:
198 * @entity: an #AdgEntity
199 * @cr: a #cairo_t drawing context
201 * Causes the rendering of @entity on @cr.
203 signals[RENDER] =
204 g_signal_new("render",
205 G_OBJECT_CLASS_TYPE(gobject_class),
206 G_SIGNAL_RUN_FIRST,
207 G_STRUCT_OFFSET(AdgEntityClass, render),
208 NULL, NULL,
209 g_cclosure_marshal_VOID__POINTER,
210 G_TYPE_NONE, 1, G_TYPE_POINTER);
213 static void
214 adg_entity_init(AdgEntity *entity)
216 AdgEntityPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(entity,
217 ADG_TYPE_ENTITY,
218 AdgEntityPrivate);
219 data->parent = NULL;
220 data->flags = 0;
221 data->context = NULL;
223 entity->data = data;
226 static void
227 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
229 AdgEntity *entity = (AdgEntity *) object;
231 switch (prop_id) {
232 case PROP_PARENT:
233 g_value_set_object(value, get_parent(entity));
234 break;
235 case PROP_CONTEXT:
236 g_value_set_object(value, get_context(entity));
237 break;
238 default:
239 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
240 break;
244 static void
245 set_property(GObject *object,
246 guint prop_id, const GValue *value, GParamSpec *pspec)
248 AdgEntity *entity = (AdgEntity *) object;
250 switch (prop_id) {
251 case PROP_PARENT:
252 set_parent(entity, (AdgContainer *) g_value_get_object(value));
253 break;
254 case PROP_CONTEXT:
255 set_context(entity, g_value_get_object(value));
256 break;
257 default:
258 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
259 break;
263 static void
264 dispose(GObject *object)
266 AdgEntity *entity;
267 AdgEntityPrivate *data;
268 GObjectClass *object_class;
270 entity = (AdgEntity *) object;
271 data = entity->data;
272 object_class = (GObjectClass *) adg_entity_parent_class;
274 if (data->parent)
275 adg_container_remove(data->parent, entity);
277 if (object_class->dispose != NULL)
278 object_class->dispose(object);
283 * adg_entity_get_parent:
284 * @entity: an #AdgEntity
286 * Gets the container parent of @entity.
288 * This function is only useful in entity implementations.
290 * Return value: the container object or %NULL if @entity is not contained
292 AdgContainer *
293 adg_entity_get_parent(AdgEntity *entity)
295 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
297 return ADG_ENTITY_GET_CLASS(entity)->get_parent(entity);
301 * adg_entity_set_parent:
302 * @entity: an #AdgEntity
303 * @parent: an #AdgContainer
305 * Sets a new container of @entity.
307 * This function is only useful in entity implementations.
309 void
310 adg_entity_set_parent(AdgEntity *entity, AdgContainer *parent)
312 g_return_if_fail(ADG_IS_ENTITY(entity));
314 ADG_ENTITY_GET_CLASS(entity)->set_parent(entity, parent);
315 g_object_notify((GObject *) entity, "parent");
319 * adg_entity_unparent:
320 * @entity: an #AdgEntity
322 * Removes the current parent of @entity, properly handling
323 * the references between them.
325 * If @entity has no parent, this function simply returns.
327 void
328 adg_entity_unparent(AdgEntity *entity)
330 AdgContainer *old_parent;
332 g_return_if_fail(ADG_IS_ENTITY(entity));
334 old_parent = ADG_ENTITY_GET_CLASS(entity)->get_parent(entity);
336 if (old_parent == NULL)
337 return;
339 ADG_ENTITY_GET_CLASS(entity)->set_parent(entity, NULL);
340 g_signal_emit(entity, signals[PARENT_SET], 0, old_parent);
342 g_object_unref(entity);
346 * adg_entity_reparent:
347 * @entity: an #AdgEntity
348 * @parent: the new container
350 * Moves @entity from the old parent to @parent, handling reference
351 * count issues to avoid destroying the object.
353 void
354 adg_entity_reparent(AdgEntity *entity, AdgContainer *parent)
356 AdgContainer *old_parent;
358 g_return_if_fail(ADG_IS_CONTAINER(parent));
360 old_parent = adg_entity_get_parent(entity);
362 /* Reparenting on the same container: do nothing */
363 if (old_parent == parent)
364 return;
366 g_return_if_fail(ADG_IS_CONTAINER(old_parent));
368 g_object_ref(entity);
369 adg_container_remove(old_parent, entity);
370 adg_container_add(parent, entity);
371 g_object_unref(entity);
375 * adg_entity_get_context:
376 * @entity: an #AdgEntity instance
378 * Gets the context associated to @entity.
379 * If no context was explicitely set, get the parent context.
381 * Return value: the requested context or %NULL on errors
383 AdgContext *
384 adg_entity_get_context(AdgEntity *entity)
386 AdgEntityPrivate *data;
388 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
390 data = entity->data;
392 if (data->context)
393 return data->context;
395 if (data->parent)
396 return adg_entity_get_context((AdgEntity *) data->parent);
398 return NULL;
402 * adg_entity_set_context:
403 * @entity: an #AdgEntity instance
404 * @context: the new context
406 * Sets a new context. The old context (if any) will be unreferenced
407 * while a new reference will be added to @context.
409 void
410 adg_entity_set_context(AdgEntity *entity, AdgContext *context)
412 g_return_if_fail(ADG_IS_ENTITY(entity));
413 g_return_if_fail(ADG_IS_CONTEXT(context));
415 set_context(entity, context);
416 g_object_notify((GObject *) entity, "context");
420 * adg_entity_get_canvas:
421 * @entity: an #AdgEntity
423 * Walks on the @entity hierarchy and gets the first parent of @entity that is
424 * of #AdgCanvas derived type.
426 * Return value: the requested object or %NULL if there is no #AdgCanvas in
427 * the parent hierarchy.
429 AdgCanvas *
430 adg_entity_get_canvas(AdgEntity *entity)
432 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
434 while (entity) {
435 if (ADG_IS_CANVAS(entity))
436 return (AdgCanvas *) entity;
438 entity = (AdgEntity *) adg_entity_get_parent(entity);
441 return NULL;
445 * adg_entity_get_model_matrix:
446 * @entity: an #AdgEntity object
448 * Gets the model matrix to be used in rendering this @entity.
450 * Return value: the requested matrix
452 const AdgMatrix *
453 adg_entity_get_model_matrix(AdgEntity *entity)
455 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
456 return ADG_ENTITY_GET_CLASS(entity)->get_model_matrix(entity);
460 * adg_entity_get_paper_matrix:
461 * @entity: an #AdgEntity object
463 * Gets the paper matrix to be used in rendering this @entity.
465 * Return value: the requested matrix
467 const AdgMatrix *
468 adg_entity_get_paper_matrix(AdgEntity *entity)
470 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
471 return ADG_ENTITY_GET_CLASS(entity)->get_paper_matrix(entity);
475 * adg_entity_build_paper2model:
476 * @entity: an #AdgEntity
477 * @matrix: the destination matrix
479 * Builds a matrix to translate from paper to model space and
480 * put the result in @matrix.
482 * Return value: %TRUE on success, %FALSE on errors
484 gboolean
485 adg_entity_build_paper2model(AdgEntity *entity, AdgMatrix *matrix)
487 cairo_status_t status;
489 g_return_val_if_fail(ADG_IS_ENTITY(entity), FALSE);
490 g_return_val_if_fail(matrix != NULL, FALSE);
492 adg_matrix_copy(matrix, adg_entity_get_model_matrix(entity));
493 status = cairo_matrix_invert(matrix);
494 if (status != CAIRO_STATUS_SUCCESS) {
495 g_error("Unable to invert model matrix (cairo message: %s)",
496 cairo_status_to_string(status));
497 return FALSE;
500 cairo_matrix_multiply(matrix, matrix, adg_entity_get_paper_matrix(entity));
501 return TRUE;
505 * adg_entity_build_model2paper:
506 * @entity: an #AdgEntity
507 * @matrix: the destination matrix
509 * Builds a matrix to translate from model to paper space and
510 * put the result in @matrix.
512 * Return value: %TRUE on success, %FALSE on errors
514 gboolean
515 adg_entity_build_model2paper(AdgEntity *entity, AdgMatrix *matrix)
517 cairo_status_t status;
519 g_return_val_if_fail(ADG_IS_ENTITY(entity), FALSE);
520 g_return_val_if_fail(matrix != NULL, FALSE);
522 adg_matrix_copy(matrix, adg_entity_get_paper_matrix(entity));
523 status = cairo_matrix_invert(matrix);
524 if (status != CAIRO_STATUS_SUCCESS) {
525 g_error("Unable to invert paper matrix (cairo message: %s)",
526 cairo_status_to_string(status));
527 return FALSE;
530 cairo_matrix_multiply(matrix, matrix, adg_entity_get_model_matrix(entity));
531 return TRUE;
535 * adg_entity_model_matrix_changed:
536 * @entity: an #AdgEntity
537 * @parent_matrix: the parent #AdgMatrix
539 * Emits the "model-matrix-changed" signal on @entity.
541 * This function is only useful in entity implementations.
543 void
544 adg_entity_model_matrix_changed(AdgEntity *entity,
545 const AdgMatrix *parent_matrix)
547 g_return_if_fail(ADG_IS_ENTITY(entity));
549 g_signal_emit(entity, signals[MODEL_MATRIX_CHANGED], 0, parent_matrix);
553 * adg_entity_paper_matrix_changed:
554 * @entity: an #AdgEntity
555 * @parent_matrix: the parent #AdgMatrix
557 * Emits the "paper-matrix-changed" signal on @entity.
559 * This function is only useful in entity implementations.
561 void
562 adg_entity_paper_matrix_changed(AdgEntity *entity,
563 const AdgMatrix *parent_matrix)
565 g_return_if_fail(ADG_IS_ENTITY(entity));
567 g_signal_emit(entity, signals[PAPER_MATRIX_CHANGED], 0, parent_matrix);
571 * adg_entity_get_style:
572 * @entity: an #AdgEntity
573 * @style_slot: the slot of the style to get
575 * Gets a style from this entity. If the entity has no context associated
576 * or the style in undefined within this context, gets the style from its
577 * parent container.
579 * Return value: the requested style or %NULL on errors
581 AdgStyle *
582 adg_entity_get_style(AdgEntity *entity, AdgStyleSlot style_slot)
584 AdgEntityPrivate *data;
586 g_return_val_if_fail(ADG_IS_ENTITY(entity), NULL);
588 data = entity->data;
590 if (data->context) {
591 AdgStyle *style = adg_context_get_style(data->context, style_slot);
592 if (style)
593 return style;
596 if (data->parent)
597 return adg_entity_get_style((AdgEntity *) data->parent, style_slot);
599 return NULL;
603 * adg_entity_apply:
604 * @entity: an #AdgEntity
605 * @style_slot: the slot of the style to apply
606 * @cr: a #cairo_t drawing context
608 * Applies the specified style to the @cr cairo context.
610 void
611 adg_entity_apply(AdgEntity *entity, AdgStyleSlot style_slot, cairo_t *cr)
613 AdgStyle *style = adg_entity_get_style(entity, style_slot);
615 if (style)
616 adg_style_apply(style, cr);
620 * adg_entity_point_to_pair:
621 * @entity: an #AdgEntity
622 * @point: the source #AdgPoint
623 * @pair: the destination #AdgPair
624 * @cr: a #cairo_t drawing context
626 * Converts @point to @pair using the model and paper matrix of @entity,
627 * as if the current matrix is an identity matrix.
629 void
630 adg_entity_point_to_pair(AdgEntity *entity, const AdgPoint *point,
631 AdgPair *pair, cairo_t *cr)
633 AdgMatrix inverted_ctm;
634 const AdgMatrix *model_matrix;
635 const AdgMatrix *paper_matrix;
636 AdgPair model_pair, paper_pair;
638 g_return_if_fail(ADG_IS_ENTITY(entity));
639 g_return_if_fail(point != NULL);
640 g_return_if_fail(pair != NULL);
642 cairo_get_matrix(cr, &inverted_ctm);
643 cairo_matrix_invert(&inverted_ctm);
644 model_matrix = ADG_ENTITY_GET_CLASS(entity)->get_model_matrix(entity);
645 paper_matrix = ADG_ENTITY_GET_CLASS(entity)->get_paper_matrix(entity);
647 cpml_pair_copy(&model_pair, &point->model);
648 cpml_pair_transform(&model_pair, model_matrix);
650 cpml_pair_copy(&paper_pair, &point->paper);
651 cpml_pair_transform(&paper_pair, paper_matrix);
653 pair->x = model_pair.x + paper_pair.x;
654 pair->y = model_pair.y + paper_pair.y;
656 cpml_pair_transform(pair, &inverted_ctm);
660 * adg_entity_point_to_model_pair:
661 * @entity: an #AdgEntity
662 * @point: the source #AdgPoint
663 * @pair: the destination #AdgPair
665 * Converts @point to @pair in model space.
667 void
668 adg_entity_point_to_model_pair(AdgEntity *entity,
669 const AdgPoint *point, AdgPair *pair)
671 const AdgMatrix *paper_matrix;
673 g_return_if_fail(ADG_IS_ENTITY(entity));
674 g_return_if_fail(point != NULL);
675 g_return_if_fail(pair != NULL);
677 paper_matrix = ADG_ENTITY_GET_CLASS(entity)->get_paper_matrix(entity);
678 cpml_pair_copy(pair, &point->paper);
679 cpml_pair_transform(pair, paper_matrix);
681 pair->x += point->model.x;
682 pair->y += point->model.y;
686 * adg_entity_point_to_paper_pair:
687 * @entity: an #AdgEntity
688 * @point: the source #AdgPoint
689 * @pair: the destination #AdgPair
691 * Converts @point to @pair in paper space.
693 void
694 adg_entity_point_to_paper_pair(AdgEntity *entity,
695 const AdgPoint *point, AdgPair *pair)
697 const AdgMatrix *model_matrix;
699 g_return_if_fail(ADG_IS_ENTITY(entity));
700 g_return_if_fail(point != NULL);
701 g_return_if_fail(pair != NULL);
703 model_matrix = ADG_ENTITY_GET_CLASS(entity)->get_model_matrix(entity);
704 cpml_pair_copy(pair, &point->model);
705 cpml_pair_transform(pair, model_matrix);
707 pair->x += point->paper.x;
708 pair->y += point->paper.y;
709 g_print("Pair (%lf, %lf)\n", pair->x, pair->y);
713 * adg_entity_model_matrix_applied:
714 * @entity: an #AdgEntity
716 * Return value: %TRUE if the model matrix didn't change from the last render
718 gboolean
719 adg_entity_model_matrix_applied(AdgEntity *entity)
721 AdgEntityPrivate *data;
723 g_return_val_if_fail(ADG_IS_ENTITY(entity), FALSE);
725 data = entity->data;
727 return ADG_ISSET(data->flags, MODEL_MATRIX_APPLIED);
731 * adg_entity_paper_matrix_applied:
732 * @entity: an #AdgEntity
734 * Return value: %TRUE if the paper matrix didn't change from the last render
736 gboolean
737 adg_entity_paper_matrix_applied(AdgEntity *entity)
739 AdgEntityPrivate *data;
741 g_return_val_if_fail(ADG_IS_ENTITY(entity), FALSE);
743 data = entity->data;
745 return ADG_ISSET(data->flags, PAPER_MATRIX_APPLIED);
749 * adg_entity_model_applied:
750 * @entity: an #AdgEntity
752 * Return value: %TRUE if the model didn't change from the last render
754 gboolean
755 adg_entity_model_applied(AdgEntity *entity)
757 AdgEntityPrivate *data;
759 g_return_val_if_fail(ADG_IS_ENTITY(entity), FALSE);
761 data = entity->data;
763 return ADG_ISSET(data->flags, MODEL_APPLIED);
767 * adg_entity_invalidate:
768 * @entity: an #AdgEntity
770 * Emits the "invalidate" signal on @entity and all its children, if any,
771 * so subsequent rendering will need a global recomputation.
773 void
774 adg_entity_invalidate(AdgEntity *entity)
776 g_return_if_fail(ADG_IS_ENTITY(entity));
778 g_signal_emit(entity, signals[INVALIDATE], 0, NULL);
782 * adg_entity_render:
783 * @entity: an #AdgEntity
784 * @cr: a #cairo_t drawing context
786 * Emits the "render" signal on @entity and all its children, if any,
787 * causing the rendering operation the @cr cairo context.
789 void
790 adg_entity_render(AdgEntity *entity, cairo_t *cr)
792 g_return_if_fail(ADG_IS_ENTITY(entity));
794 g_signal_emit(entity, signals[RENDER], 0, cr);
798 static AdgContainer *
799 get_parent(AdgEntity *entity)
801 AdgEntityPrivate *data = entity->data;
803 return data->parent;
806 static void
807 set_parent(AdgEntity *entity, AdgContainer *parent)
809 AdgEntityPrivate *data = entity->data;
811 data->parent = parent;
814 static void
815 parent_set(AdgEntity *entity, AdgContainer *old_parent)
817 if (ADG_IS_CONTAINER(old_parent)) {
818 const AdgMatrix *old_model;
819 const AdgMatrix *old_paper;
821 old_model = adg_entity_get_model_matrix((AdgEntity *) old_parent);
822 old_paper = adg_entity_get_paper_matrix((AdgEntity *) old_parent);
824 adg_entity_model_matrix_changed(entity, old_model);
825 adg_entity_paper_matrix_changed(entity, old_paper);
829 static AdgContext *
830 get_context(AdgEntity *entity)
832 AdgEntityPrivate *data = entity->data;
833 AdgEntity *parent;
835 if (data->context)
836 return data->context;
838 parent = (AdgEntity *) data->parent;
840 return parent ? ADG_ENTITY_GET_CLASS(parent)->get_context(parent) : NULL;
843 static void
844 set_context(AdgEntity *entity, AdgContext *context)
846 AdgEntityPrivate *data = entity->data;
848 if (data->context)
849 g_object_unref((GObject *) data->context);
851 g_object_ref((GObject *) context);
852 data->context = context;
855 static void
856 model_matrix_changed(AdgEntity *entity, AdgMatrix *parent_matrix)
858 AdgEntityPrivate *data = entity->data;
860 ADG_UNSET(data->flags, MODEL_MATRIX_APPLIED);
863 static void
864 paper_matrix_changed(AdgEntity *entity, AdgMatrix *parent_matrix)
866 AdgEntityPrivate *data = entity->data;
868 ADG_UNSET(data->flags, PAPER_MATRIX_APPLIED);
871 static void
872 render(AdgEntity *entity, cairo_t *cr)
874 AdgEntityPrivate *data = entity->data;
876 ADG_SET(data->flags,
877 MODEL_MATRIX_APPLIED | PAPER_MATRIX_APPLIED | MODEL_APPLIED);
880 static const AdgMatrix *
881 get_model_matrix(AdgEntity *entity)
883 AdgEntityPrivate *data = entity->data;
885 return adg_entity_get_model_matrix((AdgEntity *) data->parent);
888 static const AdgMatrix *
889 get_paper_matrix(AdgEntity *entity)
891 AdgEntityPrivate *data = entity->data;
893 return adg_entity_get_paper_matrix((AdgEntity *) data->parent);