aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlecoanet2004-03-03 10:16:24 +0000
committerlecoanet2004-03-03 10:16:24 +0000
commite3bb24569b85ff5fea4dcc3eb10e86ae59608967 (patch)
tree4a5a104f74812cd7ac1c914c90c5ae51053d767d
parent30852dd99b28fddaef4ac37bfa225da343c6be7e (diff)
downloadtkzinc-e3bb24569b85ff5fea4dcc3eb10e86ae59608967.zip
tkzinc-e3bb24569b85ff5fea4dcc3eb10e86ae59608967.tar.gz
tkzinc-e3bb24569b85ff5fea4dcc3eb10e86ae59608967.tar.bz2
tkzinc-e3bb24569b85ff5fea4dcc3eb10e86ae59608967.tar.xz
Changes to implement a new behavior for -position attribute and local transforms.
-rw-r--r--generic/Arc.c1
-rw-r--r--generic/Curve.c1
-rw-r--r--generic/Group.c45
-rw-r--r--generic/Icon.c3
-rw-r--r--generic/Item.c50
-rw-r--r--generic/Item.h4
-rw-r--r--generic/Map.c1
-rw-r--r--generic/Rectangle.c3
-rw-r--r--generic/Reticle.c9
-rw-r--r--generic/Tabular.c5
-rw-r--r--generic/Text.c5
-rw-r--r--generic/Track.c9
-rw-r--r--generic/Triangles.c1
-rw-r--r--generic/Window.c5
14 files changed, 109 insertions, 33 deletions
diff --git a/generic/Arc.c b/generic/Arc.c
index 3d836bf..13c4f39 100644
--- a/generic/Arc.c
+++ b/generic/Arc.c
@@ -1763,6 +1763,7 @@ static ZnItemClassStruct ARC_ITEM_CLASS = {
False, /* has_anchors */
"arc",
arc_attrs,
+ -1,
Init,
Clone,
Destroy,
diff --git a/generic/Curve.c b/generic/Curve.c
index 3ed3335..7798add 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -2268,6 +2268,7 @@ static ZnItemClassStruct CURVE_ITEM_CLASS = {
False, /* has_anchors */
"curve",
cv_attrs,
+ -1,
Init,
Clone,
Destroy,
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,
diff --git a/generic/Icon.c b/generic/Icon.c
index 16ec3f0..81979a4 100644
--- a/generic/Icon.c
+++ b/generic/Icon.c
@@ -280,7 +280,7 @@ ComputeCoordinates(ZnItem item,
ZnTransformPoint(&t, quad, &pos);
}
else {
- pos = icon->pos;
+ pos.x = pos.y = 0;
}
ZnAnchor2Origin(&pos, (ZnReal) width, (ZnReal) height, icon->anchor, quad);
quad[1].x = quad[0].x;
@@ -855,6 +855,7 @@ static ZnItemClassStruct ICON_ITEM_CLASS = {
True, /* has_anchors */
"icon",
icon_attrs,
+ Tk_Offset(IconItemStruct, pos),
Init,
Clone,
Destroy,
diff --git a/generic/Item.c b/generic/Item.c
index 5935917..ae71348 100644
--- a/generic/Item.c
+++ b/generic/Item.c
@@ -1766,16 +1766,18 @@ QueryItem(ZnItem item,
*/
static void
ComposeTransform(ZnTransfo *transfo,
+ ZnPoint *pos,
ZnTransfo *current_t,
ZnTransfo *new_t,
ZnBool compose_scale,
ZnBool compose_rot)
{
ZnBool full;
+ ZnTransfo t, t2;
full = compose_scale && compose_rot;
- if (!transfo && full) {
+ if (!transfo && !pos && full) {
*new_t = *current_t;
return;
}
@@ -1784,20 +1786,40 @@ ComposeTransform(ZnTransfo *transfo,
* Full concatenation.
*/
/*ZnPrintTransfo(transfo);*/
- ZnTransfoCompose(new_t, transfo, current_t);
+ if (pos) {
+ if (!transfo) {
+ ZnTransfoSetIdentity(&t);
+ }
+ else {
+ t = *transfo;
+ }
+ ZnTranslate(&t, pos->x, pos->y);
+ ZnTransfoCompose(new_t, &t, current_t);
+ }
+ else {
+ ZnTransfoCompose(new_t, transfo, current_t);
+ }
}
else {
- ZnPoint scale, trans, local_scale, local_trans, p, p2;
+ ZnPoint scale, trans, local_scale, local_trans, p;
ZnReal local_rot, rot;
- ZnTransfo t, t2;
ZnTransfoSetIdentity(new_t);
ZnTransfoDecompose(transfo, &local_scale, &local_trans, &local_rot, NULL);
ZnScale(new_t, local_scale.x, local_scale.y);
ZnRotateRad(new_t, local_rot);
+
ZnTransfoDecompose(current_t, &scale, &trans, &rot, NULL);
- ZnTransformPoint(current_t, &local_trans, &p2);
+ if (pos) {
+ ZnTransfoSetIdentity(&t);
+ ZnTranslate(&t, pos->x, pos->y);
+ ZnTransfoCompose(&t2, &t, current_t);
+ ZnTransformPoint(&t2, &local_trans, &p);
+ }
+ else {
+ ZnTransformPoint(current_t, &local_trans, &p);
+ }
if (compose_scale) {
ZnScale(new_t, scale.x, scale.y);
@@ -1805,7 +1827,7 @@ ComposeTransform(ZnTransfo *transfo,
if (compose_rot) {
ZnRotateRad(new_t, rot);
}
- ZnTranslate(new_t, p2.x, p2.y);
+ ZnTranslate(new_t, p.x, p.y);
}
}
@@ -1822,10 +1844,11 @@ static void
GetItemTransform(ZnItem item,
ZnTransfo *t)
{
- ZnItem *items;
+ ZnItem *items;
int i;
ZnTransfo t_tmp, *t1, *t2, *swap;
-
+ ZnPoint *pos = NULL;
+
if (item_stack == NULL) {
item_stack = ZnListNew(16, sizeof(ZnItem));
}
@@ -1843,7 +1866,13 @@ GetItemTransform(ZnItem item,
t2 = &t_tmp;
items = (ZnItem *) ZnListArray(item_stack);
for (i = ZnListSize(item_stack)-1; i >= 0; i--) {
- ComposeTransform(items[i]->transfo, t1, t2,
+ if (items[i]->class->pos_offset >= 0) {
+ pos = ((void *) items[i]) + items[i]->class->pos_offset;
+ if (pos->x == 0 && pos->y == 0) {
+ pos = NULL;
+ }
+ }
+ ComposeTransform(items[i]->transfo, pos, t1, t2,
ISSET(items[i]->flags, ZN_COMPOSE_SCALE_BIT),
ISSET(items[i]->flags, ZN_COMPOSE_ROTATION_BIT));
swap = t2;
@@ -1893,6 +1922,7 @@ ZnFreeTransformStack(ZnWInfo *wi)
void
ZnPushTransform(ZnWInfo *wi,
ZnTransfo *transfo,
+ ZnPoint *pos,
ZnBool compose_scale,
ZnBool compose_rot)
{
@@ -1907,7 +1937,7 @@ ZnPushTransform(ZnWInfo *wi,
num_t = ZnListSize(wi->transfo_stack);
ZnListAssertSize(wi->transfo_stack, num_t+1);
next_t = (ZnTransfo *) ZnListAt(wi->transfo_stack, num_t);
- ComposeTransform(transfo, wi->current_transfo, next_t,
+ ComposeTransform(transfo, pos, wi->current_transfo, next_t,
compose_scale, compose_rot);
wi->current_transfo = next_t;
}
diff --git a/generic/Item.h b/generic/Item.h
index b9367f5..8da80df 100644
--- a/generic/Item.h
+++ b/generic/Item.h
@@ -262,6 +262,8 @@ typedef struct _ZnItemClassStruct {
ZnBool has_anchors; /* 1 if anchors are supported */
char *name;
ZnAttrConfig *attr_desc;
+ int pos_offset; /* Offset of -position attrib, */
+ /* if any, -1 otherwise. */
ZnItemInitMethod Init;
ZnItemCloneMethod Clone;
ZnItemDestroyMethod Destroy;
@@ -349,7 +351,7 @@ void ZnInitTransformStack(struct _ZnWInfo *wi);
void ZnFreeTransformStack(struct _ZnWInfo *wi);
void ZnResetTransformStack(struct _ZnWInfo *wi);
void ZnPushTransform(struct _ZnWInfo *wi, struct _ZnTransfo *transfo,
- ZnBool compose_scale, ZnBool compose_rot);
+ ZnPoint *pos, ZnBool compose_scale, ZnBool compose_rot);
void ZnPopTransform(struct _ZnWInfo *wi);
void ZnInitClipStack(struct _ZnWInfo *wi);
void ZnFreeClipStack(struct _ZnWInfo *wi);
diff --git a/generic/Map.c b/generic/Map.c
index 6e6143e..622668d 100644
--- a/generic/Map.c
+++ b/generic/Map.c
@@ -1611,6 +1611,7 @@ static ZnItemClassStruct MAP_ITEM_CLASS = {
False, /* has_anchors */
"map",
map_attrs,
+ -1,
Init,
Clone,
Destroy,
diff --git a/generic/Rectangle.c b/generic/Rectangle.c
index 2c8b6c0..a8cefb4 100644
--- a/generic/Rectangle.c
+++ b/generic/Rectangle.c
@@ -421,7 +421,7 @@ ToArea(ZnItem item,
ZnBBox *area = ta->area;
result = -1;
-
+
if (ISSET(rect->flags, FILLED_BIT)) {
result = ZnPolygonInBBox(rect->dev, 4, area, NULL);
}
@@ -917,6 +917,7 @@ static ZnItemClassStruct RECTANGLE_ITEM_CLASS = {
False, /* has_anchors */
"rectangle",
rect_attrs,
+ -1,
Init,
Clone,
Destroy,
diff --git a/generic/Reticle.c b/generic/Reticle.c
index 6825ac8..0e42097 100644
--- a/generic/Reticle.c
+++ b/generic/Reticle.c
@@ -262,12 +262,12 @@ ComputeCoordinates(ZnItem item,
ZnPoint p, xp;
/* Compute center device coordinates */
- ZnTransformPoint(wi->current_transfo, &reticle->pos, &reticle->dev);
- p.x = reticle->pos.x + reticle->step_size;
- p.y = reticle->pos.y;
+ p.x = p.y = 0;
+ ZnTransformPoint(wi->current_transfo, &p, &reticle->dev);
+ p.x = reticle->step_size;
ZnTransformPoint(wi->current_transfo, &p, &xp);
reticle->step_size_dev = hypot(xp.x - reticle->dev.x, xp.y - reticle->dev.y);
- p.x = reticle->pos.x + reticle->first_radius;
+ p.x = reticle->first_radius;
ZnTransformPoint(wi->current_transfo, &p, &xp);
reticle->first_radius_dev = hypot(xp.x - reticle->dev.x, xp.y - reticle->dev.y);
if (reticle->first_radius_dev < 1.0) {
@@ -599,6 +599,7 @@ static ZnItemClassStruct RETICLE_ITEM_CLASS = {
False, /* has_anchors */
"reticle",
reticle_attrs,
+ Tk_Offset(ReticleItemStruct, pos),
Init,
Clone,
Destroy,
diff --git a/generic/Tabular.c b/generic/Tabular.c
index 5f508eb..42fa9e3 100644
--- a/generic/Tabular.c
+++ b/generic/Tabular.c
@@ -274,7 +274,9 @@ ComputeCoordinates(ZnItem item,
&field_set->label_pos);
}
else {
- ZnTransformPoint(wi->current_transfo, &tab->pos,
+ ZnPoint pos;
+ pos.x = pos.y = 0;
+ ZnTransformPoint(wi->current_transfo, &pos,
&field_set->label_pos);
}
@@ -673,6 +675,7 @@ static ZnItemClassStruct TABULAR_ITEM_CLASS = {
True, /* has_anchors */
"tabular",
tabular_attrs,
+ Tk_Offset(TabularItemStruct, pos),
Init,
Clone,
Destroy,
diff --git a/generic/Text.c b/generic/Text.c
index 891ab85..5d82e69 100644
--- a/generic/Text.c
+++ b/generic/Text.c
@@ -424,7 +424,9 @@ ComputeTransfoAndOrigin(ZnItem item,
return item->transfo;
}
else {
- ZnAnchor2Origin(&text->pos, (ZnReal) text->max_width,
+ ZnPoint p;
+ p.x = p.y = 0;
+ ZnAnchor2Origin(&p, (ZnReal) text->max_width,
(ZnReal) text->height, text->anchor, origin);
origin->x = ZnNearestInt(origin->x);
origin->y = ZnNearestInt(origin->y);
@@ -2001,6 +2003,7 @@ static ZnItemClassStruct TEXT_ITEM_CLASS = {
True, /* has_anchors */
"text",
text_attrs,
+ Tk_Offset(TextItemStruct, pos),
Init,
Clone,
Destroy,
diff --git a/generic/Track.c b/generic/Track.c
index 1d68217..77366cf 100644
--- a/generic/Track.c
+++ b/generic/Track.c
@@ -2288,12 +2288,20 @@ Selection(ZnItem item,
*
**********************************************************************************
*/
+/*
+ * Track and WP -position attribute is not handled the same way as other
+ * interface items like texts, icons and such, as it make little sense
+ * to change the local transform of a track. It is always processed as
+ * a point in the coordinate system of the track's parent. It is the same
+ * for the points in the history and the speed vector end.
+ */
static ZnItemClassStruct TRACK_ITEM_CLASS = {
sizeof(TrackItemStruct),
4, /* num_parts */
True, /* has_anchors */
"track",
track_attrs,
+ -1,
Init,
Clone,
Destroy,
@@ -2327,6 +2335,7 @@ static ZnItemClassStruct WAY_POINT_ITEM_CLASS = {
True, /* has_anchors */
"waypoint",
wp_attrs,
+ -1,
Init,
Clone,
Destroy,
diff --git a/generic/Triangles.c b/generic/Triangles.c
index 93b763e..358341e 100644
--- a/generic/Triangles.c
+++ b/generic/Triangles.c
@@ -847,6 +847,7 @@ static ZnItemClassStruct TRIANGLES_ITEM_CLASS = {
False, /* has_anchors */
"triangles",
tr_attrs,
+ -1,
Init,
Clone,
Destroy,
diff --git a/generic/Window.c b/generic/Window.c
index 011a406..0e29e3e 100644
--- a/generic/Window.c
+++ b/generic/Window.c
@@ -377,7 +377,9 @@ ComputeCoordinates(ZnItem item,
&wind->pos_dev);
}
else {
- ZnTransformPoint(wi->current_transfo, &wind->pos, &wind->pos_dev);
+ ZnPoint pos;
+ pos.x = pos.y = 0.0;
+ ZnTransformPoint(wi->current_transfo, &pos, &wind->pos_dev);
}
ZnAnchor2Origin(&wind->pos_dev, (ZnReal) wind->real_width, (ZnReal) wind->real_height,
@@ -659,6 +661,7 @@ static ZnItemClassStruct WINDOW_ITEM_CLASS = {
True, /* has_anchors */
"window",
wind_attrs,
+ Tk_Offset(WindowItemStruct, pos),
Init,
Clone,
Destroy,