From ab5566d01571157dcdba7dd884a5b936a907a4fe Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Wed, 23 Sep 2009 15:29:51 +0200 Subject: [PATCH] [AdgEntity] before,after => transform Condensed adg_entity_before_global_map() and adg_entity_after_global_map() in adg_entity_transform_global_map() using the new AdgTransformationMode enum. The same for local map transformations. --- adg/adg-entity.c | 94 ++++++++++++-------------------------------------------- adg/adg-entity.h | 16 +++++----- 2 files changed, 27 insertions(+), 83 deletions(-) diff --git a/adg/adg-entity.c b/adg/adg-entity.c index 596d4b07..56686dec 100644 --- a/adg/adg-entity.c +++ b/adg/adg-entity.c @@ -439,23 +439,26 @@ adg_entity_set_global_map(AdgEntity *entity, const AdgMatrix *map) } /** - * adg_entity_before_global_map: + * adg_entity_transform_global_map: * @entity: an #AdgEntity object * @transformation: the transformation to apply + * @mode: how @transformation should be applied * * Convenient function to change the global map of @entity by - * applying @tranformation before the current matrix. This is - * logically equivalent to the following code: + * applying @tranformation using the @mode operator. This is + * logically equivalent to the following: * * |[ * AdgMatrix tmp_map; * adg_entity_get_global_map(entity, &tmp_map); - * cairo_matrix_multiply(&tmp_map, &tmp_map, transformation); + * adg_matrix_transform(&tmp_map, transformation, mode); * adg_entity_set_global_map(entity, &tmp_map); * ]| **/ void -adg_entity_before_global_map(AdgEntity *entity, const AdgMatrix *transformation) +adg_entity_transform_global_map(AdgEntity *entity, + const AdgMatrix *transformation, + AdgTransformationMode mode) { AdgEntityPrivate *data; AdgMatrix map; @@ -464,39 +467,9 @@ adg_entity_before_global_map(AdgEntity *entity, const AdgMatrix *transformation) g_return_if_fail(transformation != NULL); data = entity->data; - cairo_matrix_multiply(&map, &data->global_map, transformation); - if (set_global_map(entity, &map)) - g_object_notify((GObject *) entity, "global-map"); -} - -/** - * adg_entity_after_global_map: - * @entity: an #AdgEntity object - * @transformation: the transformation to apply - * - * Convenient function to change the global map of @entity by - * applying @tranformation after the current matrix. This is - * logically equivalent to the following code: - * - * |[ - * AdgMatrix tmp_map; - * adg_entity_get_global_map(entity, &tmp_map); - * cairo_matrix_multiply(&tmp_map, transformation, &tmp_map); - * adg_entity_set_global_map(entity, &tmp_map); - * ]| - **/ -void -adg_entity_after_global_map(AdgEntity *entity, const AdgMatrix *transformation) -{ - AdgEntityPrivate *data; - AdgMatrix map; - - g_return_if_fail(ADG_IS_ENTITY(entity)); - g_return_if_fail(transformation != NULL); - - data = entity->data; - cairo_matrix_multiply(&map, transformation, &data->global_map); + adg_matrix_copy(&map, &data->global_map); + adg_matrix_transform(&map, transformation, mode); if (set_global_map(entity, &map)) g_object_notify((GObject *) entity, "global-map"); @@ -589,23 +562,26 @@ adg_entity_set_local_map(AdgEntity *entity, const AdgMatrix *map) } /** - * adg_entity_before_local_map: + * adg_entity_transform_local_map: * @entity: an #AdgEntity object * @transformation: the transformation to apply + * @mode: how @transformation should be applied * * Convenient function to change the local map of @entity by - * applying @tranformation before the current matrix. This is - * logically equivalent to the following code: + * applying @tranformation using the @mode operator. This is + * logically equivalent to the following: * * |[ * AdgMatrix tmp_map; * adg_entity_get_local_map(entity, &tmp_map); - * cairo_matrix_multiply(&tmp_map, &tmp_map, transformation); + * adg_matrix_transform(&tmp_map, transformation, mode); * adg_entity_set_local_map(entity, &tmp_map); * ]| **/ void -adg_entity_before_local_map(AdgEntity *entity, const AdgMatrix *transformation) +adg_entity_transform_local_map(AdgEntity *entity, + const AdgMatrix *transformation, + AdgTransformationMode mode) { AdgEntityPrivate *data; AdgMatrix map; @@ -614,39 +590,9 @@ adg_entity_before_local_map(AdgEntity *entity, const AdgMatrix *transformation) g_return_if_fail(transformation != NULL); data = entity->data; - cairo_matrix_multiply(&map, &data->local_map, transformation); - if (set_local_map(entity, &map)) - g_object_notify((GObject *) entity, "local-map"); -} - -/** - * adg_entity_after_local_map: - * @entity: an #AdgEntity object - * @transformation: the transformation to apply - * - * Convenient function to change the local map of @entity by - * applying @tranformation after the current matrix. This is - * logically equivalent to the following code: - * - * |[ - * AdgMatrix tmp_map; - * adg_entity_get_local_map(entity, &tmp_map); - * cairo_matrix_multiply(&tmp_map, transformation, &tmp_map); - * adg_entity_set_local_map(entity, &tmp_map); - * ]| - **/ -void -adg_entity_after_local_map(AdgEntity *entity, const AdgMatrix *transformation) -{ - AdgEntityPrivate *data; - AdgMatrix map; - - g_return_if_fail(ADG_IS_ENTITY(entity)); - g_return_if_fail(transformation != NULL); - - data = entity->data; - cairo_matrix_multiply(&map, transformation, &data->local_map); + adg_matrix_copy(&map, &data->local_map); + adg_matrix_transform(&map, transformation, mode); if (set_local_map(entity, &map)) g_object_notify((GObject *) entity, "local-map"); diff --git a/adg/adg-entity.h b/adg/adg-entity.h index 490b4e96..a35343b5 100644 --- a/adg/adg-entity.h +++ b/adg/adg-entity.h @@ -61,7 +61,7 @@ struct _AdgEntityClass { /* Virtual Table */ void (*invalidate) (AdgEntity *entity); - void (*arrange) (AdgEntity *entity); + void (*arrange) (AdgEntity *entity); void (*render) (AdgEntity *entity, cairo_t *cr); }; @@ -77,10 +77,9 @@ void adg_entity_get_global_map (AdgEntity *entity, AdgMatrix *map); void adg_entity_set_global_map (AdgEntity *entity, const AdgMatrix *map); -void adg_entity_before_global_map (AdgEntity *entity, - const AdgMatrix *transformation); -void adg_entity_after_global_map (AdgEntity *entity, - const AdgMatrix *transformation); +void adg_entity_transform_global_map (AdgEntity *entity, + const AdgMatrix *transformation, + AdgTransformationMode mode); void adg_entity_get_global_matrix (AdgEntity *entity, AdgMatrix *matrix); void adg_entity_set_global_matrix (AdgEntity *entity, @@ -89,10 +88,9 @@ void adg_entity_get_local_map (AdgEntity *entity, AdgMatrix *map); void adg_entity_set_local_map (AdgEntity *entity, const AdgMatrix *map); -void adg_entity_before_local_map (AdgEntity *entity, - const AdgMatrix *transformation); -void adg_entity_after_local_map (AdgEntity *entity, - const AdgMatrix *transformation); +void adg_entity_transform_local_map (AdgEntity *entity, + const AdgMatrix *transformation, + AdgTransformationMode mode); void adg_entity_get_local_matrix (AdgEntity *entity, AdgMatrix *matrix); void adg_entity_set_local_matrix (AdgEntity *entity, -- 2.11.4.GIT