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