From 174f8612fdb56eb1e21fceb67debdd5c73e1b550 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Thu, 4 Mar 2004 10:11:24 +0000 Subject: The coords command will return a flat point instead of a list of one point for all items with a -position. --- generic/tkZinc.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'generic/tkZinc.c') diff --git a/generic/tkZinc.c b/generic/tkZinc.c index 5782f6a..cab10d3 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -3419,16 +3419,28 @@ Coords(ZnWInfo *wi, /*printf(" coords: read %d points, first is %g@%g\n", num_points, points->x, points->y);*/ l = Tcl_GetObjResult(wi->interp); - for (i = 0; i < num_points; i++, points++) { - entries[0] = Tcl_NewDoubleObj(points->x); - entries[1] = Tcl_NewDoubleObj(points->y); - if (controls && controls[i]) { - c[0] = controls[i]; - entries[2] = Tcl_NewStringObj(c, -1); - Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(3, entries)); - } - else { - Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(2, entries)); + if (item->class->pos_offset >= 0) { + /* + * Special case for items with a -position. In this case + * we are guaranteed to return exactly one point, it is + * then more friendly to return it flat instead of as the + * only element of a list. + */ + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(points->x)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(points->y)); + } + else { + for (i = 0; i < num_points; i++, points++) { + entries[0] = Tcl_NewDoubleObj(points->x); + entries[1] = Tcl_NewDoubleObj(points->y); + if (controls && controls[i]) { + c[0] = controls[i]; + entries[2] = Tcl_NewStringObj(c, -1); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(3, entries)); + } + else { + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(2, entries)); + } } } return TCL_OK; -- cgit v1.1