From c2766a893ab04c4f54c6c36df345f6411af5d82e Mon Sep 17 00:00:00 2001 From: Bernd Jendrissek Date: Wed, 10 Jan 2018 18:54:59 +0200 Subject: [PATCH] Take advantage of s_visit_list. --- libgeda/src/o_list.c | 65 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/libgeda/src/o_list.c b/libgeda/src/o_list.c index a59519cdb..c72d57497 100644 --- a/libgeda/src/o_list.c +++ b/libgeda/src/o_list.c @@ -333,6 +333,20 @@ void o_list_delete_rest(TOPLEVEL *toplevel, OBJECT *list) } } +struct affine_context { + int x; + int y; + int angle; +}; + +static enum visit_result translate_world_one(OBJECT *o, void *userdata) +{ + struct affine_context *ctx = userdata; + + o_translate_world(ctx->x, ctx->y, o); + + return VISIT_RES_OK; +} /*! \todo Finish function description!!! * \brief @@ -340,12 +354,14 @@ void o_list_delete_rest(TOPLEVEL *toplevel, OBJECT *list) */ void o_list_translate_world(int dx, int dy, OBJECT *list) { - OBJECT *o_current = list; + struct affine_context ctx = { + .x = dx, + .y = dy, + }; - while ( o_current != NULL ) { - o_translate_world(dx, dy, o_current); - o_current = o_current->next; - } + /* XXX o_text_create_string still uses partial lists. */ + s_visit_list(list, list->type == OBJ_HEAD ? LIST_KIND_HEAD : LIST_KIND_REST, + &translate_world_one, &ctx, VISIT_ANY, 1); } @@ -365,7 +381,14 @@ void o_glist_translate_world(int dx, int dy, GList const *list) } } +static enum visit_result rotate_world_one(OBJECT *o, void *userdata) +{ + struct affine_context *ctx = userdata; + + o_rotate_world(ctx->x, ctx->y, ctx->angle, o); + return VISIT_RES_OK; +} /*! \todo Finish function description!!! * \brief @@ -373,12 +396,15 @@ void o_glist_translate_world(int dx, int dy, GList const *list) */ void o_list_rotate_world(int x, int y, int angle, OBJECT *list) { - OBJECT *o_current = list; + struct affine_context ctx = { + .x = x, + .y = y, + .angle = angle, + }; - while ( o_current != NULL ) { - o_rotate_world(x, y, angle, o_current); - o_current = o_current->next; - } + /* XXX o_text_create_string still uses partial lists. */ + s_visit_list(list, list->type == OBJ_HEAD ? LIST_KIND_HEAD : LIST_KIND_REST, + &rotate_world_one, &ctx, VISIT_ANY, 1); } @@ -398,6 +424,15 @@ void o_glist_rotate_world(int x, int y, int angle, GList const *list) } } +static enum visit_result mirror_world_one(OBJECT *o, void *userdata) +{ + struct affine_context *ctx = userdata; + + o_mirror_world(ctx->x, ctx->y, o); + + return VISIT_RES_OK; +} + /*! \todo Finish function description!!! * \brief @@ -405,12 +440,12 @@ void o_glist_rotate_world(int x, int y, int angle, GList const *list) */ void o_list_mirror_world(int x, int y, OBJECT *list) { - OBJECT *o_current = list; + struct affine_context ctx = { + .x = x, + .y = y, + }; - while ( o_current != NULL ) { - o_mirror_world(x, y, o_current); - o_current = o_current->next; - } + s_visit_list(list, LIST_KIND_HEAD, &mirror_world_one, &ctx, VISIT_ANY, 1); } -- 2.11.4.GIT