Debian Codegraph @

pTk/mTk/generic/tkCanvPoly.c

raw symbols SCIP
1 /*
2 * tkCanvPoly.c --
3 *
4 * This file implements polygon items for canvas widgets.
5 *
6 * Copyright (c) 1991-1994 The Regents of the University of California.
7 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
8 * Copyright (c) 1998-2000 Ajuba Solutions.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id: tkCanvPoly.c,v 1.10.2.1 2003/05/11 00:57:09 hobbs Exp $
14 */
15
16 #include "tkPort.h"
17 #include "tkInt.h"
18 #include "tkCanvases.h"
19
20 /*
21 * The structure below defines the record for each polygon item.
22 */
23
24 typedef struct PolygonItem {
25 Tk_Item header; /* Generic stuff that's the same for all
26 * types. MUST BE FIRST IN STRUCTURE. */
27 Tk_Outline outline; /* Outline structure */
28 int numPoints; /* Number of points in polygon.
29 * Polygon is always closed. */
30 int pointsAllocated; /* Number of points for which space is
31 * allocated at *coordPtr. */
32 double *coordPtr; /* Pointer to malloc-ed array containing
33 * x- and y-coords of all points in polygon.
34 * X-coords are even-valued indices, y-coords
35 * are corresponding odd-valued indices. */
36 int joinStyle; /* Join style for outline */
37 Tk_TSOffset tsoffset;
38 XColor *fillColor; /* Foreground color for polygon. */
39 XColor *activeFillColor; /* Foreground color for polygon if state is active. */
40 XColor *disabledFillColor; /* Foreground color for polygon if state is disabled. */
41 Pixmap fillStipple; /* Stipple bitmap for filling polygon. */
42 Pixmap activeFillStipple; /* Stipple bitmap for filling polygon if state is active. */
43 Pixmap disabledFillStipple; /* Stipple bitmap for filling polygon if state is disabled. */
44 GC fillGC; /* Graphics context for filling polygon. */
45 Tk_SmoothMethod *smooth; /* Non-zero means draw shape smoothed (i.e.
46 * with Bezier splines). */
47 int splineSteps; /* Number of steps in each spline segment. */
48 int autoClosed; /* Zero means the given polygon was closed,
49 one means that we auto closed it. */
50 Tk_Tile fillTile;
51 } PolygonItem;
52
53 /*
54 * Information used for parsing configuration specs:
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 * Prototypes for procedures defined in this file:
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 * The structures below defines the polygon item type by means
211 * of procedures that can be invoked by generic item code.
212 */
213
214 Tk_ItemType tkPolygonType = {
215 "polygon", /* name */
216 sizeof(PolygonItem), /* itemSize */
217 CreatePolygon, /* createProc */
218 configSpecs, /* configSpecs */
219 ConfigurePolygon, /* configureProc */
220 PolygonCoords, /* coordProc */
221 DeletePolygon, /* deleteProc */
222 DisplayPolygon, /* displayProc */
223 TK_CONFIG_OBJS, /* flags */
224 PolygonToPoint, /* pointProc */
225 PolygonToArea, /* areaProc */
226 PolygonToPostscript, /* postscriptProc */
227 ScalePolygon, /* scaleProc */
228 TranslatePolygon, /* translateProc */
229 GetPolygonIndex, /* indexProc */
230 (Tk_ItemCursorProc *) NULL, /* icursorProc */
231 (Tk_ItemSelectionProc *) NULL, /* selectionProc */
232 PolygonInsert, /* insertProc */
233 PolygonDeleteCoords, /* dTextProc */
234 (Tk_ItemType *) NULL, /* nextPtr */
235 };
236
237 /*
238 * The definition below determines how large are static arrays
239 * used to hold spline points (splines larger than this have to
240 * have their arrays malloc-ed).
241 */
242
243 #define MAX_STATIC_POINTS 200
244
245 /*
246 *--------------------------------------------------------------
247 *
248 * CreatePolygon --
249 *
250 * This procedure is invoked to create a new polygon item in
251 * a canvas.
252 *
253 * Results:
254 * A standard Tcl return value. If an error occurred in
255 * creating the item, then an error message is left in
256 * the interp's result; in this case itemPtr is
257 * left uninitialized, so it can be safely freed by the
258 * caller.
259 *
260 * Side effects:
261 * A new polygon item is created.
262 *
263 *--------------------------------------------------------------
264 */
265
266 static int
267 CreatePolygon(interp, canvas, itemPtr, objc, objv)
268 Tcl_Interp *interp; /* Interpreter for error reporting. */
269 Tk_Canvas canvas; /* Canvas to hold new item. */
270 Tk_Item *itemPtr; /* Record to hold new item; header
271 * has been initialized by caller. */
272 int objc; /* Number of arguments in objv. */
273 Tcl_Obj *CONST objv[]; /* Arguments describing polygon. */
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 * Carry out initialization that is needed in order to clean
284 * up after errors during the the remainder of this procedure.
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 * Count the number of points and then parse them into a point
308 * array. Leading arguments are assumed to be points if they
309 * start with a digit or a minus sign followed by a digit.
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 * PolygonCoords --
336 *
337 * This procedure is invoked to process the "coords" widget
338 * command on polygons. See the user documentation for details
339 * on what it does.
340 *
341 * Results:
342 * Returns TCL_OK or TCL_ERROR, and sets the interp's result.
343 *
344 * Side effects:
345 * The coordinates for the given item may be changed.
346 *
347 *--------------------------------------------------------------
348 */
349
350 static int
351 PolygonCoords(interp, canvas, itemPtr, objc, objv)
352 Tcl_Interp *interp; /* Used for error reporting. */
353 Tk_Canvas canvas; /* Canvas containing item. */
354 Tk_Item *itemPtr; /* Item whose coordinates are to be
355 * read or modified. */
356 int objc; /* Number of coordinates supplied in
357 * objv. */
358 Tcl_Obj *CONST objv[]; /* Array of coordinates: x1, y1,
359 * x2, y2, ... */
360 {
361 PolygonItem *polyPtr = (PolygonItem *) itemPtr;
362 int i, numPoints;
363
364 if (objc == 0) {
365 /*
366 * Print the coords used to create the polygon. If we auto
367 * closed the polygon then we don't report the last point.
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 * One extra point gets allocated here, because we always
398 * add another point to close the polygon.
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 * Close the polygon if it isn't already closed.
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 * ConfigurePolygon --
434 *
435 * This procedure is invoked to configure various aspects
436 * of a polygon item such as its background color.
437 *
438 * Results:
439 * A standard Tcl result code. If an error occurs, then
440 * an error message is left in the interp's result.
441 *
442 * Side effects:
443 * Configuration information, such as colors and stipple
444 * patterns, may be set for itemPtr.
445 *
446 *--------------------------------------------------------------
447 */
448
449 static int
450 ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags)
451 Tcl_Interp *interp; /* Interpreter for error reporting. */
452 Tk_Canvas canvas; /* Canvas containing itemPtr. */
453 Tk_Item *itemPtr; /* Polygon item to reconfigure. */
454 int objc; /* Number of elements in objv. */
455 Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */
456 int flags; /* Flags to pass to Tk_ConfigureWidget. */
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 * A few of the options require additional processing, such as
475 * graphics contexts.
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 * Keep spline parameters within reasonable limits.
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 * DeletePolygon --
563 *
564 * This procedure is called to clean up the data structure
565 * associated with a polygon item.
566 *
567 * Results:
568 * None.
569 *
570 * Side effects:
571 * Resources associated with itemPtr are released.
572 *
573 *--------------------------------------------------------------
574 */
575
576 static void
577 DeletePolygon(canvas, itemPtr, display)
578 Tk_Canvas canvas; /* Info about overall canvas widget. */
579 Tk_Item *itemPtr; /* Item that is being deleted. */
580 Display *display; /* Display containing window for
581 * canvas. */
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 * ComputePolygonBbox --
616 *
617 * This procedure is invoked to compute the bounding box of
618 * all the pixels that may be drawn as part of a polygon.
619 *
620 * Results:
621 * None.
622 *
623 * Side effects:
624 * The fields x1, y1, x2, and y2 are updated in the header
625 * for itemPtr.
626 *
627 *--------------------------------------------------------------
628 */
629
630 static void
631 ComputePolygonBbox(canvas, polyPtr)
632 Tk_Canvas canvas; /* Canvas that contains item. */
633 PolygonItem *polyPtr; /* Item whose bbox is to be
634 * recomputed. */
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 * Compute the bounding box of all the points in the polygon,
664 * then expand in all directions by the outline's width to take
665 * care of butting or rounded corners and projecting or
666 * rounded caps. This expansion is an overestimate (worst-case
667 * is square root of two over two) but it's simple. Don't do
668 * anything special for curves. This causes an additional
669 * overestimate in the bounding box, but is faster.
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 * For mitered lines, make a second pass through all the points.
749 * Compute the locations of the two miter vertex points and add
750 * those into the bounding box.
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 * Add one more pixel of fudge factor just to be safe (e.g.
781 * X may round differently than we do).
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 * TkFillPolygon --
794 *
795 * This procedure is invoked to convert a polygon to screen
796 * coordinates and display it using a particular GC.
797 *
798 * Results:
799 * None.
800 *
801 * Side effects:
802 * ItemPtr is drawn in drawable using the transformation
803 * information in canvas.
804 *
805 *--------------------------------------------------------------
806 */
807
808 void
809 TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC)
810 Tk_Canvas canvas; /* Canvas whose coordinate system
811 * is to be used for drawing. */
812 double *coordPtr; /* Array of coordinates for polygon:
813 * x1, y1, x2, y2, .... */
814 int numPoints; /* Twice this many coordinates are
815 * present at *coordPtr. */
816 Display *display; /* Display on which to draw polygon. */
817 Drawable drawable; /* Pixmap or window in which to draw
818 * polygon. */
819 GC gc; /* Graphics context for drawing. */
820 GC outlineGC; /* If not None, use this to draw an
821 * outline around the polygon after
822 * filling it. */
823 {
824 XPoint staticPoints[MAX_STATIC_POINTS];
825 XPoint *pointPtr;
826 XPoint *pPtr;
827 int i;
828
829 /*
830 * Build up an array of points in screen coordinates. Use a
831 * static array unless the polygon has an enormous number of points;
832 * in this case, dynamically allocate an array.
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 * Display polygon, then free up polygon storage if it was dynamically
848 * allocated.
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 * DisplayPolygon --
868 *
869 * This procedure is invoked to draw a polygon item in a given
870 * drawable.
871 *
872 * Results:
873 * None.
874 *
875 * Side effects:
876 * ItemPtr is drawn in drawable using the transformation
877 * information in canvas.
878 *
879 *--------------------------------------------------------------
880 */
881
882 static void
883 DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height)
884 Tk_Canvas canvas; /* Canvas that contains item. */
885 Tk_Item *itemPtr; /* Item to be displayed. */
886 Display *display; /* Display on which to draw item. */
887 Drawable drawable; /* Pixmap or window in which to draw
888 * item. */
889 int x, y, width, height; /* Describes region of canvas that
890 * must be redisplayed (not used). */
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 * If we're stippling then modify the stipple offset in the GC. Be
921 * sure to reset the offset when done, since the GC is supposed to be
922 * read-only.
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 * This is a smoothed polygon. Display using a set of generated
972 * spline points rather than the original points.
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 * PolygonInsert --
1009 *
1010 * Insert coords into a polugon item at a given index.
1011 *
1012 * Results:
1013 * None.
1014 *
1015 * Side effects:
1016 * The coords in the given item is modified.
1017 *
1018 *--------------------------------------------------------------
1019 */
1020
1021 static void
1022 PolygonInsert(canvas, itemPtr, beforeThis, obj)
1023 Tk_Canvas canvas; /* Canvas containing text item. */
1024 Tk_Item *itemPtr; /* Line item to be modified. */
1025 int beforeThis; /* Index before which new coordinates
1026 * are to be inserted. */
1027 Tcl_Obj *obj; /* New coordinates to be inserted. */
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 * Close the polygon if it isn't already closed, or remove autoclosing
1068 * if the user's coordinates are now closed.
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 * This is some optimizing code that will result that only the part
1089 * of the polygon that changed (and the objects that are overlapping
1090 * with that part) need to be redrawn. A special flag is set that
1091 * instructs the general canvas code not to redraw the whole
1092 * object. If this flag is not set, the canvas will do the redrawing,
1093 * otherwise I have to do it here.
1094 */
1095 double width;
1096 int j;
1097 itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
1098
1099 /*
1100 * The header elements that normally are used for the
1101 * bounding box, are now used to calculate the bounding
1102 * box for only the part that has to be redrawn. That
1103 * doesn't matter, because afterwards the bounding
1104 * box has to be re-calculated anyway.
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 } /* be carefull; beforeThis could now be negative */
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 * PolygonDeleteCoords --
1143 *
1144 * Delete one or more coordinates from a polygon item.
1145 *
1146 * Results:
1147 * None.
1148 *
1149 * Side effects:
1150 * Characters between "first" and "last", inclusive, get
1151 * deleted from itemPtr.
1152 *
1153 *--------------------------------------------------------------
1154 */
1155
1156 static void
1157 PolygonDeleteCoords(canvas, itemPtr, first, last)
1158 Tk_Canvas canvas; /* Canvas containing itemPtr. */
1159 Tk_Item *itemPtr; /* Item in which to delete characters. */
1160 int first; /* Index of first character to delete. */
1161 int last; /* Index of last character to delete. */
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 * PolygonToPoint --
1206 *
1207 * Computes the distance from a given point to a given
1208 * polygon, in canvas units.
1209 *
1210 * Results:
1211 * The return value is 0 if the point whose x and y coordinates
1212 * are pointPtr[0] and pointPtr[1] is inside the polygon. If the
1213 * point isn't inside the polygon then the return value is the
1214 * distance from the point to the polygon.
1215 *
1216 * Side effects:
1217 * None.
1218 *
1219 *--------------------------------------------------------------
1220 */
1221
1222 /* ARGSUSED */
1223 static double
1224 PolygonToPoint(canvas, itemPtr, pointPtr)
1225 Tk_Canvas canvas; /* Canvas containing item. */
1226 Tk_Item *itemPtr; /* Item to check against point. */
1227 double *pointPtr; /* Pointer to x and y coordinates. */
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; /* Non-zero means that a mitered corner
1237 * had to be treated as beveled after all
1238 * because the angle was < 11 degrees. */
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 * Handle smoothed polygons by generating an expanded set of points
1258 * against which to do the check.
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 * The overall idea is to iterate through all of the edges of
1297 * the line, computing a polygon for each edge and testing the
1298 * point against that polygon. In addition, there are additional
1299 * tests to deal with rounded joints and caps.
1300 */
1301
1302 changedMiterToBevel = 0;
1303 for (count = numPoints, coordPtr = polyPoints; count >= 2;
1304 count--, coordPtr += 2) {
1305
1306 /*
1307 * If rounding is done around the first point then compute
1308 * the distance between the point and the point.
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 * Compute the polygonal shape corresponding to this edge,
1324 * consisting of two points for the first point of the edge
1325 * and two points for the last point of the edge.
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 * If this line uses beveled joints, then check the distance
1342 * to a polygon comprising the last two points of the previous
1343 * polygon and the first two from this polygon; this checks
1344 * the wedges that fill the mitered joint.
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 * PolygonToArea --
1396 *
1397 * This procedure is called to determine whether an item
1398 * lies entirely inside, entirely outside, or overlapping
1399 * a given rectangular area.
1400 *
1401 * Results:
1402 * -1 is returned if the item is entirely outside the area
1403 * given by rectPtr, 0 if it overlaps, and 1 if it is entirely
1404 * inside the given area.
1405 *
1406 * Side effects:
1407 * None.
1408 *
1409 *--------------------------------------------------------------
1410 */
1411
1412 /* ARGSUSED */
1413 static int
1414 PolygonToArea(canvas, itemPtr, rectPtr)
1415 Tk_Canvas canvas; /* Canvas containing item. */
1416 Tk_Item *itemPtr; /* Item to check against polygon. */
1417 double *rectPtr; /* Pointer to array of four coordinates
1418 * (x1, y1, x2, y2) describing rectangular
1419 * area. */
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; /* Non-zero means that a mitered corner
1428 * had to be treated as beveled after all
1429 * because the angle was < 11 degrees. */
1430 int inside; /* Tentative guess about what to return,
1431 * based on all points seen so far: one
1432 * means everything seen so far was
1433 * inside the area; -1 means everything
1434 * was outside the area. 0 means overlap
1435 * has been found. */
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 * Handle smoothed polygons by generating an expanded set of points
1465 * against which to do the check.
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 * Simple test to see if we are in the polygon. Polygons are
1488 * different from othe canvas items in that they register points
1489 * being inside even if it isn't filled.
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 * Iterate through all of the edges of the line, computing a polygon
1498 * for each edge and testing the area against that polygon. In
1499 * addition, there are additional tests to deal with rounded joints
1500 * and caps.
1501 */
1502
1503 changedMiterToBevel = 0;
1504 for (count = numPoints, coordPtr = polyPoints; count >= 2;
1505 count--, coordPtr += 2) {
1506
1507 /*
1508 * If rounding is done around the first point of the edge
1509 * then test a circular region around the point with the
1510 * area.
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 * Compute the polygonal shape corresponding to this edge,
1526 * consisting of two points for the first point of the edge
1527 * and two points for the last point of the edge.
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 * If the last joint was beveled, then also check a
1544 * polygon comprising the last two points of the previous
1545 * polygon and the first two from this polygon; this checks
1546 * the wedges that fill the beveled joint.
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 * ScalePolygon --
1592 *
1593 * This procedure is invoked to rescale a polygon item.
1594 *
1595 * Results:
1596 * None.
1597 *
1598 * Side effects:
1599 * The polygon referred to by itemPtr is rescaled so that the
1600 * following transformation is applied to all point
1601 * coordinates:
1602 * x' = originX + scaleX*(x-originX)
1603 * y' = originY + scaleY*(y-originY)
1604 *
1605 *--------------------------------------------------------------
1606 */
1607
1608 static void
1609 ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY)
1610 Tk_Canvas canvas; /* Canvas containing polygon. */
1611 Tk_Item *itemPtr; /* Polygon to be scaled. */
1612 double originX, originY; /* Origin about which to scale rect. */
1613 double scaleX; /* Amount to scale in X direction. */
1614 double scaleY; /* Amount to scale in Y direction. */
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 * GetPolygonIndex --
1632 *
1633 * Parse an index into a polygon item and return either its value
1634 * or an error.
1635 *
1636 * Results:
1637 * A standard Tcl result. If all went well, then *indexPtr is
1638 * filled in with the index (into itemPtr) corresponding to
1639 * string. Otherwise an error message is left in
1640 * interp->result.
1641 *
1642 * Side effects:
1643 * None.
1644 *
1645 *--------------------------------------------------------------
1646 */
1647
1648 static int
1649 GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr)
1650 Tcl_Interp *interp; /* Used for error reporting. */
1651 Tk_Canvas canvas; /* Canvas containing item. */
1652 Tk_Item *itemPtr; /* Item for which the index is being
1653 * specified. */
1654 Tcl_Obj *obj; /* Specification of a particular coord
1655 * in itemPtr's line. */
1656 int *indexPtr; /* Where to store converted index. */
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 * Some of the paths here leave messages in interp->result,
1683 * so we have to clear it out before storing our own message.
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; /* if odd, make it even */
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 * TranslatePolygon --
1738 *
1739 * This procedure is called to move a polygon by a given
1740 * amount.
1741 *
1742 * Results:
1743 * None.
1744 *
1745 * Side effects:
1746 * The position of the polygon is offset by (xDelta, yDelta),
1747 * and the bounding box is updated in the generic part of the
1748 * item structure.
1749 *
1750 *--------------------------------------------------------------
1751 */
1752
1753 static void
1754 TranslatePolygon(canvas, itemPtr, deltaX, deltaY)
1755 Tk_Canvas canvas; /* Canvas containing item. */
1756 Tk_Item *itemPtr; /* Item that is being moved. */
1757 double deltaX, deltaY; /* Amount by which item is to be
1758 * moved. */
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 * PolygonToPostscript --
1776 *
1777 * This procedure is called to generate Postscript for
1778 * polygon items.
1779 *
1780 * Results:
1781 * The return value is a standard Tcl result. If an error
1782 * occurs in generating Postscript then an error message is
1783 * left in the interp's result, replacing whatever used
1784 * to be there. If no error occurs, then Postscript for the
1785 * item is appended to the result.
1786 *
1787 * Side effects:
1788 * None.
1789 *
1790 *--------------------------------------------------------------
1791 */
1792
1793 static int
1794 PolygonToPostscript(interp, canvas, itemPtr, prepass)
1795 Tcl_Interp *interp; /* Leave Postscript or error message
1796 * here. */
1797 Tk_Canvas canvas; /* Information about overall canvas. */
1798 Tk_Item *itemPtr; /* Item for which Postscript is
1799 * wanted. */
1800 int prepass; /* 1 means this is a prepass to
1801 * collect font information; 0 means
1802 * final Postscript is being created. */
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 * Fill the area of the polygon.
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 * Now draw the outline, if there is one.
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