Debian Codegraph @

pTk/ptkCanvGrid.c

raw symbols SCIP
1 /*
2 * ptkCanvGrid.c --
3 *
4 * This file implements grid items for canvas
5 * widgets.
6 *
7 * Copyright (c) 1991-1994 The Regents of the University of California.
8 * Copyright (c) 1994-1996 Sun Microsystems, Inc.
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: tkGrid.c,v 1.2 1998/09/14 18:23:16 stanton Exp $
14 */
15
16 #include "tkPort.h"
17 #include "tk.h"
18 #include "tkInt.h"
19 #include "tkCanvases.h"
20
21 /*
22 * The structure below defines the record for each rectangle/oval item.
23 */
24
25 typedef struct GridItem {
26 Tk_Item header; /* Generic stuff that's the same for all
27 * types. MUST BE FIRST IN STRUCTURE. */
28 Tk_Outline outline; /* Outline structure */
29 double bbox[4]; /* Coordinates of bounding box for rectangle
30 * or oval (x1, y1, x2, y2). Item includes
31 * x1 and x2 but not y1 and y2. */
32 int drawLines; /* Draw lines rather than dots */
33 } GridItem;
34
35 /*
36 * Information used for parsing configuration specs:
37 */
38
39 static Tk_CustomOption stateOption = {
40 TkStateParseProc,
41 TkStatePrintProc, (ClientData) 2
42 };
43 static Tk_CustomOption tagsOption = {
44 Tk_CanvasTagsParseProc,
45 Tk_CanvasTagsPrintProc, (ClientData) NULL
46 };
47 static Tk_CustomOption dashOption = {
48 TkCanvasDashParseProc,
49 TkCanvasDashPrintProc, (ClientData) NULL
50 };
51 static Tk_CustomOption tileOption = {
52 Tk_TileParseProc,
53 Tk_TilePrintProc, (ClientData) NULL
54 };
55 static Tk_CustomOption offsetOption = {
56 Tk_OffsetParseProc,
57 Tk_OffsetPrintProc, (ClientData) TK_OFFSET_RELATIVE
58 };
59 static Tk_CustomOption pixelOption = {
60 Tk_PixelParseProc,
61 Tk_PixelPrintProc, (ClientData) NULL
62 };
63
64 static Tk_ConfigSpec configSpecs[] = {
65 {TK_CONFIG_CUSTOM, "-dash", NULL, NULL,
66 NULL, Tk_Offset(GridItem, outline.dash),
67 TK_CONFIG_NULL_OK, &dashOption},
68 {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL,
69 "0", Tk_Offset(GridItem, outline.offset),
70 TK_CONFIG_DONT_SET_DEFAULT},
71 {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL,
72 NULL, Tk_Offset(GridItem, outline.disabledDash),
73 TK_CONFIG_NULL_OK, &dashOption},
74 {TK_CONFIG_COLOR, "-disabledcolor", NULL, NULL,
75 NULL, Tk_Offset(GridItem, outline.disabledColor),
76 TK_CONFIG_NULL_OK},
77 {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
78 NULL, Tk_Offset(GridItem, outline.disabledStipple),
79 TK_CONFIG_NULL_OK},
80 #ifdef NOTYET
81 {TK_CONFIG_CUSTOM, "-disabledtile", NULL, NULL,
82 NULL, Tk_Offset(GridItem, outline.disabledTile),
83 TK_CONFIG_NULL_OK, &tileOption},
84 #endif
85 {TK_CONFIG_PIXELS, "-disabledwidth", NULL, NULL,
86 "0.0", Tk_Offset(GridItem, outline.disabledWidth),
87 TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
88 {TK_CONFIG_BOOLEAN, "-lines", NULL, NULL,
89 "0", Tk_Offset(GridItem, drawLines), TK_CONFIG_NULL_OK},
90 /* Previously only -fill was implemented, but -color documented.
91 Misuse the "synonym" mechanism to support both. The dbName
92 specification is here just to make TK_CONFIG_SYNONYM work.
93 */
94 {TK_CONFIG_COLOR, "-color", "canvasGridColor", NULL,
95 "black", Tk_Offset(GridItem, outline.color), TK_CONFIG_NULL_OK},
96 {TK_CONFIG_SYNONYM, "-fill", "canvasGridColor", NULL,
97 NULL, 0, 0},
98 {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
99 "0,0", Tk_Offset(GridItem, outline.tsoffset),
100 TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
101 {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
102 NULL, Tk_Offset(GridItem, outline.stipple),
103 TK_CONFIG_NULL_OK},
104 #ifdef NOT_YET
105 {TK_CONFIG_CUSTOM, "-tile", NULL, NULL,
106 NULL, Tk_Offset(GridItem, outline.tile),
107 TK_CONFIG_NULL_OK, &tileOption},
108 #endif
109 {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
110 NULL, Tk_Offset(Tk_Item, state),TK_CONFIG_NULL_OK,
111 &stateOption},
112 {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
113 NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
114 {TK_CONFIG_CALLBACK, "-updatecommand", NULL, NULL,
115 NULL, Tk_Offset(Tk_Item, updateCmd), TK_CONFIG_NULL_OK},
116 {TK_CONFIG_CUSTOM, "-width", NULL, NULL,
117 "1.0", Tk_Offset(GridItem, outline.width),
118 TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
119 {TK_CONFIG_END, NULL, NULL, NULL,
120 NULL, 0, 0}
121 };
122
123 /*
124 * Prototypes for procedures defined in this file:
125 */
126
127 static void ComputeGridBbox _ANSI_ARGS_((Tk_Canvas canvas,
128 GridItem *gridPtr));
129 static int ConfigureGrid _ANSI_ARGS_((Tcl_Interp *interp,
130 Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
131 CONST84 Tcl_Obj *CONST *args, int flags));
132 static int CreateGrid _ANSI_ARGS_((Tcl_Interp *interp,
133 Tk_Canvas canvas, struct Tk_Item *itemPtr,
134 int argc, CONST84 Tcl_Obj *CONST *args));
135 static void DeleteGrid _ANSI_ARGS_((Tk_Canvas canvas,
136 Tk_Item *itemPtr, Display *display));
137 static void DisplayGrid _ANSI_ARGS_((Tk_Canvas canvas,
138 Tk_Item *itemPtr, Display *display, Drawable dst,
139 int x, int y, int width, int height));
140 static int GridCoords _ANSI_ARGS_((Tcl_Interp *interp,
141 Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
142 CONST84 Tcl_Obj *CONST *args));
143 static int GridToPostscript _ANSI_ARGS_((Tcl_Interp *interp,
144 Tk_Canvas canvas, Tk_Item *itemPtr, int prepass));
145 static int GridToArea _ANSI_ARGS_((Tk_Canvas canvas,
146 Tk_Item *itemPtr, double *areaPtr));
147 static double GridToPoint _ANSI_ARGS_((Tk_Canvas canvas,
148 Tk_Item *itemPtr, double *pointPtr));
149 static void ScaleGrid _ANSI_ARGS_((Tk_Canvas canvas,
150 Tk_Item *itemPtr, double originX, double originY,
151 double scaleX, double scaleY));
152 static void TranslateGrid _ANSI_ARGS_((Tk_Canvas canvas,
153 Tk_Item *itemPtr, double deltaX, double deltaY));
154
155 /*
156 * The structures below defines the rectangle and oval item types
157 * by means of procedures that can be invoked by generic item code.
158 */
159
160 Tk_ItemType ptkCanvGridType = {
161 "grid", /* name */
162 sizeof(GridItem), /* itemSize */
163 CreateGrid, /* createProc */
164 configSpecs, /* configSpecs */
165 ConfigureGrid, /* configureProc */
166 GridCoords, /* coordProc */
167 DeleteGrid, /* deleteProc */
168 DisplayGrid, /* displayProc */
169 TK_ITEM_ALWAYS_REDRAW|TK_CONFIG_OBJS,/* flags */
170 GridToPoint, /* pointProc */
171 GridToArea, /* areaProc */
172 GridToPostscript, /* postscriptProc */
173 ScaleGrid, /* scaleProc */
174 TranslateGrid, /* translateProc */
175 (Tk_ItemIndexProc *) NULL, /* indexProc */
176 (Tk_ItemCursorProc *) NULL, /* icursorProc */
177 (Tk_ItemSelectionProc *) NULL, /* selectionProc */
178 (Tk_ItemInsertProc *) NULL, /* insertProc */
179 (Tk_ItemDCharsProc *) NULL, /* dTextProc */
180 (Tk_ItemType *) NULL, /* nextPtr */
181 (Tk_ItemBboxProc *) ComputeGridBbox,/* bboxProc */
182 Tk_Offset(Tk_VisitorType, visitGrid), /* acceptProc */
183 NULL, /* getCoordPtr */
184 NULL /* setCoordPtr */
185 };
186
187
188 /*
189 *--------------------------------------------------------------
190 *
191 * CreateGrid --
192 *
193 * This procedure is invoked to create a new rectangle
194 * or oval item in a canvas.
195 *
196 * Results:
197 * A standard Tcl return value. If an error occurred in
198 * creating the item, then an error message is left in
199 * Tcl_GetResult(interp); in this case itemPtr is left uninitialized,
200 * so it can be safely freed by the caller.
201 *
202 * Side effects:
203 * A new rectangle or oval item is created.
204 *
205 *--------------------------------------------------------------
206 */
207
208 static int
209 CreateGrid(interp, canvas, itemPtr, argc, args)
210 Tcl_Interp *interp; /* For error reporting. */
211 Tk_Canvas canvas; /* Canvas to hold new item. */
212 Tk_Item *itemPtr; /* Record to hold new item; header
213 * has been initialized by caller. */
214 int argc; /* Number of arguments in args. */
215 CONST84 Tcl_Obj *CONST *args; /* Arguments describing rectangle. */
216 {
217 GridItem *gridPtr = (GridItem *) itemPtr;
218 int i;
219
220 if (argc==1) {
221 i = 1;
222 } else {
223 char *arg = Tcl_GetStringFromObj(args[1], NULL);
224 if ((argc>1) && (arg[0] == '-')
225 && (arg[1] >= 'a') && (arg[1] <= 'z')) {
226 i = 1;
227 } else {
228 i = 4;
229 }
230 }
231
232 if (argc < i) {
233 Tcl_AppendResult(interp, "wrong # args: should be \"",
234 Tk_PathName(Tk_CanvasTkwin(canvas)), " create ",
235 itemPtr->typePtr->name, " x1 y1 x2 y2 ?options?\"",
236 NULL);
237 return TCL_ERROR;
238 }
239
240 /*
241 * Carry out initialization that is needed in order to clean
242 * up after errors during the the remainder of this procedure.
243 */
244
245 Tk_CreateOutline(&(gridPtr->outline));
246
247 /*
248 * Process the arguments to fill in the item record.
249 */
250
251 if ((GridCoords(interp, canvas, itemPtr, i, args) != TCL_OK)) {
252 goto error;
253 }
254 if (ConfigureGrid(interp, canvas, itemPtr, argc-i, args+i, 0)
255 == TCL_OK) {
256 return TCL_OK;
257 }
258
259 error:
260 DeleteGrid(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas)));
261 return TCL_ERROR;
262 }
263
264 /*
265 *--------------------------------------------------------------
266 *
267 * GridCoords --
268 *
269 * This procedure is invoked to process the "coords" widget
270 * command on rectangles and ovals. See the user documentation
271 * for details on what it does.
272 *
273 * Results:
274 * Returns TCL_OK or TCL_ERROR, and sets Tcl_GetResult(interp).
275 *
276 * Side effects:
277 * The coordinates for the given item may be changed.
278 *
279 *--------------------------------------------------------------
280 */
281
282 static int
283 GridCoords(interp, canvas, itemPtr, argc, args)
284 Tcl_Interp *interp; /* Used for error reporting. */
285 Tk_Canvas canvas; /* Canvas containing item. */
286 Tk_Item *itemPtr; /* Item whose coordinates are to be
287 * read or modified. */
288 int argc; /* Number of coordinates supplied in
289 * args. */
290 Tcl_Obj *CONST *args; /* Array of coordinates: x1, y1,
291 * x2, y2, ... */
292 {
293 GridItem *gridPtr = (GridItem *) itemPtr;
294 char c0[TCL_DOUBLE_SPACE];
295
296 if (argc == 0) {
297 Tcl_Obj *obj = Tcl_NewObj();
298 Tcl_Obj *subobj = Tcl_NewDoubleObj(gridPtr->bbox[0]);
299 Tcl_ListObjAppendElement(interp, obj, subobj);
300 subobj = Tcl_NewDoubleObj(gridPtr->bbox[1]);
301 Tcl_ListObjAppendElement(interp, obj, subobj);
302 subobj = Tcl_NewDoubleObj(gridPtr->bbox[2]);
303 Tcl_ListObjAppendElement(interp, obj, subobj);
304 subobj = Tcl_NewDoubleObj(gridPtr->bbox[3]);
305 Tcl_ListObjAppendElement(interp, obj, subobj);
306 Tcl_SetObjResult(interp, obj);
307 } else if ((argc == 1)||(argc == 4)) {
308 if (argc==1) {
309 if (Tcl_ListObjGetElements(interp, args[0], &argc, (Tcl_Obj ***)&args) != TCL_OK) {
310 return TCL_ERROR;
311 } else if (argc != 4) {
312 sprintf(c0,"%d",argc);
313 Tcl_AppendResult(interp, "wrong # coordinates: expected 4, got ",
314 c0, NULL);
315 return TCL_ERROR;
316 }
317 }
318 if ((Tk_CanvasGetCoordFromObj(interp, canvas, args[0],
319 &gridPtr->bbox[0]) != TCL_OK)
320 || (Tk_CanvasGetCoordFromObj(interp, canvas, args[1],
321 &gridPtr->bbox[1]) != TCL_OK)
322 || (Tk_CanvasGetCoordFromObj(interp, canvas, args[2],
323 &gridPtr->bbox[2]) != TCL_OK)
324 || (Tk_CanvasGetCoordFromObj(interp, canvas, args[3],
325 &gridPtr->bbox[3]) != TCL_OK)) {
326 return TCL_ERROR;
327 }
328 ComputeGridBbox(canvas, gridPtr);
329 } else {
330 sprintf(c0,"%d",argc);
331 Tcl_AppendResult(interp, "wrong # coordinates: expected 0 or 4, got ",
332 c0, NULL);
333 return TCL_ERROR;
334 }
335 return TCL_OK;
336 }
337
338 /*
339 *--------------------------------------------------------------
340 *
341 * ConfigureGrid --
342 *
343 * This procedure is invoked to configure various aspects
344 * of a rectangle or oval item, such as its border and
345 * background colors.
346 *
347 * Results:
348 * A standard Tcl result code. If an error occurs, then
349 * an error message is left in Tcl_GetResult(interp).
350 *
351 * Side effects:
352 * Configuration information, such as colors and stipple
353 * patterns, may be set for itemPtr.
354 *
355 *--------------------------------------------------------------
356 */
357
358 static int
359 ConfigureGrid(interp, canvas, itemPtr, argc, args, flags)
360 Tcl_Interp *interp; /* Used for error reporting. */
361 Tk_Canvas canvas; /* Canvas containing itemPtr. */
362 Tk_Item *itemPtr; /* Rectangle item to reconfigure. */
363 int argc; /* Number of elements in args. */
364 CONST84 Tcl_Obj *CONST *args; /* Arguments describing things to configure. */
365 int flags; /* Flags to pass to Tk_ConfigureWidget. */
366 {
367 GridItem *gridPtr = (GridItem *) itemPtr;
368 XGCValues gcValues;
369 GC newGC;
370 unsigned long mask;
371 Tk_Window tkwin;
372 Tk_Tile tile;
373 XColor *color;
374 Pixmap stipple;
375 Tk_State state;
376 Pixmap pixmap;
377
378 tkwin = Tk_CanvasTkwin(canvas);
379
380 if (Tk_ConfigureWidget(interp, tkwin, configSpecs, argc, args,
381 (char *) gridPtr, flags|TK_CONFIG_OBJS) != TCL_OK) {
382 return TCL_ERROR;
383 }
384
385 /*
386 * A few of the options require additional processing, such as
387 * graphics contexts.
388 */
389
390 itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
391
392 mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(gridPtr->outline));
393 if (mask) {
394 gcValues.cap_style = CapProjecting;
395 mask |= GCCapStyle;
396 newGC = Tk_GetGC(tkwin, mask, &gcValues);
397 } else {
398 newGC = None;
399 }
400 if (gridPtr->outline.gc != None) {
401 Tk_FreeGC(Tk_Display(tkwin), gridPtr->outline.gc);
402 }
403 gridPtr->outline.gc = newGC;
404
405 ComputeGridBbox(canvas, gridPtr);
406
407 return TCL_OK;
408 }
409
410 /*
411 *--------------------------------------------------------------
412 *
413 * DeleteGrid --
414 *
415 * This procedure is called to clean up the data structure
416 * associated with a rectangle or oval item.
417 *
418 * Results:
419 * None.
420 *
421 * Side effects:
422 * Resources associated with itemPtr are released.
423 *
424 *--------------------------------------------------------------
425 */
426
427 static void
428 DeleteGrid(canvas, itemPtr, display)
429 Tk_Canvas canvas; /* Info about overall widget. */
430 Tk_Item *itemPtr; /* Item that is being deleted. */
431 Display *display; /* Display containing window for
432 * canvas. */
433 {
434 GridItem *gridPtr = (GridItem *) itemPtr;
435 Tk_DeleteOutline(display, &(gridPtr->outline));
436 }
437
438 /*
439 *--------------------------------------------------------------
440 *
441 * ComputeGridBbox --
442 *
443 * This procedure is invoked to compute the bounding box of
444 * all the pixels that may be drawn as part of a rectangle
445 * or oval.
446 *
447 * Results:
448 * None.
449 *
450 * Side effects:
451 * The fields x1, y1, x2, and y2 are updated in the header
452 * for itemPtr.
453 *
454 *--------------------------------------------------------------
455 */
456
457 /* ARGSUSED */
458 static void
459 ComputeGridBbox(canvas, gridPtr)
460 Tk_Canvas canvas; /* Canvas that contains item. */
461 GridItem *gridPtr; /* Item whose bbox is to be
462 * recomputed. */
463 {
464 TkCanvas *canvasPtr = (TkCanvas *) canvas;
465 /* After a change in params we cover the whole (visible) canvas */
466 gridPtr->header.x1 = canvasPtr->xOrigin;
467 gridPtr->header.y1 = canvasPtr->yOrigin;
468 gridPtr->header.x2 = gridPtr->header.x1+Tk_Width(canvasPtr->tkwin);
469 gridPtr->header.y2 = gridPtr->header.y1+Tk_Height(canvasPtr->tkwin);
470 }
471
472 /*
473 *--------------------------------------------------------------
474 *
475 * DisplayGrid --
476 *
477 * This procedure is invoked to draw a rectangle or oval
478 * item in a given drawable.
479 *
480 * Results:
481 * None.
482 *
483 * Side effects:
484 * ItemPtr is drawn in drawable using the transformation
485 * information in canvas.
486 *
487 *--------------------------------------------------------------
488 */
489
490 static void
491 DisplayGrid(canvas, itemPtr, display, drawable, x, y, width, height)
492 Tk_Canvas canvas; /* Canvas that contains item. */
493 Tk_Item *itemPtr; /* Item to be displayed. */
494 Display *display; /* Display on which to draw item. */
495 Drawable drawable; /* Pixmap or window in which to draw
496 * item. */
497 int x, y, width, height; /* Describes region of canvas that
498 * must be redisplayed (not used). */
499 {
500 TkCanvas *canvasPtr = (TkCanvas *) canvas;
501 GridItem *gridPtr = (GridItem *) itemPtr;
502 short x1, y1, x2, y2;
503 Tk_State state = Tk_GetItemState(canvas, itemPtr);
504
505 double cx = (double) x;
506 double cy = (double) y;
507 double mx = cx + (double) width;
508 double my = cy + (double) height;
509 double gx = gridPtr->bbox[0];
510 double gy = gridPtr->bbox[1];
511 double deltaX = gridPtr->bbox[2]-gridPtr->bbox[0];
512 double deltaY = gridPtr->bbox[3]-gridPtr->bbox[1];
513
514 /* Set our bbox to what is drawable, we have "always redraw" set
515 * so this ensures we overlap the "old" area during scroll etc.
516 * and we will get re-called
517 */
518
519 ComputeGridBbox(canvas, gridPtr);
520
521 /* Clip grid to the scroll region */
522 if (canvasPtr->regionArg != NULL)
523 {
524 if (cx < (double) (canvasPtr->scrollX1))
525 {
526 cx = (double) (canvasPtr->scrollX1);
527 }
528 if (cy < (double) (canvasPtr->scrollY1))
529 {
530 cy = (double) (canvasPtr->scrollY1);
531 }
532 if (mx > (double) (canvasPtr->scrollX2))
533 {
534 mx = (double) (canvasPtr->scrollX2);
535 }
536 if (my > (double) (canvasPtr->scrollY2))
537 {
538 my = (double) (canvasPtr->scrollY2);
539 }
540 }
541
542 /* Compute first grid point within the region to be drawn */
543 if (cx <= gx)
544 {
545 gx = cx + fmod((gx-cx), deltaX);
546 }
547 else
548 {
549 gx = cx + (deltaX - fmod((cx - gx), deltaX));
550 }
551 if (cy <= gy)
552 {
553 gy = cy + fmod((gy-cy), deltaY);
554 }
555 else
556 {
557 gy = cy + (deltaY - fmod((cy - gy), deltaY));
558 }
559
560 if (gridPtr->outline.gc != None) {
561 Tk_ChangeOutlineGC(canvas, itemPtr, &(gridPtr->outline));
562 if (gridPtr->drawLines) {
563 while (gx < mx) {
564 Tk_CanvasDrawableCoords(canvas, gx, cy, &x1, &y1);
565 Tk_CanvasDrawableCoords(canvas, gx, my, &x2, &y2);
566 XDrawLine(display, drawable, gridPtr->outline.gc, x1, y1, x2, y2);
567 gx += deltaX;
568 }
569 while (gy < my) {
570 Tk_CanvasDrawableCoords(canvas, cx, gy, &x1, &y1);
571 Tk_CanvasDrawableCoords(canvas, mx, gy, &x2, &y2);
572 XDrawLine(display, drawable, gridPtr->outline.gc, x1, y1, x2, y2);
573 gy += deltaY;
574 }
575 } else {
576 double halfWidth = gridPtr->outline.width/2;
577 double sy = gy;
578 while (gx < mx) {
579 gy = sy;
580 while (gy < my) {
581 Tk_CanvasDrawableCoords(canvas, gx-halfWidth, gy-halfWidth, &x1, &y1);
582 XFillRectangle(display, drawable, gridPtr->outline.gc, x1, y1,
583 gridPtr->outline.width, gridPtr->outline.width);
584 gy += deltaY;
585 }
586 gx += deltaX;
587 }
588 }
589 Tk_ResetOutlineGC(canvas, itemPtr, &(gridPtr->outline));
590 }
591 }
592
593 /*
594 *--------------------------------------------------------------
595 *
596 * GridToPoint --
597 *
598 * Computes the distance from a given point to a given
599 * rectangle, in canvas units.
600 *
601 * Results:
602 * The return value is 0 if the point whose x and y coordinates
603 * are coordPtr[0] and coordPtr[1] is inside the rectangle. If the
604 * point isn't inside the rectangle then the return value is the
605 * distance from the point to the rectangle. If itemPtr is filled,
606 * then anywhere in the interior is considered "inside"; if
607 * itemPtr isn't filled, then "inside" means only the area
608 * occupied by the outline.
609 *
610 * Side effects:
611 * None.
612 *
613 *--------------------------------------------------------------
614 */
615
616 /* ARGSUSED */
617 static double
618 GridToPoint(canvas, itemPtr, pointPtr)
619 Tk_Canvas canvas; /* Canvas containing item. */
620 Tk_Item *itemPtr; /* Item to check against point. */
621 double *pointPtr; /* Pointer to x and y coordinates. */
622 {
623 GridItem *gridPtr = (GridItem *) itemPtr;
624 /* A grid is always a long way from anywhere */
625 return 1.0e37;
626 }
627
628
629 /*
630 *--------------------------------------------------------------
631 *
632 * GridToArea --
633 *
634 * This procedure is called to determine whether an item
635 * lies entirely inside, entirely outside, or overlapping
636 * a given rectangle.
637 *
638 * Results:
639 * -1 is returned if the item is entirely outside the area
640 * given by rectPtr, 0 if it overlaps, and 1 if it is entirely
641 * inside the given area.
642 *
643 * Side effects:
644 * None.
645 *
646 *--------------------------------------------------------------
647 */
648
649 /* ARGSUSED */
650 static int
651 GridToArea(canvas, itemPtr, areaPtr)
652 Tk_Canvas canvas; /* Canvas containing item. */
653 Tk_Item *itemPtr; /* Item to check against rectangle. */
654 double *areaPtr; /* Pointer to array of four coordinates
655 * (x1, y1, x2, y2) describing rectangular
656 * area. */
657 {
658 GridItem *rectPtr = (GridItem *) itemPtr;
659 /* A grid is never inside any area */
660 return -1;
661 }
662
663
664 /*
665 *--------------------------------------------------------------
666 *
667 * ScaleGrid --
668 *
669 * This procedure is invoked to rescale a rectangle or oval
670 * item.
671 *
672 * Results:
673 * None.
674 *
675 * Side effects:
676 * The rectangle or oval referred to by itemPtr is rescaled
677 * so that the following transformation is applied to all
678 * point coordinates:
679 * x' = originX + scaleX*(x-originX)
680 * y' = originY + scaleY*(y-originY)
681 *
682 *--------------------------------------------------------------
683 */
684
685 static void
686 ScaleGrid(canvas, itemPtr, originX, originY, scaleX, scaleY)
687 Tk_Canvas canvas; /* Canvas containing rectangle. */
688 Tk_Item *itemPtr; /* Rectangle to be scaled. */
689 double originX, originY; /* Origin about which to scale rect. */
690 double scaleX; /* Amount to scale in X direction. */
691 double scaleY; /* Amount to scale in Y direction. */
692 {
693 GridItem *gridPtr = (GridItem *) itemPtr;
694 gridPtr->bbox[0] = originX + scaleX*(gridPtr->bbox[0] - originX);
695 gridPtr->bbox[1] = originY + scaleY*(gridPtr->bbox[1] - originY);
696 gridPtr->bbox[2] = originX + scaleX*(gridPtr->bbox[2] - originX);
697 gridPtr->bbox[3] = originY + scaleY*(gridPtr->bbox[3] - originY);
698 ComputeGridBbox(canvas, gridPtr);
699 }
700
701 /*
702 *--------------------------------------------------------------
703 *
704 * TranslateGrid --
705 *
706 * This procedure is called to move a rectangle or oval by a
707 * given amount.
708 *
709 * Results:
710 * None.
711 *
712 * Side effects:
713 * The position of the rectangle or oval is offset by
714 * (xDelta, yDelta), and the bounding box is updated in the
715 * generic part of the item structure.
716 *
717 *--------------------------------------------------------------
718 */
719
720 static void
721 TranslateGrid(canvas, itemPtr, deltaX, deltaY)
722 Tk_Canvas canvas; /* Canvas containing item. */
723 Tk_Item *itemPtr; /* Item that is being moved. */
724 double deltaX, deltaY; /* Amount by which item is to be
725 * moved. */
726 {
727 GridItem *gridPtr = (GridItem *) itemPtr;
728
729 gridPtr->bbox[0] += deltaX;
730 gridPtr->bbox[1] += deltaY;
731 gridPtr->bbox[2] += deltaX;
732 gridPtr->bbox[3] += deltaY;
733 ComputeGridBbox(canvas, gridPtr);
734 }
735
736 /*
737 *--------------------------------------------------------------
738 *
739 * GridToPostscript --
740 *
741 * This procedure is called to generate Postscript for
742 * rectangle and oval items.
743 *
744 * Results:
745 * The return value is a standard Tcl result. If an error
746 * occurs in generating Postscript then an error message is
747 * left in Tcl_GetResult(interp), replacing whatever used to be there.
748 * If no error occurs, then Postscript for the rectangle is
749 * appended to the result.
750 *
751 * Side effects:
752 * None.
753 *
754 *--------------------------------------------------------------
755 */
756
757 static int
758 GridToPostscript(interp, canvas, itemPtr, prepass)
759 Tcl_Interp *interp; /* Interpreter for error reporting. */
760 Tk_Canvas canvas; /* Information about overall canvas. */
761 Tk_Item *itemPtr; /* Item for which Postscript is
762 * wanted. */
763 int prepass; /* 1 means this is a prepass to
764 * collect font information; 0 means
765 * final Postscript is being created. */
766 {
767 GridItem *gridPtr = (GridItem *) itemPtr;
768 return TCL_OK;
769 }
770