From e3bb24569b85ff5fea4dcc3eb10e86ae59608967 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 3 Mar 2004 10:16:24 +0000 Subject: Changes to implement a new behavior for -position attribute and local transforms. --- generic/Group.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'generic/Group.c') diff --git a/generic/Group.c b/generic/Group.c index cba0a2e..a9ad3a3 100644 --- a/generic/Group.c +++ b/generic/Group.c @@ -52,7 +52,8 @@ typedef struct _GroupItemStruct { /* Public data */ ZnItem clip; unsigned char alpha; - + ZnPoint pos; + /* Private data */ ZnItem head; /* Doubly linked list of all items. */ ZnItem tail; @@ -95,6 +96,8 @@ static ZnAttrConfig group_attrs[] = { { ZN_CONFIG_BOOL, "-composescale", NULL, Tk_Offset(GroupItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_TRANSFO_FLAG, False }, + { ZN_CONFIG_POINT, "-position", NULL, + Tk_Offset(GroupItemStruct, pos), 0, ZN_TRANSFO_FLAG, False}, { ZN_CONFIG_PRI, "-priority", NULL, Tk_Offset(GroupItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, @@ -130,6 +133,7 @@ Init(ZnItem item, group->clip = ZN_NO_ITEM; group->alpha = 100; group->dependents = NULL; + group->pos.x = group->pos.y = 0.0; SET(item->flags, ZN_VISIBLE_BIT); SET(item->flags, ZN_SENSITIVE_BIT); SET(item->flags, ZN_COMPOSE_ALPHA_BIT); @@ -551,13 +555,23 @@ PopClip(GroupItem group, static void PushTransform(ZnItem item) { + ZnPoint *pos; + + pos = NULL; + if (item->class->pos_offset >= 0) { + pos = (ZnPoint *) (((char *) item) + item->class->pos_offset); + if (pos->x == 0 && pos->y == 0) { + pos = NULL; + } + } if (!item->transfo && + !pos && ISSET(item->flags, ZN_COMPOSE_SCALE_BIT) && ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)) { return; } - ZnPushTransform(item->wi, item->transfo, + ZnPushTransform(item->wi, item->transfo, pos, ISSET(item->flags, ZN_COMPOSE_SCALE_BIT), ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)); /*printf("Pushing transfo for item: %d\n;", item->id); @@ -576,7 +590,17 @@ PushTransform(ZnItem item) static void PopTransform(ZnItem item) { + ZnPoint *pos; + + pos = NULL; + if (item->class->pos_offset >= 0) { + pos = ((void *) item) + item->class->pos_offset; + if (pos->x == 0 && pos->y == 0) { + pos = NULL; + } + } if (!item->transfo && + !pos && ISSET(item->flags, ZN_COMPOSE_SCALE_BIT) && ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)) { return; @@ -1302,9 +1326,11 @@ Coords(ZnItem item, char **controls __unused, unsigned int *num_pts) { + GroupItem group = (GroupItem) item; + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, - " groups can't add or remove vertices", NULL); + " can't add or remove vertices in groups", NULL); return TCL_ERROR; } else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { @@ -1313,20 +1339,12 @@ Coords(ZnItem item, " coords command need 1 point on groups", NULL); return TCL_ERROR; } - if (!item->transfo) { - item->transfo = ZnTransfoNew(); - } - ZnSetTranslation(item->transfo, (*pts)[0].x, (*pts)[0].y); + group->pos = (*pts)[0]; ZnITEM.Invalidate(item, ZN_TRANSFO_FLAG); } else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { - ZnPoint *p; - - ZnListAssertSize(item->wi->work_pts, 1); - p = (ZnPoint *) ZnListArray(item->wi->work_pts); - ZnTransfoDecompose(item->transfo, NULL, p, NULL, NULL); *num_pts = 1; - *pts = p; + **pts = group->pos; } return TCL_OK; } @@ -1674,6 +1692,7 @@ static ZnItemClassStruct GROUP_ITEM_CLASS = { False, /* has_anchors */ "group", group_attrs, + Tk_Offset(GroupItemStruct, pos), Init, Clone, Destroy, -- cgit v1.1