| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tkPort.h" |
| 17 |
#include "tkInt.h" |
| 18 |
#include "tkCanvases.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
typedef struct PolygonItem { |
| 25 |
Tk_Item header; |
| 26 |
|
| 27 |
Tk_Outline outline; |
| 28 |
int numPoints; |
| 29 |
|
| 30 |
int pointsAllocated; |
| 31 |
|
| 32 |
double *coordPtr; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
int joinStyle; |
| 37 |
Tk_TSOffset tsoffset; |
| 38 |
XColor *fillColor; |
| 39 |
XColor *activeFillColor; |
| 40 |
XColor *disabledFillColor; |
| 41 |
Pixmap fillStipple; |
| 42 |
Pixmap activeFillStipple; |
| 43 |
Pixmap disabledFillStipple; |
| 44 |
GC fillGC; |
| 45 |
Tk_SmoothMethod *smooth; |
| 46 |
|
| 47 |
int splineSteps; |
| 48 |
int autoClosed; |
| 49 |
|
| 50 |
Tk_Tile fillTile; |
| 51 |
} PolygonItem; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
static Tk_CustomOption smoothOption = { |
| 58 |
TkSmoothParseProc, |
| 59 |
TkSmoothPrintProc, (ClientData) NULL |
| 60 |
}; |
| 61 |
static Tk_CustomOption stateOption = { |
| 62 |
TkStateParseProc, |
| 63 |
TkStatePrintProc, (ClientData) 2 |
| 64 |
}; |
| 65 |
static Tk_CustomOption tagsOption = { |
| 66 |
Tk_CanvasTagsParseProc, |
| 67 |
Tk_CanvasTagsPrintProc, (ClientData) NULL |
| 68 |
}; |
| 69 |
static Tk_CustomOption dashOption = { |
| 70 |
TkCanvasDashParseProc, |
| 71 |
TkCanvasDashPrintProc, (ClientData) NULL |
| 72 |
}; |
| 73 |
static Tk_CustomOption tileOption = { |
| 74 |
Tk_TileParseProc, |
| 75 |
Tk_TilePrintProc, (ClientData) NULL |
| 76 |
}; |
| 77 |
static Tk_CustomOption offsetOption = { |
| 78 |
Tk_OffsetParseProc, |
| 79 |
Tk_OffsetPrintProc, |
| 80 |
(ClientData) (TK_OFFSET_RELATIVE|TK_OFFSET_INDEX) |
| 81 |
}; |
| 82 |
static Tk_CustomOption pixelOption = { |
| 83 |
Tk_PixelParseProc, |
| 84 |
Tk_PixelPrintProc, (ClientData) NULL |
| 85 |
}; |
| 86 |
|
| 87 |
static Tk_ConfigSpec configSpecs[] = { |
| 88 |
{TK_CONFIG_CUSTOM, "-activedash", (char *) NULL, (char *) NULL, |
| 89 |
(char *) NULL, Tk_Offset(PolygonItem, outline.activeDash), |
| 90 |
TK_CONFIG_NULL_OK, &dashOption}, |
| 91 |
{TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, |
| 92 |
(char *) NULL, Tk_Offset(PolygonItem, activeFillColor), |
| 93 |
TK_CONFIG_NULL_OK}, |
| 94 |
{TK_CONFIG_COLOR, "-activeoutline", (char *) NULL, (char *) NULL, |
| 95 |
(char *) NULL, Tk_Offset(PolygonItem, outline.activeColor), |
| 96 |
TK_CONFIG_NULL_OK}, |
| 97 |
{TK_CONFIG_BITMAP, "-activeoutlinestipple", (char *) NULL, (char *) NULL, |
| 98 |
(char *) NULL, Tk_Offset(PolygonItem, outline.activeStipple), |
| 99 |
TK_CONFIG_NULL_OK}, |
| 100 |
{TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, |
| 101 |
(char *) NULL, Tk_Offset(PolygonItem, activeFillStipple), |
| 102 |
TK_CONFIG_NULL_OK}, |
| 103 |
{TK_CONFIG_CUSTOM, "-activewidth", (char *) NULL, (char *) NULL, |
| 104 |
"0.0", Tk_Offset(PolygonItem, outline.activeWidth), |
| 105 |
TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, |
| 106 |
{TK_CONFIG_CUSTOM, "-dash", (char *) NULL, (char *) NULL, |
| 107 |
(char *) NULL, Tk_Offset(PolygonItem, outline.dash), |
| 108 |
TK_CONFIG_NULL_OK, &dashOption}, |
| 109 |
{TK_CONFIG_PIXELS, "-dashoffset", (char *) NULL, (char *) NULL, |
| 110 |
"0", Tk_Offset(PolygonItem, outline.offset), |
| 111 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 112 |
{TK_CONFIG_CUSTOM, "-disableddash", (char *) NULL, (char *) NULL, |
| 113 |
(char *) NULL, Tk_Offset(PolygonItem, outline.disabledDash), |
| 114 |
TK_CONFIG_NULL_OK, &dashOption}, |
| 115 |
{TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, |
| 116 |
(char *) NULL, Tk_Offset(PolygonItem, disabledFillColor), |
| 117 |
TK_CONFIG_NULL_OK}, |
| 118 |
{TK_CONFIG_COLOR, "-disabledoutline", (char *) NULL, (char *) NULL, |
| 119 |
(char *) NULL, Tk_Offset(PolygonItem, outline.disabledColor), |
| 120 |
TK_CONFIG_NULL_OK}, |
| 121 |
{TK_CONFIG_BITMAP, "-disabledoutlinestipple", (char *) NULL, (char *) NULL, |
| 122 |
(char *) NULL, Tk_Offset(PolygonItem, outline.disabledStipple), |
| 123 |
TK_CONFIG_NULL_OK}, |
| 124 |
{TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, |
| 125 |
(char *) NULL, Tk_Offset(PolygonItem, disabledFillStipple), |
| 126 |
TK_CONFIG_NULL_OK}, |
| 127 |
{TK_CONFIG_CUSTOM, "-disabledwidth", (char *) NULL, (char *) NULL, |
| 128 |
"0.0", Tk_Offset(PolygonItem, outline.disabledWidth), |
| 129 |
TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, |
| 130 |
{TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, |
| 131 |
"black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK}, |
| 132 |
{TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL, |
| 133 |
"round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT}, |
| 134 |
{TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, |
| 135 |
"0 0", Tk_Offset(PolygonItem, tsoffset), |
| 136 |
TK_CONFIG_NULL_OK, &offsetOption}, |
| 137 |
{TK_CONFIG_COLOR, "-outline", (char *) NULL, (char *) NULL, |
| 138 |
(char *) NULL, Tk_Offset(PolygonItem, outline.color), |
| 139 |
TK_CONFIG_NULL_OK}, |
| 140 |
{TK_CONFIG_CUSTOM, "-outlineoffset", (char *) NULL, (char *) NULL, |
| 141 |
"0 0", Tk_Offset(PolygonItem, outline.tsoffset), |
| 142 |
TK_CONFIG_NULL_OK, &offsetOption}, |
| 143 |
{TK_CONFIG_BITMAP, "-outlinestipple", (char *) NULL, (char *) NULL, |
| 144 |
(char *) NULL, Tk_Offset(PolygonItem, outline.stipple), |
| 145 |
TK_CONFIG_NULL_OK}, |
| 146 |
{TK_CONFIG_CUSTOM, "-smooth", (char *) NULL, (char *) NULL, |
| 147 |
"0", Tk_Offset(PolygonItem, smooth), |
| 148 |
TK_CONFIG_DONT_SET_DEFAULT, &smoothOption}, |
| 149 |
{TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL, |
| 150 |
"12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT}, |
| 151 |
{TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, |
| 152 |
(char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, |
| 153 |
&stateOption}, |
| 154 |
{TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, |
| 155 |
(char *) NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK}, |
| 156 |
{TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, |
| 157 |
(char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, |
| 158 |
{TK_CONFIG_CUSTOM, "-tile", (char *) NULL, (char *) NULL, |
| 159 |
(char *) NULL, Tk_Offset(PolygonItem, fillTile), |
| 160 |
TK_CONFIG_NULL_OK, &tileOption}, |
| 161 |
{TK_CONFIG_CALLBACK, "-updatecommand", (char *) NULL, (char *) NULL, |
| 162 |
(char *) NULL, Tk_Offset(Tk_Item, updateCmd), TK_CONFIG_NULL_OK}, |
| 163 |
{TK_CONFIG_CUSTOM, "-width", (char *) NULL, (char *) NULL, |
| 164 |
"1.0", Tk_Offset(PolygonItem, outline.width), |
| 165 |
TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, |
| 166 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 167 |
(char *) NULL, 0, 0} |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
static void ComputePolygonBbox _ANSI_ARGS_((Tk_Canvas canvas, |
| 175 |
PolygonItem *polyPtr)); |
| 176 |
static int ConfigurePolygon _ANSI_ARGS_((Tcl_Interp *interp, |
| 177 |
Tk_Canvas canvas, Tk_Item *itemPtr, int objc, |
| 178 |
Tcl_Obj *CONST objv[], int flags)); |
| 179 |
static int CreatePolygon _ANSI_ARGS_((Tcl_Interp *interp, |
| 180 |
Tk_Canvas canvas, struct Tk_Item *itemPtr, |
| 181 |
int objc, Tcl_Obj *CONST objv[])); |
| 182 |
static void DeletePolygon _ANSI_ARGS_((Tk_Canvas canvas, |
| 183 |
Tk_Item *itemPtr, Display *display)); |
| 184 |
static void DisplayPolygon _ANSI_ARGS_((Tk_Canvas canvas, |
| 185 |
Tk_Item *itemPtr, Display *display, Drawable dst, |
| 186 |
int x, int y, int width, int height)); |
| 187 |
static int GetPolygonIndex _ANSI_ARGS_((Tcl_Interp *interp, |
| 188 |
Tk_Canvas canvas, Tk_Item *itemPtr, |
| 189 |
Tcl_Obj *obj, int *indexPtr)); |
| 190 |
static int PolygonCoords _ANSI_ARGS_((Tcl_Interp *interp, |
| 191 |
Tk_Canvas canvas, Tk_Item *itemPtr, |
| 192 |
int objc, Tcl_Obj *CONST objv[])); |
| 193 |
static void PolygonDeleteCoords _ANSI_ARGS_((Tk_Canvas canvas, |
| 194 |
Tk_Item *itemPtr, int first, int last)); |
| 195 |
static void PolygonInsert _ANSI_ARGS_((Tk_Canvas canvas, |
| 196 |
Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj)); |
| 197 |
static int PolygonToArea _ANSI_ARGS_((Tk_Canvas canvas, |
| 198 |
Tk_Item *itemPtr, double *rectPtr)); |
| 199 |
static double PolygonToPoint _ANSI_ARGS_((Tk_Canvas canvas, |
| 200 |
Tk_Item *itemPtr, double *pointPtr)); |
| 201 |
static int PolygonToPostscript _ANSI_ARGS_((Tcl_Interp *interp, |
| 202 |
Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); |
| 203 |
static void ScalePolygon _ANSI_ARGS_((Tk_Canvas canvas, |
| 204 |
Tk_Item *itemPtr, double originX, double originY, |
| 205 |
double scaleX, double scaleY)); |
| 206 |
static void TranslatePolygon _ANSI_ARGS_((Tk_Canvas canvas, |
| 207 |
Tk_Item *itemPtr, double deltaX, double deltaY)); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
Tk_ItemType tkPolygonType = { |
| 215 |
"polygon", |
| 216 |
sizeof(PolygonItem), |
| 217 |
CreatePolygon, |
| 218 |
configSpecs, |
| 219 |
ConfigurePolygon, |
| 220 |
PolygonCoords, |
| 221 |
DeletePolygon, |
| 222 |
DisplayPolygon, |
| 223 |
TK_CONFIG_OBJS, |
| 224 |
PolygonToPoint, |
| 225 |
PolygonToArea, |
| 226 |
PolygonToPostscript, |
| 227 |
ScalePolygon, |
| 228 |
TranslatePolygon, |
| 229 |
GetPolygonIndex, |
| 230 |
(Tk_ItemCursorProc *) NULL, |
| 231 |
(Tk_ItemSelectionProc *) NULL, |
| 232 |
PolygonInsert, |
| 233 |
PolygonDeleteCoords, |
| 234 |
(Tk_ItemType *) NULL, |
| 235 |
}; |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
#define MAX_STATIC_POINTS 200 |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
static int |
| 267 |
CreatePolygon(interp, canvas, itemPtr, objc, objv) |
| 268 |
Tcl_Interp *interp; |
| 269 |
Tk_Canvas canvas; |
| 270 |
Tk_Item *itemPtr; |
| 271 |
|
| 272 |
int objc; |
| 273 |
Tcl_Obj *CONST objv[]; |
| 274 |
{ |
| 275 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 276 |
int i; |
| 277 |
|
| 278 |
if (objc == 0) { |
| 279 |
panic("canvas did not pass any coords\n"); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
Tk_CreateOutline(&(polyPtr->outline)); |
| 288 |
polyPtr->numPoints = 0; |
| 289 |
polyPtr->pointsAllocated = 0; |
| 290 |
polyPtr->coordPtr = NULL; |
| 291 |
polyPtr->joinStyle = JoinRound; |
| 292 |
polyPtr->tsoffset.flags = 0; |
| 293 |
polyPtr->tsoffset.xoffset = 0; |
| 294 |
polyPtr->tsoffset.yoffset = 0; |
| 295 |
polyPtr->fillColor = NULL; |
| 296 |
polyPtr->activeFillColor = NULL; |
| 297 |
polyPtr->disabledFillColor = NULL; |
| 298 |
polyPtr->fillStipple = None; |
| 299 |
polyPtr->activeFillStipple = None; |
| 300 |
polyPtr->disabledFillStipple = None; |
| 301 |
polyPtr->fillGC = None; |
| 302 |
polyPtr->smooth = (Tk_SmoothMethod *) NULL; |
| 303 |
polyPtr->splineSteps = 12; |
| 304 |
polyPtr->autoClosed = 0; |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
for (i = 0; i < objc; i++) { |
| 313 |
char *arg = Tcl_GetString(objv[i]); |
| 314 |
if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { |
| 315 |
break; |
| 316 |
} |
| 317 |
} |
| 318 |
if (i && PolygonCoords(interp, canvas, itemPtr, i, objv) != TCL_OK) { |
| 319 |
goto error; |
| 320 |
} |
| 321 |
|
| 322 |
if (ConfigurePolygon(interp, canvas, itemPtr, objc-i, objv+i, 0) |
| 323 |
== TCL_OK) { |
| 324 |
return TCL_OK; |
| 325 |
} |
| 326 |
|
| 327 |
error: |
| 328 |
DeletePolygon(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); |
| 329 |
return TCL_ERROR; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
static int |
| 351 |
PolygonCoords(interp, canvas, itemPtr, objc, objv) |
| 352 |
Tcl_Interp *interp; |
| 353 |
Tk_Canvas canvas; |
| 354 |
Tk_Item *itemPtr; |
| 355 |
|
| 356 |
int objc; |
| 357 |
|
| 358 |
Tcl_Obj *CONST objv[]; |
| 359 |
|
| 360 |
{ |
| 361 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 362 |
int i, numPoints; |
| 363 |
|
| 364 |
if (objc == 0) { |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
Tcl_Obj *subobj, *obj = Tcl_NewObj(); |
| 370 |
for (i = 0; i < 2*(polyPtr->numPoints - polyPtr->autoClosed); i++) { |
| 371 |
subobj = Tcl_NewDoubleObj(polyPtr->coordPtr[i]); |
| 372 |
Tcl_ListObjAppendElement(interp, obj, subobj); |
| 373 |
} |
| 374 |
Tcl_SetObjResult(interp, obj); |
| 375 |
return TCL_OK; |
| 376 |
} |
| 377 |
if (objc == 1) { |
| 378 |
if (Tcl_ListObjGetElements(interp, objv[0], &objc, |
| 379 |
(Tcl_Obj ***) &objv) != TCL_OK) { |
| 380 |
return TCL_ERROR; |
| 381 |
} |
| 382 |
} |
| 383 |
if (objc & 1) { |
| 384 |
char buf[64 + TCL_INTEGER_SPACE]; |
| 385 |
sprintf(buf, "wrong # coordinates: expected an even number, got %d", |
| 386 |
objc); |
| 387 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 388 |
return TCL_ERROR; |
| 389 |
} else { |
| 390 |
numPoints = objc/2; |
| 391 |
if (polyPtr->pointsAllocated <= numPoints) { |
| 392 |
if (polyPtr->coordPtr != NULL) { |
| 393 |
ckfree((char *) polyPtr->coordPtr); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
polyPtr->coordPtr = (double *) ckalloc((unsigned) |
| 402 |
(sizeof(double) * (objc+2))); |
| 403 |
polyPtr->pointsAllocated = numPoints+1; |
| 404 |
} |
| 405 |
for (i = objc-1; i >= 0; i--) { |
| 406 |
if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i], |
| 407 |
&polyPtr->coordPtr[i]) != TCL_OK) { |
| 408 |
return TCL_ERROR; |
| 409 |
} |
| 410 |
} |
| 411 |
polyPtr->numPoints = numPoints; |
| 412 |
polyPtr->autoClosed = 0; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0]) |
| 419 |
|| (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) { |
| 420 |
polyPtr->autoClosed = 1; |
| 421 |
polyPtr->numPoints++; |
| 422 |
polyPtr->coordPtr[objc] = polyPtr->coordPtr[0]; |
| 423 |
polyPtr->coordPtr[objc+1] = polyPtr->coordPtr[1]; |
| 424 |
} |
| 425 |
ComputePolygonBbox(canvas, polyPtr); |
| 426 |
} |
| 427 |
return TCL_OK; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
static int |
| 450 |
ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) |
| 451 |
Tcl_Interp *interp; |
| 452 |
Tk_Canvas canvas; |
| 453 |
Tk_Item *itemPtr; |
| 454 |
int objc; |
| 455 |
Tcl_Obj *CONST objv[]; |
| 456 |
int flags; |
| 457 |
{ |
| 458 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 459 |
XGCValues gcValues; |
| 460 |
GC newGC; |
| 461 |
unsigned long mask; |
| 462 |
Tk_Window tkwin; |
| 463 |
XColor *color; |
| 464 |
Pixmap stipple; |
| 465 |
Tk_State state; |
| 466 |
|
| 467 |
tkwin = Tk_CanvasTkwin(canvas); |
| 468 |
if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, |
| 469 |
objv, (char *) polyPtr, flags|TK_CONFIG_OBJS)) { |
| 470 |
return TCL_ERROR; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
state = Tk_GetItemState(canvas, itemPtr); |
| 479 |
|
| 480 |
if (polyPtr->outline.activeWidth > polyPtr->outline.width || |
| 481 |
polyPtr->outline.activeDash.number != 0 || |
| 482 |
polyPtr->outline.activeColor != NULL || |
| 483 |
polyPtr->outline.activeStipple != None || |
| 484 |
polyPtr->activeFillColor != NULL || |
| 485 |
polyPtr->activeFillStipple != None) { |
| 486 |
itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT; |
| 487 |
} else { |
| 488 |
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; |
| 489 |
} |
| 490 |
|
| 491 |
if (state==TK_STATE_HIDDEN) { |
| 492 |
ComputePolygonBbox(canvas, polyPtr); |
| 493 |
return TCL_OK; |
| 494 |
} |
| 495 |
|
| 496 |
mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(polyPtr->outline)); |
| 497 |
if (mask) { |
| 498 |
gcValues.cap_style = CapRound; |
| 499 |
gcValues.join_style = polyPtr->joinStyle; |
| 500 |
mask |= GCCapStyle|GCJoinStyle; |
| 501 |
newGC = Tk_GetGC(tkwin, mask, &gcValues); |
| 502 |
} else { |
| 503 |
newGC = None; |
| 504 |
} |
| 505 |
if (polyPtr->outline.gc != None) { |
| 506 |
Tk_FreeGC(Tk_Display(tkwin), polyPtr->outline.gc); |
| 507 |
} |
| 508 |
polyPtr->outline.gc = newGC; |
| 509 |
|
| 510 |
color = polyPtr->fillColor; |
| 511 |
stipple = polyPtr->fillStipple; |
| 512 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 513 |
if (polyPtr->activeFillColor!=NULL) { |
| 514 |
color = polyPtr->activeFillColor; |
| 515 |
} |
| 516 |
if (polyPtr->activeFillStipple!=None) { |
| 517 |
stipple = polyPtr->activeFillStipple; |
| 518 |
} |
| 519 |
} else if (state==TK_STATE_DISABLED) { |
| 520 |
if (polyPtr->disabledFillColor!=NULL) { |
| 521 |
color = polyPtr->disabledFillColor; |
| 522 |
} |
| 523 |
if (polyPtr->disabledFillStipple!=None) { |
| 524 |
stipple = polyPtr->disabledFillStipple; |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
if (color == NULL) { |
| 529 |
newGC = None; |
| 530 |
} else { |
| 531 |
gcValues.foreground = color->pixel; |
| 532 |
mask = GCForeground; |
| 533 |
if (stipple != None) { |
| 534 |
gcValues.stipple = stipple; |
| 535 |
gcValues.fill_style = FillStippled; |
| 536 |
mask |= GCStipple|GCFillStyle; |
| 537 |
} |
| 538 |
newGC = Tk_GetGC(tkwin, mask, &gcValues); |
| 539 |
} |
| 540 |
if (polyPtr->fillGC != None) { |
| 541 |
Tk_FreeGC(Tk_Display(tkwin), polyPtr->fillGC); |
| 542 |
} |
| 543 |
polyPtr->fillGC = newGC; |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
if (polyPtr->splineSteps < 1) { |
| 550 |
polyPtr->splineSteps = 1; |
| 551 |
} else if (polyPtr->splineSteps > 100) { |
| 552 |
polyPtr->splineSteps = 100; |
| 553 |
} |
| 554 |
|
| 555 |
ComputePolygonBbox(canvas, polyPtr); |
| 556 |
return TCL_OK; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
static void |
| 577 |
DeletePolygon(canvas, itemPtr, display) |
| 578 |
Tk_Canvas canvas; |
| 579 |
Tk_Item *itemPtr; |
| 580 |
Display *display; |
| 581 |
|
| 582 |
{ |
| 583 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 584 |
|
| 585 |
Tk_DeleteOutline(display,&(polyPtr->outline)); |
| 586 |
if (polyPtr->coordPtr != NULL) { |
| 587 |
ckfree((char *) polyPtr->coordPtr); |
| 588 |
} |
| 589 |
if (polyPtr->fillColor != NULL) { |
| 590 |
Tk_FreeColor(polyPtr->fillColor); |
| 591 |
} |
| 592 |
if (polyPtr->activeFillColor != NULL) { |
| 593 |
Tk_FreeColor(polyPtr->activeFillColor); |
| 594 |
} |
| 595 |
if (polyPtr->disabledFillColor != NULL) { |
| 596 |
Tk_FreeColor(polyPtr->disabledFillColor); |
| 597 |
} |
| 598 |
if (polyPtr->fillStipple != None) { |
| 599 |
Tk_FreeBitmap(display, polyPtr->fillStipple); |
| 600 |
} |
| 601 |
if (polyPtr->activeFillStipple != None) { |
| 602 |
Tk_FreeBitmap(display, polyPtr->activeFillStipple); |
| 603 |
} |
| 604 |
if (polyPtr->disabledFillStipple != None) { |
| 605 |
Tk_FreeBitmap(display, polyPtr->disabledFillStipple); |
| 606 |
} |
| 607 |
if (polyPtr->fillGC != None) { |
| 608 |
Tk_FreeGC(display, polyPtr->fillGC); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
static void |
| 631 |
ComputePolygonBbox(canvas, polyPtr) |
| 632 |
Tk_Canvas canvas; |
| 633 |
PolygonItem *polyPtr; |
| 634 |
|
| 635 |
{ |
| 636 |
double *coordPtr; |
| 637 |
int i; |
| 638 |
double width; |
| 639 |
Tk_State state = Tk_GetItemState(canvas, &polyPtr->header); |
| 640 |
Tk_TSOffset *tsoffset; |
| 641 |
|
| 642 |
width = polyPtr->outline.width; |
| 643 |
if (polyPtr->coordPtr == NULL || (polyPtr->numPoints < 1) || (state==TK_STATE_HIDDEN)) { |
| 644 |
polyPtr->header.x1 = polyPtr->header.x2 = |
| 645 |
polyPtr->header.y1 = polyPtr->header.y2 = -1; |
| 646 |
return; |
| 647 |
} |
| 648 |
if (((TkCanvas *)canvas)->currentItemPtr == (Tk_Item *)polyPtr) { |
| 649 |
if (polyPtr->outline.activeWidth>width) { |
| 650 |
width = polyPtr->outline.activeWidth; |
| 651 |
} |
| 652 |
} else if (state==TK_STATE_DISABLED) { |
| 653 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 654 |
width = polyPtr->outline.disabledWidth; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
coordPtr = polyPtr->coordPtr; |
| 659 |
polyPtr->header.x1 = polyPtr->header.x2 = (int) *coordPtr; |
| 660 |
polyPtr->header.y1 = polyPtr->header.y2 = (int) coordPtr[1]; |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
for (i = 1, coordPtr = polyPtr->coordPtr+2; i < polyPtr->numPoints-1; |
| 673 |
i++, coordPtr += 2) { |
| 674 |
TkIncludePoint((Tk_Item *) polyPtr, coordPtr); |
| 675 |
} |
| 676 |
|
| 677 |
tsoffset = &polyPtr->tsoffset; |
| 678 |
if (tsoffset->flags & TK_OFFSET_INDEX) { |
| 679 |
int index = tsoffset->flags & ~TK_OFFSET_INDEX; |
| 680 |
if (tsoffset->flags == INT_MAX) { |
| 681 |
index = (polyPtr->numPoints - polyPtr->autoClosed) * 2; |
| 682 |
if (index < 0) { |
| 683 |
index = 0; |
| 684 |
} |
| 685 |
} |
| 686 |
index %= (polyPtr->numPoints - polyPtr->autoClosed) * 2; |
| 687 |
if (index <0) { |
| 688 |
index += (polyPtr->numPoints - polyPtr->autoClosed) * 2; |
| 689 |
} |
| 690 |
tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5); |
| 691 |
tsoffset->yoffset = (int) (polyPtr->coordPtr[index+1] + 0.5); |
| 692 |
} else { |
| 693 |
if (tsoffset->flags & TK_OFFSET_LEFT) { |
| 694 |
tsoffset->xoffset = polyPtr->header.x1; |
| 695 |
} else if (tsoffset->flags & TK_OFFSET_CENTER) { |
| 696 |
tsoffset->xoffset = (polyPtr->header.x1 + polyPtr->header.x2)/2; |
| 697 |
} else if (tsoffset->flags & TK_OFFSET_RIGHT) { |
| 698 |
tsoffset->xoffset = polyPtr->header.x2; |
| 699 |
} |
| 700 |
if (tsoffset->flags & TK_OFFSET_TOP) { |
| 701 |
tsoffset->yoffset = polyPtr->header.y1; |
| 702 |
} else if (tsoffset->flags & TK_OFFSET_MIDDLE) { |
| 703 |
tsoffset->yoffset = (polyPtr->header.y1 + polyPtr->header.y2)/2; |
| 704 |
} else if (tsoffset->flags & TK_OFFSET_BOTTOM) { |
| 705 |
tsoffset->yoffset = polyPtr->header.y2; |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
if (polyPtr->outline.gc != None) { |
| 710 |
tsoffset = &polyPtr->outline.tsoffset; |
| 711 |
if (tsoffset) { |
| 712 |
if (tsoffset->flags & TK_OFFSET_INDEX) { |
| 713 |
int index = tsoffset->flags & ~TK_OFFSET_INDEX; |
| 714 |
if (tsoffset->flags == INT_MAX) { |
| 715 |
index = (polyPtr->numPoints - 1) * 2; |
| 716 |
} |
| 717 |
index %= (polyPtr->numPoints - 1) * 2; |
| 718 |
if (index <0) { |
| 719 |
index += (polyPtr->numPoints - 1) * 2; |
| 720 |
} |
| 721 |
tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5); |
| 722 |
tsoffset->yoffset = (int) (polyPtr->coordPtr[index+1] + 0.5); |
| 723 |
} else { |
| 724 |
if (tsoffset->flags & TK_OFFSET_LEFT) { |
| 725 |
tsoffset->xoffset = polyPtr->header.x1; |
| 726 |
} else if (tsoffset->flags & TK_OFFSET_CENTER) { |
| 727 |
tsoffset->xoffset = (polyPtr->header.x1 + polyPtr->header.x2)/2; |
| 728 |
} else if (tsoffset->flags & TK_OFFSET_RIGHT) { |
| 729 |
tsoffset->xoffset = polyPtr->header.x2; |
| 730 |
} |
| 731 |
if (tsoffset->flags & TK_OFFSET_TOP) { |
| 732 |
tsoffset->yoffset = polyPtr->header.y1; |
| 733 |
} else if (tsoffset->flags & TK_OFFSET_MIDDLE) { |
| 734 |
tsoffset->yoffset = (polyPtr->header.y1 + polyPtr->header.y2)/2; |
| 735 |
} else if (tsoffset->flags & TK_OFFSET_BOTTOM) { |
| 736 |
tsoffset->yoffset = polyPtr->header.y2; |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
i = (int) ((width+1.5)/2.0); |
| 742 |
polyPtr->header.x1 -= i; |
| 743 |
polyPtr->header.x2 += i; |
| 744 |
polyPtr->header.y1 -= i; |
| 745 |
polyPtr->header.y2 += i; |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
if (polyPtr->joinStyle == JoinMiter) { |
| 754 |
double miter[4]; |
| 755 |
int j; |
| 756 |
coordPtr = polyPtr->coordPtr; |
| 757 |
if (polyPtr->numPoints>3) { |
| 758 |
if (TkGetMiterPoints(coordPtr+2*(polyPtr->numPoints-2), |
| 759 |
coordPtr, coordPtr+2, width, |
| 760 |
miter, miter+2)) { |
| 761 |
for (j = 0; j < 4; j += 2) { |
| 762 |
TkIncludePoint((Tk_Item *) polyPtr, miter+j); |
| 763 |
} |
| 764 |
} |
| 765 |
} |
| 766 |
for (i = polyPtr->numPoints ; i >= 3; |
| 767 |
i--, coordPtr += 2) { |
| 768 |
|
| 769 |
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, |
| 770 |
width, miter, miter+2)) { |
| 771 |
for (j = 0; j < 4; j += 2) { |
| 772 |
TkIncludePoint((Tk_Item *) polyPtr, miter+j); |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
} |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
polyPtr->header.x1 -= 1; |
| 785 |
polyPtr->header.x2 += 1; |
| 786 |
polyPtr->header.y1 -= 1; |
| 787 |
polyPtr->header.y2 += 1; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
void |
| 809 |
TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) |
| 810 |
Tk_Canvas canvas; |
| 811 |
|
| 812 |
double *coordPtr; |
| 813 |
|
| 814 |
int numPoints; |
| 815 |
|
| 816 |
Display *display; |
| 817 |
Drawable drawable; |
| 818 |
|
| 819 |
GC gc; |
| 820 |
GC outlineGC; |
| 821 |
|
| 822 |
|
| 823 |
{ |
| 824 |
XPoint staticPoints[MAX_STATIC_POINTS]; |
| 825 |
XPoint *pointPtr; |
| 826 |
XPoint *pPtr; |
| 827 |
int i; |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
if (numPoints <= MAX_STATIC_POINTS) { |
| 836 |
pointPtr = staticPoints; |
| 837 |
} else { |
| 838 |
pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint))); |
| 839 |
} |
| 840 |
|
| 841 |
for (i = 0, pPtr = pointPtr; i < numPoints; i += 1, coordPtr += 2, pPtr++) { |
| 842 |
Tk_CanvasDrawableCoords(canvas, coordPtr[0], coordPtr[1], &pPtr->x, |
| 843 |
&pPtr->y); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
if (gc != None && numPoints>3) { |
| 852 |
XFillPolygon(display, drawable, gc, pointPtr, numPoints, Complex, |
| 853 |
CoordModeOrigin); |
| 854 |
} |
| 855 |
if (outlineGC != None) { |
| 856 |
XDrawLines(display, drawable, outlineGC, pointPtr, |
| 857 |
numPoints, CoordModeOrigin); |
| 858 |
} |
| 859 |
if (pointPtr != staticPoints) { |
| 860 |
ckfree((char *) pointPtr); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
static void |
| 883 |
DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) |
| 884 |
Tk_Canvas canvas; |
| 885 |
Tk_Item *itemPtr; |
| 886 |
Display *display; |
| 887 |
Drawable drawable; |
| 888 |
|
| 889 |
int x, y, width, height; |
| 890 |
|
| 891 |
{ |
| 892 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 893 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 894 |
Tk_Tile tile = polyPtr->fillTile; |
| 895 |
Pixmap stipple = polyPtr->fillStipple; |
| 896 |
double linewidth = polyPtr->outline.width; |
| 897 |
|
| 898 |
if (((polyPtr->fillGC == None) && (polyPtr->outline.gc == None)) || |
| 899 |
(polyPtr->numPoints < 1) || |
| 900 |
(polyPtr->numPoints < 3 && polyPtr->outline.gc == None)) { |
| 901 |
return; |
| 902 |
} |
| 903 |
|
| 904 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 905 |
if (polyPtr->outline.activeWidth>linewidth) { |
| 906 |
linewidth = polyPtr->outline.activeWidth; |
| 907 |
} |
| 908 |
if (polyPtr->activeFillStipple != None) { |
| 909 |
stipple = polyPtr->activeFillStipple; |
| 910 |
} |
| 911 |
} else if (state==TK_STATE_DISABLED) { |
| 912 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 913 |
linewidth = polyPtr->outline.disabledWidth; |
| 914 |
} |
| 915 |
if (polyPtr->disabledFillStipple != None) { |
| 916 |
stipple = polyPtr->disabledFillStipple; |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
if ((stipple != None) && (polyPtr->fillGC != None)) { |
| 926 |
Tk_TSOffset *tsoffset = &polyPtr->tsoffset; |
| 927 |
int w=0; int h=0; |
| 928 |
int flags = tsoffset->flags; |
| 929 |
if (!(flags & TK_OFFSET_INDEX) && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) { |
| 930 |
Tk_SizeOfBitmap(display, stipple, &w, &h); |
| 931 |
if (flags & TK_OFFSET_CENTER) { |
| 932 |
w /= 2; |
| 933 |
} else { |
| 934 |
w = 0; |
| 935 |
} |
| 936 |
if (flags & TK_OFFSET_MIDDLE) { |
| 937 |
h /= 2; |
| 938 |
} else { |
| 939 |
h = 0; |
| 940 |
} |
| 941 |
} |
| 942 |
tsoffset->xoffset -= w; |
| 943 |
tsoffset->yoffset -= h; |
| 944 |
Tk_CanvasSetOffset(canvas, polyPtr->fillGC, tsoffset); |
| 945 |
tsoffset->xoffset += w; |
| 946 |
tsoffset->yoffset += h; |
| 947 |
} |
| 948 |
Tk_ChangeOutlineGC(canvas, itemPtr, &(polyPtr->outline)); |
| 949 |
|
| 950 |
if(polyPtr->numPoints < 3) { |
| 951 |
short x,y; |
| 952 |
int intLineWidth = (int) (linewidth + 0.5); |
| 953 |
if (intLineWidth < 1) { |
| 954 |
intLineWidth = 1; |
| 955 |
} |
| 956 |
Tk_CanvasDrawableCoords(canvas, polyPtr->coordPtr[0], |
| 957 |
polyPtr->coordPtr[1], &x,&y); |
| 958 |
XFillArc(display, drawable, polyPtr->outline.gc, |
| 959 |
x - intLineWidth/2, y - intLineWidth/2, |
| 960 |
(unsigned int)intLineWidth+1, (unsigned int)intLineWidth+1, |
| 961 |
0, 64*360); |
| 962 |
} else if (!polyPtr->smooth || polyPtr->numPoints < 4) { |
| 963 |
TkFillPolygon(canvas, polyPtr->coordPtr, polyPtr->numPoints, |
| 964 |
display, drawable, polyPtr->fillGC, polyPtr->outline.gc); |
| 965 |
} else { |
| 966 |
int numPoints; |
| 967 |
XPoint staticPoints[MAX_STATIC_POINTS]; |
| 968 |
XPoint *pointPtr; |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, |
| 976 |
polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, |
| 977 |
(double *) NULL); |
| 978 |
if (numPoints <= MAX_STATIC_POINTS) { |
| 979 |
pointPtr = staticPoints; |
| 980 |
} else { |
| 981 |
pointPtr = (XPoint *) ckalloc((unsigned) |
| 982 |
(numPoints * sizeof(XPoint))); |
| 983 |
} |
| 984 |
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, |
| 985 |
polyPtr->numPoints, polyPtr->splineSteps, pointPtr, |
| 986 |
(double *) NULL); |
| 987 |
if (polyPtr->fillGC != None) { |
| 988 |
XFillPolygon(display, drawable, polyPtr->fillGC, pointPtr, |
| 989 |
numPoints, Complex, CoordModeOrigin); |
| 990 |
} |
| 991 |
if (polyPtr->outline.gc != None) { |
| 992 |
XDrawLines(display, drawable, polyPtr->outline.gc, pointPtr, |
| 993 |
numPoints, CoordModeOrigin); |
| 994 |
} |
| 995 |
if (pointPtr != staticPoints) { |
| 996 |
ckfree((char *) pointPtr); |
| 997 |
} |
| 998 |
} |
| 999 |
Tk_ResetOutlineGC(canvas, itemPtr, &(polyPtr->outline)); |
| 1000 |
if ((stipple != None) && (polyPtr->fillGC != None)) { |
| 1001 |
XSetTSOrigin(display, polyPtr->fillGC, 0, 0); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
static void |
| 1022 |
PolygonInsert(canvas, itemPtr, beforeThis, obj) |
| 1023 |
Tk_Canvas canvas; |
| 1024 |
Tk_Item *itemPtr; |
| 1025 |
int beforeThis; |
| 1026 |
|
| 1027 |
Tcl_Obj *obj; |
| 1028 |
{ |
| 1029 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1030 |
int length, objc, i; |
| 1031 |
Tcl_Obj **objv; |
| 1032 |
double *new; |
| 1033 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1034 |
|
| 1035 |
if (state == TK_STATE_NULL) { |
| 1036 |
state = ((TkCanvas *)canvas)->canvas_state; |
| 1037 |
} |
| 1038 |
|
| 1039 |
if (!obj || (Tcl_ListObjGetElements((Tcl_Interp *) NULL, obj, &objc, &objv) != TCL_OK) |
| 1040 |
|| !objc || objc&1) { |
| 1041 |
return; |
| 1042 |
} |
| 1043 |
length = 2*(polyPtr->numPoints - polyPtr->autoClosed); |
| 1044 |
while(beforeThis>length) beforeThis-=length; |
| 1045 |
while(beforeThis<0) beforeThis+=length; |
| 1046 |
new = (double *) ckalloc((unsigned)(sizeof(double) * (length + 2 + objc))); |
| 1047 |
for (i=0; i<beforeThis; i++) { |
| 1048 |
new[i] = polyPtr->coordPtr[i]; |
| 1049 |
} |
| 1050 |
for (i=0; i<objc; i++) { |
| 1051 |
if (Tcl_GetDoubleFromObj((Tcl_Interp *) NULL,objv[i], |
| 1052 |
new+(i+beforeThis))!=TCL_OK) { |
| 1053 |
ckfree((char *) new); |
| 1054 |
return; |
| 1055 |
} |
| 1056 |
} |
| 1057 |
|
| 1058 |
for(i=beforeThis; i<length; i++) { |
| 1059 |
new[i+objc] = polyPtr->coordPtr[i]; |
| 1060 |
} |
| 1061 |
if(polyPtr->coordPtr) ckfree((char *) polyPtr->coordPtr); |
| 1062 |
length+=objc; |
| 1063 |
polyPtr->coordPtr = new; |
| 1064 |
polyPtr->numPoints = (length/2) + polyPtr->autoClosed; |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
if (polyPtr->autoClosed) { |
| 1072 |
if ((new[length-2] == new[0]) && (new[length-1] == new[1])) { |
| 1073 |
polyPtr->autoClosed = 0; |
| 1074 |
polyPtr->numPoints--; |
| 1075 |
} |
| 1076 |
} |
| 1077 |
else { |
| 1078 |
if ((new[length-2] != new[0]) || (new[length-1] != new[1])) { |
| 1079 |
polyPtr->autoClosed = 1; |
| 1080 |
polyPtr->numPoints++; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
|
| 1084 |
new[length] = new[0]; |
| 1085 |
new[length+1] = new[1]; |
| 1086 |
if (((length-objc)>3) && (state != TK_STATE_HIDDEN)) { |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
double width; |
| 1096 |
int j; |
| 1097 |
itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis]; |
| 1108 |
itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1]; |
| 1109 |
beforeThis-=2; objc+=4; |
| 1110 |
if(polyPtr->smooth) { |
| 1111 |
beforeThis-=2; objc+=4; |
| 1112 |
} |
| 1113 |
for(i=beforeThis; i<beforeThis+objc; i+=2) { |
| 1114 |
j=i; |
| 1115 |
if(j<0) j+=length; |
| 1116 |
if(j>=length) j-=length; |
| 1117 |
TkIncludePoint(itemPtr, polyPtr->coordPtr+j); |
| 1118 |
} |
| 1119 |
width = polyPtr->outline.width; |
| 1120 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 1121 |
if (polyPtr->outline.activeWidth>width) { |
| 1122 |
width = polyPtr->outline.activeWidth; |
| 1123 |
} |
| 1124 |
} else if (state==TK_STATE_DISABLED) { |
| 1125 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 1126 |
width = polyPtr->outline.disabledWidth; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
itemPtr->x1 -= (int) width; itemPtr->y1 -= (int) width; |
| 1130 |
itemPtr->x2 += (int) width; itemPtr->y2 += (int) width; |
| 1131 |
Tk_CanvasEventuallyRedraw(canvas, |
| 1132 |
itemPtr->x1, itemPtr->y1, |
| 1133 |
itemPtr->x2, itemPtr->y2); |
| 1134 |
} |
| 1135 |
|
| 1136 |
ComputePolygonBbox(canvas, polyPtr); |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
static void |
| 1157 |
PolygonDeleteCoords(canvas, itemPtr, first, last) |
| 1158 |
Tk_Canvas canvas; |
| 1159 |
Tk_Item *itemPtr; |
| 1160 |
int first; |
| 1161 |
int last; |
| 1162 |
{ |
| 1163 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1164 |
int count, i; |
| 1165 |
int length = 2*(polyPtr->numPoints - polyPtr->autoClosed); |
| 1166 |
|
| 1167 |
while(first>=length) first-=length; |
| 1168 |
while(first<0) first+=length; |
| 1169 |
while(last>=length) last-=length; |
| 1170 |
while(last<0) last+=length; |
| 1171 |
|
| 1172 |
first &= -2; |
| 1173 |
last &= -2; |
| 1174 |
|
| 1175 |
count = last + 2 - first; |
| 1176 |
if(count<=0) count +=length; |
| 1177 |
|
| 1178 |
if(count >= length) { |
| 1179 |
polyPtr->numPoints = 0; |
| 1180 |
if(polyPtr->coordPtr != NULL) { |
| 1181 |
ckfree((char *) polyPtr->coordPtr); |
| 1182 |
} |
| 1183 |
ComputePolygonBbox(canvas, polyPtr); |
| 1184 |
return; |
| 1185 |
} |
| 1186 |
|
| 1187 |
if(last>=first) { |
| 1188 |
for(i=last+2; i<length; i++) { |
| 1189 |
polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i]; |
| 1190 |
} |
| 1191 |
} else { |
| 1192 |
for(i=last; i<=first; i++) { |
| 1193 |
polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i]; |
| 1194 |
} |
| 1195 |
} |
| 1196 |
polyPtr->coordPtr[length-count] = polyPtr->coordPtr[0]; |
| 1197 |
polyPtr->coordPtr[length-count+1] = polyPtr->coordPtr[1]; |
| 1198 |
polyPtr->numPoints -= count/2; |
| 1199 |
ComputePolygonBbox(canvas, polyPtr); |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
static double |
| 1224 |
PolygonToPoint(canvas, itemPtr, pointPtr) |
| 1225 |
Tk_Canvas canvas; |
| 1226 |
Tk_Item *itemPtr; |
| 1227 |
double *pointPtr; |
| 1228 |
{ |
| 1229 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1230 |
double *coordPtr, *polyPoints; |
| 1231 |
double staticSpace[2*MAX_STATIC_POINTS]; |
| 1232 |
double poly[10]; |
| 1233 |
double radius; |
| 1234 |
double bestDist, dist; |
| 1235 |
int numPoints, count; |
| 1236 |
int changedMiterToBevel; |
| 1237 |
|
| 1238 |
|
| 1239 |
double width; |
| 1240 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1241 |
|
| 1242 |
bestDist = 1.0e36; |
| 1243 |
|
| 1244 |
width = polyPtr->outline.width; |
| 1245 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 1246 |
if (polyPtr->outline.activeWidth>width) { |
| 1247 |
width = polyPtr->outline.activeWidth; |
| 1248 |
} |
| 1249 |
} else if (state==TK_STATE_DISABLED) { |
| 1250 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 1251 |
width = polyPtr->outline.disabledWidth; |
| 1252 |
} |
| 1253 |
} |
| 1254 |
radius = width/2.0; |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
if ((polyPtr->smooth) && (polyPtr->numPoints>2)) { |
| 1262 |
numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, |
| 1263 |
polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, |
| 1264 |
(double *) NULL); |
| 1265 |
if (numPoints <= MAX_STATIC_POINTS) { |
| 1266 |
polyPoints = staticSpace; |
| 1267 |
} else { |
| 1268 |
polyPoints = (double *) ckalloc((unsigned) |
| 1269 |
(2*numPoints*sizeof(double))); |
| 1270 |
} |
| 1271 |
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, |
| 1272 |
polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, |
| 1273 |
polyPoints); |
| 1274 |
} else { |
| 1275 |
numPoints = polyPtr->numPoints; |
| 1276 |
polyPoints = polyPtr->coordPtr; |
| 1277 |
} |
| 1278 |
|
| 1279 |
bestDist = TkPolygonToPoint(polyPoints, numPoints, pointPtr); |
| 1280 |
if (bestDist<=0.0) { |
| 1281 |
goto donepoint; |
| 1282 |
} |
| 1283 |
if ((polyPtr->outline.gc != None) && (polyPtr->joinStyle == JoinRound)) { |
| 1284 |
dist = bestDist - radius; |
| 1285 |
if (dist <= 0.0) { |
| 1286 |
bestDist = 0.0; |
| 1287 |
goto donepoint; |
| 1288 |
} else { |
| 1289 |
bestDist = dist; |
| 1290 |
} |
| 1291 |
} |
| 1292 |
|
| 1293 |
if ((polyPtr->outline.gc == None) || (width <= 1)) goto donepoint; |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
changedMiterToBevel = 0; |
| 1303 |
for (count = numPoints, coordPtr = polyPoints; count >= 2; |
| 1304 |
count--, coordPtr += 2) { |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
if (polyPtr->joinStyle == JoinRound) { |
| 1312 |
dist = hypot(coordPtr[0] - pointPtr[0], coordPtr[1] - pointPtr[1]) |
| 1313 |
- radius; |
| 1314 |
if (dist <= 0.0) { |
| 1315 |
bestDist = 0.0; |
| 1316 |
goto donepoint; |
| 1317 |
} else if (dist < bestDist) { |
| 1318 |
bestDist = dist; |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
if (count == numPoints) { |
| 1329 |
TkGetButtPoints(coordPtr+2, coordPtr, (double) width, |
| 1330 |
0, poly, poly+2); |
| 1331 |
} else if ((polyPtr->joinStyle == JoinMiter) && !changedMiterToBevel) { |
| 1332 |
poly[0] = poly[6]; |
| 1333 |
poly[1] = poly[7]; |
| 1334 |
poly[2] = poly[4]; |
| 1335 |
poly[3] = poly[5]; |
| 1336 |
} else { |
| 1337 |
TkGetButtPoints(coordPtr+2, coordPtr, (double) width, 0, |
| 1338 |
poly, poly+2); |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { |
| 1348 |
poly[8] = poly[0]; |
| 1349 |
poly[9] = poly[1]; |
| 1350 |
dist = TkPolygonToPoint(poly, 5, pointPtr); |
| 1351 |
if (dist <= 0.0) { |
| 1352 |
bestDist = 0.0; |
| 1353 |
goto donepoint; |
| 1354 |
} else if (dist < bestDist) { |
| 1355 |
bestDist = dist; |
| 1356 |
} |
| 1357 |
changedMiterToBevel = 0; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
if (count == 2) { |
| 1361 |
TkGetButtPoints(coordPtr, coordPtr+2, (double) width, |
| 1362 |
0, poly+4, poly+6); |
| 1363 |
} else if (polyPtr->joinStyle == JoinMiter) { |
| 1364 |
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, |
| 1365 |
(double) width, poly+4, poly+6) == 0) { |
| 1366 |
changedMiterToBevel = 1; |
| 1367 |
TkGetButtPoints(coordPtr, coordPtr+2, (double) width, |
| 1368 |
0, poly+4, poly+6); |
| 1369 |
} |
| 1370 |
} else { |
| 1371 |
TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, |
| 1372 |
poly+4, poly+6); |
| 1373 |
} |
| 1374 |
poly[8] = poly[0]; |
| 1375 |
poly[9] = poly[1]; |
| 1376 |
dist = TkPolygonToPoint(poly, 5, pointPtr); |
| 1377 |
if (dist <= 0.0) { |
| 1378 |
bestDist = 0.0; |
| 1379 |
goto donepoint; |
| 1380 |
} else if (dist < bestDist) { |
| 1381 |
bestDist = dist; |
| 1382 |
} |
| 1383 |
} |
| 1384 |
|
| 1385 |
donepoint: |
| 1386 |
if ((polyPoints != staticSpace) && polyPoints != polyPtr->coordPtr) { |
| 1387 |
ckfree((char *) polyPoints); |
| 1388 |
} |
| 1389 |
return bestDist; |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
static int |
| 1414 |
PolygonToArea(canvas, itemPtr, rectPtr) |
| 1415 |
Tk_Canvas canvas; |
| 1416 |
Tk_Item *itemPtr; |
| 1417 |
double *rectPtr; |
| 1418 |
|
| 1419 |
|
| 1420 |
{ |
| 1421 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1422 |
double *coordPtr; |
| 1423 |
double staticSpace[2*MAX_STATIC_POINTS]; |
| 1424 |
double *polyPoints, poly[10]; |
| 1425 |
double radius; |
| 1426 |
int numPoints, count; |
| 1427 |
int changedMiterToBevel; |
| 1428 |
|
| 1429 |
|
| 1430 |
int inside; |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
double width; |
| 1437 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1438 |
|
| 1439 |
width = polyPtr->outline.width; |
| 1440 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 1441 |
if (polyPtr->outline.activeWidth>width) { |
| 1442 |
width = polyPtr->outline.activeWidth; |
| 1443 |
} |
| 1444 |
} else if (state==TK_STATE_DISABLED) { |
| 1445 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 1446 |
width = polyPtr->outline.disabledWidth; |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
radius = width/2.0; |
| 1451 |
inside = -1; |
| 1452 |
|
| 1453 |
if ((state==TK_STATE_HIDDEN) || polyPtr->numPoints<2) { |
| 1454 |
return -1; |
| 1455 |
} else if (polyPtr->numPoints <3) { |
| 1456 |
double oval[4]; |
| 1457 |
oval[0] = polyPtr->coordPtr[0]-radius; |
| 1458 |
oval[1] = polyPtr->coordPtr[1]-radius; |
| 1459 |
oval[2] = polyPtr->coordPtr[0]+radius; |
| 1460 |
oval[3] = polyPtr->coordPtr[1]+radius; |
| 1461 |
return TkOvalToArea(oval, rectPtr); |
| 1462 |
} |
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
if (polyPtr->smooth) { |
| 1469 |
numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, |
| 1470 |
polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, |
| 1471 |
(double *) NULL); |
| 1472 |
if (numPoints <= MAX_STATIC_POINTS) { |
| 1473 |
polyPoints = staticSpace; |
| 1474 |
} else { |
| 1475 |
polyPoints = (double *) ckalloc((unsigned) |
| 1476 |
(2*numPoints*sizeof(double))); |
| 1477 |
} |
| 1478 |
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, |
| 1479 |
polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, |
| 1480 |
polyPoints); |
| 1481 |
} else { |
| 1482 |
numPoints = polyPtr->numPoints; |
| 1483 |
polyPoints = polyPtr->coordPtr; |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
inside = TkPolygonToArea(polyPoints, numPoints, rectPtr); |
| 1492 |
if (inside==0) goto donearea; |
| 1493 |
|
| 1494 |
if (polyPtr->outline.gc == None) goto donearea ; |
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
changedMiterToBevel = 0; |
| 1504 |
for (count = numPoints, coordPtr = polyPoints; count >= 2; |
| 1505 |
count--, coordPtr += 2) { |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
if (polyPtr->joinStyle == JoinRound) { |
| 1514 |
poly[0] = coordPtr[0] - radius; |
| 1515 |
poly[1] = coordPtr[1] - radius; |
| 1516 |
poly[2] = coordPtr[0] + radius; |
| 1517 |
poly[3] = coordPtr[1] + radius; |
| 1518 |
if (TkOvalToArea(poly, rectPtr) != inside) { |
| 1519 |
inside = 0; |
| 1520 |
goto donearea; |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
if (count == numPoints) { |
| 1531 |
TkGetButtPoints(coordPtr+2, coordPtr, width, |
| 1532 |
0, poly, poly+2); |
| 1533 |
} else if ((polyPtr->joinStyle == JoinMiter) && !changedMiterToBevel) { |
| 1534 |
poly[0] = poly[6]; |
| 1535 |
poly[1] = poly[7]; |
| 1536 |
poly[2] = poly[4]; |
| 1537 |
poly[3] = poly[5]; |
| 1538 |
} else { |
| 1539 |
TkGetButtPoints(coordPtr+2, coordPtr, width, 0, |
| 1540 |
poly, poly+2); |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { |
| 1550 |
poly[8] = poly[0]; |
| 1551 |
poly[9] = poly[1]; |
| 1552 |
if (TkPolygonToArea(poly, 5, rectPtr) != inside) { |
| 1553 |
inside = 0; |
| 1554 |
goto donearea; |
| 1555 |
} |
| 1556 |
changedMiterToBevel = 0; |
| 1557 |
} |
| 1558 |
} |
| 1559 |
if (count == 2) { |
| 1560 |
TkGetButtPoints(coordPtr, coordPtr+2, width, |
| 1561 |
0, poly+4, poly+6); |
| 1562 |
} else if (polyPtr->joinStyle == JoinMiter) { |
| 1563 |
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, |
| 1564 |
width, poly+4, poly+6) == 0) { |
| 1565 |
changedMiterToBevel = 1; |
| 1566 |
TkGetButtPoints(coordPtr, coordPtr+2, width, |
| 1567 |
0, poly+4, poly+6); |
| 1568 |
} |
| 1569 |
} else { |
| 1570 |
TkGetButtPoints(coordPtr, coordPtr+2, width, 0, |
| 1571 |
poly+4, poly+6); |
| 1572 |
} |
| 1573 |
poly[8] = poly[0]; |
| 1574 |
poly[9] = poly[1]; |
| 1575 |
if (TkPolygonToArea(poly, 5, rectPtr) != inside) { |
| 1576 |
inside = 0; |
| 1577 |
goto donearea; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
|
| 1581 |
donearea: |
| 1582 |
if ((polyPoints != staticSpace) && (polyPoints != polyPtr->coordPtr)) { |
| 1583 |
ckfree((char *) polyPoints); |
| 1584 |
} |
| 1585 |
return inside; |
| 1586 |
} |
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
static void |
| 1609 |
ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) |
| 1610 |
Tk_Canvas canvas; |
| 1611 |
Tk_Item *itemPtr; |
| 1612 |
double originX, originY; |
| 1613 |
double scaleX; |
| 1614 |
double scaleY; |
| 1615 |
{ |
| 1616 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1617 |
double *coordPtr; |
| 1618 |
int i; |
| 1619 |
|
| 1620 |
for (i = 0, coordPtr = polyPtr->coordPtr; i < polyPtr->numPoints; |
| 1621 |
i++, coordPtr += 2) { |
| 1622 |
*coordPtr = originX + scaleX*(*coordPtr - originX); |
| 1623 |
coordPtr[1] = originY + scaleY*(coordPtr[1] - originY); |
| 1624 |
} |
| 1625 |
ComputePolygonBbox(canvas, polyPtr); |
| 1626 |
} |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
static int |
| 1649 |
GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) |
| 1650 |
Tcl_Interp *interp; |
| 1651 |
Tk_Canvas canvas; |
| 1652 |
Tk_Item *itemPtr; |
| 1653 |
|
| 1654 |
Tcl_Obj *obj; |
| 1655 |
|
| 1656 |
int *indexPtr; |
| 1657 |
{ |
| 1658 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1659 |
int length; |
| 1660 |
char *string; |
| 1661 |
int i; |
| 1662 |
double x ,y, bestDist, dist, *coordPtr; |
| 1663 |
char *end, *p; |
| 1664 |
|
| 1665 |
Tcl_Obj **objv; |
| 1666 |
|
| 1667 |
if (Tcl_ListObjGetElements(interp, obj, &i, &objv) == TCL_OK && i == 2 |
| 1668 |
&& Tcl_GetDoubleFromObj(interp, objv[0], &x) == TCL_OK |
| 1669 |
&& Tcl_GetDoubleFromObj(interp, objv[1], &y) == TCL_OK) { |
| 1670 |
goto doxy; |
| 1671 |
} |
| 1672 |
|
| 1673 |
string = Tcl_GetStringFromObj(obj, &length); |
| 1674 |
|
| 1675 |
if (string[0] == 'e') { |
| 1676 |
if (strncmp(string, "end", length) == 0) { |
| 1677 |
*indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed); |
| 1678 |
} else { |
| 1679 |
badIndex: |
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); |
| 1687 |
Tcl_AppendResult(interp, "bad index \"", string, "\"", |
| 1688 |
(char *) NULL); |
| 1689 |
return TCL_ERROR; |
| 1690 |
} |
| 1691 |
} else if (string[0] == '@') { |
| 1692 |
|
| 1693 |
p = string+1; |
| 1694 |
x = strtod(p, &end); |
| 1695 |
if ((end == p) || (*end != ',')) { |
| 1696 |
goto badIndex; |
| 1697 |
} |
| 1698 |
p = end+1; |
| 1699 |
y = strtod(p, &end); |
| 1700 |
if ((end == p) || (*end != 0)) { |
| 1701 |
goto badIndex; |
| 1702 |
} |
| 1703 |
doxy: |
| 1704 |
bestDist = 1.0e36; |
| 1705 |
coordPtr = polyPtr->coordPtr; |
| 1706 |
*indexPtr = 0; |
| 1707 |
for(i=0; i<(polyPtr->numPoints-1); i++) { |
| 1708 |
dist = hypot(coordPtr[0] - x, coordPtr[1] - y); |
| 1709 |
if (dist<bestDist) { |
| 1710 |
bestDist = dist; |
| 1711 |
*indexPtr = 2*i; |
| 1712 |
} |
| 1713 |
coordPtr += 2; |
| 1714 |
} |
| 1715 |
} else { |
| 1716 |
int count = 2*(polyPtr->numPoints - polyPtr->autoClosed); |
| 1717 |
if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) { |
| 1718 |
goto badIndex; |
| 1719 |
} |
| 1720 |
*indexPtr &= -2; |
| 1721 |
if (count) { |
| 1722 |
if (*indexPtr > 0) { |
| 1723 |
*indexPtr = ((*indexPtr - 2) % count) + 2; |
| 1724 |
} else { |
| 1725 |
*indexPtr = -((-(*indexPtr)) % count); |
| 1726 |
} |
| 1727 |
} else { |
| 1728 |
*indexPtr = 0; |
| 1729 |
} |
| 1730 |
} |
| 1731 |
return TCL_OK; |
| 1732 |
} |
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
static void |
| 1754 |
TranslatePolygon(canvas, itemPtr, deltaX, deltaY) |
| 1755 |
Tk_Canvas canvas; |
| 1756 |
Tk_Item *itemPtr; |
| 1757 |
double deltaX, deltaY; |
| 1758 |
|
| 1759 |
{ |
| 1760 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1761 |
double *coordPtr; |
| 1762 |
int i; |
| 1763 |
|
| 1764 |
for (i = 0, coordPtr = polyPtr->coordPtr; i < polyPtr->numPoints; |
| 1765 |
i++, coordPtr += 2) { |
| 1766 |
*coordPtr += deltaX; |
| 1767 |
coordPtr[1] += deltaY; |
| 1768 |
} |
| 1769 |
ComputePolygonBbox(canvas, polyPtr); |
| 1770 |
} |
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
static int |
| 1794 |
PolygonToPostscript(interp, canvas, itemPtr, prepass) |
| 1795 |
Tcl_Interp *interp; |
| 1796 |
|
| 1797 |
Tk_Canvas canvas; |
| 1798 |
Tk_Item *itemPtr; |
| 1799 |
|
| 1800 |
int prepass; |
| 1801 |
|
| 1802 |
|
| 1803 |
{ |
| 1804 |
PolygonItem *polyPtr = (PolygonItem *) itemPtr; |
| 1805 |
char *style; |
| 1806 |
XColor *color; |
| 1807 |
XColor *fillColor; |
| 1808 |
Pixmap stipple; |
| 1809 |
Pixmap fillStipple; |
| 1810 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1811 |
double width; |
| 1812 |
|
| 1813 |
if (polyPtr->numPoints<2 || polyPtr->coordPtr==NULL) { |
| 1814 |
return TCL_OK; |
| 1815 |
} |
| 1816 |
|
| 1817 |
width = polyPtr->outline.width; |
| 1818 |
color = polyPtr->outline.color; |
| 1819 |
stipple = polyPtr->fillStipple; |
| 1820 |
fillColor = polyPtr->fillColor; |
| 1821 |
fillStipple = polyPtr->fillStipple; |
| 1822 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 1823 |
if (polyPtr->outline.activeWidth>width) { |
| 1824 |
width = polyPtr->outline.activeWidth; |
| 1825 |
} |
| 1826 |
if (polyPtr->outline.activeColor!=NULL) { |
| 1827 |
color = polyPtr->outline.activeColor; |
| 1828 |
} |
| 1829 |
if (polyPtr->outline.activeStipple!=None) { |
| 1830 |
stipple = polyPtr->outline.activeStipple; |
| 1831 |
} |
| 1832 |
if (polyPtr->activeFillColor!=NULL) { |
| 1833 |
fillColor = polyPtr->activeFillColor; |
| 1834 |
} |
| 1835 |
if (polyPtr->activeFillStipple!=None) { |
| 1836 |
fillStipple = polyPtr->activeFillStipple; |
| 1837 |
} |
| 1838 |
} else if (state==TK_STATE_DISABLED) { |
| 1839 |
if (polyPtr->outline.disabledWidth>0.0) { |
| 1840 |
width = polyPtr->outline.disabledWidth; |
| 1841 |
} |
| 1842 |
if (polyPtr->outline.disabledColor!=NULL) { |
| 1843 |
color = polyPtr->outline.disabledColor; |
| 1844 |
} |
| 1845 |
if (polyPtr->outline.disabledStipple!=None) { |
| 1846 |
stipple = polyPtr->outline.disabledStipple; |
| 1847 |
} |
| 1848 |
if (polyPtr->disabledFillColor!=NULL) { |
| 1849 |
fillColor = polyPtr->disabledFillColor; |
| 1850 |
} |
| 1851 |
if (polyPtr->disabledFillStipple!=None) { |
| 1852 |
fillStipple = polyPtr->disabledFillStipple; |
| 1853 |
} |
| 1854 |
} |
| 1855 |
if (polyPtr->numPoints==2) { |
| 1856 |
char string[128]; |
| 1857 |
if (color == NULL) { |
| 1858 |
return TCL_OK; |
| 1859 |
} |
| 1860 |
|
| 1861 |
sprintf(string, "%.15g %.15g translate %.15g %.15g", |
| 1862 |
polyPtr->coordPtr[0], Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]), |
| 1863 |
width/2.0, width/2.0); |
| 1864 |
Tcl_AppendResult(interp, "matrix currentmatrix\n",string, |
| 1865 |
" scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (char *) NULL); |
| 1866 |
if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { |
| 1867 |
return TCL_ERROR; |
| 1868 |
} |
| 1869 |
if (stipple != None) { |
| 1870 |
Tcl_AppendResult(interp, "clip ", (char *) NULL); |
| 1871 |
if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { |
| 1872 |
return TCL_ERROR; |
| 1873 |
} |
| 1874 |
} else { |
| 1875 |
Tcl_AppendResult(interp, "fill\n", (char *) NULL); |
| 1876 |
} |
| 1877 |
return TCL_OK; |
| 1878 |
} |
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
if (fillColor != NULL && polyPtr->numPoints>3) { |
| 1885 |
if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) { |
| 1886 |
Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr, |
| 1887 |
polyPtr->numPoints); |
| 1888 |
} else { |
| 1889 |
polyPtr->smooth->postscriptProc(interp, canvas, polyPtr->coordPtr, |
| 1890 |
polyPtr->numPoints, polyPtr->splineSteps); |
| 1891 |
} |
| 1892 |
if (Tk_CanvasPsColor(interp, canvas, fillColor) != TCL_OK) { |
| 1893 |
return TCL_ERROR; |
| 1894 |
} |
| 1895 |
if (fillStipple != None) { |
| 1896 |
Tcl_AppendResult(interp, "eoclip ", (char *) NULL); |
| 1897 |
if (Tk_CanvasPsStipple(interp, canvas, fillStipple) |
| 1898 |
!= TCL_OK) { |
| 1899 |
return TCL_ERROR; |
| 1900 |
} |
| 1901 |
if (color != NULL) { |
| 1902 |
Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL); |
| 1903 |
} |
| 1904 |
} else { |
| 1905 |
Tcl_AppendResult(interp, "eofill\n", (char *) NULL); |
| 1906 |
} |
| 1907 |
} |
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
if (color != NULL) { |
| 1914 |
|
| 1915 |
if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) { |
| 1916 |
Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr, |
| 1917 |
polyPtr->numPoints); |
| 1918 |
} else { |
| 1919 |
polyPtr->smooth->postscriptProc(interp, canvas, polyPtr->coordPtr, |
| 1920 |
polyPtr->numPoints, polyPtr->splineSteps); |
| 1921 |
} |
| 1922 |
|
| 1923 |
if (polyPtr->joinStyle == JoinRound) { |
| 1924 |
style = "1"; |
| 1925 |
} else if (polyPtr->joinStyle == JoinBevel) { |
| 1926 |
style = "2"; |
| 1927 |
} else { |
| 1928 |
style = "0"; |
| 1929 |
} |
| 1930 |
Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", |
| 1931 |
(char *) NULL); |
| 1932 |
if (Tk_CanvasPsOutline(canvas, itemPtr, |
| 1933 |
&(polyPtr->outline)) != TCL_OK) { |
| 1934 |
return TCL_ERROR; |
| 1935 |
} |
| 1936 |
} |
| 1937 |
return TCL_OK; |
| 1938 |
} |
| 1939 |
|