| 1 |
578 |
markom |
/*
|
| 2 |
|
|
* tkCanvEdge.c --
|
| 3 |
|
|
*
|
| 4 |
|
|
* This file implements edge items for canvas widgets.
|
| 5 |
|
|
*
|
| 6 |
|
|
* Copyright (c) 1993 by Sven Delmas
|
| 7 |
|
|
* All rights reserved.
|
| 8 |
|
|
* See the file COPYRIGHT for the copyright notes.
|
| 9 |
|
|
*
|
| 10 |
|
|
*
|
| 11 |
|
|
* This source is based upon the file tkCanvLine.c from:
|
| 12 |
|
|
*
|
| 13 |
|
|
* John Ousterhout
|
| 14 |
|
|
*
|
| 15 |
|
|
* Copyright (c) 1992-1993 The Regents of the University of California.
|
| 16 |
|
|
* All rights reserved.
|
| 17 |
|
|
*
|
| 18 |
|
|
* Permission is hereby granted, without written agreement and without
|
| 19 |
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
| 20 |
|
|
* software and its documentation for any purpose, provided that the
|
| 21 |
|
|
* above copyright notice and the following two paragraphs appear in
|
| 22 |
|
|
* all copies of this software.
|
| 23 |
|
|
*
|
| 24 |
|
|
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
| 25 |
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
| 26 |
|
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
| 27 |
|
|
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 28 |
|
|
*
|
| 29 |
|
|
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
| 30 |
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
| 31 |
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
| 32 |
|
|
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
| 33 |
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
| 34 |
|
|
*/
|
| 35 |
|
|
|
| 36 |
|
|
/* 05may96 wmt: converted to tk4.1 */
|
| 37 |
|
|
|
| 38 |
|
|
#ifdef HAVE_CONFIG_H
|
| 39 |
|
|
#include <config.h>
|
| 40 |
|
|
#endif
|
| 41 |
|
|
#ifdef HAVE_UNISTD_H
|
| 42 |
|
|
#include <unistd.h>
|
| 43 |
|
|
#endif
|
| 44 |
|
|
#include <stdio.h>
|
| 45 |
|
|
#include <math.h>
|
| 46 |
|
|
#include "tkInt.h"
|
| 47 |
|
|
#include "tkCanvas.h"
|
| 48 |
|
|
/* #include "tkConfig.h" 05nov95 wmt */
|
| 49 |
|
|
#include "tkPort.h"
|
| 50 |
|
|
|
| 51 |
|
|
#ifdef _MSC_VER
|
| 52 |
|
|
#define F_OK 0
|
| 53 |
|
|
#endif
|
| 54 |
|
|
|
| 55 |
|
|
/*
|
| 56 |
|
|
* The structure below defines the record for each edge item.
|
| 57 |
|
|
*/
|
| 58 |
|
|
typedef struct EdgeItem {
|
| 59 |
|
|
Tk_Item header; /* Generic stuff that's the same for all
|
| 60 |
|
|
* types. MUST BE FIRST IN STRUCTURE. */
|
| 61 |
|
|
Tk_Canvas canvas; /* Canvas containing item. Needed for
|
| 62 |
|
|
* parsing arrow shapes. a register variable */
|
| 63 |
|
|
int numPoints; /* Number of points in edge (always >= 2). */
|
| 64 |
|
|
double *coordPtr; /* Pointer to malloc-ed array containing
|
| 65 |
|
|
* x- and y-coords of all points in edge.
|
| 66 |
|
|
* X-coords are even-valued indices, y-coords
|
| 67 |
|
|
* are corresponding odd-valued indices. If
|
| 68 |
|
|
* the edge has arrowheads then the first
|
| 69 |
|
|
* and last points have been adjusted to refer
|
| 70 |
|
|
* to the necks of the arrowheads rather than
|
| 71 |
|
|
* their tips. The actual endpoints are
|
| 72 |
|
|
* stored in the *firstArrowPtr and
|
| 73 |
|
|
* *lastArrowPtr, if they exist. */
|
| 74 |
|
|
|
| 75 |
|
|
char *label; /* Label to display. */
|
| 76 |
|
|
char *menu1; /* Standard menu for item, usually
|
| 77 |
|
|
* activated with button-3. */
|
| 78 |
|
|
char *menu2; /* Alternative menu for item, usually
|
| 79 |
|
|
* activated with meta-button-3. */
|
| 80 |
|
|
char *menu3; /* Alternative menu for item, usually
|
| 81 |
|
|
* activated with control-button-3. */
|
| 82 |
|
|
char *name; /* Name for item. */
|
| 83 |
|
|
char *state; /* State of item, this value is used
|
| 84 |
|
|
* to represent the selection status
|
| 85 |
|
|
* (normal, selected). */
|
| 86 |
|
|
char *graphName; /* Name of the Graph. */
|
| 87 |
|
|
char *from; /* From icon id. */
|
| 88 |
|
|
char *to; /* To icon id. */
|
| 89 |
|
|
Tk_Font tkfont; /* Font for drawing text. */
|
| 90 |
|
|
Tk_TextLayout textLayout; /* Cached text layout information. */
|
| 91 |
|
|
Tk_Justify justify; /* Justification to use for text within
|
| 92 |
|
|
* window. */
|
| 93 |
|
|
|
| 94 |
|
|
int width; /* Width of edge. */
|
| 95 |
|
|
int textHeight; /* Height of text label in points. */
|
| 96 |
|
|
int textWidth; /* Width of text label in points. */
|
| 97 |
|
|
XColor *fgColor; /* Foreground color for edge. */
|
| 98 |
|
|
XColor *bgColor; /* Background color to use for icon. */
|
| 99 |
|
|
Pixmap fillStipple; /* Stipple bitmap for filling edge. */
|
| 100 |
|
|
int capStyle; /* Cap style for edge. */
|
| 101 |
|
|
int joinStyle; /* Join style for edge. */
|
| 102 |
|
|
|
| 103 |
|
|
GC invertedGc; /* Graphics context to use for drawing
|
| 104 |
|
|
* the edge label on screen. */
|
| 105 |
|
|
GC gc; /* Graphics context for filling edge. */
|
| 106 |
|
|
Tk_Uid arrow; /* Indicates whether or not to draw arrowheads:
|
| 107 |
|
|
* "none", "first", "last", or "both". */
|
| 108 |
|
|
float arrowShapeA; /* Distance from tip of arrowhead to center. */
|
| 109 |
|
|
float arrowShapeB; /* Distance from tip of arrowhead to trailing
|
| 110 |
|
|
* point, measured along shaft. */
|
| 111 |
|
|
float arrowShapeC; /* Distance of trailing points from outside
|
| 112 |
|
|
* edge of shaft. */
|
| 113 |
|
|
double *firstArrowPtr; /* Points to array of PTS_IN_ARROW points
|
| 114 |
|
|
* describing polygon for arrowhead at first
|
| 115 |
|
|
* point in edge. First point of arrowhead
|
| 116 |
|
|
* is tip. Malloc'ed. NULL means no arrowhead
|
| 117 |
|
|
* at first point. */
|
| 118 |
|
|
double *lastArrowPtr; /* Points to polygon for arrowhead at last
|
| 119 |
|
|
* point in edge (PTS_IN_ARROW points, first
|
| 120 |
|
|
* of which is tip). Malloc'ed. NULL means
|
| 121 |
|
|
* no arrowhead at last point. */
|
| 122 |
|
|
int smooth; /* Non-zero means draw edge smoothed (i.e.
|
| 123 |
|
|
* with Bezier splines). */
|
| 124 |
|
|
int splineSteps; /* Number of steps in each spline segment. */
|
| 125 |
|
|
} EdgeItem;
|
| 126 |
|
|
|
| 127 |
|
|
/*
|
| 128 |
|
|
* Number of points in an arrowHead:
|
| 129 |
|
|
*/
|
| 130 |
|
|
#define PTS_IN_ARROW 6
|
| 131 |
|
|
|
| 132 |
|
|
/*
|
| 133 |
|
|
* Prototypes for procedures defined in this file:
|
| 134 |
|
|
*/
|
| 135 |
|
|
static int ArrowheadPostscript _ANSI_ARGS_((Tcl_Interp *interp,
|
| 136 |
|
|
Tk_Canvas canvas, EdgeItem *edgePtr,
|
| 137 |
|
|
double *arrowPtr));
|
| 138 |
|
|
static void ComputeEdgeBbox _ANSI_ARGS_((Tk_Canvas canvas,
|
| 139 |
|
|
EdgeItem *edgePtr));
|
| 140 |
|
|
static int ConfigureEdge _ANSI_ARGS_((Tcl_Interp *interp,
|
| 141 |
|
|
Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
|
| 142 |
|
|
char **argv, int flags));
|
| 143 |
|
|
static int ConfigureArrows _ANSI_ARGS_((Tk_Canvas canvas,
|
| 144 |
|
|
EdgeItem *edgePtr));
|
| 145 |
|
|
static int CreateEdge _ANSI_ARGS_((Tcl_Interp *interp,
|
| 146 |
|
|
Tk_Canvas canvas, struct Tk_Item *itemPtr,
|
| 147 |
|
|
int argc, char **argv));
|
| 148 |
|
|
static void DeleteEdge _ANSI_ARGS_((Tk_Canvas canvas,
|
| 149 |
|
|
Tk_Item *itemPtr, Display *display));
|
| 150 |
|
|
static void DisplayEdge _ANSI_ARGS_((Tk_Canvas canvas,
|
| 151 |
|
|
Tk_Item *itemPtr, Display *display, Drawable dst,
|
| 152 |
|
|
int x, int y, int width, int height));
|
| 153 |
|
|
static int EdgeCoords _ANSI_ARGS_((Tcl_Interp *interp,
|
| 154 |
|
|
Tk_Canvas canvas, Tk_Item *itemPtr,
|
| 155 |
|
|
int argc, char **argv));
|
| 156 |
|
|
static int EdgeToArea _ANSI_ARGS_((Tk_Canvas canvas,
|
| 157 |
|
|
Tk_Item *itemPtr, double *rectPtr));
|
| 158 |
|
|
static double EdgeToPoint _ANSI_ARGS_((Tk_Canvas canvas,
|
| 159 |
|
|
Tk_Item *itemPtr, double *coordPtr));
|
| 160 |
|
|
static int EdgeToPostscript _ANSI_ARGS_((Tcl_Interp *interp,
|
| 161 |
|
|
Tk_Canvas canvas, Tk_Item *itemPtr, int prepass));
|
| 162 |
|
|
static int ParseArrowShape _ANSI_ARGS_((ClientData clientData,
|
| 163 |
|
|
Tcl_Interp *interp, Tk_Window tkwin, char *value,
|
| 164 |
|
|
char *recordPtr, int offset));
|
| 165 |
|
|
static char * PrintArrowShape _ANSI_ARGS_((ClientData clientData,
|
| 166 |
|
|
Tk_Window tkwin, char *recordPtr, int offset,
|
| 167 |
|
|
Tcl_FreeProc **freeProcPtr));
|
| 168 |
|
|
static void ScaleEdge _ANSI_ARGS_((Tk_Canvas canvas,
|
| 169 |
|
|
Tk_Item *itemPtr, double originX, double originY,
|
| 170 |
|
|
double scaleX, double scaleY));
|
| 171 |
|
|
static void TranslateEdge _ANSI_ARGS_((Tk_Canvas canvas,
|
| 172 |
|
|
Tk_Item *itemPtr, double deltaX, double deltaY));
|
| 173 |
|
|
|
| 174 |
|
|
/*
|
| 175 |
|
|
* Information used for parsing configuration specs. If you change any
|
| 176 |
|
|
* of the default strings, be sure to change the corresponding default
|
| 177 |
|
|
* values in CreateEdge.
|
| 178 |
|
|
*/
|
| 179 |
|
|
static Tk_CustomOption arrowShapeOption =
|
| 180 |
|
|
{ ParseArrowShape, PrintArrowShape, (ClientData) NULL};
|
| 181 |
|
|
|
| 182 |
|
|
static Tk_CustomOption tagsOption = {Tk_CanvasTagsParseProc,
|
| 183 |
|
|
Tk_CanvasTagsPrintProc, (ClientData) NULL};
|
| 184 |
|
|
|
| 185 |
|
|
static Tk_ConfigSpec configSpecs[] = {
|
| 186 |
|
|
{TK_CONFIG_UID, "-arrow", (char *) NULL, (char *) NULL,
|
| 187 |
|
|
"none", Tk_Offset(EdgeItem, arrow), TK_CONFIG_DONT_SET_DEFAULT},
|
| 188 |
|
|
{TK_CONFIG_CUSTOM, "-arrowshape", (char *) NULL, (char *) NULL,
|
| 189 |
|
|
"8 10 3", Tk_Offset(EdgeItem, arrowShapeA),
|
| 190 |
|
|
TK_CONFIG_DONT_SET_DEFAULT, &arrowShapeOption},
|
| 191 |
|
|
{TK_CONFIG_COLOR, "-background", (char *) NULL, (char *) NULL,
|
| 192 |
|
|
(char *) NULL, Tk_Offset(EdgeItem, bgColor), TK_CONFIG_NULL_OK},
|
| 193 |
|
|
{TK_CONFIG_CAP_STYLE, "-capstyle", (char *) NULL, (char *) NULL,
|
| 194 |
|
|
"butt", Tk_Offset(EdgeItem, capStyle), TK_CONFIG_DONT_SET_DEFAULT},
|
| 195 |
|
|
{TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL,
|
| 196 |
|
|
"black", Tk_Offset(EdgeItem, fgColor), TK_CONFIG_NULL_OK},
|
| 197 |
|
|
{TK_CONFIG_FONT, "-font", (char *) NULL, (char *) NULL,
|
| 198 |
|
|
"Helvetica 12 bold", Tk_Offset(EdgeItem, tkfont), 0},
|
| 199 |
|
|
{TK_CONFIG_STRING, "-from", (char *) NULL, (char *) NULL,
|
| 200 |
|
|
"", Tk_Offset(EdgeItem, from), 0},
|
| 201 |
|
|
{TK_CONFIG_STRING, "-graphname", (char *) NULL, (char *) NULL,
|
| 202 |
|
|
"", Tk_Offset(EdgeItem, graphName), 0},
|
| 203 |
|
|
{TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL,
|
| 204 |
|
|
"round", Tk_Offset(EdgeItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT},
|
| 205 |
|
|
{TK_CONFIG_STRING, "-label", (char *) NULL, (char *) NULL,
|
| 206 |
|
|
"", Tk_Offset(EdgeItem, label), 0},
|
| 207 |
|
|
{TK_CONFIG_STRING, "-menu1", (char *) NULL, (char *) NULL,
|
| 208 |
|
|
"", Tk_Offset(EdgeItem, menu1), 0},
|
| 209 |
|
|
{TK_CONFIG_STRING, "-menu2", (char *) NULL, (char *) NULL,
|
| 210 |
|
|
"", Tk_Offset(EdgeItem, menu2), 0},
|
| 211 |
|
|
{TK_CONFIG_STRING, "-menu3", (char *) NULL, (char *) NULL,
|
| 212 |
|
|
"", Tk_Offset(EdgeItem, menu3), 0},
|
| 213 |
|
|
{TK_CONFIG_STRING, "-name", (char *) NULL, (char *) NULL,
|
| 214 |
|
|
"", Tk_Offset(EdgeItem, name), 0},
|
| 215 |
|
|
{TK_CONFIG_BOOLEAN, "-smooth", (char *) NULL, (char *) NULL,
|
| 216 |
|
|
"0", Tk_Offset(EdgeItem, smooth), TK_CONFIG_DONT_SET_DEFAULT},
|
| 217 |
|
|
{TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL,
|
| 218 |
|
|
"12", Tk_Offset(EdgeItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT},
|
| 219 |
|
|
{TK_CONFIG_STRING, "-state", (char *) NULL, (char *) NULL,
|
| 220 |
|
|
"", Tk_Offset(EdgeItem, state), 0},
|
| 221 |
|
|
{TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL,
|
| 222 |
|
|
(char *) NULL, Tk_Offset(EdgeItem, fillStipple), TK_CONFIG_NULL_OK},
|
| 223 |
|
|
{TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL,
|
| 224 |
|
|
(char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
|
| 225 |
|
|
{TK_CONFIG_PIXELS, "-textheight", (char *) NULL, (char *) NULL,
|
| 226 |
|
|
"0", Tk_Offset(EdgeItem, textHeight), TK_CONFIG_DONT_SET_DEFAULT},
|
| 227 |
|
|
{TK_CONFIG_PIXELS, "-textwidth", (char *) NULL, (char *) NULL,
|
| 228 |
|
|
"0", Tk_Offset(EdgeItem, textWidth), TK_CONFIG_DONT_SET_DEFAULT},
|
| 229 |
|
|
{TK_CONFIG_STRING, "-to", (char *) NULL, (char *) NULL,
|
| 230 |
|
|
"", Tk_Offset(EdgeItem, to), 0},
|
| 231 |
|
|
{TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL,
|
| 232 |
|
|
"1", Tk_Offset(EdgeItem, width), TK_CONFIG_DONT_SET_DEFAULT},
|
| 233 |
|
|
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify",
|
| 234 |
|
|
"left", Tk_Offset(EdgeItem, justify), 0},
|
| 235 |
|
|
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
|
| 236 |
|
|
(char *) NULL, 0, 0}
|
| 237 |
|
|
};
|
| 238 |
|
|
|
| 239 |
|
|
/*
|
| 240 |
|
|
* The structures below defines the edge item type by means
|
| 241 |
|
|
* of procedures that can be invoked by generic item code.
|
| 242 |
|
|
*/
|
| 243 |
|
|
Tk_ItemType tkEdgeType = {
|
| 244 |
|
|
"edge", /* name */
|
| 245 |
|
|
sizeof(EdgeItem), /* itemSize */
|
| 246 |
|
|
CreateEdge, /* createProc */
|
| 247 |
|
|
configSpecs, /* configSpecs */
|
| 248 |
|
|
ConfigureEdge, /* configureProc */
|
| 249 |
|
|
EdgeCoords, /* coordProc */
|
| 250 |
|
|
DeleteEdge, /* deleteProc */
|
| 251 |
|
|
DisplayEdge, /* displayProc */
|
| 252 |
|
|
0, /* alwaysRedraw */
|
| 253 |
|
|
EdgeToPoint, /* pointProc */
|
| 254 |
|
|
EdgeToArea, /* areaProc */
|
| 255 |
|
|
EdgeToPostscript, /* postscriptProc */
|
| 256 |
|
|
ScaleEdge, /* scaleProc */
|
| 257 |
|
|
TranslateEdge, /* translateProc */
|
| 258 |
|
|
(Tk_ItemIndexProc *) NULL, /* indexProc */
|
| 259 |
|
|
(Tk_ItemCursorProc *) NULL, /* icursorProc */
|
| 260 |
|
|
(Tk_ItemSelectionProc *) NULL, /* selectionProc */
|
| 261 |
|
|
(Tk_ItemInsertProc *) NULL, /* insertProc */
|
| 262 |
|
|
(Tk_ItemDCharsProc *) NULL, /* dTextProc */
|
| 263 |
|
|
(Tk_ItemType *) NULL /* nextPtr */
|
| 264 |
|
|
};
|
| 265 |
|
|
|
| 266 |
|
|
/*
|
| 267 |
|
|
* The Tk_Uid's below refer to uids for the various arrow types:
|
| 268 |
|
|
*/
|
| 269 |
|
|
static Tk_Uid noneUid = NULL;
|
| 270 |
|
|
static Tk_Uid firstUid = NULL;
|
| 271 |
|
|
static Tk_Uid lastUid = NULL;
|
| 272 |
|
|
static Tk_Uid bothUid = NULL;
|
| 273 |
|
|
|
| 274 |
|
|
/*
|
| 275 |
|
|
* The definition below determines how large are static arrays
|
| 276 |
|
|
* used to hold spline points (splines larger than this have to
|
| 277 |
|
|
* have their arrays malloc-ed).
|
| 278 |
|
|
*/
|
| 279 |
|
|
#define MAX_STATIC_POINTS 200
|
| 280 |
|
|
|
| 281 |
|
|
/*
|
| 282 |
|
|
*--------------------------------------------------------------
|
| 283 |
|
|
*
|
| 284 |
|
|
* CreateEdge --
|
| 285 |
|
|
*
|
| 286 |
|
|
* This procedure is invoked to create a new edge item in
|
| 287 |
|
|
* a canvas.
|
| 288 |
|
|
*
|
| 289 |
|
|
* Results:
|
| 290 |
|
|
* A standard Tcl return value. If an error occurred in
|
| 291 |
|
|
* creating the item, then an error message is left in
|
| 292 |
|
|
* interp->result; in this case itemPtr is
|
| 293 |
|
|
* left uninitialized, so it can be safely freed by the
|
| 294 |
|
|
* caller.
|
| 295 |
|
|
*
|
| 296 |
|
|
* Side effects:
|
| 297 |
|
|
* A new edge item is created.
|
| 298 |
|
|
*
|
| 299 |
|
|
*--------------------------------------------------------------
|
| 300 |
|
|
*/
|
| 301 |
|
|
|
| 302 |
|
|
static int
|
| 303 |
|
|
CreateEdge(interp, canvas, itemPtr, argc, argv)
|
| 304 |
|
|
Tcl_Interp *interp; /* Interpreter for error reporting. */
|
| 305 |
|
|
Tk_Canvas canvas; /* Canvas to hold new item. */
|
| 306 |
|
|
Tk_Item *itemPtr; /* Record to hold new item; header
|
| 307 |
|
|
* has been initialized by caller. */
|
| 308 |
|
|
int argc; /* Number of arguments in argv. */
|
| 309 |
|
|
char **argv; /* Arguments describing edge. */
|
| 310 |
|
|
{
|
| 311 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 312 |
|
|
int i;
|
| 313 |
|
|
|
| 314 |
|
|
if (argc < 4) {
|
| 315 |
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
| 316 |
|
|
Tk_PathName(Tk_CanvasTkwin(canvas)), "\" create ",
|
| 317 |
|
|
itemPtr->typePtr->name,
|
| 318 |
|
|
" x1 y1 x2 y2 ?x3 y3 ...? ?options?",
|
| 319 |
|
|
(char *) NULL);
|
| 320 |
|
|
return TCL_ERROR;
|
| 321 |
|
|
}
|
| 322 |
|
|
|
| 323 |
|
|
/*
|
| 324 |
|
|
* Carry out initialization that is needed to set defaults and to
|
| 325 |
|
|
* allow proper cleanup after errors during the the remainder of
|
| 326 |
|
|
* this procedure.
|
| 327 |
|
|
*/
|
| 328 |
|
|
edgePtr->bgColor = None;
|
| 329 |
|
|
edgePtr->canvas = canvas;
|
| 330 |
|
|
edgePtr->capStyle = CapButt;
|
| 331 |
|
|
edgePtr->coordPtr = NULL;
|
| 332 |
|
|
edgePtr->fgColor = None;
|
| 333 |
|
|
edgePtr->fillStipple = None;
|
| 334 |
|
|
edgePtr->tkfont = NULL;
|
| 335 |
|
|
edgePtr->from = NULL;
|
| 336 |
|
|
edgePtr->graphName = NULL;
|
| 337 |
|
|
edgePtr->joinStyle = JoinRound;
|
| 338 |
|
|
edgePtr->label = NULL;
|
| 339 |
|
|
edgePtr->menu1 = NULL;
|
| 340 |
|
|
edgePtr->menu2 = NULL;
|
| 341 |
|
|
edgePtr->menu3 = NULL;
|
| 342 |
|
|
edgePtr->name = NULL;
|
| 343 |
|
|
edgePtr->numPoints = 0;
|
| 344 |
|
|
edgePtr->smooth = 0;
|
| 345 |
|
|
edgePtr->splineSteps = 12;
|
| 346 |
|
|
edgePtr->state = NULL;
|
| 347 |
|
|
edgePtr->textWidth = 0;
|
| 348 |
|
|
edgePtr->to = NULL;
|
| 349 |
|
|
edgePtr->width = 1;
|
| 350 |
|
|
edgePtr->textLayout = NULL;
|
| 351 |
|
|
edgePtr->justify = TK_JUSTIFY_LEFT;
|
| 352 |
|
|
|
| 353 |
|
|
edgePtr->invertedGc = None;
|
| 354 |
|
|
edgePtr->gc = None;
|
| 355 |
|
|
if (noneUid == NULL) {
|
| 356 |
|
|
noneUid = Tk_GetUid("none");
|
| 357 |
|
|
firstUid = Tk_GetUid("first");
|
| 358 |
|
|
lastUid = Tk_GetUid("last");
|
| 359 |
|
|
bothUid = Tk_GetUid("both");
|
| 360 |
|
|
}
|
| 361 |
|
|
edgePtr->arrow = noneUid;
|
| 362 |
|
|
edgePtr->arrowShapeA = 8.0;
|
| 363 |
|
|
edgePtr->arrowShapeB = 10.0;
|
| 364 |
|
|
edgePtr->arrowShapeC = 3.0;
|
| 365 |
|
|
edgePtr->firstArrowPtr = NULL;
|
| 366 |
|
|
edgePtr->lastArrowPtr = NULL;
|
| 367 |
|
|
|
| 368 |
|
|
/*
|
| 369 |
|
|
* Count the number of points and then parse them into a point
|
| 370 |
|
|
* array. Leading arguments are assumed to be points if they
|
| 371 |
|
|
* start with a digit or a minus sign followed by a digit.
|
| 372 |
|
|
*/
|
| 373 |
|
|
|
| 374 |
|
|
for (i = 4; i < (argc-1); i+=2) {
|
| 375 |
|
|
if ((!isdigit(UCHAR(argv[i][0]))) &&
|
| 376 |
|
|
((argv[i][0] != '-') || (!isdigit(UCHAR(argv[i][1]))))) {
|
| 377 |
|
|
break;
|
| 378 |
|
|
}
|
| 379 |
|
|
}
|
| 380 |
|
|
if (EdgeCoords(interp, canvas, itemPtr, i, argv) != TCL_OK) {
|
| 381 |
|
|
goto error;
|
| 382 |
|
|
}
|
| 383 |
|
|
if (ConfigureEdge(interp, canvas, itemPtr, argc-i, argv+i, 0) == TCL_OK) {
|
| 384 |
|
|
return TCL_OK;
|
| 385 |
|
|
}
|
| 386 |
|
|
|
| 387 |
|
|
error:
|
| 388 |
|
|
DeleteEdge(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas)));
|
| 389 |
|
|
return TCL_ERROR;
|
| 390 |
|
|
}
|
| 391 |
|
|
|
| 392 |
|
|
/*
|
| 393 |
|
|
*--------------------------------------------------------------
|
| 394 |
|
|
*
|
| 395 |
|
|
* EdgeCoords --
|
| 396 |
|
|
*
|
| 397 |
|
|
* This procedure is invoked to process the "coords" widget
|
| 398 |
|
|
* command on edges. See the user documentation for details
|
| 399 |
|
|
* on what it does.
|
| 400 |
|
|
*
|
| 401 |
|
|
* Results:
|
| 402 |
|
|
* Returns TCL_OK or TCL_ERROR, and sets interp->result.
|
| 403 |
|
|
*
|
| 404 |
|
|
* Side effects:
|
| 405 |
|
|
* The coordinates for the given item may be changed.
|
| 406 |
|
|
*
|
| 407 |
|
|
*--------------------------------------------------------------
|
| 408 |
|
|
*/
|
| 409 |
|
|
|
| 410 |
|
|
static int
|
| 411 |
|
|
EdgeCoords(interp, canvas, itemPtr, argc, argv)
|
| 412 |
|
|
Tcl_Interp *interp; /* Used for error reporting. */
|
| 413 |
|
|
Tk_Canvas canvas; /* Canvas containing item. */
|
| 414 |
|
|
Tk_Item *itemPtr; /* Item whose coordinates are to be
|
| 415 |
|
|
* read or modified. */
|
| 416 |
|
|
int argc; /* Number of coordinates supplied in
|
| 417 |
|
|
* argv. */
|
| 418 |
|
|
char **argv; /* Array of coordinates: x1, y1,
|
| 419 |
|
|
* x2, y2, ... */
|
| 420 |
|
|
{
|
| 421 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 422 |
|
|
char buffer[TCL_DOUBLE_SPACE];
|
| 423 |
|
|
int i, numPoints;
|
| 424 |
|
|
|
| 425 |
|
|
if (argc == 0) {
|
| 426 |
|
|
double *coordPtr;
|
| 427 |
|
|
int numCoords;
|
| 428 |
|
|
|
| 429 |
|
|
numCoords = 2*edgePtr->numPoints;
|
| 430 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 431 |
|
|
coordPtr = edgePtr->firstArrowPtr;
|
| 432 |
|
|
} else {
|
| 433 |
|
|
coordPtr = edgePtr->coordPtr;
|
| 434 |
|
|
}
|
| 435 |
|
|
for (i = 0; i < numCoords; i++, coordPtr++) {
|
| 436 |
|
|
if (i == 2) {
|
| 437 |
|
|
coordPtr = edgePtr->coordPtr+2;
|
| 438 |
|
|
}
|
| 439 |
|
|
if ((edgePtr->lastArrowPtr != NULL) && (i == (numCoords-2))) {
|
| 440 |
|
|
coordPtr = edgePtr->lastArrowPtr;
|
| 441 |
|
|
}
|
| 442 |
|
|
Tcl_PrintDouble(interp, *coordPtr, buffer);
|
| 443 |
|
|
Tcl_AppendElement(interp, buffer);
|
| 444 |
|
|
}
|
| 445 |
|
|
} else if (argc < 4) {
|
| 446 |
|
|
Tcl_AppendResult(interp,
|
| 447 |
|
|
"too few coordinates for edge: must have at least 4",
|
| 448 |
|
|
(char *) NULL);
|
| 449 |
|
|
return TCL_ERROR;
|
| 450 |
|
|
} else if (argc & 1) {
|
| 451 |
|
|
Tcl_AppendResult(interp,
|
| 452 |
|
|
"odd number of coordinates specified for edge",
|
| 453 |
|
|
(char *) NULL);
|
| 454 |
|
|
return TCL_ERROR;
|
| 455 |
|
|
} else {
|
| 456 |
|
|
numPoints = argc/2;
|
| 457 |
|
|
if (edgePtr->numPoints != numPoints) {
|
| 458 |
|
|
if (edgePtr->coordPtr != NULL) {
|
| 459 |
|
|
ckfree((char *) edgePtr->coordPtr);
|
| 460 |
|
|
}
|
| 461 |
|
|
edgePtr->coordPtr = (double *) ckalloc((unsigned)
|
| 462 |
|
|
(sizeof(double) * argc));
|
| 463 |
|
|
edgePtr->numPoints = numPoints;
|
| 464 |
|
|
}
|
| 465 |
|
|
for (i = argc-1; i >= 0; i--) {
|
| 466 |
|
|
if (Tk_CanvasGetCoord(interp, canvas, argv[i], &edgePtr->coordPtr[i])
|
| 467 |
|
|
!= TCL_OK) {
|
| 468 |
|
|
return TCL_ERROR;
|
| 469 |
|
|
}
|
| 470 |
|
|
}
|
| 471 |
|
|
|
| 472 |
|
|
/*
|
| 473 |
|
|
* Update arrowheads by throwing away any existing arrow-head
|
| 474 |
|
|
* information and calling ConfigureArrows to recompute it.
|
| 475 |
|
|
*/
|
| 476 |
|
|
|
| 477 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 478 |
|
|
ckfree((char *) edgePtr->firstArrowPtr);
|
| 479 |
|
|
edgePtr->firstArrowPtr = NULL;
|
| 480 |
|
|
}
|
| 481 |
|
|
if (edgePtr->lastArrowPtr != NULL) {
|
| 482 |
|
|
ckfree((char *) edgePtr->lastArrowPtr);
|
| 483 |
|
|
edgePtr->lastArrowPtr = NULL;
|
| 484 |
|
|
}
|
| 485 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 486 |
|
|
ConfigureArrows(canvas, edgePtr);
|
| 487 |
|
|
}
|
| 488 |
|
|
ComputeEdgeBbox(canvas, edgePtr);
|
| 489 |
|
|
}
|
| 490 |
|
|
return TCL_OK;
|
| 491 |
|
|
}
|
| 492 |
|
|
|
| 493 |
|
|
/*
|
| 494 |
|
|
*--------------------------------------------------------------
|
| 495 |
|
|
*
|
| 496 |
|
|
* ConfigureEdge --
|
| 497 |
|
|
*
|
| 498 |
|
|
* This procedure is invoked to configure various aspects
|
| 499 |
|
|
* of a edge item such as its background color.
|
| 500 |
|
|
*
|
| 501 |
|
|
* Results:
|
| 502 |
|
|
* A standard Tcl result code. If an error occurs, then
|
| 503 |
|
|
* an error message is left in interp->result.
|
| 504 |
|
|
*
|
| 505 |
|
|
* Side effects:
|
| 506 |
|
|
* Configuration information, such as colors and stipple
|
| 507 |
|
|
* patterns, may be set for itemPtr.
|
| 508 |
|
|
*
|
| 509 |
|
|
*--------------------------------------------------------------
|
| 510 |
|
|
*/
|
| 511 |
|
|
|
| 512 |
|
|
static int
|
| 513 |
|
|
ConfigureEdge(interp, canvas, itemPtr, argc, argv, flags)
|
| 514 |
|
|
Tcl_Interp *interp; /* Used for error reporting. */
|
| 515 |
|
|
Tk_Canvas canvas; /* Canvas containing itemPtr. */
|
| 516 |
|
|
Tk_Item *itemPtr; /* Edge item to reconfigure. */
|
| 517 |
|
|
int argc; /* Number of elements in argv. */
|
| 518 |
|
|
char **argv; /* Arguments describing things to configure. */
|
| 519 |
|
|
int flags; /* Flags to pass to Tk_ConfigureWidget. */
|
| 520 |
|
|
{
|
| 521 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 522 |
|
|
XGCValues gcValues;
|
| 523 |
|
|
GC newGC;
|
| 524 |
|
|
unsigned long mask;
|
| 525 |
|
|
char *value, *fullName, **list;
|
| 526 |
|
|
int counter, listCounter = 0;
|
| 527 |
|
|
Tcl_DString varName, fileName, buffer;
|
| 528 |
|
|
Tk_Window tkwin;
|
| 529 |
|
|
Tk_3DBorder bgBorder;
|
| 530 |
|
|
|
| 531 |
|
|
tkwin = Tk_CanvasTkwin(canvas);
|
| 532 |
|
|
bgBorder = ((TkCanvas *) canvas)->bgBorder;
|
| 533 |
|
|
|
| 534 |
|
|
if (Tk_ConfigureWidget(interp, tkwin,
|
| 535 |
|
|
configSpecs, argc, argv,
|
| 536 |
|
|
(char *) edgePtr, flags) != TCL_OK) {
|
| 537 |
|
|
return TCL_ERROR;
|
| 538 |
|
|
}
|
| 539 |
|
|
|
| 540 |
|
|
/*
|
| 541 |
|
|
* A few of the options require additional processing, such as
|
| 542 |
|
|
* graphics contexts.
|
| 543 |
|
|
*/
|
| 544 |
|
|
|
| 545 |
|
|
/* the normal gc */
|
| 546 |
|
|
if (edgePtr->fgColor == NULL) {
|
| 547 |
|
|
newGC = None;
|
| 548 |
|
|
} else {
|
| 549 |
|
|
mask = GCBackground|GCForeground|GCJoinStyle|GCLineWidth;
|
| 550 |
|
|
if (edgePtr->bgColor != NULL) {
|
| 551 |
|
|
gcValues.background = edgePtr->bgColor->pixel;
|
| 552 |
|
|
} else {
|
| 553 |
|
|
gcValues.background = Tk_3DBorderColor(bgBorder)->pixel;
|
| 554 |
|
|
}
|
| 555 |
|
|
gcValues.foreground = edgePtr->fgColor->pixel;
|
| 556 |
|
|
gcValues.join_style = edgePtr->joinStyle;
|
| 557 |
|
|
if (edgePtr->width < 0) {
|
| 558 |
|
|
edgePtr->width = 1;
|
| 559 |
|
|
}
|
| 560 |
|
|
gcValues.line_width = edgePtr->width;
|
| 561 |
|
|
if (edgePtr->fillStipple != None) {
|
| 562 |
|
|
gcValues.stipple = edgePtr->fillStipple;
|
| 563 |
|
|
gcValues.fill_style = FillStippled;
|
| 564 |
|
|
mask |= GCStipple|GCFillStyle;
|
| 565 |
|
|
}
|
| 566 |
|
|
if (edgePtr->arrow == noneUid) {
|
| 567 |
|
|
gcValues.cap_style = edgePtr->capStyle;
|
| 568 |
|
|
mask |= GCCapStyle;
|
| 569 |
|
|
}
|
| 570 |
|
|
if (edgePtr->tkfont != NULL) {
|
| 571 |
|
|
gcValues.font = Tk_FontId(edgePtr->tkfont);
|
| 572 |
|
|
mask |= GCFont;
|
| 573 |
|
|
}
|
| 574 |
|
|
newGC = Tk_GetGC(tkwin, mask, &gcValues);
|
| 575 |
|
|
}
|
| 576 |
|
|
if (edgePtr->gc != None) {
|
| 577 |
|
|
Tk_FreeGC(((TkCanvas *) canvas)->display, edgePtr->gc);
|
| 578 |
|
|
}
|
| 579 |
|
|
edgePtr->gc = newGC;
|
| 580 |
|
|
|
| 581 |
|
|
/* the inverted gc */
|
| 582 |
|
|
if (edgePtr->fgColor == NULL) {
|
| 583 |
|
|
newGC = None;
|
| 584 |
|
|
} else {
|
| 585 |
|
|
mask = GCForeground | GCBackground;
|
| 586 |
|
|
gcValues.background = edgePtr->fgColor->pixel;
|
| 587 |
|
|
if (edgePtr->bgColor != NULL) {
|
| 588 |
|
|
gcValues.foreground = edgePtr->bgColor->pixel;
|
| 589 |
|
|
} else {
|
| 590 |
|
|
gcValues.foreground = Tk_3DBorderColor(bgBorder)->pixel;
|
| 591 |
|
|
}
|
| 592 |
|
|
if (edgePtr->tkfont != NULL) {
|
| 593 |
|
|
gcValues.font = Tk_FontId(edgePtr->tkfont);
|
| 594 |
|
|
mask |= GCFont;
|
| 595 |
|
|
}
|
| 596 |
|
|
newGC = Tk_GetGC(tkwin, mask, &gcValues);
|
| 597 |
|
|
}
|
| 598 |
|
|
if (edgePtr->invertedGc != None) {
|
| 599 |
|
|
Tk_FreeGC(((TkCanvas *) canvas)->display, edgePtr->invertedGc);
|
| 600 |
|
|
}
|
| 601 |
|
|
edgePtr->invertedGc = newGC;
|
| 602 |
|
|
|
| 603 |
|
|
/*
|
| 604 |
|
|
* Keep spline parameters within reasonable limits.
|
| 605 |
|
|
*/
|
| 606 |
|
|
if (edgePtr->splineSteps < 1) {
|
| 607 |
|
|
edgePtr->splineSteps = 1;
|
| 608 |
|
|
} else if (edgePtr->splineSteps > 100) {
|
| 609 |
|
|
edgePtr->splineSteps = 100;
|
| 610 |
|
|
}
|
| 611 |
|
|
|
| 612 |
|
|
/*
|
| 613 |
|
|
* Setup arrowheads, if needed. If arrowheads are turned off,
|
| 614 |
|
|
* restore the edge's endpoints (they were shortened when the
|
| 615 |
|
|
* arrowheads were added).
|
| 616 |
|
|
*/
|
| 617 |
|
|
if ((edgePtr->firstArrowPtr != NULL) && (edgePtr->arrow != firstUid)
|
| 618 |
|
|
&& (edgePtr->arrow != bothUid)) {
|
| 619 |
|
|
edgePtr->coordPtr[0] = edgePtr->firstArrowPtr[0];
|
| 620 |
|
|
edgePtr->coordPtr[1] = edgePtr->firstArrowPtr[1];
|
| 621 |
|
|
ckfree((char *) edgePtr->firstArrowPtr);
|
| 622 |
|
|
edgePtr->firstArrowPtr = NULL;
|
| 623 |
|
|
}
|
| 624 |
|
|
if ((edgePtr->lastArrowPtr != NULL) && (edgePtr->arrow != lastUid)
|
| 625 |
|
|
&& (edgePtr->arrow != bothUid)) {
|
| 626 |
|
|
int index;
|
| 627 |
|
|
|
| 628 |
|
|
index = 2*(edgePtr->numPoints-1);
|
| 629 |
|
|
edgePtr->coordPtr[index] = edgePtr->lastArrowPtr[0];
|
| 630 |
|
|
edgePtr->coordPtr[index+1] = edgePtr->lastArrowPtr[1];
|
| 631 |
|
|
ckfree((char *) edgePtr->lastArrowPtr);
|
| 632 |
|
|
edgePtr->lastArrowPtr = NULL;
|
| 633 |
|
|
}
|
| 634 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 635 |
|
|
if ((edgePtr->arrow != firstUid) && (edgePtr->arrow != lastUid)
|
| 636 |
|
|
&& (edgePtr->arrow != bothUid)) {
|
| 637 |
|
|
Tcl_AppendResult(interp, "bad arrow spec \"",
|
| 638 |
|
|
edgePtr->arrow,
|
| 639 |
|
|
"\": must be none, first, last, or both",
|
| 640 |
|
|
(char *) NULL);
|
| 641 |
|
|
edgePtr->arrow = noneUid;
|
| 642 |
|
|
return TCL_ERROR;
|
| 643 |
|
|
}
|
| 644 |
|
|
ConfigureArrows(canvas, edgePtr);
|
| 645 |
|
|
}
|
| 646 |
|
|
|
| 647 |
|
|
/* Calculate the text width & height in points. */
|
| 648 |
|
|
Tk_FreeTextLayout(edgePtr->textLayout);
|
| 649 |
|
|
edgePtr->textLayout = Tk_ComputeTextLayout(edgePtr->tkfont,
|
| 650 |
|
|
edgePtr->label,
|
| 651 |
|
|
strlen (edgePtr->label),
|
| 652 |
|
|
edgePtr->width,
|
| 653 |
|
|
edgePtr->justify,
|
| 654 |
|
|
0, &edgePtr->textWidth, &edgePtr->textHeight);
|
| 655 |
|
|
|
| 656 |
|
|
/* do we have a menu ? */
|
| 657 |
|
|
if (edgePtr->menu1 != NULL && strlen(edgePtr->menu1) > (size_t) 0 &&
|
| 658 |
|
|
edgePtr->menu1[0] != '.') {
|
| 659 |
|
|
/* do we have to load the new menu definition ? */
|
| 660 |
|
|
(void) Tcl_VarEval(interp, "info commands .emenu-",
|
| 661 |
|
|
edgePtr->menu1, (char *) NULL);
|
| 662 |
|
|
if (strlen(interp->result) == 0) {
|
| 663 |
|
|
/* the following code retrieves the path list for the menus. This */
|
| 664 |
|
|
/* is done because I don't want to attatch the pathname list to */
|
| 665 |
|
|
/* each icon. */
|
| 666 |
|
|
Tcl_DStringInit(&varName);
|
| 667 |
|
|
Tcl_DStringAppend(&varName, "ip_priv(", -1);
|
| 668 |
|
|
Tcl_DStringAppend(&varName, Tk_PathName(tkwin), -1);
|
| 669 |
|
|
Tcl_DStringAppend(&varName, ",edgemenupath)", -1);
|
| 670 |
|
|
if ((value = Tcl_GetVar(interp, varName.string,
|
| 671 |
|
|
TCL_GLOBAL_ONLY)) != NULL) {
|
| 672 |
|
|
if (Tcl_SplitList(interp, value, &listCounter,
|
| 673 |
|
|
&list) == TCL_OK) {
|
| 674 |
|
|
/* walk through list of pathnames. */
|
| 675 |
|
|
for (counter = 0; counter < listCounter; counter++) {
|
| 676 |
|
|
/* create the filename to load. */
|
| 677 |
|
|
Tcl_DStringInit(&fileName);
|
| 678 |
|
|
Tcl_DStringAppend(&fileName, list[counter], -1);
|
| 679 |
|
|
Tcl_DStringAppend(&fileName, "/", -1);
|
| 680 |
|
|
Tcl_DStringAppend(&fileName, edgePtr->menu1, -1);
|
| 681 |
|
|
Tcl_DStringAppend(&fileName, ".emenu", -1);
|
| 682 |
|
|
Tcl_DStringInit(&buffer);
|
| 683 |
|
|
fullName = Tcl_TildeSubst(interp,
|
| 684 |
|
|
fileName.string, &buffer);
|
| 685 |
|
|
if (access(fullName, F_OK) != -1) {
|
| 686 |
|
|
/* load new menu. */
|
| 687 |
|
|
Tcl_VarEval(interp, "source ", fullName,
|
| 688 |
|
|
(char *) NULL);
|
| 689 |
|
|
}
|
| 690 |
|
|
Tcl_DStringFree(&fileName);
|
| 691 |
|
|
Tcl_DStringFree(&buffer);
|
| 692 |
|
|
}
|
| 693 |
|
|
ckfree((char *) list);
|
| 694 |
|
|
}
|
| 695 |
|
|
}
|
| 696 |
|
|
Tcl_DStringFree(&varName);
|
| 697 |
|
|
}
|
| 698 |
|
|
}
|
| 699 |
|
|
|
| 700 |
|
|
/* do we have a menu ? */
|
| 701 |
|
|
if (edgePtr->menu2 != NULL && strlen(edgePtr->menu2) > (size_t) 0 &&
|
| 702 |
|
|
edgePtr->menu2[0] != '.') {
|
| 703 |
|
|
/* do we have to load the new menu definition ? */
|
| 704 |
|
|
(void) Tcl_VarEval(interp, "info commands .emenu-",
|
| 705 |
|
|
edgePtr->menu2, (char *) NULL);
|
| 706 |
|
|
if (strlen(interp->result) == 0) {
|
| 707 |
|
|
/* the following code retrieves the path list for the menus. This */
|
| 708 |
|
|
/* is done because I don't want to attatch the pathname list to */
|
| 709 |
|
|
/* each icon. */
|
| 710 |
|
|
Tcl_DStringInit(&varName);
|
| 711 |
|
|
Tcl_DStringAppend(&varName, "ip_priv(", -1);
|
| 712 |
|
|
Tcl_DStringAppend(&varName, Tk_PathName(tkwin), -1);
|
| 713 |
|
|
Tcl_DStringAppend(&varName, ",edgemenupath)", -1);
|
| 714 |
|
|
if ((value = Tcl_GetVar(interp, varName.string,
|
| 715 |
|
|
TCL_GLOBAL_ONLY)) != NULL) {
|
| 716 |
|
|
if (Tcl_SplitList(interp, value, &listCounter,
|
| 717 |
|
|
&list) == TCL_OK) {
|
| 718 |
|
|
/* walk through list of pathnames. */
|
| 719 |
|
|
for (counter = 0; counter < listCounter; counter++) {
|
| 720 |
|
|
/* create the filename to load. */
|
| 721 |
|
|
Tcl_DStringInit(&fileName);
|
| 722 |
|
|
Tcl_DStringAppend(&fileName, list[counter], -1);
|
| 723 |
|
|
Tcl_DStringAppend(&fileName, "/", -1);
|
| 724 |
|
|
Tcl_DStringAppend(&fileName, edgePtr->menu2, -1);
|
| 725 |
|
|
Tcl_DStringAppend(&fileName, ".emenu", -1);
|
| 726 |
|
|
Tcl_DStringInit(&buffer);
|
| 727 |
|
|
fullName = Tcl_TildeSubst(interp,
|
| 728 |
|
|
fileName.string, &buffer);
|
| 729 |
|
|
if (access(fullName, F_OK) != -1) {
|
| 730 |
|
|
/* load new menu. */
|
| 731 |
|
|
Tcl_VarEval(interp, "source ", fullName,
|
| 732 |
|
|
(char *) NULL);
|
| 733 |
|
|
}
|
| 734 |
|
|
Tcl_DStringFree(&fileName);
|
| 735 |
|
|
Tcl_DStringFree(&buffer);
|
| 736 |
|
|
}
|
| 737 |
|
|
ckfree((char *) list);
|
| 738 |
|
|
}
|
| 739 |
|
|
}
|
| 740 |
|
|
Tcl_DStringFree(&varName);
|
| 741 |
|
|
}
|
| 742 |
|
|
}
|
| 743 |
|
|
|
| 744 |
|
|
/* do we have a menu ? */
|
| 745 |
|
|
if (edgePtr->menu3 != NULL && strlen(edgePtr->menu3) > (size_t) 0 &&
|
| 746 |
|
|
edgePtr->menu3[0] != '.') {
|
| 747 |
|
|
/* do we have to load the new menu definition ? */
|
| 748 |
|
|
(void) Tcl_VarEval(interp, "info commands .emenu-",
|
| 749 |
|
|
edgePtr->menu3, (char *) NULL);
|
| 750 |
|
|
if (strlen(interp->result) == 0) {
|
| 751 |
|
|
/* the following code retrieves the path list for the menus. This */
|
| 752 |
|
|
/* is done because I don't want to attatch the pathname list to */
|
| 753 |
|
|
/* each icon. */
|
| 754 |
|
|
Tcl_DStringInit(&varName);
|
| 755 |
|
|
Tcl_DStringAppend(&varName, "ip_priv(", -1);
|
| 756 |
|
|
Tcl_DStringAppend(&varName, Tk_PathName(tkwin), -1);
|
| 757 |
|
|
Tcl_DStringAppend(&varName, ",edgemenupath)", -1);
|
| 758 |
|
|
if ((value = Tcl_GetVar(interp, varName.string,
|
| 759 |
|
|
TCL_GLOBAL_ONLY)) != NULL) {
|
| 760 |
|
|
if (Tcl_SplitList(interp, value, &listCounter,
|
| 761 |
|
|
&list) == TCL_OK) {
|
| 762 |
|
|
/* walk through list of pathnames. */
|
| 763 |
|
|
for (counter = 0; counter < listCounter; counter++) {
|
| 764 |
|
|
/* create the filename to load. */
|
| 765 |
|
|
Tcl_DStringInit(&fileName);
|
| 766 |
|
|
Tcl_DStringAppend(&fileName, list[counter], -1);
|
| 767 |
|
|
Tcl_DStringAppend(&fileName, "/", -1);
|
| 768 |
|
|
Tcl_DStringAppend(&fileName, edgePtr->menu3, -1);
|
| 769 |
|
|
Tcl_DStringAppend(&fileName, ".emenu", -1);
|
| 770 |
|
|
Tcl_DStringInit(&buffer);
|
| 771 |
|
|
fullName = Tcl_TildeSubst(interp,
|
| 772 |
|
|
fileName.string, &buffer);
|
| 773 |
|
|
if (access(fullName, F_OK) != -1) {
|
| 774 |
|
|
/* load new menu. */
|
| 775 |
|
|
Tcl_VarEval(interp, "source ", fullName,
|
| 776 |
|
|
(char *) NULL);
|
| 777 |
|
|
}
|
| 778 |
|
|
Tcl_DStringFree(&fileName);
|
| 779 |
|
|
Tcl_DStringFree(&buffer);
|
| 780 |
|
|
}
|
| 781 |
|
|
ckfree((char *) list);
|
| 782 |
|
|
}
|
| 783 |
|
|
}
|
| 784 |
|
|
Tcl_DStringFree(&varName);
|
| 785 |
|
|
}
|
| 786 |
|
|
}
|
| 787 |
|
|
|
| 788 |
|
|
/*
|
| 789 |
|
|
* Recompute bounding box for edge.
|
| 790 |
|
|
*/
|
| 791 |
|
|
|
| 792 |
|
|
ComputeEdgeBbox(canvas, edgePtr);
|
| 793 |
|
|
|
| 794 |
|
|
return TCL_OK;
|
| 795 |
|
|
}
|
| 796 |
|
|
|
| 797 |
|
|
/*
|
| 798 |
|
|
*--------------------------------------------------------------
|
| 799 |
|
|
*
|
| 800 |
|
|
* DeleteEdge --
|
| 801 |
|
|
*
|
| 802 |
|
|
* This procedure is called to clean up the data structure
|
| 803 |
|
|
* associated with a edge item.
|
| 804 |
|
|
*
|
| 805 |
|
|
* Results:
|
| 806 |
|
|
* None.
|
| 807 |
|
|
*
|
| 808 |
|
|
* Side effects:
|
| 809 |
|
|
* Resources associated with itemPtr are released.
|
| 810 |
|
|
*
|
| 811 |
|
|
*--------------------------------------------------------------
|
| 812 |
|
|
*/
|
| 813 |
|
|
|
| 814 |
|
|
static void
|
| 815 |
|
|
DeleteEdge(canvas, itemPtr, display)
|
| 816 |
|
|
Tk_Canvas canvas; /* Info about overall canvas widget. */
|
| 817 |
|
|
Tk_Item *itemPtr; /* Item that is being deleted. */
|
| 818 |
|
|
Display *display; /* Display containing window for
|
| 819 |
|
|
* canvas. */
|
| 820 |
|
|
{
|
| 821 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 822 |
|
|
|
| 823 |
|
|
if (edgePtr->bgColor != NULL) {
|
| 824 |
|
|
Tk_FreeColor(edgePtr->bgColor);
|
| 825 |
|
|
}
|
| 826 |
|
|
if (edgePtr->coordPtr != NULL) {
|
| 827 |
|
|
ckfree((char *) edgePtr->coordPtr);
|
| 828 |
|
|
}
|
| 829 |
|
|
if (edgePtr->fgColor != NULL) {
|
| 830 |
|
|
Tk_FreeColor(edgePtr->fgColor);
|
| 831 |
|
|
}
|
| 832 |
|
|
if (edgePtr->fillStipple != None) {
|
| 833 |
|
|
Tk_FreeBitmap(display, edgePtr->fillStipple);
|
| 834 |
|
|
}
|
| 835 |
|
|
if (edgePtr->tkfont != NULL) {
|
| 836 |
|
|
Tk_FreeFont(edgePtr->tkfont);
|
| 837 |
|
|
}
|
| 838 |
|
|
if (edgePtr->from != NULL) {
|
| 839 |
|
|
ckfree(edgePtr->from);
|
| 840 |
|
|
}
|
| 841 |
|
|
if (edgePtr->graphName != NULL) {
|
| 842 |
|
|
ckfree(edgePtr->graphName);
|
| 843 |
|
|
}
|
| 844 |
|
|
if (edgePtr->label != NULL) {
|
| 845 |
|
|
ckfree(edgePtr->label);
|
| 846 |
|
|
}
|
| 847 |
|
|
if (edgePtr->menu1 != NULL) {
|
| 848 |
|
|
ckfree(edgePtr->menu1);
|
| 849 |
|
|
}
|
| 850 |
|
|
if (edgePtr->menu2 != NULL) {
|
| 851 |
|
|
ckfree(edgePtr->menu2);
|
| 852 |
|
|
}
|
| 853 |
|
|
if (edgePtr->menu3 != NULL) {
|
| 854 |
|
|
ckfree(edgePtr->menu3);
|
| 855 |
|
|
}
|
| 856 |
|
|
if (edgePtr->name != NULL) {
|
| 857 |
|
|
ckfree(edgePtr->name);
|
| 858 |
|
|
}
|
| 859 |
|
|
if (edgePtr->state != NULL) {
|
| 860 |
|
|
ckfree(edgePtr->state);
|
| 861 |
|
|
}
|
| 862 |
|
|
if (edgePtr->to != NULL) {
|
| 863 |
|
|
ckfree(edgePtr->to);
|
| 864 |
|
|
}
|
| 865 |
|
|
|
| 866 |
|
|
if (edgePtr->invertedGc != None) {
|
| 867 |
|
|
Tk_FreeGC(display, edgePtr->invertedGc);
|
| 868 |
|
|
}
|
| 869 |
|
|
if (edgePtr->gc != None) {
|
| 870 |
|
|
Tk_FreeGC(display, edgePtr->gc);
|
| 871 |
|
|
}
|
| 872 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 873 |
|
|
ckfree((char *) edgePtr->firstArrowPtr);
|
| 874 |
|
|
}
|
| 875 |
|
|
if (edgePtr->lastArrowPtr != NULL) {
|
| 876 |
|
|
ckfree((char *) edgePtr->lastArrowPtr);
|
| 877 |
|
|
}
|
| 878 |
|
|
if (edgePtr->textLayout != NULL) {
|
| 879 |
|
|
ckfree((char *) edgePtr->textLayout);
|
| 880 |
|
|
}
|
| 881 |
|
|
}
|
| 882 |
|
|
|
| 883 |
|
|
/*
|
| 884 |
|
|
*--------------------------------------------------------------
|
| 885 |
|
|
*
|
| 886 |
|
|
* ComputeEdgeBbox --
|
| 887 |
|
|
*
|
| 888 |
|
|
* This procedure is invoked to compute the bounding box of
|
| 889 |
|
|
* all the pixels that may be drawn as part of a edge.
|
| 890 |
|
|
*
|
| 891 |
|
|
* Results:
|
| 892 |
|
|
* None.
|
| 893 |
|
|
*
|
| 894 |
|
|
* Side effects:
|
| 895 |
|
|
* The fields x1, y1, x2, and y2 are updated in the header
|
| 896 |
|
|
* for itemPtr.
|
| 897 |
|
|
*
|
| 898 |
|
|
*--------------------------------------------------------------
|
| 899 |
|
|
*/
|
| 900 |
|
|
|
| 901 |
|
|
static void
|
| 902 |
|
|
ComputeEdgeBbox(canvas, edgePtr)
|
| 903 |
|
|
Tk_Canvas canvas; /* Canvas that contains item. */
|
| 904 |
|
|
EdgeItem *edgePtr; /* Item whose bbos is to be
|
| 905 |
|
|
* recomputed. */
|
| 906 |
|
|
{
|
| 907 |
|
|
double *coordPtr;
|
| 908 |
|
|
int i, lineWidth, lineHeight;
|
| 909 |
|
|
|
| 910 |
|
|
coordPtr = edgePtr->coordPtr;
|
| 911 |
|
|
edgePtr->header.x1 = edgePtr->header.x2 = *coordPtr;
|
| 912 |
|
|
edgePtr->header.y1 = edgePtr->header.y2 = coordPtr[1];
|
| 913 |
|
|
|
| 914 |
|
|
/*
|
| 915 |
|
|
* Compute the bounding box of all the points in the edge,
|
| 916 |
|
|
* then expand in all directions by the edge's width to take
|
| 917 |
|
|
* care of butting or rounded corners and projecting or
|
| 918 |
|
|
* rounded caps. This expansion is an overestimate (worst-case
|
| 919 |
|
|
* is square root of two over two) but it's simple. Don't do
|
| 920 |
|
|
* anything special for curves. This causes an additional
|
| 921 |
|
|
* overestimate in the bounding box, but is faster.
|
| 922 |
|
|
*/
|
| 923 |
|
|
|
| 924 |
|
|
for (i = 1, coordPtr = edgePtr->coordPtr+2; i < edgePtr->numPoints;
|
| 925 |
|
|
i++, coordPtr += 2) {
|
| 926 |
|
|
TkIncludePoint((Tk_Item *) edgePtr, coordPtr);
|
| 927 |
|
|
}
|
| 928 |
|
|
edgePtr->header.x1 -= edgePtr->width;
|
| 929 |
|
|
edgePtr->header.x2 += edgePtr->width;
|
| 930 |
|
|
edgePtr->header.y1 -= edgePtr->width;
|
| 931 |
|
|
edgePtr->header.y2 += edgePtr->width;
|
| 932 |
|
|
|
| 933 |
|
|
/*
|
| 934 |
|
|
* For mitered edges, make a second pass through all the points.
|
| 935 |
|
|
* Compute the locations of the two miter vertex points and add
|
| 936 |
|
|
* those into the bounding box.
|
| 937 |
|
|
*/
|
| 938 |
|
|
|
| 939 |
|
|
if (edgePtr->joinStyle == JoinMiter) {
|
| 940 |
|
|
for (i = edgePtr->numPoints, coordPtr = edgePtr->coordPtr; i >= 3;
|
| 941 |
|
|
i--, coordPtr += 2) {
|
| 942 |
|
|
double miter[4];
|
| 943 |
|
|
int j;
|
| 944 |
|
|
|
| 945 |
|
|
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
|
| 946 |
|
|
(double) edgePtr->width, miter, miter+2)) {
|
| 947 |
|
|
for (j = 0; j < 4; j += 2) {
|
| 948 |
|
|
TkIncludePoint((Tk_Item *) edgePtr, miter+j);
|
| 949 |
|
|
}
|
| 950 |
|
|
}
|
| 951 |
|
|
}
|
| 952 |
|
|
}
|
| 953 |
|
|
|
| 954 |
|
|
/*
|
| 955 |
|
|
* Add in the sizes of arrowheads, if any.
|
| 956 |
|
|
*/
|
| 957 |
|
|
|
| 958 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 959 |
|
|
if (edgePtr->arrow != lastUid) {
|
| 960 |
|
|
for (i = 0, coordPtr = edgePtr->firstArrowPtr; i < PTS_IN_ARROW;
|
| 961 |
|
|
i++, coordPtr += 2) {
|
| 962 |
|
|
TkIncludePoint((Tk_Item *) edgePtr, coordPtr);
|
| 963 |
|
|
}
|
| 964 |
|
|
}
|
| 965 |
|
|
if (edgePtr->arrow != firstUid) {
|
| 966 |
|
|
for (i = 0, coordPtr = edgePtr->lastArrowPtr; i < PTS_IN_ARROW;
|
| 967 |
|
|
i++, coordPtr += 2) {
|
| 968 |
|
|
TkIncludePoint((Tk_Item *) edgePtr, coordPtr);
|
| 969 |
|
|
}
|
| 970 |
|
|
}
|
| 971 |
|
|
}
|
| 972 |
|
|
|
| 973 |
|
|
/*
|
| 974 |
|
|
* Add one more pixel of fudge factor just to be safe (e.g.
|
| 975 |
|
|
* X may round differently than we do).
|
| 976 |
|
|
*/
|
| 977 |
|
|
|
| 978 |
|
|
edgePtr->header.x1 -= 1;
|
| 979 |
|
|
edgePtr->header.x2 += 1;
|
| 980 |
|
|
edgePtr->header.y1 -= 1;
|
| 981 |
|
|
edgePtr->header.y2 += 1;
|
| 982 |
|
|
|
| 983 |
|
|
/* maybe we have a label that is wider than the line */
|
| 984 |
|
|
if (edgePtr->tkfont != NULL && edgePtr->label != NULL) {
|
| 985 |
|
|
Tk_FreeTextLayout(edgePtr->textLayout);
|
| 986 |
|
|
edgePtr->textLayout = Tk_ComputeTextLayout(edgePtr->tkfont,
|
| 987 |
|
|
edgePtr->label,
|
| 988 |
|
|
strlen (edgePtr->label),
|
| 989 |
|
|
edgePtr->width,
|
| 990 |
|
|
edgePtr->justify,
|
| 991 |
|
|
0, &lineWidth, &lineHeight);
|
| 992 |
|
|
lineWidth = strlen(edgePtr->label);
|
| 993 |
|
|
if (lineWidth > (edgePtr->header.x2 - edgePtr->header.x2)) {
|
| 994 |
|
|
edgePtr->header.x1 -=
|
| 995 |
|
|
(lineWidth - (edgePtr->header.x2 - edgePtr->header.x2)) / 2;
|
| 996 |
|
|
edgePtr->header.x2 +=
|
| 997 |
|
|
(lineWidth - (edgePtr->header.x2 - edgePtr->header.x2)) / 2;
|
| 998 |
|
|
}
|
| 999 |
|
|
if (lineHeight >
|
| 1000 |
|
|
(edgePtr->header.y2 - edgePtr->header.y2)) {
|
| 1001 |
|
|
edgePtr->header.y1 -=
|
| 1002 |
|
|
(lineHeight - (edgePtr->header.y2 - edgePtr->header.y2))
|
| 1003 |
|
|
/ 2;
|
| 1004 |
|
|
edgePtr->header.y2 +=
|
| 1005 |
|
|
(lineHeight - (edgePtr->header.y2 - edgePtr->header.y2)) / 2;
|
| 1006 |
|
|
}
|
| 1007 |
|
|
}
|
| 1008 |
|
|
}
|
| 1009 |
|
|
|
| 1010 |
|
|
/*
|
| 1011 |
|
|
*--------------------------------------------------------------
|
| 1012 |
|
|
*
|
| 1013 |
|
|
* DisplayEdge --
|
| 1014 |
|
|
*
|
| 1015 |
|
|
* This procedure is invoked to draw a edge item in a given
|
| 1016 |
|
|
* drawable.
|
| 1017 |
|
|
*
|
| 1018 |
|
|
* Results:
|
| 1019 |
|
|
* None.
|
| 1020 |
|
|
*
|
| 1021 |
|
|
* Side effects:
|
| 1022 |
|
|
* ItemPtr is drawn in drawable using the transformation
|
| 1023 |
|
|
* information in canvas.
|
| 1024 |
|
|
*
|
| 1025 |
|
|
*--------------------------------------------------------------
|
| 1026 |
|
|
*/
|
| 1027 |
|
|
|
| 1028 |
|
|
static void
|
| 1029 |
|
|
DisplayEdge(canvas, itemPtr, display, drawable, x, y, width, height)
|
| 1030 |
|
|
Tk_Canvas canvas; /* Canvas that contains item. */
|
| 1031 |
|
|
Tk_Item *itemPtr; /* Item to be displayed. */
|
| 1032 |
|
|
Display *display; /* Display on which to draw item. */
|
| 1033 |
|
|
Drawable drawable; /* Pixmap or window in which to draw
|
| 1034 |
|
|
* item. */
|
| 1035 |
|
|
int x, y, width, height; /* Describes region of canvas that
|
| 1036 |
|
|
* must be redisplayed (not used). */
|
| 1037 |
|
|
{
|
| 1038 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1039 |
|
|
XPoint staticPoints[MAX_STATIC_POINTS];
|
| 1040 |
|
|
XPoint *pointPtr;
|
| 1041 |
|
|
XPoint *pPtr;
|
| 1042 |
|
|
register double *coordPtr;
|
| 1043 |
|
|
int i, numPoints, lineHeight;
|
| 1044 |
|
|
int centerX, centerY, lineWidth;
|
| 1045 |
|
|
short drawableX, drawableY;
|
| 1046 |
|
|
|
| 1047 |
|
|
if (edgePtr->gc == None) {
|
| 1048 |
|
|
return;
|
| 1049 |
|
|
}
|
| 1050 |
|
|
|
| 1051 |
|
|
/*
|
| 1052 |
|
|
* Build up an array of points in screen coordinates. Use a
|
| 1053 |
|
|
* static array unless the edge has an enormous number of points;
|
| 1054 |
|
|
* in this case, dynamically allocate an array. For smoothed edges,
|
| 1055 |
|
|
* generate the curve points on each redisplay.
|
| 1056 |
|
|
*/
|
| 1057 |
|
|
|
| 1058 |
|
|
if ((edgePtr->smooth) && (edgePtr->numPoints > 2)) {
|
| 1059 |
|
|
numPoints = 1 + edgePtr->numPoints*edgePtr->splineSteps;
|
| 1060 |
|
|
} else {
|
| 1061 |
|
|
numPoints = edgePtr->numPoints;
|
| 1062 |
|
|
}
|
| 1063 |
|
|
|
| 1064 |
|
|
if (numPoints <= MAX_STATIC_POINTS) {
|
| 1065 |
|
|
pointPtr = staticPoints;
|
| 1066 |
|
|
} else {
|
| 1067 |
|
|
pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint)));
|
| 1068 |
|
|
}
|
| 1069 |
|
|
|
| 1070 |
|
|
if (edgePtr->smooth) {
|
| 1071 |
|
|
numPoints = TkMakeBezierCurve(canvas, edgePtr->coordPtr,
|
| 1072 |
|
|
edgePtr->numPoints,
|
| 1073 |
|
|
edgePtr->splineSteps, pointPtr,
|
| 1074 |
|
|
(double *) NULL);
|
| 1075 |
|
|
} else {
|
| 1076 |
|
|
for (i = 0, coordPtr = edgePtr->coordPtr, pPtr = pointPtr;
|
| 1077 |
|
|
i < edgePtr->numPoints; i += 1, coordPtr += 2, pPtr++) {
|
| 1078 |
|
|
Tk_CanvasDrawableCoords(canvas, coordPtr[0], coordPtr[1],
|
| 1079 |
|
|
&pPtr->x, &pPtr->y);
|
| 1080 |
|
|
}
|
| 1081 |
|
|
}
|
| 1082 |
|
|
|
| 1083 |
|
|
/*
|
| 1084 |
|
|
* Display edge, the free up edge storage if it was dynamically
|
| 1085 |
|
|
* allocated. If we're stippling, then modify the stipple offset
|
| 1086 |
|
|
* in the GC. Be sure to reset the offset when done, since the
|
| 1087 |
|
|
* GC is supposed to be read-only.
|
| 1088 |
|
|
*/
|
| 1089 |
|
|
|
| 1090 |
|
|
if (edgePtr->fillStipple != None) {
|
| 1091 |
|
|
XSetTSOrigin(display, edgePtr->gc,
|
| 1092 |
|
|
-((TkCanvas *) canvas)->drawableXOrigin,
|
| 1093 |
|
|
-((TkCanvas *) canvas)->drawableYOrigin);
|
| 1094 |
|
|
}
|
| 1095 |
|
|
XDrawLines(display, drawable, edgePtr->gc,
|
| 1096 |
|
|
pointPtr, numPoints, CoordModeOrigin);
|
| 1097 |
|
|
if (pointPtr[numPoints-1].x > pointPtr[numPoints-2].x) {
|
| 1098 |
|
|
centerX = ((pointPtr[numPoints-1].x - pointPtr[numPoints-2].x) / 2) +
|
| 1099 |
|
|
pointPtr[numPoints-2].x;
|
| 1100 |
|
|
} else {
|
| 1101 |
|
|
centerX = ((pointPtr[numPoints-2].x - pointPtr[numPoints-1].x) / 2) +
|
| 1102 |
|
|
pointPtr[numPoints-1].x;
|
| 1103 |
|
|
}
|
| 1104 |
|
|
if (pointPtr[numPoints-1].y > pointPtr[numPoints-2].y) {
|
| 1105 |
|
|
centerY = ((pointPtr[numPoints-1].y - pointPtr[numPoints-2].y) / 2) +
|
| 1106 |
|
|
pointPtr[numPoints-2].y;
|
| 1107 |
|
|
} else {
|
| 1108 |
|
|
centerY = ((pointPtr[numPoints-2].y - pointPtr[numPoints-1].y) / 2) +
|
| 1109 |
|
|
pointPtr[numPoints-1].y;
|
| 1110 |
|
|
}
|
| 1111 |
|
|
if (pointPtr != staticPoints) {
|
| 1112 |
|
|
ckfree((char *) pointPtr);
|
| 1113 |
|
|
}
|
| 1114 |
|
|
|
| 1115 |
|
|
/*
|
| 1116 |
|
|
* Display arrowheads, if they are wanted.
|
| 1117 |
|
|
*/
|
| 1118 |
|
|
|
| 1119 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 1120 |
|
|
if (edgePtr->arrow != lastUid) {
|
| 1121 |
|
|
TkFillPolygon(canvas, edgePtr->firstArrowPtr, PTS_IN_ARROW,
|
| 1122 |
|
|
display, drawable, edgePtr->gc, NULL);
|
| 1123 |
|
|
}
|
| 1124 |
|
|
if (edgePtr->arrow != firstUid) {
|
| 1125 |
|
|
TkFillPolygon(canvas, edgePtr->lastArrowPtr, PTS_IN_ARROW,
|
| 1126 |
|
|
display, drawable, edgePtr->gc, NULL);
|
| 1127 |
|
|
}
|
| 1128 |
|
|
}
|
| 1129 |
|
|
if (edgePtr->fillStipple != None) {
|
| 1130 |
|
|
XSetTSOrigin(display, edgePtr->gc, 0, 0);
|
| 1131 |
|
|
}
|
| 1132 |
|
|
|
| 1133 |
|
|
/* display the label */
|
| 1134 |
|
|
if (edgePtr->label != NULL && (size_t) strlen(edgePtr->label) > 0) {
|
| 1135 |
|
|
Tk_FreeTextLayout(edgePtr->textLayout);
|
| 1136 |
|
|
edgePtr->textLayout = Tk_ComputeTextLayout(edgePtr->tkfont,
|
| 1137 |
|
|
edgePtr->label,
|
| 1138 |
|
|
strlen (edgePtr->label),
|
| 1139 |
|
|
edgePtr->width,
|
| 1140 |
|
|
edgePtr->justify,
|
| 1141 |
|
|
0, &lineWidth, &lineHeight);
|
| 1142 |
|
|
lineWidth = strlen(edgePtr->label);
|
| 1143 |
|
|
if (strcmp(edgePtr->state, "selected") == 0) {
|
| 1144 |
|
|
XFillRectangle(display, drawable,
|
| 1145 |
|
|
edgePtr->gc,
|
| 1146 |
|
|
centerX - (lineWidth / 2) - 1,
|
| 1147 |
|
|
centerY - (lineHeight / 2) - 1,
|
| 1148 |
|
|
lineWidth + 2, lineHeight + 2);
|
| 1149 |
|
|
Tk_CanvasDrawableCoords(canvas,
|
| 1150 |
|
|
(double) (edgePtr->header.x1 + x),
|
| 1151 |
|
|
(double) (edgePtr->header.y1 + y),
|
| 1152 |
|
|
&drawableX, &drawableY);
|
| 1153 |
|
|
Tk_DrawTextLayout(display, drawable, edgePtr->gc,
|
| 1154 |
|
|
edgePtr->textLayout,
|
| 1155 |
|
|
drawableX, drawableY,
|
| 1156 |
|
|
0, -1);
|
| 1157 |
|
|
} else {
|
| 1158 |
|
|
XFillRectangle(display, drawable,
|
| 1159 |
|
|
edgePtr->invertedGc,
|
| 1160 |
|
|
centerX - (lineWidth / 2) - 1,
|
| 1161 |
|
|
centerY - (lineHeight / 2) - 1,
|
| 1162 |
|
|
lineWidth + 2, lineHeight + 2);
|
| 1163 |
|
|
Tk_CanvasDrawableCoords(canvas,
|
| 1164 |
|
|
(double) (edgePtr->header.x1 + x),
|
| 1165 |
|
|
(double) (edgePtr->header.y1 + y),
|
| 1166 |
|
|
&drawableX, &drawableY);
|
| 1167 |
|
|
Tk_DrawTextLayout(display, drawable, edgePtr->gc,
|
| 1168 |
|
|
edgePtr->textLayout,
|
| 1169 |
|
|
drawableX, drawableY,
|
| 1170 |
|
|
0, -1);
|
| 1171 |
|
|
}
|
| 1172 |
|
|
}
|
| 1173 |
|
|
}
|
| 1174 |
|
|
|
| 1175 |
|
|
/*
|
| 1176 |
|
|
*--------------------------------------------------------------
|
| 1177 |
|
|
*
|
| 1178 |
|
|
* EdgeToPoint --
|
| 1179 |
|
|
*
|
| 1180 |
|
|
* Computes the distance from a given point to a given
|
| 1181 |
|
|
* edge, in canvas units.
|
| 1182 |
|
|
*
|
| 1183 |
|
|
* Results:
|
| 1184 |
|
|
* The return value is 0 if the point whose x and y coordinates
|
| 1185 |
|
|
* are pointPtr[0] and pointPtr[1] is inside the edge. If the
|
| 1186 |
|
|
* point isn't inside the edge then the return value is the
|
| 1187 |
|
|
* distance from the point to the edge.
|
| 1188 |
|
|
*
|
| 1189 |
|
|
* Side effects:
|
| 1190 |
|
|
* None.
|
| 1191 |
|
|
*
|
| 1192 |
|
|
*--------------------------------------------------------------
|
| 1193 |
|
|
*/
|
| 1194 |
|
|
|
| 1195 |
|
|
/* ARGSUSED */
|
| 1196 |
|
|
static double
|
| 1197 |
|
|
EdgeToPoint(canvas, itemPtr, pointPtr)
|
| 1198 |
|
|
Tk_Canvas canvas; /* Canvas containing item. */
|
| 1199 |
|
|
Tk_Item *itemPtr; /* Item to check against point. */
|
| 1200 |
|
|
double *pointPtr; /* Pointer to x and y coordinates. */
|
| 1201 |
|
|
{
|
| 1202 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1203 |
|
|
register double *coordPtr, *edgePoints;
|
| 1204 |
|
|
double staticSpace[2*MAX_STATIC_POINTS];
|
| 1205 |
|
|
double poly[10];
|
| 1206 |
|
|
double bestDist, dist;
|
| 1207 |
|
|
int numPoints, count;
|
| 1208 |
|
|
int changedMiterToBevel; /* Non-zero means that a mitered corner
|
| 1209 |
|
|
* had to be treated as beveled after all
|
| 1210 |
|
|
* because the angle was < 11 degrees. */
|
| 1211 |
|
|
|
| 1212 |
|
|
bestDist = 1.0e40;
|
| 1213 |
|
|
|
| 1214 |
|
|
/*
|
| 1215 |
|
|
* Handle smoothed edges by generating an expanded set of points
|
| 1216 |
|
|
* against which to do the check.
|
| 1217 |
|
|
*/
|
| 1218 |
|
|
|
| 1219 |
|
|
if ((edgePtr->smooth) && (edgePtr->numPoints > 2)) {
|
| 1220 |
|
|
numPoints = 1 + edgePtr->numPoints*edgePtr->splineSteps;
|
| 1221 |
|
|
if (numPoints <= MAX_STATIC_POINTS) {
|
| 1222 |
|
|
edgePoints = staticSpace;
|
| 1223 |
|
|
} else {
|
| 1224 |
|
|
edgePoints = (double *) ckalloc((unsigned)
|
| 1225 |
|
|
(2*numPoints*sizeof(double)));
|
| 1226 |
|
|
}
|
| 1227 |
|
|
numPoints = TkMakeBezierCurve(canvas, edgePtr->coordPtr,
|
| 1228 |
|
|
edgePtr->numPoints,
|
| 1229 |
|
|
edgePtr->splineSteps, (XPoint *) NULL,
|
| 1230 |
|
|
edgePoints);
|
| 1231 |
|
|
} else {
|
| 1232 |
|
|
numPoints = edgePtr->numPoints;
|
| 1233 |
|
|
edgePoints = edgePtr->coordPtr;
|
| 1234 |
|
|
}
|
| 1235 |
|
|
|
| 1236 |
|
|
/*
|
| 1237 |
|
|
* The overall idea is to iterate through all of the edges of
|
| 1238 |
|
|
* the edge, computing a polygon for each edge and testing the
|
| 1239 |
|
|
* point against that polygon. In addition, there are additional
|
| 1240 |
|
|
* tests to deal with rounded joints and caps.
|
| 1241 |
|
|
*/
|
| 1242 |
|
|
|
| 1243 |
|
|
changedMiterToBevel = 0;
|
| 1244 |
|
|
for (count = numPoints, coordPtr = edgePoints; count >= 2;
|
| 1245 |
|
|
count--, coordPtr += 2) {
|
| 1246 |
|
|
|
| 1247 |
|
|
/*
|
| 1248 |
|
|
* If rounding is done around the first point then compute
|
| 1249 |
|
|
* the distance between the point and the point.
|
| 1250 |
|
|
*/
|
| 1251 |
|
|
|
| 1252 |
|
|
if (((edgePtr->capStyle == CapRound) && (count == numPoints))
|
| 1253 |
|
|
|| ((edgePtr->joinStyle == JoinRound)
|
| 1254 |
|
|
&& (count != numPoints))) {
|
| 1255 |
|
|
dist = hypot(coordPtr[0] - pointPtr[0], coordPtr[1] - pointPtr[1])
|
| 1256 |
|
|
- edgePtr->width/2.0;
|
| 1257 |
|
|
if (dist <= 0.0) {
|
| 1258 |
|
|
bestDist = 0.0;
|
| 1259 |
|
|
goto done;
|
| 1260 |
|
|
} else if (dist < bestDist) {
|
| 1261 |
|
|
bestDist = dist;
|
| 1262 |
|
|
}
|
| 1263 |
|
|
}
|
| 1264 |
|
|
|
| 1265 |
|
|
/*
|
| 1266 |
|
|
* Compute the polygonal shape corresponding to this edge,
|
| 1267 |
|
|
* consisting of two points for the first point of the edge
|
| 1268 |
|
|
* and two points for the last point of the edge.
|
| 1269 |
|
|
*/
|
| 1270 |
|
|
|
| 1271 |
|
|
if (count == numPoints) {
|
| 1272 |
|
|
TkGetButtPoints(coordPtr+2, coordPtr, (double) edgePtr->width,
|
| 1273 |
|
|
edgePtr->capStyle == CapProjecting, poly, poly+2);
|
| 1274 |
|
|
} else if ((edgePtr->joinStyle == JoinMiter) && !changedMiterToBevel) {
|
| 1275 |
|
|
poly[0] = poly[6];
|
| 1276 |
|
|
poly[1] = poly[7];
|
| 1277 |
|
|
poly[2] = poly[4];
|
| 1278 |
|
|
poly[3] = poly[5];
|
| 1279 |
|
|
} else {
|
| 1280 |
|
|
TkGetButtPoints(coordPtr+2, coordPtr, (double) edgePtr->width, 0,
|
| 1281 |
|
|
poly, poly+2);
|
| 1282 |
|
|
|
| 1283 |
|
|
/*
|
| 1284 |
|
|
* If this edge uses beveled joints, then check the distance
|
| 1285 |
|
|
* to a polygon comprising the last two points of the previous
|
| 1286 |
|
|
* polygon and the first two from this polygon; this checks
|
| 1287 |
|
|
* the wedges that fill the mitered joint.
|
| 1288 |
|
|
*/
|
| 1289 |
|
|
|
| 1290 |
|
|
if ((edgePtr->joinStyle == JoinBevel) || changedMiterToBevel) {
|
| 1291 |
|
|
poly[8] = poly[0];
|
| 1292 |
|
|
poly[9] = poly[1];
|
| 1293 |
|
|
dist = TkPolygonToPoint(poly, 5, pointPtr);
|
| 1294 |
|
|
if (dist <= 0.0) {
|
| 1295 |
|
|
bestDist = 0.0;
|
| 1296 |
|
|
goto done;
|
| 1297 |
|
|
} else if (dist < bestDist) {
|
| 1298 |
|
|
bestDist = dist;
|
| 1299 |
|
|
}
|
| 1300 |
|
|
changedMiterToBevel = 0;
|
| 1301 |
|
|
}
|
| 1302 |
|
|
}
|
| 1303 |
|
|
if (count == 2) {
|
| 1304 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width,
|
| 1305 |
|
|
edgePtr->capStyle == CapProjecting, poly+4, poly+6);
|
| 1306 |
|
|
} else if (edgePtr->joinStyle == JoinMiter) {
|
| 1307 |
|
|
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
|
| 1308 |
|
|
(double) edgePtr->width, poly+4, poly+6) == 0) {
|
| 1309 |
|
|
changedMiterToBevel = 1;
|
| 1310 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width,
|
| 1311 |
|
|
0, poly+4, poly+6);
|
| 1312 |
|
|
}
|
| 1313 |
|
|
} else {
|
| 1314 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width, 0,
|
| 1315 |
|
|
poly+4, poly+6);
|
| 1316 |
|
|
}
|
| 1317 |
|
|
poly[8] = poly[0];
|
| 1318 |
|
|
poly[9] = poly[1];
|
| 1319 |
|
|
dist = TkPolygonToPoint(poly, 5, pointPtr);
|
| 1320 |
|
|
if (dist <= 0.0) {
|
| 1321 |
|
|
bestDist = 0.0;
|
| 1322 |
|
|
goto done;
|
| 1323 |
|
|
} else if (dist < bestDist) {
|
| 1324 |
|
|
bestDist = dist;
|
| 1325 |
|
|
}
|
| 1326 |
|
|
}
|
| 1327 |
|
|
|
| 1328 |
|
|
/*
|
| 1329 |
|
|
* If caps are rounded, check the distance to the cap around the
|
| 1330 |
|
|
* final end point of the edge.
|
| 1331 |
|
|
*/
|
| 1332 |
|
|
|
| 1333 |
|
|
if (edgePtr->capStyle == CapRound) {
|
| 1334 |
|
|
dist = hypot(coordPtr[0] - pointPtr[0], coordPtr[1] - pointPtr[1])
|
| 1335 |
|
|
- edgePtr->width/2.0;
|
| 1336 |
|
|
if (dist <= 0.0) {
|
| 1337 |
|
|
bestDist = 0.0;
|
| 1338 |
|
|
goto done;
|
| 1339 |
|
|
} else if (dist < bestDist) {
|
| 1340 |
|
|
bestDist = dist;
|
| 1341 |
|
|
}
|
| 1342 |
|
|
}
|
| 1343 |
|
|
|
| 1344 |
|
|
/*
|
| 1345 |
|
|
* If there are arrowheads, check the distance to the arrowheads.
|
| 1346 |
|
|
*/
|
| 1347 |
|
|
|
| 1348 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 1349 |
|
|
if (edgePtr->arrow != lastUid) {
|
| 1350 |
|
|
dist = TkPolygonToPoint(edgePtr->firstArrowPtr, PTS_IN_ARROW,
|
| 1351 |
|
|
pointPtr);
|
| 1352 |
|
|
if (dist <= 0.0) {
|
| 1353 |
|
|
bestDist = 0.0;
|
| 1354 |
|
|
goto done;
|
| 1355 |
|
|
} else if (dist < bestDist) {
|
| 1356 |
|
|
bestDist = dist;
|
| 1357 |
|
|
}
|
| 1358 |
|
|
}
|
| 1359 |
|
|
if (edgePtr->arrow != firstUid) {
|
| 1360 |
|
|
dist = TkPolygonToPoint(edgePtr->lastArrowPtr, PTS_IN_ARROW,
|
| 1361 |
|
|
pointPtr);
|
| 1362 |
|
|
if (dist <= 0.0) {
|
| 1363 |
|
|
bestDist = 0.0;
|
| 1364 |
|
|
goto done;
|
| 1365 |
|
|
} else if (dist < bestDist) {
|
| 1366 |
|
|
bestDist = dist;
|
| 1367 |
|
|
}
|
| 1368 |
|
|
}
|
| 1369 |
|
|
}
|
| 1370 |
|
|
|
| 1371 |
|
|
done:
|
| 1372 |
|
|
if ((edgePoints != staticSpace) && (edgePoints != edgePtr->coordPtr)) {
|
| 1373 |
|
|
ckfree((char *) edgePoints);
|
| 1374 |
|
|
}
|
| 1375 |
|
|
return bestDist;
|
| 1376 |
|
|
}
|
| 1377 |
|
|
|
| 1378 |
|
|
/*
|
| 1379 |
|
|
*--------------------------------------------------------------
|
| 1380 |
|
|
*
|
| 1381 |
|
|
* EdgeToArea --
|
| 1382 |
|
|
*
|
| 1383 |
|
|
* This procedure is called to determine whether an item
|
| 1384 |
|
|
* lies entirely inside, entirely outside, or overlapping
|
| 1385 |
|
|
* a given rectangular area.
|
| 1386 |
|
|
*
|
| 1387 |
|
|
* Results:
|
| 1388 |
|
|
* -1 is returned if the item is entirely outside the
|
| 1389 |
|
|
* area, 0 if it overlaps, and 1 if it is entirely
|
| 1390 |
|
|
* inside the given area.
|
| 1391 |
|
|
*
|
| 1392 |
|
|
* Side effects:
|
| 1393 |
|
|
* None.
|
| 1394 |
|
|
*
|
| 1395 |
|
|
*--------------------------------------------------------------
|
| 1396 |
|
|
*/
|
| 1397 |
|
|
|
| 1398 |
|
|
/* ARGSUSED */
|
| 1399 |
|
|
static int
|
| 1400 |
|
|
EdgeToArea(canvas, itemPtr, rectPtr)
|
| 1401 |
|
|
Tk_Canvas canvas; /* Canvas containing item. */
|
| 1402 |
|
|
Tk_Item *itemPtr; /* Item to check against edge. */
|
| 1403 |
|
|
double *rectPtr;
|
| 1404 |
|
|
{
|
| 1405 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1406 |
|
|
register double *coordPtr;
|
| 1407 |
|
|
double staticSpace[2*MAX_STATIC_POINTS];
|
| 1408 |
|
|
double *edgePoints, poly[10];
|
| 1409 |
|
|
double radius;
|
| 1410 |
|
|
int numPoints, count;
|
| 1411 |
|
|
int changedMiterToBevel; /* Non-zero means that a mitered corner
|
| 1412 |
|
|
* had to be treated as beveled after all
|
| 1413 |
|
|
* because the angle was < 11 degrees. */
|
| 1414 |
|
|
int inside; /* Tentative guess about what to return,
|
| 1415 |
|
|
* based on all points seen so far: one
|
| 1416 |
|
|
* means everything seen so far was
|
| 1417 |
|
|
* inside the area; -1 means everything
|
| 1418 |
|
|
* was outside the area. 0 means overlap
|
| 1419 |
|
|
* has been found. */
|
| 1420 |
|
|
|
| 1421 |
|
|
radius = edgePtr->width/2.0;
|
| 1422 |
|
|
inside = -1;
|
| 1423 |
|
|
|
| 1424 |
|
|
/*
|
| 1425 |
|
|
* Handle smoothed edges by generating an expanded set of points
|
| 1426 |
|
|
* against which to do the check.
|
| 1427 |
|
|
*/
|
| 1428 |
|
|
|
| 1429 |
|
|
if ((edgePtr->smooth) && (edgePtr->numPoints > 2)) {
|
| 1430 |
|
|
numPoints = 1 + edgePtr->numPoints*edgePtr->splineSteps;
|
| 1431 |
|
|
if (numPoints <= MAX_STATIC_POINTS) {
|
| 1432 |
|
|
edgePoints = staticSpace;
|
| 1433 |
|
|
} else {
|
| 1434 |
|
|
edgePoints = (double *) ckalloc((unsigned)
|
| 1435 |
|
|
(2*numPoints*sizeof(double)));
|
| 1436 |
|
|
}
|
| 1437 |
|
|
numPoints = TkMakeBezierCurve(canvas, edgePtr->coordPtr,
|
| 1438 |
|
|
edgePtr->numPoints,
|
| 1439 |
|
|
edgePtr->splineSteps, (XPoint *) NULL,
|
| 1440 |
|
|
edgePoints);
|
| 1441 |
|
|
} else {
|
| 1442 |
|
|
numPoints = edgePtr->numPoints;
|
| 1443 |
|
|
edgePoints = edgePtr->coordPtr;
|
| 1444 |
|
|
}
|
| 1445 |
|
|
|
| 1446 |
|
|
coordPtr = edgePoints;
|
| 1447 |
|
|
if ((coordPtr[0] >= rectPtr[0]) && (coordPtr[0] <= rectPtr[2])
|
| 1448 |
|
|
&& (coordPtr[1] >= rectPtr[1]) && (coordPtr[1] <= rectPtr[3])) {
|
| 1449 |
|
|
inside = 1;
|
| 1450 |
|
|
}
|
| 1451 |
|
|
|
| 1452 |
|
|
/*
|
| 1453 |
|
|
* Iterate through all of the edges of the edge, computing a polygon
|
| 1454 |
|
|
* for each edge and testing the area against that polygon. In
|
| 1455 |
|
|
* addition, there are additional tests to deal with rounded joints
|
| 1456 |
|
|
* and caps.
|
| 1457 |
|
|
*/
|
| 1458 |
|
|
|
| 1459 |
|
|
changedMiterToBevel = 0;
|
| 1460 |
|
|
for (count = numPoints; count >= 2; count--, coordPtr += 2) {
|
| 1461 |
|
|
|
| 1462 |
|
|
/*
|
| 1463 |
|
|
* If rounding is done around the first point of the edge
|
| 1464 |
|
|
* then test a circular region around the point with the
|
| 1465 |
|
|
* area.
|
| 1466 |
|
|
*/
|
| 1467 |
|
|
|
| 1468 |
|
|
if (((edgePtr->capStyle == CapRound) && (count == numPoints))
|
| 1469 |
|
|
|| ((edgePtr->joinStyle == JoinRound)
|
| 1470 |
|
|
&& (count != numPoints))) {
|
| 1471 |
|
|
poly[0] = coordPtr[0] - radius;
|
| 1472 |
|
|
poly[1] = coordPtr[1] - radius;
|
| 1473 |
|
|
poly[2] = coordPtr[0] + radius;
|
| 1474 |
|
|
poly[3] = coordPtr[1] + radius;
|
| 1475 |
|
|
if (TkOvalToArea(poly, rectPtr) != inside) {
|
| 1476 |
|
|
inside = 0;
|
| 1477 |
|
|
goto done;
|
| 1478 |
|
|
}
|
| 1479 |
|
|
}
|
| 1480 |
|
|
|
| 1481 |
|
|
/*
|
| 1482 |
|
|
* Compute the polygonal shape corresponding to this edge,
|
| 1483 |
|
|
* consisting of two points for the first point of the edge
|
| 1484 |
|
|
* and two points for the last point of the edge.
|
| 1485 |
|
|
*/
|
| 1486 |
|
|
|
| 1487 |
|
|
if (count == numPoints) {
|
| 1488 |
|
|
TkGetButtPoints(coordPtr+2, coordPtr, (double) edgePtr->width,
|
| 1489 |
|
|
edgePtr->capStyle == CapProjecting, poly, poly+2);
|
| 1490 |
|
|
} else if ((edgePtr->joinStyle == JoinMiter) && !changedMiterToBevel) {
|
| 1491 |
|
|
poly[0] = poly[6];
|
| 1492 |
|
|
poly[1] = poly[7];
|
| 1493 |
|
|
poly[2] = poly[4];
|
| 1494 |
|
|
poly[3] = poly[5];
|
| 1495 |
|
|
} else {
|
| 1496 |
|
|
TkGetButtPoints(coordPtr+2, coordPtr, (double) edgePtr->width, 0,
|
| 1497 |
|
|
poly, poly+2);
|
| 1498 |
|
|
|
| 1499 |
|
|
/*
|
| 1500 |
|
|
* If the last joint was beveled, then also check a
|
| 1501 |
|
|
* polygon comprising the last two points of the previous
|
| 1502 |
|
|
* polygon and the first two from this polygon; this checks
|
| 1503 |
|
|
* the wedges that fill the beveled joint.
|
| 1504 |
|
|
*/
|
| 1505 |
|
|
|
| 1506 |
|
|
if ((edgePtr->joinStyle == JoinBevel) || changedMiterToBevel) {
|
| 1507 |
|
|
poly[8] = poly[0];
|
| 1508 |
|
|
poly[9] = poly[1];
|
| 1509 |
|
|
if (TkPolygonToArea(poly, 5, rectPtr) != inside) {
|
| 1510 |
|
|
inside = 0;
|
| 1511 |
|
|
goto done;
|
| 1512 |
|
|
}
|
| 1513 |
|
|
changedMiterToBevel = 0;
|
| 1514 |
|
|
}
|
| 1515 |
|
|
}
|
| 1516 |
|
|
if (count == 2) {
|
| 1517 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width,
|
| 1518 |
|
|
edgePtr->capStyle == CapProjecting, poly+4, poly+6);
|
| 1519 |
|
|
} else if (edgePtr->joinStyle == JoinMiter) {
|
| 1520 |
|
|
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
|
| 1521 |
|
|
(double) edgePtr->width, poly+4, poly+6) == 0) {
|
| 1522 |
|
|
changedMiterToBevel = 1;
|
| 1523 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width,
|
| 1524 |
|
|
0, poly+4, poly+6);
|
| 1525 |
|
|
}
|
| 1526 |
|
|
} else {
|
| 1527 |
|
|
TkGetButtPoints(coordPtr, coordPtr+2, (double) edgePtr->width, 0,
|
| 1528 |
|
|
poly+4, poly+6);
|
| 1529 |
|
|
}
|
| 1530 |
|
|
poly[8] = poly[0];
|
| 1531 |
|
|
poly[9] = poly[1];
|
| 1532 |
|
|
if (TkPolygonToArea(poly, 5, rectPtr) != inside) {
|
| 1533 |
|
|
inside = 0;
|
| 1534 |
|
|
goto done;
|
| 1535 |
|
|
}
|
| 1536 |
|
|
}
|
| 1537 |
|
|
|
| 1538 |
|
|
/*
|
| 1539 |
|
|
* If caps are rounded, check the cap around the final point
|
| 1540 |
|
|
* of the edge.
|
| 1541 |
|
|
*/
|
| 1542 |
|
|
|
| 1543 |
|
|
if (edgePtr->capStyle == CapRound) {
|
| 1544 |
|
|
poly[0] = coordPtr[0] - radius;
|
| 1545 |
|
|
poly[1] = coordPtr[1] - radius;
|
| 1546 |
|
|
poly[2] = coordPtr[0] + radius;
|
| 1547 |
|
|
poly[3] = coordPtr[1] + radius;
|
| 1548 |
|
|
if (TkOvalToArea(poly, rectPtr) != inside) {
|
| 1549 |
|
|
inside = 0;
|
| 1550 |
|
|
goto done;
|
| 1551 |
|
|
}
|
| 1552 |
|
|
}
|
| 1553 |
|
|
|
| 1554 |
|
|
/*
|
| 1555 |
|
|
* Check arrowheads, if any.
|
| 1556 |
|
|
*/
|
| 1557 |
|
|
|
| 1558 |
|
|
if (edgePtr->arrow != noneUid) {
|
| 1559 |
|
|
if (edgePtr->arrow != lastUid) {
|
| 1560 |
|
|
if (TkPolygonToArea(edgePtr->firstArrowPtr, PTS_IN_ARROW,
|
| 1561 |
|
|
rectPtr) != inside) {
|
| 1562 |
|
|
inside = 0;
|
| 1563 |
|
|
goto done;
|
| 1564 |
|
|
}
|
| 1565 |
|
|
}
|
| 1566 |
|
|
if (edgePtr->arrow != firstUid) {
|
| 1567 |
|
|
if (TkPolygonToArea(edgePtr->lastArrowPtr, PTS_IN_ARROW,
|
| 1568 |
|
|
rectPtr) != inside) {
|
| 1569 |
|
|
inside = 0;
|
| 1570 |
|
|
goto done;
|
| 1571 |
|
|
}
|
| 1572 |
|
|
}
|
| 1573 |
|
|
}
|
| 1574 |
|
|
|
| 1575 |
|
|
done:
|
| 1576 |
|
|
if ((edgePoints != staticSpace) && (edgePoints != edgePtr->coordPtr)) {
|
| 1577 |
|
|
ckfree((char *) edgePoints);
|
| 1578 |
|
|
}
|
| 1579 |
|
|
return inside;
|
| 1580 |
|
|
}
|
| 1581 |
|
|
|
| 1582 |
|
|
/*
|
| 1583 |
|
|
*--------------------------------------------------------------
|
| 1584 |
|
|
*
|
| 1585 |
|
|
* ScaleEdge --
|
| 1586 |
|
|
*
|
| 1587 |
|
|
* This procedure is invoked to rescale a edge item.
|
| 1588 |
|
|
*
|
| 1589 |
|
|
* Results:
|
| 1590 |
|
|
* None.
|
| 1591 |
|
|
*
|
| 1592 |
|
|
* Side effects:
|
| 1593 |
|
|
* The edge referred to by itemPtr is rescaled so that the
|
| 1594 |
|
|
* following transformation is applied to all point
|
| 1595 |
|
|
* coordinates:
|
| 1596 |
|
|
* x' = originX + scaleX*(x-originX)
|
| 1597 |
|
|
* y' = originY + scaleY*(y-originY)
|
| 1598 |
|
|
*
|
| 1599 |
|
|
*--------------------------------------------------------------
|
| 1600 |
|
|
*/
|
| 1601 |
|
|
|
| 1602 |
|
|
static void
|
| 1603 |
|
|
ScaleEdge(canvas, itemPtr, originX, originY, scaleX, scaleY)
|
| 1604 |
|
|
Tk_Canvas canvas; /* Canvas containing edge. */
|
| 1605 |
|
|
Tk_Item *itemPtr; /* Edge to be scaled. */
|
| 1606 |
|
|
double originX, originY; /* Origin about which to scale rect. */
|
| 1607 |
|
|
double scaleX; /* Amount to scale in X direction. */
|
| 1608 |
|
|
double scaleY; /* Amount to scale in Y direction. */
|
| 1609 |
|
|
{
|
| 1610 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1611 |
|
|
double *coordPtr;
|
| 1612 |
|
|
int i;
|
| 1613 |
|
|
|
| 1614 |
|
|
for (i = 0, coordPtr = edgePtr->coordPtr; i < edgePtr->numPoints;
|
| 1615 |
|
|
i++, coordPtr += 2) {
|
| 1616 |
|
|
coordPtr[0] = originX + scaleX*(*coordPtr - originX);
|
| 1617 |
|
|
coordPtr[1] = originY + scaleY*(coordPtr[1] - originY);
|
| 1618 |
|
|
}
|
| 1619 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 1620 |
|
|
for (i = 0, coordPtr = edgePtr->firstArrowPtr; i < PTS_IN_ARROW;
|
| 1621 |
|
|
i++, coordPtr += 2) {
|
| 1622 |
|
|
coordPtr[0] = originX + scaleX*(coordPtr[0] - originX);
|
| 1623 |
|
|
coordPtr[1] = originY + scaleY*(coordPtr[1] - originY);
|
| 1624 |
|
|
}
|
| 1625 |
|
|
}
|
| 1626 |
|
|
if (edgePtr->lastArrowPtr != NULL) {
|
| 1627 |
|
|
for (i = 0, coordPtr = edgePtr->lastArrowPtr; i < PTS_IN_ARROW;
|
| 1628 |
|
|
i++, coordPtr += 2) {
|
| 1629 |
|
|
coordPtr[0] = originX + scaleX*(coordPtr[0] - originX);
|
| 1630 |
|
|
coordPtr[1] = originY + scaleY*(coordPtr[1] - originY);
|
| 1631 |
|
|
}
|
| 1632 |
|
|
}
|
| 1633 |
|
|
ComputeEdgeBbox(canvas, edgePtr);
|
| 1634 |
|
|
}
|
| 1635 |
|
|
|
| 1636 |
|
|
/*
|
| 1637 |
|
|
*--------------------------------------------------------------
|
| 1638 |
|
|
*
|
| 1639 |
|
|
* TranslateEdge --
|
| 1640 |
|
|
*
|
| 1641 |
|
|
* This procedure is called to move a edge by a given amount.
|
| 1642 |
|
|
*
|
| 1643 |
|
|
* Results:
|
| 1644 |
|
|
* None.
|
| 1645 |
|
|
*
|
| 1646 |
|
|
* Side effects:
|
| 1647 |
|
|
* The position of the edge is offset by (xDelta, yDelta), and
|
| 1648 |
|
|
* the bounding box is updated in the generic part of the item
|
| 1649 |
|
|
* structure.
|
| 1650 |
|
|
*
|
| 1651 |
|
|
*--------------------------------------------------------------
|
| 1652 |
|
|
*/
|
| 1653 |
|
|
|
| 1654 |
|
|
static void
|
| 1655 |
|
|
TranslateEdge(canvas, itemPtr, deltaX, deltaY)
|
| 1656 |
|
|
Tk_Canvas canvas; /* Canvas containing item. */
|
| 1657 |
|
|
Tk_Item *itemPtr; /* Item that is being moved. */
|
| 1658 |
|
|
double deltaX, deltaY; /* Amount by which item is to be
|
| 1659 |
|
|
* moved. */
|
| 1660 |
|
|
{
|
| 1661 |
|
|
EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1662 |
|
|
double *coordPtr;
|
| 1663 |
|
|
int i;
|
| 1664 |
|
|
|
| 1665 |
|
|
for (i = 0, coordPtr = edgePtr->coordPtr; i < edgePtr->numPoints;
|
| 1666 |
|
|
i++, coordPtr += 2) {
|
| 1667 |
|
|
coordPtr[0] += deltaX;
|
| 1668 |
|
|
coordPtr[1] += deltaY;
|
| 1669 |
|
|
}
|
| 1670 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 1671 |
|
|
for (i = 0, coordPtr = edgePtr->firstArrowPtr; i < PTS_IN_ARROW;
|
| 1672 |
|
|
i++, coordPtr += 2) {
|
| 1673 |
|
|
coordPtr[0] += deltaX;
|
| 1674 |
|
|
coordPtr[1] += deltaY;
|
| 1675 |
|
|
}
|
| 1676 |
|
|
}
|
| 1677 |
|
|
if (edgePtr->lastArrowPtr != NULL) {
|
| 1678 |
|
|
for (i = 0, coordPtr = edgePtr->lastArrowPtr; i < PTS_IN_ARROW;
|
| 1679 |
|
|
i++, coordPtr += 2) {
|
| 1680 |
|
|
coordPtr[0] += deltaX;
|
| 1681 |
|
|
coordPtr[1] += deltaY;
|
| 1682 |
|
|
}
|
| 1683 |
|
|
}
|
| 1684 |
|
|
ComputeEdgeBbox(canvas, edgePtr);
|
| 1685 |
|
|
}
|
| 1686 |
|
|
|
| 1687 |
|
|
/*
|
| 1688 |
|
|
*--------------------------------------------------------------
|
| 1689 |
|
|
*
|
| 1690 |
|
|
* ParseArrowShape --
|
| 1691 |
|
|
*
|
| 1692 |
|
|
* This procedure is called back during option parsing to
|
| 1693 |
|
|
* parse arrow shape information.
|
| 1694 |
|
|
*
|
| 1695 |
|
|
* Results:
|
| 1696 |
|
|
* The return value is a standard Tcl result: TCL_OK means
|
| 1697 |
|
|
* that the arrow shape information was parsed ok, and
|
| 1698 |
|
|
* TCL_ERROR means it couldn't be parsed.
|
| 1699 |
|
|
*
|
| 1700 |
|
|
* Side effects:
|
| 1701 |
|
|
* Arrow information in recordPtr is updated.
|
| 1702 |
|
|
*
|
| 1703 |
|
|
*--------------------------------------------------------------
|
| 1704 |
|
|
*/
|
| 1705 |
|
|
|
| 1706 |
|
|
/* ARGSUSED */
|
| 1707 |
|
|
static int
|
| 1708 |
|
|
ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset)
|
| 1709 |
|
|
ClientData clientData; /* Not used. */
|
| 1710 |
|
|
Tcl_Interp *interp; /* Used for error reporting. */
|
| 1711 |
|
|
Tk_Window tkwin; /* Not used. */
|
| 1712 |
|
|
char *value; /* Textual specification of arrow shape. */
|
| 1713 |
|
|
char *recordPtr; /* Pointer to item record in which to
|
| 1714 |
|
|
* store arrow information. */
|
| 1715 |
|
|
int offset; /* Offset of shape information in widget
|
| 1716 |
|
|
* record. */
|
| 1717 |
|
|
{
|
| 1718 |
|
|
EdgeItem *edgePtr = (EdgeItem *) recordPtr;
|
| 1719 |
|
|
double a, b, c;
|
| 1720 |
|
|
int argc;
|
| 1721 |
|
|
char **argv = NULL;
|
| 1722 |
|
|
|
| 1723 |
|
|
if (offset != Tk_Offset(EdgeItem, arrowShapeA)) {
|
| 1724 |
|
|
panic("ParseArrowShape received bogus offset");
|
| 1725 |
|
|
}
|
| 1726 |
|
|
|
| 1727 |
|
|
if (Tcl_SplitList(interp, value, &argc, &argv) != TCL_OK) {
|
| 1728 |
|
|
syntaxError:
|
| 1729 |
|
|
Tcl_ResetResult(interp);
|
| 1730 |
|
|
Tcl_AppendResult(interp, "bad arrow shape \"", value,
|
| 1731 |
|
|
"\": must be list with three numbers", (char *) NULL);
|
| 1732 |
|
|
if (argv != NULL) {
|
| 1733 |
|
|
ckfree((char *) argv);
|
| 1734 |
|
|
}
|
| 1735 |
|
|
return TCL_ERROR;
|
| 1736 |
|
|
}
|
| 1737 |
|
|
if (argc != 3) {
|
| 1738 |
|
|
goto syntaxError;
|
| 1739 |
|
|
}
|
| 1740 |
|
|
if ((Tk_CanvasGetCoord(interp, edgePtr->canvas, argv[0], &a) != TCL_OK)
|
| 1741 |
|
|
|| (Tk_CanvasGetCoord(interp, edgePtr->canvas, argv[1], &b) != TCL_OK)
|
| 1742 |
|
|
|| (Tk_CanvasGetCoord(interp, edgePtr->canvas, argv[2], &c) != TCL_OK)) {
|
| 1743 |
|
|
goto syntaxError;
|
| 1744 |
|
|
}
|
| 1745 |
|
|
edgePtr->arrowShapeA = a;
|
| 1746 |
|
|
edgePtr->arrowShapeB = b;
|
| 1747 |
|
|
edgePtr->arrowShapeC = c;
|
| 1748 |
|
|
ckfree((char *) argv);
|
| 1749 |
|
|
return TCL_OK;
|
| 1750 |
|
|
}
|
| 1751 |
|
|
|
| 1752 |
|
|
/*
|
| 1753 |
|
|
*--------------------------------------------------------------
|
| 1754 |
|
|
*
|
| 1755 |
|
|
* PrintArrowShape --
|
| 1756 |
|
|
*
|
| 1757 |
|
|
* This procedure is a callback invoked by the configuration
|
| 1758 |
|
|
* code to return a printable value describing an arrow shape.
|
| 1759 |
|
|
*
|
| 1760 |
|
|
* Results:
|
| 1761 |
|
|
* None.
|
| 1762 |
|
|
*
|
| 1763 |
|
|
* Side effects:
|
| 1764 |
|
|
* None.
|
| 1765 |
|
|
*
|
| 1766 |
|
|
*--------------------------------------------------------------
|
| 1767 |
|
|
*/
|
| 1768 |
|
|
|
| 1769 |
|
|
/* ARGSUSED */
|
| 1770 |
|
|
static char *
|
| 1771 |
|
|
PrintArrowShape(clientData, tkwin, recordPtr, offset, freeProcPtr)
|
| 1772 |
|
|
ClientData clientData; /* Not used. */
|
| 1773 |
|
|
Tk_Window tkwin; /* Window associated with edgePtr's widget. */
|
| 1774 |
|
|
char *recordPtr; /* Pointer to item record containing current
|
| 1775 |
|
|
* shape information. */
|
| 1776 |
|
|
int offset; /* Offset of arrow information in record. */
|
| 1777 |
|
|
Tcl_FreeProc **freeProcPtr;/* Store address of procedure to call to
|
| 1778 |
|
|
* free string here. */
|
| 1779 |
|
|
{
|
| 1780 |
|
|
EdgeItem *edgePtr = (EdgeItem *) recordPtr;
|
| 1781 |
|
|
char *buffer;
|
| 1782 |
|
|
|
| 1783 |
|
|
buffer = ckalloc(120);
|
| 1784 |
|
|
sprintf(buffer, "%.5g %.5g %.5g", edgePtr->arrowShapeA,
|
| 1785 |
|
|
edgePtr->arrowShapeB, edgePtr->arrowShapeC);
|
| 1786 |
|
|
*freeProcPtr = (Tcl_FreeProc *) free;
|
| 1787 |
|
|
return buffer;
|
| 1788 |
|
|
}
|
| 1789 |
|
|
|
| 1790 |
|
|
/*
|
| 1791 |
|
|
*--------------------------------------------------------------
|
| 1792 |
|
|
*
|
| 1793 |
|
|
* ConfigureArrows --
|
| 1794 |
|
|
*
|
| 1795 |
|
|
* If arrowheads have been requested for a edge, this
|
| 1796 |
|
|
* procedure makes arrangements for the arrowheads.
|
| 1797 |
|
|
*
|
| 1798 |
|
|
* Results:
|
| 1799 |
|
|
* A standard Tcl return value. If an error occurs, then
|
| 1800 |
|
|
* an error message is left in interp->result.
|
| 1801 |
|
|
*
|
| 1802 |
|
|
* Side effects:
|
| 1803 |
|
|
* Information in edgePtr is set up for one or two arrowheads.
|
| 1804 |
|
|
* the firstArrowPtr and lastArrowPtr polygons are allocated
|
| 1805 |
|
|
* and initialized, if need be, and the end points of the edge
|
| 1806 |
|
|
* are adjusted so that a thick edge doesn't stick out past
|
| 1807 |
|
|
* the arrowheads.
|
| 1808 |
|
|
*
|
| 1809 |
|
|
*--------------------------------------------------------------
|
| 1810 |
|
|
*/
|
| 1811 |
|
|
|
| 1812 |
|
|
/* ARGSUSED */
|
| 1813 |
|
|
static int
|
| 1814 |
|
|
ConfigureArrows(canvas, edgePtr)
|
| 1815 |
|
|
Tk_Canvas canvas; /* Canvas in which arrows will be
|
| 1816 |
|
|
* displayed (interp and tkwin
|
| 1817 |
|
|
* fields are needed). */
|
| 1818 |
|
|
EdgeItem *edgePtr; /* Item to configure for arrows. */
|
| 1819 |
|
|
{
|
| 1820 |
|
|
double *poly, *coordPtr;
|
| 1821 |
|
|
double dx, dy, length, sinTheta, cosTheta, temp, shapeC;
|
| 1822 |
|
|
double fracHeight; /* Edge width as fraction of
|
| 1823 |
|
|
* arrowhead width. */
|
| 1824 |
|
|
double backup; /* Distance to backup end points
|
| 1825 |
|
|
* so the edge ends in the middle
|
| 1826 |
|
|
* of the arrowhead. */
|
| 1827 |
|
|
double vertX, vertY; /* Position of arrowhead vertex. */
|
| 1828 |
|
|
|
| 1829 |
|
|
/*
|
| 1830 |
|
|
* If there's an arrowhead on the first point of the edge, compute
|
| 1831 |
|
|
* its polygon and adjust the first point of the edge so that the
|
| 1832 |
|
|
* edge doesn't stick out past the leading edge of the arrowhead.
|
| 1833 |
|
|
*/
|
| 1834 |
|
|
|
| 1835 |
|
|
shapeC = edgePtr->arrowShapeC + edgePtr->width/2.0;
|
| 1836 |
|
|
fracHeight = (edgePtr->width/2.0)/shapeC;
|
| 1837 |
|
|
backup = fracHeight*edgePtr->arrowShapeB
|
| 1838 |
|
|
+ edgePtr->arrowShapeA*(1.0 - fracHeight)/2.0;
|
| 1839 |
|
|
if (edgePtr->arrow != lastUid) {
|
| 1840 |
|
|
poly = edgePtr->firstArrowPtr;
|
| 1841 |
|
|
if (poly == NULL) {
|
| 1842 |
|
|
poly = (double *) ckalloc((unsigned)
|
| 1843 |
|
|
(2*PTS_IN_ARROW*sizeof(double)));
|
| 1844 |
|
|
poly[0] = poly[10] = edgePtr->coordPtr[0];
|
| 1845 |
|
|
poly[1] = poly[11] = edgePtr->coordPtr[1];
|
| 1846 |
|
|
edgePtr->firstArrowPtr = poly;
|
| 1847 |
|
|
}
|
| 1848 |
|
|
dx = poly[0] - edgePtr->coordPtr[2];
|
| 1849 |
|
|
dy = poly[1] - edgePtr->coordPtr[3];
|
| 1850 |
|
|
length = hypot(dx, dy);
|
| 1851 |
|
|
if (length == 0) {
|
| 1852 |
|
|
sinTheta = cosTheta = 0.0;
|
| 1853 |
|
|
} else {
|
| 1854 |
|
|
sinTheta = dy/length;
|
| 1855 |
|
|
cosTheta = dx/length;
|
| 1856 |
|
|
}
|
| 1857 |
|
|
vertX = poly[0] - edgePtr->arrowShapeA*cosTheta;
|
| 1858 |
|
|
vertY = poly[1] - edgePtr->arrowShapeA*sinTheta;
|
| 1859 |
|
|
temp = shapeC*sinTheta;
|
| 1860 |
|
|
poly[2] = poly[0] - edgePtr->arrowShapeB*cosTheta + temp;
|
| 1861 |
|
|
poly[8] = poly[2] - 2*temp;
|
| 1862 |
|
|
temp = shapeC*cosTheta;
|
| 1863 |
|
|
poly[3] = poly[1] - edgePtr->arrowShapeB*sinTheta - temp;
|
| 1864 |
|
|
poly[9] = poly[3] + 2*temp;
|
| 1865 |
|
|
poly[4] = poly[2]*fracHeight + vertX*(1.0-fracHeight);
|
| 1866 |
|
|
poly[5] = poly[3]*fracHeight + vertY*(1.0-fracHeight);
|
| 1867 |
|
|
poly[6] = poly[8]*fracHeight + vertX*(1.0-fracHeight);
|
| 1868 |
|
|
poly[7] = poly[9]*fracHeight + vertY*(1.0-fracHeight);
|
| 1869 |
|
|
|
| 1870 |
|
|
/*
|
| 1871 |
|
|
* Polygon done. Now move the first point towards the second so
|
| 1872 |
|
|
* that the corners at the end of the edge are inside the
|
| 1873 |
|
|
* arrowhead.
|
| 1874 |
|
|
*/
|
| 1875 |
|
|
|
| 1876 |
|
|
edgePtr->coordPtr[0] = poly[0] - backup*cosTheta;
|
| 1877 |
|
|
edgePtr->coordPtr[1] = poly[1] - backup*sinTheta;
|
| 1878 |
|
|
}
|
| 1879 |
|
|
|
| 1880 |
|
|
/*
|
| 1881 |
|
|
* Similar arrowhead calculation for the last point of the edge.
|
| 1882 |
|
|
*/
|
| 1883 |
|
|
|
| 1884 |
|
|
if (edgePtr->arrow != firstUid) {
|
| 1885 |
|
|
coordPtr = edgePtr->coordPtr + 2*(edgePtr->numPoints-2);
|
| 1886 |
|
|
poly = edgePtr->lastArrowPtr;
|
| 1887 |
|
|
if (poly == NULL) {
|
| 1888 |
|
|
poly = (double *) ckalloc((unsigned)
|
| 1889 |
|
|
(2*PTS_IN_ARROW*sizeof(double)));
|
| 1890 |
|
|
poly[0] = poly[10] = coordPtr[2];
|
| 1891 |
|
|
poly[1] = poly[11] = coordPtr[3];
|
| 1892 |
|
|
edgePtr->lastArrowPtr = poly;
|
| 1893 |
|
|
}
|
| 1894 |
|
|
dx = poly[0] - coordPtr[0];
|
| 1895 |
|
|
dy = poly[1] - coordPtr[1];
|
| 1896 |
|
|
length = hypot(dx, dy);
|
| 1897 |
|
|
if (length == 0) {
|
| 1898 |
|
|
sinTheta = cosTheta = 0.0;
|
| 1899 |
|
|
} else {
|
| 1900 |
|
|
sinTheta = dy/length;
|
| 1901 |
|
|
cosTheta = dx/length;
|
| 1902 |
|
|
}
|
| 1903 |
|
|
vertX = poly[0] - edgePtr->arrowShapeA*cosTheta;
|
| 1904 |
|
|
vertY = poly[1] - edgePtr->arrowShapeA*sinTheta;
|
| 1905 |
|
|
temp = shapeC*sinTheta;
|
| 1906 |
|
|
poly[2] = poly[0] - edgePtr->arrowShapeB*cosTheta + temp;
|
| 1907 |
|
|
poly[8] = poly[2] - 2*temp;
|
| 1908 |
|
|
temp = shapeC*cosTheta;
|
| 1909 |
|
|
poly[3] = poly[1] - edgePtr->arrowShapeB*sinTheta - temp;
|
| 1910 |
|
|
poly[9] = poly[3] + 2*temp;
|
| 1911 |
|
|
poly[4] = poly[2]*fracHeight + vertX*(1.0-fracHeight);
|
| 1912 |
|
|
poly[5] = poly[3]*fracHeight + vertY*(1.0-fracHeight);
|
| 1913 |
|
|
poly[6] = poly[8]*fracHeight + vertX*(1.0-fracHeight);
|
| 1914 |
|
|
poly[7] = poly[9]*fracHeight + vertY*(1.0-fracHeight);
|
| 1915 |
|
|
coordPtr[2] = poly[0] - backup*cosTheta;
|
| 1916 |
|
|
coordPtr[3] = poly[1] - backup*sinTheta;
|
| 1917 |
|
|
}
|
| 1918 |
|
|
|
| 1919 |
|
|
return TCL_OK;
|
| 1920 |
|
|
}
|
| 1921 |
|
|
|
| 1922 |
|
|
/*
|
| 1923 |
|
|
*--------------------------------------------------------------
|
| 1924 |
|
|
*
|
| 1925 |
|
|
* EdgeToPostscript --
|
| 1926 |
|
|
*
|
| 1927 |
|
|
* This procedure is called to generate Postscript for
|
| 1928 |
|
|
* edge items.
|
| 1929 |
|
|
*
|
| 1930 |
|
|
* Results:
|
| 1931 |
|
|
* The return value is a standard Tcl result. If an error
|
| 1932 |
|
|
* occurs in generating Postscript then an error message is
|
| 1933 |
|
|
* left in interp->result, replacing whatever used
|
| 1934 |
|
|
* to be there. If no error occurs, then Postscript for the
|
| 1935 |
|
|
* item is appended to the result.
|
| 1936 |
|
|
*
|
| 1937 |
|
|
* Side effects:
|
| 1938 |
|
|
* None.
|
| 1939 |
|
|
*
|
| 1940 |
|
|
*--------------------------------------------------------------
|
| 1941 |
|
|
*/
|
| 1942 |
|
|
|
| 1943 |
|
|
static int
|
| 1944 |
|
|
EdgeToPostscript(interp, canvas, itemPtr, prepass)
|
| 1945 |
|
|
Tcl_Interp *interp; /* Leave Postscript or error message
|
| 1946 |
|
|
* here. */
|
| 1947 |
|
|
Tk_Canvas canvas; /* Information about overall canvas. */
|
| 1948 |
|
|
Tk_Item *itemPtr; /* Item for which Postscript is
|
| 1949 |
|
|
* wanted. */
|
| 1950 |
|
|
int prepass; /* 1 means this is a prepass to
|
| 1951 |
|
|
* collect font information; 0 means
|
| 1952 |
|
|
* final Postscript is being created. */
|
| 1953 |
|
|
{
|
| 1954 |
|
|
register EdgeItem *edgePtr = (EdgeItem *) itemPtr;
|
| 1955 |
|
|
char buffer[200];
|
| 1956 |
|
|
char *style;
|
| 1957 |
|
|
|
| 1958 |
|
|
if (edgePtr->fgColor == NULL) {
|
| 1959 |
|
|
return TCL_OK;
|
| 1960 |
|
|
}
|
| 1961 |
|
|
|
| 1962 |
|
|
/*
|
| 1963 |
|
|
* Generate a path for the edge's center-edge (do this differently
|
| 1964 |
|
|
* for straight edges and smoothed edges).
|
| 1965 |
|
|
*/
|
| 1966 |
|
|
|
| 1967 |
|
|
if (!edgePtr->smooth) {
|
| 1968 |
|
|
Tk_CanvasPsPath(interp, canvas, edgePtr->coordPtr, edgePtr->numPoints);
|
| 1969 |
|
|
} else {
|
| 1970 |
|
|
if (edgePtr->fillStipple == None) {
|
| 1971 |
|
|
TkMakeBezierPostscript(interp, canvas, edgePtr->coordPtr, edgePtr->numPoints);
|
| 1972 |
|
|
} else {
|
| 1973 |
|
|
/*
|
| 1974 |
|
|
* Special hack: Postscript printers don't appear to be able
|
| 1975 |
|
|
* to turn a path drawn with "curveto"s into a clipping path
|
| 1976 |
|
|
* without exceeding resource limits, so TkMakeBezierPostscript
|
| 1977 |
|
|
* won't work for stippled curves. Instead, generate all of
|
| 1978 |
|
|
* the intermediate points here and output them into the
|
| 1979 |
|
|
* Postscript file with "edgeto"s instead.
|
| 1980 |
|
|
*/
|
| 1981 |
|
|
|
| 1982 |
|
|
double staticPoints[2*MAX_STATIC_POINTS];
|
| 1983 |
|
|
double *pointPtr;
|
| 1984 |
|
|
int numPoints;
|
| 1985 |
|
|
|
| 1986 |
|
|
numPoints = 1 + edgePtr->numPoints*edgePtr->splineSteps;
|
| 1987 |
|
|
pointPtr = staticPoints;
|
| 1988 |
|
|
if (numPoints > MAX_STATIC_POINTS) {
|
| 1989 |
|
|
pointPtr = (double *) ckalloc((unsigned)
|
| 1990 |
|
|
(numPoints * 2 * sizeof(double)));
|
| 1991 |
|
|
}
|
| 1992 |
|
|
numPoints = TkMakeBezierCurve(canvas, edgePtr->coordPtr,
|
| 1993 |
|
|
edgePtr->numPoints,
|
| 1994 |
|
|
edgePtr->splineSteps, (XPoint *) NULL,
|
| 1995 |
|
|
pointPtr);
|
| 1996 |
|
|
Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints);
|
| 1997 |
|
|
if (pointPtr != staticPoints) {
|
| 1998 |
|
|
ckfree((char *) pointPtr);
|
| 1999 |
|
|
}
|
| 2000 |
|
|
}
|
| 2001 |
|
|
}
|
| 2002 |
|
|
|
| 2003 |
|
|
/*
|
| 2004 |
|
|
* Set other edge-drawing parameters and stroke out the edge.
|
| 2005 |
|
|
*/
|
| 2006 |
|
|
|
| 2007 |
|
|
sprintf(buffer, "%d setlinewidth\n", edgePtr->width);
|
| 2008 |
|
|
Tcl_AppendResult(interp, buffer, (char *) NULL);
|
| 2009 |
|
|
style = "0 setlinecap\n";
|
| 2010 |
|
|
if (edgePtr->capStyle == CapRound) {
|
| 2011 |
|
|
style = "1 setlinecap\n";
|
| 2012 |
|
|
} else if (edgePtr->capStyle == CapProjecting) {
|
| 2013 |
|
|
style = "2 setlinecap\n";
|
| 2014 |
|
|
}
|
| 2015 |
|
|
Tcl_AppendResult(interp, style, (char *) NULL);
|
| 2016 |
|
|
style = "0 setlinejoin\n";
|
| 2017 |
|
|
if (edgePtr->joinStyle == JoinRound) {
|
| 2018 |
|
|
style = "1 setlinejoin\n";
|
| 2019 |
|
|
} else if (edgePtr->joinStyle == JoinBevel) {
|
| 2020 |
|
|
style = "2 setlinejoin\n";
|
| 2021 |
|
|
}
|
| 2022 |
|
|
Tcl_AppendResult(interp, style, (char *) NULL);
|
| 2023 |
|
|
if (Tk_CanvasPsColor(interp, canvas, edgePtr->fgColor) != TCL_OK) {
|
| 2024 |
|
|
return TCL_ERROR;
|
| 2025 |
|
|
};
|
| 2026 |
|
|
if (edgePtr->fillStipple != None) {
|
| 2027 |
|
|
if (Tk_CanvasPsStipple(interp, canvas, edgePtr->fillStipple)
|
| 2028 |
|
|
!= TCL_OK) {
|
| 2029 |
|
|
return TCL_ERROR;
|
| 2030 |
|
|
}
|
| 2031 |
|
|
} else {
|
| 2032 |
|
|
Tcl_AppendResult(interp, "stroke\n", (char *) NULL);
|
| 2033 |
|
|
}
|
| 2034 |
|
|
|
| 2035 |
|
|
/*
|
| 2036 |
|
|
* Output polygons for the arrowheads, if there are any.
|
| 2037 |
|
|
*/
|
| 2038 |
|
|
|
| 2039 |
|
|
if (edgePtr->firstArrowPtr != NULL) {
|
| 2040 |
|
|
if (ArrowheadPostscript(interp, canvas, edgePtr, edgePtr->firstArrowPtr) !=
|
| 2041 |
|
|
TCL_OK) {
|
| 2042 |
|
|
return TCL_ERROR;
|
| 2043 |
|
|
}
|
| 2044 |
|
|
}
|
| 2045 |
|
|
if (edgePtr->lastArrowPtr != NULL) {
|
| 2046 |
|
|
if (ArrowheadPostscript(interp, canvas, edgePtr, edgePtr->lastArrowPtr) !=
|
| 2047 |
|
|
TCL_OK) {
|
| 2048 |
|
|
return TCL_ERROR;
|
| 2049 |
|
|
}
|
| 2050 |
|
|
}
|
| 2051 |
|
|
return TCL_OK;
|
| 2052 |
|
|
}
|
| 2053 |
|
|
|
| 2054 |
|
|
/*
|
| 2055 |
|
|
*--------------------------------------------------------------
|
| 2056 |
|
|
*
|
| 2057 |
|
|
* ArrowheadPostscript --
|
| 2058 |
|
|
*
|
| 2059 |
|
|
* This procedure is called to generate Postscript for
|
| 2060 |
|
|
* an arrowhead for a edge item.
|
| 2061 |
|
|
*
|
| 2062 |
|
|
* Results:
|
| 2063 |
|
|
* The return value is a standard Tcl result. If an error
|
| 2064 |
|
|
* occurs in generating Postscript then an error message is
|
| 2065 |
|
|
* left in interp->result, replacing whatever used
|
| 2066 |
|
|
* to be there. If no error occurs, then Postscript for the
|
| 2067 |
|
|
* arrowhead is appended to the result.
|
| 2068 |
|
|
*
|
| 2069 |
|
|
* Side effects:
|
| 2070 |
|
|
* None.
|
| 2071 |
|
|
*
|
| 2072 |
|
|
*--------------------------------------------------------------
|
| 2073 |
|
|
*/
|
| 2074 |
|
|
|
| 2075 |
|
|
static int
|
| 2076 |
|
|
ArrowheadPostscript(interp, canvas, edgePtr, arrowPtr)
|
| 2077 |
|
|
Tcl_Interp *interp; /* Leave Postscript or error message
|
| 2078 |
|
|
* here. */
|
| 2079 |
|
|
Tk_Canvas canvas; /* Information about overall canvas. */
|
| 2080 |
|
|
EdgeItem *edgePtr; /* Edge item for which Postscript is
|
| 2081 |
|
|
* being generated. */
|
| 2082 |
|
|
double *arrowPtr; /* Pointer to first of five points
|
| 2083 |
|
|
* describing arrowhead polygon. */
|
| 2084 |
|
|
{
|
| 2085 |
|
|
Tk_CanvasPsPath(interp, canvas, arrowPtr, PTS_IN_ARROW);
|
| 2086 |
|
|
if (edgePtr->fillStipple != None) {
|
| 2087 |
|
|
if (Tk_CanvasPsStipple(interp, canvas, edgePtr->fillStipple)
|
| 2088 |
|
|
!= TCL_OK) {
|
| 2089 |
|
|
return TCL_ERROR;
|
| 2090 |
|
|
}
|
| 2091 |
|
|
} else {
|
| 2092 |
|
|
Tcl_AppendResult(interp, "fill\n", (char *) NULL);
|
| 2093 |
|
|
}
|
| 2094 |
|
|
return TCL_OK;
|
| 2095 |
|
|
}
|