diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Color.c | 2 | ||||
-rw-r--r-- | generic/Draw.c | 2 | ||||
-rw-r--r-- | generic/Group.c | 2 | ||||
-rw-r--r-- | generic/Item.c | 19 | ||||
-rw-r--r-- | generic/Item.h | 2 | ||||
-rw-r--r-- | generic/Transfo.c | 32 | ||||
-rw-r--r-- | generic/Transfo.h | 7 | ||||
-rw-r--r-- | generic/tkZinc.c | 171 |
8 files changed, 157 insertions, 80 deletions
diff --git a/generic/Color.c b/generic/Color.c index 55c38bd..a2fb693 100644 --- a/generic/Color.c +++ b/generic/Color.c @@ -538,7 +538,7 @@ ReduceGradient(Tk_Window tkwin, } ZnTransfoSetIdentity(&t); - ZnTranslate(&t, -grad->p.x, -grad->p.y); + ZnTranslate(&t, -grad->p.x, -grad->p.y, False); ZnRotateRad(&t, -angle); ZnScale(&t, 1/len, 1/len); pbbox[0].x = -50; diff --git a/generic/Draw.c b/generic/Draw.c index ee37388..c727e6a 100644 --- a/generic/Draw.c +++ b/generic/Draw.c @@ -1601,7 +1601,7 @@ ComputeCircularGradient(ZnWInfo *wi, /* * Then, center the oval on the focal point. */ - ZnTranslate(&t1, focal_point.x, focal_point.y); + ZnTranslate(&t1, focal_point.x, focal_point.y, False); /* * Last, compose with the current transform. */ diff --git a/generic/Group.c b/generic/Group.c index b218ee2..15d4100 100644 --- a/generic/Group.c +++ b/generic/Group.c @@ -1339,7 +1339,7 @@ Coords(ZnItem item, if (!item->transfo) { item->transfo = ZnTransfoNew(); } - ZnSetTranslation(item->transfo, (*pts)[0].x, (*pts)[0].y); + ZnTranslate(item->transfo, (*pts)[0].x, (*pts)[0].y, True); ZnITEM.Invalidate(item, ZN_TRANSFO_FLAG); } else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { diff --git a/generic/Item.c b/generic/Item.c index c3231a8..64a4368 100644 --- a/generic/Item.c +++ b/generic/Item.c @@ -1820,7 +1820,7 @@ ComposeTransform(ZnTransfo *transfo, else { t = *transfo; } - ZnTranslate(&t, pos->x, pos->y); + ZnTranslate(&t, pos->x, pos->y, False); ZnTransfoCompose(new_t, &t, current_t); } else { @@ -1840,7 +1840,7 @@ ComposeTransform(ZnTransfo *transfo, if (pos) { ZnTransfoSetIdentity(&t); - ZnTranslate(&t, pos->x, pos->y); + ZnTranslate(&t, pos->x, pos->y, False); ZnTransfoCompose(&t2, &t, current_t); ZnTransformPoint(&t2, &local_trans, &p); } @@ -1854,7 +1854,7 @@ ComposeTransform(ZnTransfo *transfo, if (compose_rot) { ZnRotateRad(new_t, rot); } - ZnTranslate(new_t, p.x, p.y); + ZnTranslate(new_t, p.x, p.y, False); } } @@ -2438,12 +2438,13 @@ SetTransfo(ZnItem item, static void TranslateItem(ZnItem item, ZnReal dx, - ZnReal dy) + ZnReal dy, + ZnBool abs) { if (!item->transfo) { item->transfo = ZnTransfoNew(); } - ZnTranslate(item->transfo, dx, dy); + ZnTranslate(item->transfo, dx, dy, abs); Invalidate(item, ZN_TRANSFO_FLAG); } @@ -2458,11 +2459,11 @@ ScaleItem(ZnItem item, item->transfo = ZnTransfoNew(); } if (p) { - ZnTranslate(item->transfo, -p->x, -p->y); + ZnTranslate(item->transfo, -p->x, -p->y, False); } ZnScale(item->transfo, sx, sy); if (p) { - ZnTranslate(item->transfo, p->x, p->y); + ZnTranslate(item->transfo, p->x, p->y, False); } Invalidate(item, ZN_TRANSFO_FLAG); } @@ -2491,7 +2492,7 @@ RotateItem(ZnItem item, item->transfo = ZnTransfoNew(); } if (p) { - ZnTranslate(item->transfo, -p->x, -p->y); + ZnTranslate(item->transfo, -p->x, -p->y, False); } if (deg) { ZnRotateDeg(item->transfo, angle); @@ -2500,7 +2501,7 @@ RotateItem(ZnItem item, ZnRotateRad(item->transfo, angle); } if (p) { - ZnTranslate(item->transfo, p->x, p->y); + ZnTranslate(item->transfo, p->x, p->y, False); } Invalidate(item, ZN_TRANSFO_FLAG); diff --git a/generic/Item.h b/generic/Item.h index d8e992c..f67e833 100644 --- a/generic/Item.h +++ b/generic/Item.h @@ -319,7 +319,7 @@ extern struct _ZnITEM { ZnBool (*HasTag)(ZnItem item, Tk_Uid tag); void (*ResetTransfo)(ZnItem item); void (*SetTransfo)(ZnItem item, struct _ZnTransfo *t); - void (*TranslateItem)(ZnItem item, ZnReal tx, ZnReal ty); + void (*TranslateItem)(ZnItem item, ZnReal tx, ZnReal ty, ZnBool abs); void (*ScaleItem)(ZnItem item, ZnReal sx, ZnReal sy, ZnPoint *p); void (*SkewItem)(ZnItem item, ZnReal x_skew, ZnReal y_skew); void (*RotateItem)(ZnItem item, ZnReal angle, ZnBool deg, ZnPoint *p); diff --git a/generic/Transfo.c b/generic/Transfo.c index 2d9b59f..b8f4fb5 100644 --- a/generic/Transfo.c +++ b/generic/Transfo.c @@ -610,37 +610,29 @@ ZnTransformPoints(ZnTransfo *t, * * ZnTranslate -- * Translate the given transformation by delta_x, delta_y. Returns - * the resulting transformation. - * - * ZnSetTranslation -- - * Set the translation instead of combining it into the - * transformation. + * the resulting transformation. If abs is true, delta_x and + * delta_y are used to set the translation instead of adding deltas. * ************************************************************************* */ ZnTransfo * ZnTranslate(ZnTransfo *t, ZnReal delta_x, - ZnReal delta_y) -{ - t->_[2][0] = t->_[2][0] + delta_x; - t->_[2][1] = t->_[2][1] + delta_y; - - return t; -} - -ZnTransfo * -ZnSetTranslation(ZnTransfo *t, - ZnReal delta_x, - ZnReal delta_y) + ZnReal delta_y, + ZnBool abs) { - t->_[2][0] = delta_x; - t->_[2][1] = delta_y; + if (abs) { + t->_[2][0] = delta_x; + t->_[2][1] = delta_y; + } + else { + t->_[2][0] = t->_[2][0] + delta_x; + t->_[2][1] = t->_[2][1] + delta_y; + } return t; } - /* ************************************************************************* * diff --git a/generic/Transfo.h b/generic/Transfo.h index 6a01a32..c10621b 100644 --- a/generic/Transfo.h +++ b/generic/Transfo.h @@ -92,11 +92,8 @@ ZnTransformPoints(ZnTransfo *t, ZnTransfo * ZnTranslate(ZnTransfo *t, ZnReal delta_x, - ZnReal delta_y); -ZnTransfo * -ZnSetTranslation(ZnTransfo *t, - ZnReal delta_x, - ZnReal delta_y); + ZnReal delta_y, + ZnBool abs); ZnTransfo * ZnScale(ZnTransfo *t, ZnReal scale_x, diff --git a/generic/tkZinc.c b/generic/tkZinc.c index 4801b4d..9f0ad08 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -2355,7 +2355,7 @@ SetOrigin(ZnWInfo *wi, wi->origin.x = x_origin; wi->origin.y = y_origin; ZnITEM.ResetTransfo(wi->top_group); - ZnITEM.TranslateItem(wi->top_group, -x_origin, -y_origin); + ZnITEM.TranslateItem(wi->top_group, -x_origin, -y_origin, False); SET(wi->flags, ZN_UPDATE_SCROLLBARS); } } @@ -3670,7 +3670,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_Obj *CONST args[]) /* Arguments. */ { ZnWInfo *wi = (ZnWInfo *) client_data; - int result, cmd_index, index; + int length, result, cmd_index, index; ZnItem item, item2; int field = ZN_NO_PART; unsigned int num = 0, i, j; @@ -3701,9 +3701,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "index", "insert", "itemcget", "itemconfigure", "layout", "lower", "monitor", "numparts", "postscript", "raise", "remove", "rotate", "scale", "select", "skew", "smooth", - "tapply", "tcompose", "tdelete", "transform", "translate", - "treset", "trestore", "tsave", "tset", "type", "vertexat", - "xview", "yview", NULL + "tapply", "tcompose", "tdelete", "tget", "transform", + "translate", "treset", "trestore", "tsave", "tset", + "type", "vertexat", "xview", "yview", NULL }; enum sub_cmds { ZN_W_ADD, ZN_W_ADDTAG, ZN_W_ANCHORXY, ZN_W_BBOX, ZN_W_BECOMES, ZN_W_BIND, @@ -3714,9 +3714,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZN_W_INDEX, ZN_W_INSERT, ZN_W_ITEMCGET, ZN_W_ITEMCONFIGURE, ZN_W_LAYOUT, ZN_W_LOWER, ZN_W_MONITOR, ZN_W_NUMPARTS, ZN_W_POSTSCRIPT, ZN_W_RAISE, ZN_W_REMOVE, ZN_W_ROTATE, ZN_W_SCALE, ZN_W_SELECT, ZN_W_SKEW, ZN_W_SMOOTH, - ZN_W_TAPPLY, ZN_W_TCOMPOSE, ZN_W_TDELETE, ZN_W_TRANSFORM, ZN_W_TRANSLATE, - ZN_W_TRESET, ZN_W_TRESTORE, ZN_W_TSAVE, ZN_W_TSET, ZN_W_TYPE, ZN_W_VERTEX_AT, - ZN_W_XVIEW, ZN_W_YVIEW + ZN_W_TAPPLY, ZN_W_TCOMPOSE, ZN_W_TDELETE, ZN_W_TGET, ZN_W_TRANSFORM, + ZN_W_TRANSLATE, ZN_W_TRESET, ZN_W_TRESTORE, ZN_W_TSAVE, ZN_W_TSET, + ZN_W_TYPE, ZN_W_VERTEX_AT, ZN_W_XVIEW, ZN_W_YVIEW }; #ifdef PTK_800 static char *sel_cmd_strings[] = @@ -4750,7 +4750,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ * Inserting characters invalidates selection indices. */ if ((ti->sel_item == item) && (ti->sel_field == field)) { - int length = strlen(chars); + length = strlen(chars); if (ti->sel_first >= index) { ti->sel_first += length; } @@ -5117,7 +5117,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (t) { if (argc > 5) { - ZnTranslate(t, -p.x, -p.y); + ZnTranslate(t, -p.x, -p.y, False); } if (deg) { ZnRotateDeg(t, d); @@ -5126,7 +5126,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZnRotateRad(t, d); } if (argc > 5) { - ZnTranslate(t, p.x, p.y); + ZnTranslate(t, p.x, p.y, False); } } else { @@ -5179,11 +5179,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (t) { if (argc == 7) { - ZnTranslate(t, -p.x, -p.y); + ZnTranslate(t, -p.x, -p.y, False); } ZnScale(t, scale.x, scale.y); if (argc == 7) { - ZnTranslate(t, p.x, p.y); + ZnTranslate(t, p.x, p.y, False); } } else { @@ -5385,8 +5385,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_TCOMPOSE: { - Tcl_HashEntry *e; - ZnTransfo *t, *to; + ZnTransfo *to; ZnBool invert=False; ZnTransfo res_t, inv_t; @@ -5401,9 +5400,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ argc--; } - e = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[3])); - if (e != NULL) { - t = (ZnTransfo *) Tcl_GetHashValue(e); + entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[3])); + if (entry != NULL) { + t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { result = ZnItemWithTagOrId(wi, args[3], &item, &search_var); @@ -5417,9 +5416,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ t = item->transfo; } - e = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); - if (e != NULL) { - to = (ZnTransfo *) Tcl_GetHashValue(e); + entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); + if (entry != NULL) { + to = (ZnTransfo *) Tcl_GetHashValue(entry); } else { result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); @@ -5447,7 +5446,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } else { ZnTransfoFree(to); - Tcl_SetHashValue(e, ZnTransfoDuplicate(&res_t)); + Tcl_SetHashValue(entry, ZnTransfoDuplicate(&res_t)); } break; @@ -5457,23 +5456,106 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_TDELETE: { - Tcl_HashEntry *e; if (argc != 3) { Tcl_WrongNumArgs(interp, 1, args, "tdelete tName"); goto error; } - e = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); - if (e == NULL) { + entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); + if (entry == NULL) { Tcl_AppendResult(interp, "\"", Tcl_GetString(args[2]), "\" must be a transform name", (char *) NULL); goto error; } - t = (ZnTransfo *) Tcl_GetHashValue(e); + t = (ZnTransfo *) Tcl_GetHashValue(entry); ZnTransfoFree(t); - Tcl_DeleteHashEntry(e); + Tcl_DeleteHashEntry(entry); } break; /* + * tget + */ + case ZN_W_TGET: + { + ZnPoint scale, trans; + ZnReal rotation, skewxy; + ZnBool raw=1, get_trans=0, get_rot=0; + ZnBool get_scale=0, get_skew=0; + ZnTransfo tid; + + if ((argc != 3) && (argc != 4)) { + err_tget: + Tcl_WrongNumArgs(interp, 1, args, "tget transform ?all|translation|scale|rotation|skew?"); + goto error; + } + if (argc == 4) { + raw = 0; + str = Tcl_GetString(args[3]); + length = strlen(str); + if (strncmp(str, "all", length) == 0) { + get_scale = get_rot = get_trans = get_skew = 1; + } + else if (strncmp(str, "translation", length) == 0) { + get_trans = 1; + } + else if (strncmp(str, "scale", length) == 0) { + get_scale = 1; + } + else if (strncmp(str, "rotation", length) == 0) { + get_rot = 1; + } + else if (strncmp(str, "skew", length) == 0) { + get_skew = 1; + } + else { + goto err_tget; + } + } + entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); + if (entry != NULL) { + t = (ZnTransfo *) Tcl_GetHashValue(entry); + } + else { + result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "\"", Tcl_GetString(args[3]), + "\" must be either a tag, ", + "an id or a transform name", (char *) NULL); + goto error; + } + t = item->transfo; + } + l = Tcl_GetObjResult(interp); + if (raw) { + if (!t) { + ZnTransfoSetIdentity(&tid); + t = &tid; + } + for (i = 0; i < 6; i++) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(t->_[i/2][i%2])); + } + } + else { + ZnTransfoDecompose(t, get_scale?&scale:NULL, get_trans?&trans:NULL, + get_rot?&rotation:NULL, get_skew?&skewxy:NULL); + if (get_trans) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(trans.x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(trans.y)); + } + if (get_scale) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(scale.x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(scale.y)); + } + if (get_rot) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(rotation)); + } + if (get_skew) { + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(skewxy)); + } + } + break; + } + /* * transform */ case ZN_W_TRANSFORM: @@ -5483,7 +5565,6 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZnTransfo *from_t=NULL, *to_t=NULL, *result_t; ZnTransfo t1, t2, t3; ZnBool old_format; - Tcl_HashEntry *e; if ((argc != 4) && (argc != 5)) { Tcl_WrongNumArgs(interp, 1, args, "transform ?tagOrIdFrom? tagOrIdTo coordlist"); @@ -5500,10 +5581,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZnTransfoSetIdentity(from_t); } else { - e = Tcl_FindHashEntry(wi->t_table, tag); - if (e != NULL) { + entry = Tcl_FindHashEntry(wi->t_table, tag); + if (entry != NULL) { /* from is a named transform */ - from_t = (ZnTransfo *) Tcl_GetHashValue(e); + from_t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); @@ -5528,10 +5609,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZnTransfoSetIdentity(to_t); } else { - e = Tcl_FindHashEntry(wi->t_table, tag); - if (e != NULL) { + entry = Tcl_FindHashEntry(wi->t_table, tag); + if (entry != NULL) { /* to is a named transform */ - to_t = (ZnTransfo *) Tcl_GetHashValue(e); + to_t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { result = ZnItemWithTagOrId(wi, args[argc-2], &item, &search_var); @@ -5602,8 +5683,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_TRANSLATE: { - if (argc != 5) { - Tcl_WrongNumArgs(interp, 1, args, "translate tagOrIdorTransform xAmount yAmount"); + ZnBool abs = False; + + if ((argc != 5) && (argc != 6)) { + Tcl_WrongNumArgs(interp, 1, args, "translate tagOrIdorTransform xAmount yAmount ?abs?"); goto error; } entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); @@ -5623,14 +5706,19 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } p.y = d; + if (argc == 6) { + if (Tcl_GetBooleanFromObj(interp, args[5], &abs) == TCL_ERROR) { + goto error; + } + } if (t) { - ZnTranslate(t, p.x, p.y); + ZnTranslate(t, p.x, p.y, abs); } else { for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item =ZnTagSearchNext(search_var)) { - ZnITEM.TranslateItem(item, p.x, p.y); + ZnITEM.TranslateItem(item, p.x, p.y, abs); } } } @@ -5754,7 +5842,6 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ case ZN_W_TSET: { ZnTransfo new; - Tcl_HashEntry *e; if (argc != 9) { Tcl_WrongNumArgs(interp, 1, args, @@ -5768,9 +5855,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } new._[i/2][i%2] = d; } - e = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); - if (e != NULL) { - t = (ZnTransfo *) Tcl_GetHashValue(e); + entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); + if (entry != NULL) { + t = (ZnTransfo *) Tcl_GetHashValue(entry); *t = new; } else { |