| 1 |
|
| 2 |
/* |
| 3 |
* bltGrMarker.c -- |
| 4 |
* |
| 5 |
* This module implements markers for the BLT graph widget. |
| 6 |
* |
| 7 |
* Copyright 1993-1998 Lucent Technologies, Inc. |
| 8 |
* |
| 9 |
* Permission to use, copy, modify, and distribute this software and |
| 10 |
* its documentation for any purpose and without fee is hereby |
| 11 |
* granted, provided that the above copyright notice appear in all |
| 12 |
* copies and that both that the copyright notice and warranty |
| 13 |
* disclaimer appear in supporting documentation, and that the names |
| 14 |
* of Lucent Technologies any of their entities not be used in |
| 15 |
* advertising or publicity pertaining to distribution of the software |
| 16 |
* without specific, written prior permission. |
| 17 |
* |
| 18 |
* Lucent Technologies disclaims all warranties with regard to this |
| 19 |
* software, including all implied warranties of merchantability and |
| 20 |
* fitness. In no event shall Lucent Technologies be liable for any |
| 21 |
* special, indirect or consequential damages or any damages |
| 22 |
* whatsoever resulting from loss of use, data or profits, whether in |
| 23 |
* an action of contract, negligence or other tortuous action, arising |
| 24 |
* out of or in connection with the use or performance of this |
| 25 |
* software. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "bltGraph.h" |
| 29 |
#include "bltChain.h" |
| 30 |
#include "bltGrElem.h" |
| 31 |
|
| 32 |
#define GETBITMAP(b) \ |
| 33 |
(((b)->destBitmap == None) ? (b)->srcBitmap : (b)->destBitmap) |
| 34 |
|
| 35 |
#define MAX_OUTLINE_POINTS 12 |
| 36 |
|
| 37 |
/* Map graph coordinates to normalized coordinates [0..1] */ |
| 38 |
#define NORMALIZE(A,x) (((x) - (A)->axisRange.min) / (A)->axisRange.range) |
| 39 |
|
| 40 |
#define DEF_MARKER_ANCHOR "center" |
| 41 |
#define DEF_MARKER_BACKGROUND RGB_WHITE |
| 42 |
#define DEF_MARKER_BG_MONO RGB_WHITE |
| 43 |
#define DEF_MARKER_BITMAP (char *)NULL |
| 44 |
#define DEF_MARKER_CAP_STYLE "butt" |
| 45 |
#define DEF_MARKER_COORDS (char *)NULL |
| 46 |
#define DEF_MARKER_DASHES (char *)NULL |
| 47 |
#define DEF_MARKER_DASH_OFFSET "0" |
| 48 |
#define DEF_MARKER_ELEMENT (char *)NULL |
| 49 |
#define DEF_MARKER_FOREGROUND RGB_BLACK |
| 50 |
#define DEF_MARKER_FG_MONO RGB_BLACK |
| 51 |
#define DEF_MARKER_FILL_COLOR RGB_RED |
| 52 |
#define DEF_MARKER_FILL_MONO RGB_WHITE |
| 53 |
#define DEF_MARKER_FONT STD_FONT |
| 54 |
#define DEF_MARKER_GAP_COLOR RGB_PINK |
| 55 |
#define DEF_MARKER_GAP_MONO RGB_BLACK |
| 56 |
#define DEF_MARKER_HEIGHT "0" |
| 57 |
#define DEF_MARKER_HIDE "no" |
| 58 |
#define DEF_MARKER_JOIN_STYLE "miter" |
| 59 |
#define DEF_MARKER_JUSTIFY "left" |
| 60 |
#define DEF_MARKER_LINE_WIDTH "1" |
| 61 |
#define DEF_MARKER_MAP_X "x" |
| 62 |
#define DEF_MARKER_MAP_Y "y" |
| 63 |
#define DEF_MARKER_NAME (char *)NULL |
| 64 |
#define DEF_MARKER_OUTLINE_COLOR RGB_BLACK |
| 65 |
#define DEF_MARKER_OUTLINE_MONO RGB_BLACK |
| 66 |
#define DEF_MARKER_PAD "4" |
| 67 |
#define DEF_MARKER_ROTATE "0.0" |
| 68 |
#define DEF_MARKER_SCALE "1.0" |
| 69 |
#define DEF_MARKER_SHADOW_COLOR (char *)NULL |
| 70 |
#define DEF_MARKER_SHADOW_MONO (char *)NULL |
| 71 |
#define DEF_MARKER_STATE "normal" |
| 72 |
#define DEF_MARKER_STIPPLE (char *)NULL |
| 73 |
#define DEF_MARKER_TEXT (char *)NULL |
| 74 |
#define DEF_MARKER_UNDER "no" |
| 75 |
#define DEF_MARKER_WIDTH "0" |
| 76 |
#define DEF_MARKER_WINDOW (char *)NULL |
| 77 |
#define DEF_MARKER_XOR "no" |
| 78 |
#define DEF_MARKER_X_OFFSET "0" |
| 79 |
#define DEF_MARKER_Y_OFFSET "0" |
| 80 |
|
| 81 |
#define DEF_MARKER_TEXT_TAGS "Text all" |
| 82 |
#define DEF_MARKER_IMAGE_TAGS "Image all" |
| 83 |
#define DEF_MARKER_BITMAP_TAGS "Bitmap all" |
| 84 |
#define DEF_MARKER_WINDOW_TAGS "Window all" |
| 85 |
#define DEF_MARKER_POLYGON_TAGS "Polygon all" |
| 86 |
#define DEF_MARKER_LINE_TAGS "Line all" |
| 87 |
|
| 88 |
static Tk_OptionParseProc StringToCoordinates; |
| 89 |
static Tk_OptionPrintProc CoordinatesToString; |
| 90 |
static Tk_CustomOption coordsOption = |
| 91 |
{ |
| 92 |
StringToCoordinates, CoordinatesToString, (ClientData)0 |
| 93 |
}; |
| 94 |
extern Tk_CustomOption bltColorPairOption; |
| 95 |
extern Tk_CustomOption bltDashesOption; |
| 96 |
extern Tk_CustomOption bltDistanceOption; |
| 97 |
extern Tk_CustomOption bltListOption; |
| 98 |
extern Tk_CustomOption bltPadOption; |
| 99 |
extern Tk_CustomOption bltPositiveDistanceOption; |
| 100 |
extern Tk_CustomOption bltShadowOption; |
| 101 |
extern Tk_CustomOption bltStateOption; |
| 102 |
extern Tk_CustomOption bltXAxisOption; |
| 103 |
extern Tk_CustomOption bltYAxisOption; |
| 104 |
|
| 105 |
typedef Marker *(MarkerCreateProc) _ANSI_ARGS_((void)); |
| 106 |
typedef void (MarkerDrawProc) _ANSI_ARGS_((Marker *markerPtr, |
| 107 |
Drawable drawable)); |
| 108 |
typedef void (MarkerFreeProc) _ANSI_ARGS_((Graph *graphPtr, Marker *markerPtr)); |
| 109 |
typedef int (MarkerConfigProc) _ANSI_ARGS_((Marker *markerPtr)); |
| 110 |
typedef void (MarkerMapProc) _ANSI_ARGS_((Marker *markerPtr)); |
| 111 |
typedef void (MarkerPostScriptProc) _ANSI_ARGS_((Marker *markerPtr, |
| 112 |
PsToken psToken)); |
| 113 |
typedef int (MarkerPointProc) _ANSI_ARGS_((Marker *markerPtr, |
| 114 |
Point2D *samplePtr)); |
| 115 |
typedef int (MarkerRegionProc) _ANSI_ARGS_((Marker *markerPtr, |
| 116 |
Extents2D *extsPtr, int enclosed)); |
| 117 |
|
| 118 |
typedef struct { |
| 119 |
Tk_ConfigSpec *configSpecs; /* Marker configuration specifications */ |
| 120 |
|
| 121 |
MarkerConfigProc *configProc; |
| 122 |
MarkerDrawProc *drawProc; |
| 123 |
MarkerFreeProc *freeProc; |
| 124 |
MarkerMapProc *mapProc; |
| 125 |
MarkerPointProc *pointProc; |
| 126 |
MarkerRegionProc *regionProc; |
| 127 |
MarkerPostScriptProc *postscriptProc; |
| 128 |
|
| 129 |
} MarkerClass; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
/* |
| 134 |
* ------------------------------------------------------------------- |
| 135 |
* |
| 136 |
* Marker -- |
| 137 |
* |
| 138 |
* Structure defining the generic marker. In C++ parlance this |
| 139 |
* would be the base type from which all markers are derived. |
| 140 |
* |
| 141 |
* This structure corresponds with the specific types of markers. |
| 142 |
* Don't change this structure without changing the individual |
| 143 |
* marker structures of each type below. |
| 144 |
* |
| 145 |
* ------------------------------------------------------------------- |
| 146 |
*/ |
| 147 |
struct MarkerStruct { |
| 148 |
char *name; /* Identifier for marker in list */ |
| 149 |
|
| 150 |
Blt_Uid classUid; /* Type of marker. */ |
| 151 |
|
| 152 |
Graph *graphPtr; /* Graph widget of marker. */ |
| 153 |
|
| 154 |
unsigned int flags; |
| 155 |
|
| 156 |
char **tags; |
| 157 |
|
| 158 |
int hidden; /* If non-zero, don't display the marker. */ |
| 159 |
|
| 160 |
Blt_HashEntry *hashPtr; |
| 161 |
|
| 162 |
Blt_ChainLink *linkPtr; |
| 163 |
|
| 164 |
Point2D *worldPts; /* Coordinate array to position marker */ |
| 165 |
int nWorldPts; /* Number of points in above array */ |
| 166 |
|
| 167 |
char *elemName; /* Element associated with marker */ |
| 168 |
|
| 169 |
Axis2D axes; |
| 170 |
|
| 171 |
int drawUnder; /* If non-zero, draw the marker |
| 172 |
* underneath any elements. This can |
| 173 |
* be a performance penalty because |
| 174 |
* the graph must be redraw entirely |
| 175 |
* each time the marker is redrawn. */ |
| 176 |
|
| 177 |
int clipped; /* Indicates if the marker is totally |
| 178 |
* clipped by the plotting area. */ |
| 179 |
|
| 180 |
int xOffset, yOffset; /* Pixel offset from graph position */ |
| 181 |
|
| 182 |
MarkerClass *classPtr; |
| 183 |
|
| 184 |
int state; |
| 185 |
}; |
| 186 |
|
| 187 |
/* |
| 188 |
* ------------------------------------------------------------------- |
| 189 |
* |
| 190 |
* TextMarker -- |
| 191 |
* |
| 192 |
* ------------------------------------------------------------------- |
| 193 |
*/ |
| 194 |
typedef struct { |
| 195 |
char *name; /* Identifier for marker */ |
| 196 |
Blt_Uid classUid; /* Type of marker */ |
| 197 |
Graph *graphPtr; /* The graph this marker belongs to */ |
| 198 |
unsigned int flags; |
| 199 |
char **tags; |
| 200 |
int hidden; /* If non-zero, don't display the |
| 201 |
* marker. */ |
| 202 |
|
| 203 |
Blt_HashEntry *hashPtr; |
| 204 |
Blt_ChainLink *linkPtr; |
| 205 |
|
| 206 |
Point2D *worldPts; /* Position of marker (1 X-Y coordinate) in |
| 207 |
* world (graph) coordinates. */ |
| 208 |
int nWorldPts; /* Number of points */ |
| 209 |
|
| 210 |
char *elemName; /* Element associated with marker */ |
| 211 |
Axis2D axes; |
| 212 |
int drawUnder; /* If non-zero, draw the marker |
| 213 |
* underneath any elements. There can |
| 214 |
* be a performance because the graph |
| 215 |
* must be redraw entirely each time |
| 216 |
* this marker is redrawn. */ |
| 217 |
int clipped; /* Indicates if the marker is totally |
| 218 |
* clipped by the plotting area. */ |
| 219 |
int xOffset, yOffset; /* pixel offset from anchor */ |
| 220 |
|
| 221 |
MarkerClass *classPtr; |
| 222 |
|
| 223 |
int state; |
| 224 |
/* |
| 225 |
* Text specific fields and attributes |
| 226 |
*/ |
| 227 |
#ifdef notdef |
| 228 |
char *textVarName; /* Name of variable (malloc'ed) or |
| 229 |
* NULL. If non-NULL, graph displays |
| 230 |
* the contents of this variable. */ |
| 231 |
#endif |
| 232 |
char *string; /* Text string to be display. The string |
| 233 |
* make contain newlines. */ |
| 234 |
|
| 235 |
Tk_Anchor anchor; /* Indicates how to translate the given |
| 236 |
* marker position. */ |
| 237 |
|
| 238 |
Point2D anchorPos; /* Translated anchor point. */ |
| 239 |
|
| 240 |
int width, height; /* Dimension of bounding box. */ |
| 241 |
|
| 242 |
TextStyle style; /* Text attributes (font, fg, anchor, etc) */ |
| 243 |
|
| 244 |
TextLayout *textPtr; /* Contains information about the layout |
| 245 |
* of the text. */ |
| 246 |
Point2D outline[5]; |
| 247 |
XColor *fillColor; |
| 248 |
GC fillGC; |
| 249 |
} TextMarker; |
| 250 |
|
| 251 |
|
| 252 |
static Tk_ConfigSpec textConfigSpecs[] = |
| 253 |
{ |
| 254 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 255 |
DEF_MARKER_ANCHOR, Tk_Offset(TextMarker, anchor), 0}, |
| 256 |
{TK_CONFIG_COLOR, "-background", "background", "MarkerBackground", |
| 257 |
(char *)NULL, Tk_Offset(TextMarker, fillColor), |
| 258 |
TK_CONFIG_NULL_OK}, |
| 259 |
{TK_CONFIG_SYNONYM, "-bg", "background", "Background", |
| 260 |
(char *)NULL, 0, 0}, |
| 261 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 262 |
DEF_MARKER_TEXT_TAGS, Tk_Offset(Marker, tags), |
| 263 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 264 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 265 |
DEF_MARKER_COORDS, Tk_Offset(Marker, worldPts), |
| 266 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 267 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 268 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 269 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", "Foreground", |
| 270 |
(char *)NULL, 0, 0}, |
| 271 |
{TK_CONFIG_SYNONYM, "-fill", "background", (char *)NULL, |
| 272 |
(char *)NULL, 0, 0}, |
| 273 |
{TK_CONFIG_FONT, "-font", "font", "Font", |
| 274 |
DEF_MARKER_FONT, Tk_Offset(TextMarker, style.font), 0}, |
| 275 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 276 |
DEF_MARKER_FOREGROUND, Tk_Offset(TextMarker, style.color), |
| 277 |
TK_CONFIG_COLOR_ONLY}, |
| 278 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 279 |
DEF_MARKER_FG_MONO, Tk_Offset(TextMarker, style.color), |
| 280 |
TK_CONFIG_MONO_ONLY}, |
| 281 |
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", |
| 282 |
DEF_MARKER_JUSTIFY, Tk_Offset(TextMarker, style.justify), |
| 283 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 284 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 285 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 286 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 287 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 288 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 289 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 290 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 291 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 292 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 293 |
{TK_CONFIG_SYNONYM, "-outline", "foreground", (char *)NULL, |
| 294 |
(char *)NULL, 0, 0}, |
| 295 |
{TK_CONFIG_CUSTOM, "-padx", "padX", "PadX", |
| 296 |
DEF_MARKER_PAD, Tk_Offset(TextMarker, style.padX), |
| 297 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption}, |
| 298 |
{TK_CONFIG_CUSTOM, "-pady", "padY", "PadY", |
| 299 |
DEF_MARKER_PAD, Tk_Offset(TextMarker, style.padY), |
| 300 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption}, |
| 301 |
{TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate", |
| 302 |
DEF_MARKER_ROTATE, Tk_Offset(TextMarker, style.theta), |
| 303 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 304 |
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow", |
| 305 |
DEF_MARKER_SHADOW_COLOR, Tk_Offset(TextMarker, style.shadow), |
| 306 |
TK_CONFIG_COLOR_ONLY, &bltShadowOption}, |
| 307 |
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow", |
| 308 |
DEF_MARKER_SHADOW_MONO, Tk_Offset(TextMarker, style.shadow), |
| 309 |
TK_CONFIG_MONO_ONLY, &bltShadowOption}, |
| 310 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 311 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 312 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 313 |
{TK_CONFIG_STRING, "-text", "text", "Text", |
| 314 |
DEF_MARKER_TEXT, Tk_Offset(TextMarker, string), TK_CONFIG_NULL_OK}, |
| 315 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 316 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 317 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 318 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 319 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 320 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 321 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 322 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 323 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 324 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 325 |
}; |
| 326 |
|
| 327 |
|
| 328 |
/* |
| 329 |
* ------------------------------------------------------------------- |
| 330 |
* |
| 331 |
* WindowMarker -- |
| 332 |
* |
| 333 |
* ------------------------------------------------------------------- |
| 334 |
*/ |
| 335 |
typedef struct { |
| 336 |
char *name; /* Identifier for marker */ |
| 337 |
Blt_Uid classUid; /* Type of marker */ |
| 338 |
Graph *graphPtr; /* Graph marker belongs to */ |
| 339 |
unsigned int flags; |
| 340 |
char **tags; |
| 341 |
int hidden; /* Indicates if the marker is |
| 342 |
* currently hidden or not. */ |
| 343 |
|
| 344 |
Blt_HashEntry *hashPtr; |
| 345 |
Blt_ChainLink *linkPtr; |
| 346 |
|
| 347 |
Point2D *worldPts; /* Position of marker (1 X-Y coordinate) in |
| 348 |
* world (graph) coordinates. */ |
| 349 |
int nWorldPts; /* Number of points */ |
| 350 |
|
| 351 |
char *elemName; /* Element associated with marker */ |
| 352 |
Axis2D axes; |
| 353 |
int drawUnder; /* If non-zero, draw the marker |
| 354 |
* underneath any elements. There can |
| 355 |
* be a performance because the graph |
| 356 |
* must be redraw entirely each time |
| 357 |
* this marker is redrawn. */ |
| 358 |
int clipped; /* Indicates if the marker is totally |
| 359 |
* clipped by the plotting area. */ |
| 360 |
int xOffset, yOffset; /* Pixel offset from anchor. */ |
| 361 |
|
| 362 |
MarkerClass *classPtr; |
| 363 |
|
| 364 |
int state; |
| 365 |
|
| 366 |
/* |
| 367 |
* Window specific attributes |
| 368 |
*/ |
| 369 |
char *pathName; /* Name of child widget to be displayed. */ |
| 370 |
Tk_Window tkwin; /* Window to display. */ |
| 371 |
int reqWidth, reqHeight; /* If non-zero, this overrides the size |
| 372 |
* requested by the child widget. */ |
| 373 |
|
| 374 |
Tk_Anchor anchor; /* Indicates how to translate the given |
| 375 |
* marker position. */ |
| 376 |
|
| 377 |
Point2D anchorPos; /* Translated anchor point. */ |
| 378 |
int width, height; /* Current size of the child window. */ |
| 379 |
|
| 380 |
} WindowMarker; |
| 381 |
|
| 382 |
static Tk_ConfigSpec windowConfigSpecs[] = |
| 383 |
{ |
| 384 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 385 |
DEF_MARKER_ANCHOR, Tk_Offset(WindowMarker, anchor), 0}, |
| 386 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 387 |
DEF_MARKER_WINDOW_TAGS, Tk_Offset(Marker, tags), |
| 388 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 389 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 390 |
DEF_MARKER_COORDS, Tk_Offset(WindowMarker, worldPts), |
| 391 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 392 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 393 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 394 |
{TK_CONFIG_CUSTOM, "-height", "height", "Height", |
| 395 |
DEF_MARKER_HEIGHT, Tk_Offset(WindowMarker, reqHeight), |
| 396 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveDistanceOption}, |
| 397 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 398 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 399 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 400 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 401 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 402 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 403 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 404 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 405 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 406 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 407 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 408 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 409 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 410 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 411 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 412 |
{TK_CONFIG_CUSTOM, "-width", "width", "Width", |
| 413 |
DEF_MARKER_WIDTH, Tk_Offset(WindowMarker, reqWidth), |
| 414 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveDistanceOption}, |
| 415 |
{TK_CONFIG_STRING, "-window", "window", "Window", |
| 416 |
DEF_MARKER_WINDOW, Tk_Offset(WindowMarker, pathName), |
| 417 |
TK_CONFIG_NULL_OK}, |
| 418 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 419 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 420 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 421 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 422 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 423 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 424 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 425 |
}; |
| 426 |
|
| 427 |
/* |
| 428 |
* ------------------------------------------------------------------- |
| 429 |
* |
| 430 |
* BitmapMarker -- |
| 431 |
* |
| 432 |
* ------------------------------------------------------------------- |
| 433 |
*/ |
| 434 |
typedef struct { |
| 435 |
char *name; /* Identifier for marker */ |
| 436 |
Blt_Uid classUid; /* Type of marker */ |
| 437 |
Graph *graphPtr; /* Graph marker belongs to */ |
| 438 |
unsigned int flags; |
| 439 |
char **tags; |
| 440 |
int hidden; /* Indicates if the marker is currently |
| 441 |
* hidden or not. */ |
| 442 |
|
| 443 |
Blt_HashEntry *hashPtr; |
| 444 |
Blt_ChainLink *linkPtr; |
| 445 |
|
| 446 |
Point2D *worldPts; /* Position of marker in world (graph) |
| 447 |
* coordinates. If 2 pairs of X-Y |
| 448 |
* coordinates are specified, then the |
| 449 |
* bitmap is resized to fit this area. |
| 450 |
* Otherwise if 1 pair, then the bitmap |
| 451 |
* is positioned at the coordinate at its |
| 452 |
* normal size. */ |
| 453 |
int nWorldPts; /* Number of points */ |
| 454 |
|
| 455 |
char *elemName; /* Element associated with marker */ |
| 456 |
Axis2D axes; |
| 457 |
int drawUnder; /* If non-zero, draw the marker |
| 458 |
* underneath any elements. There can |
| 459 |
* be a performance because the graph |
| 460 |
* must be redraw entirely each time |
| 461 |
* this marker is redrawn. */ |
| 462 |
|
| 463 |
int clipped; /* Indicates if the marker is totally |
| 464 |
* clipped by the plotting area. */ |
| 465 |
|
| 466 |
int xOffset, yOffset; /* Pixel offset from origin of bitmap */ |
| 467 |
|
| 468 |
MarkerClass *classPtr; |
| 469 |
|
| 470 |
int state; |
| 471 |
|
| 472 |
/* Bitmap specific attributes */ |
| 473 |
Pixmap srcBitmap; /* Original bitmap. May be further |
| 474 |
* scaled or rotated. */ |
| 475 |
double rotate; /* Requested rotation of the bitmap */ |
| 476 |
double theta; /* Normalized rotation (0..360 |
| 477 |
* degrees) */ |
| 478 |
Tk_Anchor anchor; /* If only one X-Y coordinate is |
| 479 |
* given, indicates how to translate |
| 480 |
* the given marker position. Otherwise, |
| 481 |
* if there are two X-Y coordinates, then |
| 482 |
* this value is ignored. */ |
| 483 |
Point2D anchorPos; /* Translated anchor point. */ |
| 484 |
|
| 485 |
XColor *outlineColor; /* Foreground color */ |
| 486 |
XColor *fillColor; /* Background color */ |
| 487 |
|
| 488 |
GC gc; /* Private graphic context */ |
| 489 |
GC fillGC; /* Shared graphic context */ |
| 490 |
Pixmap destBitmap; /* Bitmap to be drawn. */ |
| 491 |
int destWidth, destHeight; /* Dimensions of the final bitmap */ |
| 492 |
|
| 493 |
Point2D outline[MAX_OUTLINE_POINTS]; |
| 494 |
/* Polygon representing the background |
| 495 |
* of the bitmap. */ |
| 496 |
int nOutlinePts; |
| 497 |
} BitmapMarker; |
| 498 |
|
| 499 |
static Tk_ConfigSpec bitmapConfigSpecs[] = |
| 500 |
{ |
| 501 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 502 |
DEF_MARKER_ANCHOR, Tk_Offset(BitmapMarker, anchor), 0}, |
| 503 |
{TK_CONFIG_COLOR, "-background", "background", "Background", |
| 504 |
DEF_MARKER_BACKGROUND, Tk_Offset(BitmapMarker, fillColor), |
| 505 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 506 |
{TK_CONFIG_COLOR, "-background", "background", "Background", |
| 507 |
DEF_MARKER_BG_MONO, Tk_Offset(BitmapMarker, fillColor), |
| 508 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 509 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, |
| 510 |
(char *)NULL, 0, 0}, |
| 511 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 512 |
DEF_MARKER_BITMAP_TAGS, Tk_Offset(Marker, tags), |
| 513 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 514 |
{TK_CONFIG_BITMAP, "-bitmap", "bitmap", "Bitmap", |
| 515 |
DEF_MARKER_BITMAP, Tk_Offset(BitmapMarker, srcBitmap), |
| 516 |
TK_CONFIG_NULL_OK}, |
| 517 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 518 |
DEF_MARKER_COORDS, Tk_Offset(Marker, worldPts), |
| 519 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 520 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 521 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 522 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *)NULL, |
| 523 |
(char *)NULL, 0, 0}, |
| 524 |
{TK_CONFIG_SYNONYM, "-fill", "background", (char *)NULL, |
| 525 |
(char *)NULL, 0, 0}, |
| 526 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 527 |
DEF_MARKER_FOREGROUND, Tk_Offset(BitmapMarker, outlineColor), |
| 528 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 529 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 530 |
DEF_MARKER_FG_MONO, Tk_Offset(BitmapMarker, outlineColor), |
| 531 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 532 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 533 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 534 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 535 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 536 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 537 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 538 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 539 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 540 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 541 |
{TK_CONFIG_SYNONYM, "-outline", "foreground", (char *)NULL, |
| 542 |
(char *)NULL, 0, 0}, |
| 543 |
{TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate", |
| 544 |
DEF_MARKER_ROTATE, Tk_Offset(BitmapMarker, rotate), |
| 545 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 546 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 547 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 548 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 549 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 550 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 551 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 552 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 553 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 554 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 555 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 556 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 557 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 558 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 559 |
}; |
| 560 |
|
| 561 |
|
| 562 |
/* |
| 563 |
* ------------------------------------------------------------------- |
| 564 |
* |
| 565 |
* ImageMarker -- |
| 566 |
* |
| 567 |
* ------------------------------------------------------------------- |
| 568 |
*/ |
| 569 |
typedef struct { |
| 570 |
char *name; /* Identifier for marker */ |
| 571 |
Blt_Uid classUid; /* Type of marker */ |
| 572 |
Graph *graphPtr; /* Graph marker belongs to */ |
| 573 |
unsigned int flags; |
| 574 |
char **tags; |
| 575 |
int hidden; /* Indicates if the marker is |
| 576 |
* currently hidden or not. */ |
| 577 |
|
| 578 |
Blt_HashEntry *hashPtr; |
| 579 |
Blt_ChainLink *linkPtr; |
| 580 |
Point2D *worldPts; /* Position of marker in world (graph) |
| 581 |
* coordinates. If 2 pairs of X-Y |
| 582 |
* coordinates are specified, then the |
| 583 |
* image is resized to fit this area. |
| 584 |
* Otherwise if 1 pair, then the image |
| 585 |
* is positioned at the coordinate at |
| 586 |
* its normal size. */ |
| 587 |
int nWorldPts; /* Number of points */ |
| 588 |
|
| 589 |
char *elemName; /* Element associated with marker */ |
| 590 |
Axis2D axes; |
| 591 |
int drawUnder; /* If non-zero, draw the marker |
| 592 |
* underneath any elements. There can |
| 593 |
* be a performance because the graph |
| 594 |
* must be redraw entirely each time |
| 595 |
* this marker is redrawn. */ |
| 596 |
int clipped; /* Indicates if the marker is totally |
| 597 |
* clipped by the plotting area. */ |
| 598 |
int xOffset, yOffset; /* Pixel offset from anchor */ |
| 599 |
|
| 600 |
MarkerClass *classPtr; |
| 601 |
|
| 602 |
int state; |
| 603 |
|
| 604 |
/* Image specific attributes */ |
| 605 |
char *imageName; /* Name of image to be displayed. */ |
| 606 |
Tk_Image tkImage; /* Tk image to be displayed. */ |
| 607 |
Tk_Anchor anchor; /* Indicates how to translate the given |
| 608 |
* marker position. */ |
| 609 |
Point2D anchorPos; /* Translated anchor point. */ |
| 610 |
int width, height; /* Dimensions of the image */ |
| 611 |
Tk_Image tmpImage; |
| 612 |
Pixmap pixmap; /* Pixmap containing the scaled image */ |
| 613 |
ColorTable colorTable; /* Pointer to color table */ |
| 614 |
Blt_ColorImage srcImage; |
| 615 |
GC gc; |
| 616 |
|
| 617 |
} ImageMarker; |
| 618 |
|
| 619 |
static Tk_ConfigSpec imageConfigSpecs[] = |
| 620 |
{ |
| 621 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 622 |
DEF_MARKER_ANCHOR, Tk_Offset(ImageMarker, anchor), 0}, |
| 623 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 624 |
DEF_MARKER_IMAGE_TAGS, Tk_Offset(Marker, tags), |
| 625 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 626 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 627 |
DEF_MARKER_COORDS, Tk_Offset(Marker, worldPts), |
| 628 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 629 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 630 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 631 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 632 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 633 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 634 |
{TK_CONFIG_STRING, "-image", "image", "Image", |
| 635 |
(char *)NULL, Tk_Offset(ImageMarker, imageName), TK_CONFIG_NULL_OK}, |
| 636 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 637 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 638 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 639 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 640 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 641 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 642 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 643 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 644 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 645 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 646 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 647 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 648 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 649 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 650 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 651 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 652 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 653 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 654 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 655 |
}; |
| 656 |
|
| 657 |
/* |
| 658 |
* ------------------------------------------------------------------- |
| 659 |
* |
| 660 |
* LineMarker -- |
| 661 |
* |
| 662 |
* ------------------------------------------------------------------- |
| 663 |
*/ |
| 664 |
typedef struct { |
| 665 |
char *name; /* Identifier for marker */ |
| 666 |
Blt_Uid classUid; /* Type is "linemarker" */ |
| 667 |
Graph *graphPtr; /* Graph marker belongs to */ |
| 668 |
unsigned int flags; |
| 669 |
char **tags; |
| 670 |
int hidden; /* Indicates if the marker is currently |
| 671 |
* hidden or not. */ |
| 672 |
|
| 673 |
Blt_HashEntry *hashPtr; |
| 674 |
Blt_ChainLink *linkPtr; |
| 675 |
|
| 676 |
Point2D *worldPts; /* Position of marker (X-Y coordinates) in |
| 677 |
* world (graph) coordinates. */ |
| 678 |
int nWorldPts; /* Number of points */ |
| 679 |
|
| 680 |
char *elemName; /* Element associated with marker */ |
| 681 |
Axis2D axes; |
| 682 |
int drawUnder; /* If non-zero, draw the marker |
| 683 |
* underneath any elements. There can |
| 684 |
* be a performance because the graph |
| 685 |
* must be redraw entirely each time |
| 686 |
* this marker is redrawn. */ |
| 687 |
int clipped; /* Indicates if the marker is totally |
| 688 |
* clipped by the plotting area. */ |
| 689 |
int xOffset, yOffset; /* Pixel offset */ |
| 690 |
|
| 691 |
MarkerClass *classPtr; |
| 692 |
|
| 693 |
int state; |
| 694 |
|
| 695 |
/* Line specific attributes */ |
| 696 |
XColor *fillColor; |
| 697 |
XColor *outlineColor; /* Foreground and background colors */ |
| 698 |
|
| 699 |
int lineWidth; /* Line width. */ |
| 700 |
int capStyle; /* Cap style. */ |
| 701 |
int joinStyle; /* Join style.*/ |
| 702 |
Blt_Dashes dashes; /* Dash list values (max 11) */ |
| 703 |
|
| 704 |
GC gc; /* Private graphic context */ |
| 705 |
|
| 706 |
Segment2D *segments; /* Malloc'ed array of points. |
| 707 |
* Represents individual line segments |
| 708 |
* (2 points per segment) comprising |
| 709 |
* the mapped line. The segments may |
| 710 |
* not necessarily be connected after |
| 711 |
* clipping. */ |
| 712 |
int nSegments; /* # segments in the above array. */ |
| 713 |
|
| 714 |
int xor; |
| 715 |
int xorState; /* State of the XOR drawing. Indicates |
| 716 |
* if the marker is currently drawn. */ |
| 717 |
} LineMarker; |
| 718 |
|
| 719 |
static Tk_ConfigSpec lineConfigSpecs[] = |
| 720 |
{ |
| 721 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 722 |
DEF_MARKER_LINE_TAGS, Tk_Offset(Marker, tags), |
| 723 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 724 |
{TK_CONFIG_CAP_STYLE, "-cap", "cap", "Cap", |
| 725 |
DEF_MARKER_CAP_STYLE, Tk_Offset(LineMarker, capStyle), |
| 726 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 727 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 728 |
DEF_MARKER_COORDS, Tk_Offset(Marker, worldPts), |
| 729 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 730 |
{TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes", |
| 731 |
DEF_MARKER_DASHES, Tk_Offset(LineMarker, dashes), |
| 732 |
TK_CONFIG_NULL_OK, &bltDashesOption}, |
| 733 |
{TK_CONFIG_CUSTOM, "-dashoffset", "dashOffset", "DashOffset", |
| 734 |
DEF_MARKER_DASH_OFFSET, Tk_Offset(LineMarker, dashes.offset), |
| 735 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 736 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 737 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 738 |
{TK_CONFIG_COLOR, "-fill", "fill", "Fill", |
| 739 |
(char *)NULL, Tk_Offset(LineMarker, fillColor), TK_CONFIG_NULL_OK}, |
| 740 |
{TK_CONFIG_JOIN_STYLE, "-join", "join", "Join", |
| 741 |
DEF_MARKER_JOIN_STYLE, Tk_Offset(LineMarker, joinStyle), |
| 742 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 743 |
{TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth", |
| 744 |
DEF_MARKER_LINE_WIDTH, Tk_Offset(LineMarker, lineWidth), |
| 745 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 746 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 747 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 748 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 749 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 750 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 751 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 752 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 753 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 754 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 755 |
{TK_CONFIG_COLOR, "-outline", "outline", "Outline", |
| 756 |
DEF_MARKER_OUTLINE_COLOR, Tk_Offset(LineMarker, outlineColor), |
| 757 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 758 |
{TK_CONFIG_COLOR, "-outline", "outline", "Outline", |
| 759 |
DEF_MARKER_OUTLINE_MONO, Tk_Offset(LineMarker, outlineColor), |
| 760 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 761 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 762 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 763 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 764 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 765 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 766 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 767 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 768 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 769 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 770 |
{TK_CONFIG_BOOLEAN, "-xor", "xor", "Xor", |
| 771 |
DEF_MARKER_XOR, Tk_Offset(LineMarker, xor), TK_CONFIG_DONT_SET_DEFAULT}, |
| 772 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 773 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 774 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 775 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 776 |
}; |
| 777 |
|
| 778 |
/* |
| 779 |
* ------------------------------------------------------------------- |
| 780 |
* |
| 781 |
* PolygonMarker -- |
| 782 |
* |
| 783 |
* ------------------------------------------------------------------- |
| 784 |
*/ |
| 785 |
typedef struct { |
| 786 |
char *name; /* Identifier for marker */ |
| 787 |
Blt_Uid classUid; /* Type of marker */ |
| 788 |
Graph *graphPtr; /* Graph marker belongs to */ |
| 789 |
unsigned int flags; |
| 790 |
char **tags; |
| 791 |
int hidden; /* Indicates if the marker is currently |
| 792 |
* hidden or not. */ |
| 793 |
|
| 794 |
Blt_HashEntry *hashPtr; |
| 795 |
Blt_ChainLink *linkPtr; |
| 796 |
|
| 797 |
Point2D *worldPts; /* Position of marker (X-Y coordinates) in |
| 798 |
* world (graph) coordinates. */ |
| 799 |
int nWorldPts; /* Number of points */ |
| 800 |
|
| 801 |
char *elemName; /* Element associated with marker */ |
| 802 |
Axis2D axes; |
| 803 |
int drawUnder; /* If non-zero, draw the marker |
| 804 |
* underneath any elements. There can |
| 805 |
* be a performance because the graph |
| 806 |
* must be redraw entirely each time |
| 807 |
* this marker is redrawn. */ |
| 808 |
int clipped; /* Indicates if the marker is totally |
| 809 |
* clipped by the plotting area. */ |
| 810 |
int xOffset, yOffset; /* Pixel offset */ |
| 811 |
|
| 812 |
MarkerClass *classPtr; |
| 813 |
|
| 814 |
int state; |
| 815 |
|
| 816 |
/* Polygon specific attributes and fields */ |
| 817 |
|
| 818 |
Point2D *screenPts; /* Array of points representing the |
| 819 |
* polygon in screen coordinates. It's |
| 820 |
* not used for drawing, but to |
| 821 |
* generate the outlinePts and fillPts |
| 822 |
* arrays that are the coordinates of |
| 823 |
* the possibly clipped outline and |
| 824 |
* filled polygon. */ |
| 825 |
|
| 826 |
ColorPair outline; |
| 827 |
ColorPair fill; |
| 828 |
|
| 829 |
Pixmap stipple; /* Stipple pattern to fill the polygon. */ |
| 830 |
int lineWidth; /* Width of polygon outline. */ |
| 831 |
int capStyle; |
| 832 |
int joinStyle; |
| 833 |
Blt_Dashes dashes; /* List of dash values. Indicates how |
| 834 |
* draw the dashed line. If no dash |
| 835 |
* values are provided, or the first value |
| 836 |
* is zero, then the line is drawn solid. */ |
| 837 |
|
| 838 |
GC outlineGC; /* Graphics context to draw the outline of |
| 839 |
* the polygon. */ |
| 840 |
GC fillGC; /* Graphics context to draw the filled |
| 841 |
* polygon. */ |
| 842 |
|
| 843 |
Point2D *fillPts; /* Malloc'ed array of points used to draw |
| 844 |
* the filled polygon. These points may |
| 845 |
* form a degenerate polygon after clipping. |
| 846 |
*/ |
| 847 |
|
| 848 |
int nFillPts; /* # points in the above array. */ |
| 849 |
|
| 850 |
Segment2D *outlinePts; /* Malloc'ed array of points. |
| 851 |
* Represents individual line segments |
| 852 |
* (2 points per segment) comprising |
| 853 |
* the outline of the polygon. The |
| 854 |
* segments may not necessarily be |
| 855 |
* closed or connected after clipping. */ |
| 856 |
|
| 857 |
int nOutlinePts; /* # points in the above array. */ |
| 858 |
|
| 859 |
int xor; |
| 860 |
int xorState; /* State of the XOR drawing. Indicates |
| 861 |
* if the marker is visible. We have |
| 862 |
* to drawn it again to erase it. */ |
| 863 |
} PolygonMarker; |
| 864 |
|
| 865 |
static Tk_ConfigSpec polygonConfigSpecs[] = |
| 866 |
{ |
| 867 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 868 |
DEF_MARKER_POLYGON_TAGS, Tk_Offset(Marker, tags), |
| 869 |
TK_CONFIG_NULL_OK, &bltListOption}, |
| 870 |
{TK_CONFIG_CAP_STYLE, "-cap", "cap", "Cap", |
| 871 |
DEF_MARKER_CAP_STYLE, Tk_Offset(PolygonMarker, capStyle), |
| 872 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 873 |
{TK_CONFIG_CUSTOM, "-coords", "coords", "Coords", |
| 874 |
DEF_MARKER_COORDS, Tk_Offset(Marker, worldPts), |
| 875 |
TK_CONFIG_NULL_OK, &coordsOption}, |
| 876 |
{TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes", |
| 877 |
DEF_MARKER_DASHES, Tk_Offset(PolygonMarker, dashes), |
| 878 |
TK_CONFIG_NULL_OK, &bltDashesOption}, |
| 879 |
{TK_CONFIG_STRING, "-element", "element", "Element", |
| 880 |
DEF_MARKER_ELEMENT, Tk_Offset(Marker, elemName), TK_CONFIG_NULL_OK}, |
| 881 |
{TK_CONFIG_CUSTOM, "-fill", "fill", "Fill", |
| 882 |
DEF_MARKER_FILL_COLOR, Tk_Offset(PolygonMarker, fill), |
| 883 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK, &bltColorPairOption}, |
| 884 |
{TK_CONFIG_CUSTOM, "-fill", "fill", "Fill", |
| 885 |
DEF_MARKER_FILL_MONO, Tk_Offset(PolygonMarker, fill), |
| 886 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK, &bltColorPairOption}, |
| 887 |
{TK_CONFIG_JOIN_STYLE, "-join", "join", "Join", |
| 888 |
DEF_MARKER_JOIN_STYLE, Tk_Offset(PolygonMarker, joinStyle), |
| 889 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 890 |
{TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth", |
| 891 |
DEF_MARKER_LINE_WIDTH, Tk_Offset(PolygonMarker, lineWidth), |
| 892 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 893 |
{TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", |
| 894 |
DEF_MARKER_HIDE, Tk_Offset(Marker, hidden), |
| 895 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 896 |
{TK_CONFIG_CUSTOM, "-mapx", "mapX", "MapX", |
| 897 |
DEF_MARKER_MAP_X, Tk_Offset(Marker, axes.x), 0, &bltXAxisOption}, |
| 898 |
{TK_CONFIG_CUSTOM, "-mapy", "mapY", "MapY", |
| 899 |
DEF_MARKER_MAP_Y, Tk_Offset(Marker, axes.y), 0, &bltYAxisOption}, |
| 900 |
{TK_CONFIG_STRING, "-name", (char *)NULL, (char *)NULL, |
| 901 |
DEF_MARKER_NAME, Tk_Offset(Marker, name), TK_CONFIG_NULL_OK}, |
| 902 |
{TK_CONFIG_CUSTOM, "-outline", "outline", "Outline", |
| 903 |
DEF_MARKER_OUTLINE_COLOR, Tk_Offset(PolygonMarker, outline), |
| 904 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK, &bltColorPairOption}, |
| 905 |
{TK_CONFIG_CUSTOM, "-outline", "outline", "Outline", |
| 906 |
DEF_MARKER_OUTLINE_MONO, Tk_Offset(PolygonMarker, outline), |
| 907 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK, &bltColorPairOption}, |
| 908 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 909 |
DEF_MARKER_STATE, Tk_Offset(Marker, state), |
| 910 |
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption}, |
| 911 |
{TK_CONFIG_BITMAP, "-stipple", "stipple", "Stipple", |
| 912 |
DEF_MARKER_STIPPLE, Tk_Offset(PolygonMarker, stipple), |
| 913 |
TK_CONFIG_NULL_OK}, |
| 914 |
{TK_CONFIG_BOOLEAN, "-under", "under", "Under", |
| 915 |
DEF_MARKER_UNDER, Tk_Offset(Marker, drawUnder), |
| 916 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 917 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 918 |
DEF_MARKER_X_OFFSET, Tk_Offset(Marker, xOffset), |
| 919 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 920 |
{TK_CONFIG_BOOLEAN, "-xor", "xor", "Xor", |
| 921 |
DEF_MARKER_XOR, Tk_Offset(PolygonMarker, xor), |
| 922 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 923 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 924 |
DEF_MARKER_Y_OFFSET, Tk_Offset(Marker, yOffset), |
| 925 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 926 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 927 |
}; |
| 928 |
|
| 929 |
static MarkerCreateProc CreateBitmapMarker, CreateLineMarker, CreateImageMarker, |
| 930 |
CreatePolygonMarker, CreateTextMarker, CreateWindowMarker; |
| 931 |
|
| 932 |
static MarkerDrawProc DrawBitmapMarker, DrawLineMarker, DrawImageMarker, |
| 933 |
DrawPolygonMarker, DrawTextMarker, DrawWindowMarker; |
| 934 |
|
| 935 |
static MarkerFreeProc FreeBitmapMarker, FreeLineMarker, FreeImageMarker, |
| 936 |
FreePolygonMarker, FreeTextMarker, FreeWindowMarker; |
| 937 |
|
| 938 |
static MarkerConfigProc ConfigureBitmapMarker, ConfigureLineMarker, |
| 939 |
ConfigureImageMarker, ConfigurePolygonMarker, ConfigureTextMarker, |
| 940 |
ConfigureWindowMarker; |
| 941 |
|
| 942 |
static MarkerMapProc MapBitmapMarker, MapLineMarker, MapImageMarker, |
| 943 |
MapPolygonMarker, MapTextMarker, MapWindowMarker; |
| 944 |
|
| 945 |
static MarkerPostScriptProc BitmapMarkerToPostScript, LineMarkerToPostScript, |
| 946 |
ImageMarkerToPostScript, PolygonMarkerToPostScript, |
| 947 |
TextMarkerToPostScript, WindowMarkerToPostScript; |
| 948 |
|
| 949 |
static MarkerPointProc PointInBitmapMarker, PointInLineMarker, |
| 950 |
PointInImageMarker, PointInPolygonMarker, PointInTextMarker, |
| 951 |
PointInWindowMarker; |
| 952 |
|
| 953 |
static MarkerRegionProc RegionInBitmapMarker, RegionInLineMarker, |
| 954 |
RegionInImageMarker, RegionInPolygonMarker, RegionInTextMarker, |
| 955 |
RegionInWindowMarker; |
| 956 |
|
| 957 |
static Tk_ImageChangedProc ImageChangedProc; |
| 958 |
|
| 959 |
static MarkerClass bitmapMarkerClass = { |
| 960 |
bitmapConfigSpecs, |
| 961 |
ConfigureBitmapMarker, |
| 962 |
DrawBitmapMarker, |
| 963 |
FreeBitmapMarker, |
| 964 |
MapBitmapMarker, |
| 965 |
PointInBitmapMarker, |
| 966 |
RegionInBitmapMarker, |
| 967 |
BitmapMarkerToPostScript, |
| 968 |
}; |
| 969 |
|
| 970 |
static MarkerClass imageMarkerClass = { |
| 971 |
imageConfigSpecs, |
| 972 |
ConfigureImageMarker, |
| 973 |
DrawImageMarker, |
| 974 |
FreeImageMarker, |
| 975 |
MapImageMarker, |
| 976 |
PointInImageMarker, |
| 977 |
RegionInImageMarker, |
| 978 |
ImageMarkerToPostScript, |
| 979 |
}; |
| 980 |
|
| 981 |
static MarkerClass lineMarkerClass = { |
| 982 |
lineConfigSpecs, |
| 983 |
ConfigureLineMarker, |
| 984 |
DrawLineMarker, |
| 985 |
FreeLineMarker, |
| 986 |
MapLineMarker, |
| 987 |
PointInLineMarker, |
| 988 |
RegionInLineMarker, |
| 989 |
LineMarkerToPostScript, |
| 990 |
}; |
| 991 |
|
| 992 |
static MarkerClass polygonMarkerClass = { |
| 993 |
polygonConfigSpecs, |
| 994 |
ConfigurePolygonMarker, |
| 995 |
DrawPolygonMarker, |
| 996 |
FreePolygonMarker, |
| 997 |
MapPolygonMarker, |
| 998 |
PointInPolygonMarker, |
| 999 |
RegionInPolygonMarker, |
| 1000 |
PolygonMarkerToPostScript, |
| 1001 |
}; |
| 1002 |
|
| 1003 |
static MarkerClass textMarkerClass = { |
| 1004 |
textConfigSpecs, |
| 1005 |
ConfigureTextMarker, |
| 1006 |
DrawTextMarker, |
| 1007 |
FreeTextMarker, |
| 1008 |
MapTextMarker, |
| 1009 |
PointInTextMarker, |
| 1010 |
RegionInTextMarker, |
| 1011 |
TextMarkerToPostScript, |
| 1012 |
}; |
| 1013 |
|
| 1014 |
static MarkerClass windowMarkerClass = { |
| 1015 |
windowConfigSpecs, |
| 1016 |
ConfigureWindowMarker, |
| 1017 |
DrawWindowMarker, |
| 1018 |
FreeWindowMarker, |
| 1019 |
MapWindowMarker, |
| 1020 |
PointInWindowMarker, |
| 1021 |
RegionInWindowMarker, |
| 1022 |
WindowMarkerToPostScript, |
| 1023 |
}; |
| 1024 |
|
| 1025 |
#ifdef notdef |
| 1026 |
static MarkerClass rectangleMarkerClass = { |
| 1027 |
rectangleConfigSpecs, |
| 1028 |
ConfigureRectangleMarker, |
| 1029 |
DrawRectangleMarker, |
| 1030 |
FreeRectangleMarker, |
| 1031 |
MapRectangleMarker, |
| 1032 |
PointInRectangleMarker, |
| 1033 |
RegionInRectangleMarker, |
| 1034 |
RectangleMarkerToPostScript, |
| 1035 |
}; |
| 1036 |
|
| 1037 |
static MarkerClass ovalMarkerClass = { |
| 1038 |
ovalConfigSpecs, |
| 1039 |
ConfigureOvalMarker, |
| 1040 |
DrawOvalMarker, |
| 1041 |
FreeOvalMarker, |
| 1042 |
MapOvalMarker, |
| 1043 |
PointInOvalMarker, |
| 1044 |
RegionInOvalMarker, |
| 1045 |
OvalMarkerToPostScript, |
| 1046 |
}; |
| 1047 |
#endif |
| 1048 |
|
| 1049 |
/* |
| 1050 |
* ---------------------------------------------------------------------- |
| 1051 |
* |
| 1052 |
* BoxesDontOverlap -- |
| 1053 |
* |
| 1054 |
* Tests if the bounding box of a marker overlaps the plotting |
| 1055 |
* area in any way. If so, the marker will be drawn. Just do a |
| 1056 |
* min/max test on the extents of both boxes. |
| 1057 |
* |
| 1058 |
* Note: It's assumed that the extents of the bounding box lie |
| 1059 |
* within the area. So for a 10x10 rectangle, bottom and |
| 1060 |
* left would be 9. |
| 1061 |
* |
| 1062 |
* Results: |
| 1063 |
* Returns 0 is the marker is visible in the plotting area, and |
| 1064 |
* 1 otherwise (marker is clipped). |
| 1065 |
* |
| 1066 |
* ---------------------------------------------------------------------- |
| 1067 |
*/ |
| 1068 |
static int |
| 1069 |
BoxesDontOverlap(graphPtr, extsPtr) |
| 1070 |
Graph *graphPtr; |
| 1071 |
Extents2D *extsPtr; |
| 1072 |
{ |
| 1073 |
/*if(extsPtr->right >= extsPtr->left || extsPtr->bottom >= extsPtr->top || |
| 1074 |
graphPtr->right >= graphPtr->left || graphPtr->bottom >= graphPtr->top)*/ |
| 1075 |
if(extsPtr->right <= extsPtr->left || extsPtr->bottom <= extsPtr->top || |
| 1076 |
graphPtr->right <= graphPtr->left || graphPtr->bottom <= graphPtr->top) |
| 1077 |
{ |
| 1078 |
return 1; |
| 1079 |
} |
| 1080 |
assert(extsPtr->right >= extsPtr->left); |
| 1081 |
assert(extsPtr->bottom >= extsPtr->top); |
| 1082 |
assert(graphPtr->right >= graphPtr->left); |
| 1083 |
assert(graphPtr->bottom >= graphPtr->top); |
| 1084 |
|
| 1085 |
return (((double)graphPtr->right < extsPtr->left) || |
| 1086 |
((double)graphPtr->bottom < extsPtr->top) || |
| 1087 |
(extsPtr->right < (double)graphPtr->left) || |
| 1088 |
(extsPtr->bottom < (double)graphPtr->top)); |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
/* |
| 1093 |
* ---------------------------------------------------------------------- |
| 1094 |
* |
| 1095 |
* GetCoordinate -- |
| 1096 |
* |
| 1097 |
* Convert the expression string into a floating point value. The |
| 1098 |
* only reason we use this routine instead of Blt_ExprDouble is to |
| 1099 |
* handle "elastic" bounds. That is, convert the strings "-Inf", |
| 1100 |
* "Inf" into -(DBL_MAX) and DBL_MAX respectively. |
| 1101 |
* |
| 1102 |
* Results: |
| 1103 |
* The return value is a standard Tcl result. The value of the |
| 1104 |
* expression is passed back via valuePtr. |
| 1105 |
* |
| 1106 |
* ---------------------------------------------------------------------- |
| 1107 |
*/ |
| 1108 |
static int |
| 1109 |
GetCoordinate(interp, expr, valuePtr) |
| 1110 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1111 |
char *expr; /* Numeric expression string to parse */ |
| 1112 |
double *valuePtr; /* Real-valued result of expression */ |
| 1113 |
{ |
| 1114 |
char c; |
| 1115 |
|
| 1116 |
c = expr[0]; |
| 1117 |
if ((c == 'I') && (strcmp(expr, "Inf") == 0)) { |
| 1118 |
*valuePtr = DBL_MAX; /* Elastic upper bound */ |
| 1119 |
} else if ((c == '-') && (expr[1] == 'I') && (strcmp(expr, "-Inf") == 0)) { |
| 1120 |
*valuePtr = -DBL_MAX; /* Elastic lower bound */ |
| 1121 |
} else if ((c == '+') && (expr[1] == 'I') && (strcmp(expr, "+Inf") == 0)) { |
| 1122 |
*valuePtr = DBL_MAX; /* Elastic upper bound */ |
| 1123 |
} else if (Tcl_ExprDouble(interp, expr, valuePtr) != TCL_OK) { |
| 1124 |
return TCL_ERROR; |
| 1125 |
} |
| 1126 |
return TCL_OK; |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
/* |
| 1131 |
* ---------------------------------------------------------------------- |
| 1132 |
* |
| 1133 |
* PrintCoordinate -- |
| 1134 |
* |
| 1135 |
* Convert the floating point value into its string |
| 1136 |
* representation. The only reason this routine is used in |
| 1137 |
* instead of sprintf, is to handle the "elastic" bounds. That |
| 1138 |
* is, convert the values DBL_MAX and -(DBL_MAX) into "+Inf" and |
| 1139 |
* "-Inf" respectively. |
| 1140 |
* |
| 1141 |
* Results: |
| 1142 |
* The return value is a standard Tcl result. The string of the |
| 1143 |
* expression is passed back via string. |
| 1144 |
* |
| 1145 |
* ---------------------------------------------------------------------- */ |
| 1146 |
static char * |
| 1147 |
PrintCoordinate(interp, x) |
| 1148 |
Tcl_Interp *interp; |
| 1149 |
double x; /* Numeric value */ |
| 1150 |
{ |
| 1151 |
if (x == DBL_MAX) { |
| 1152 |
return "+Inf"; |
| 1153 |
} else if (x == -DBL_MAX) { |
| 1154 |
return "-Inf"; |
| 1155 |
} else { |
| 1156 |
static char string[TCL_DOUBLE_SPACE + 1]; |
| 1157 |
|
| 1158 |
Tcl_PrintDouble(interp, (double)x, string); |
| 1159 |
return string; |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
/* |
| 1164 |
* ---------------------------------------------------------------------- |
| 1165 |
* |
| 1166 |
* ParseCoordinates -- |
| 1167 |
* |
| 1168 |
* The Tcl coordinate list is converted to their floating point |
| 1169 |
* values. It will then replace the current marker coordinates. |
| 1170 |
* |
| 1171 |
* Since different marker types require different number of |
| 1172 |
* coordinates this must be checked here. |
| 1173 |
* |
| 1174 |
* Results: |
| 1175 |
* The return value is a standard Tcl result. |
| 1176 |
* |
| 1177 |
* Side effects: |
| 1178 |
* If the marker coordinates are reset, the graph is eventually |
| 1179 |
* redrawn with at the new marker coordinates. |
| 1180 |
* |
| 1181 |
* ---------------------------------------------------------------------- |
| 1182 |
*/ |
| 1183 |
static int |
| 1184 |
ParseCoordinates(interp, markerPtr, nExprs, exprArr) |
| 1185 |
Tcl_Interp *interp; |
| 1186 |
Marker *markerPtr; |
| 1187 |
int nExprs; |
| 1188 |
char **exprArr; |
| 1189 |
{ |
| 1190 |
int nWorldPts; |
| 1191 |
int minArgs, maxArgs; |
| 1192 |
Point2D *worldPts; |
| 1193 |
register int i; |
| 1194 |
register Point2D *pointPtr; |
| 1195 |
double x, y; |
| 1196 |
|
| 1197 |
if (nExprs == 0) { |
| 1198 |
return TCL_OK; |
| 1199 |
} |
| 1200 |
if (nExprs & 1) { |
| 1201 |
Tcl_AppendResult(interp, "odd number of marker coordinates specified", |
| 1202 |
(char *)NULL); |
| 1203 |
return TCL_ERROR; |
| 1204 |
} |
| 1205 |
if (markerPtr->classUid == bltLineMarkerUid) { |
| 1206 |
minArgs = 4, maxArgs = 0; |
| 1207 |
} else if (markerPtr->classUid == bltPolygonMarkerUid) { |
| 1208 |
minArgs = 6, maxArgs = 0; |
| 1209 |
} else if ((markerPtr->classUid == bltWindowMarkerUid) || |
| 1210 |
(markerPtr->classUid == bltTextMarkerUid)) { |
| 1211 |
minArgs = 2, maxArgs = 2; |
| 1212 |
} else if ((markerPtr->classUid == bltImageMarkerUid) || |
| 1213 |
(markerPtr->classUid == bltBitmapMarkerUid)) { |
| 1214 |
minArgs = 2, maxArgs = 4; |
| 1215 |
} else { |
| 1216 |
Tcl_AppendResult(interp, "unknown marker type", (char *)NULL); |
| 1217 |
return TCL_ERROR; |
| 1218 |
} |
| 1219 |
|
| 1220 |
if (nExprs < minArgs) { |
| 1221 |
Tcl_AppendResult(interp, "too few marker coordinates specified", |
| 1222 |
(char *)NULL); |
| 1223 |
return TCL_ERROR; |
| 1224 |
} |
| 1225 |
if ((maxArgs > 0) && (nExprs > maxArgs)) { |
| 1226 |
Tcl_AppendResult(interp, "too many marker coordinates specified", |
| 1227 |
(char *)NULL); |
| 1228 |
return TCL_ERROR; |
| 1229 |
} |
| 1230 |
nWorldPts = nExprs / 2; |
| 1231 |
worldPts = Blt_Malloc(nWorldPts * sizeof(Point2D)); |
| 1232 |
if (worldPts == NULL) { |
| 1233 |
Tcl_AppendResult(interp, "can't allocate new coordinate array", |
| 1234 |
(char *)NULL); |
| 1235 |
return TCL_ERROR; |
| 1236 |
} |
| 1237 |
|
| 1238 |
/* Don't free the old coordinate array until we've parsed the new |
| 1239 |
* coordinates without errors. */ |
| 1240 |
pointPtr = worldPts; |
| 1241 |
for (i = 0; i < nExprs; i += 2) { |
| 1242 |
if ((GetCoordinate(interp, exprArr[i], &x) != TCL_OK) || |
| 1243 |
(GetCoordinate(interp, exprArr[i + 1], &y) != TCL_OK)) { |
| 1244 |
Blt_Free(worldPts); |
| 1245 |
return TCL_ERROR; |
| 1246 |
} |
| 1247 |
pointPtr->x = x, pointPtr->y = y; |
| 1248 |
pointPtr++; |
| 1249 |
} |
| 1250 |
if (markerPtr->worldPts != NULL) { |
| 1251 |
Blt_Free(markerPtr->worldPts); |
| 1252 |
} |
| 1253 |
markerPtr->worldPts = worldPts; |
| 1254 |
markerPtr->nWorldPts = nWorldPts; |
| 1255 |
markerPtr->flags |= MAP_ITEM; |
| 1256 |
return TCL_OK; |
| 1257 |
} |
| 1258 |
|
| 1259 |
/* |
| 1260 |
* ---------------------------------------------------------------------- |
| 1261 |
* |
| 1262 |
* StringToCoordinates -- |
| 1263 |
* |
| 1264 |
* Given a Tcl list of numeric expression representing the |
| 1265 |
* element values, convert into an array of floating point |
| 1266 |
* values. In addition, the minimum and maximum values are saved. |
| 1267 |
* Since elastic values are allow (values which translate to the |
| 1268 |
* min/max of the graph), we must try to get the non-elastic |
| 1269 |
* minimum and maximum. |
| 1270 |
* |
| 1271 |
* Results: |
| 1272 |
* The return value is a standard Tcl result. The vector is |
| 1273 |
* passed back via the vecPtr. |
| 1274 |
* |
| 1275 |
* ---------------------------------------------------------------------- |
| 1276 |
*/ |
| 1277 |
/*ARGSUSED*/ |
| 1278 |
static int |
| 1279 |
StringToCoordinates(clientData, interp, tkwin, string, widgRec, offset) |
| 1280 |
ClientData clientData; /* Not used. */ |
| 1281 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1282 |
Tk_Window tkwin; /* Not used. */ |
| 1283 |
char *string; /* Tcl list of numeric expressions */ |
| 1284 |
char *widgRec; /* Marker record */ |
| 1285 |
int offset; /* Not used. */ |
| 1286 |
{ |
| 1287 |
Marker *markerPtr = (Marker *)widgRec; |
| 1288 |
int nExprs; |
| 1289 |
char **exprArr; |
| 1290 |
int result; |
| 1291 |
|
| 1292 |
nExprs = 0; |
| 1293 |
if ((string != NULL) && |
| 1294 |
(Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK)) { |
| 1295 |
return TCL_ERROR; |
| 1296 |
} |
| 1297 |
if (nExprs == 0) { |
| 1298 |
if (markerPtr->worldPts != NULL) { |
| 1299 |
Blt_Free(markerPtr->worldPts); |
| 1300 |
markerPtr->worldPts = NULL; |
| 1301 |
} |
| 1302 |
markerPtr->nWorldPts = 0; |
| 1303 |
return TCL_OK; |
| 1304 |
} |
| 1305 |
result = ParseCoordinates(interp, markerPtr, nExprs, exprArr); |
| 1306 |
Blt_Free(exprArr); |
| 1307 |
return result; |
| 1308 |
} |
| 1309 |
|
| 1310 |
/* |
| 1311 |
* ---------------------------------------------------------------------- |
| 1312 |
* |
| 1313 |
* CoordinatesToString -- |
| 1314 |
* |
| 1315 |
* Convert the vector of floating point values into a Tcl list. |
| 1316 |
* |
| 1317 |
* Results: |
| 1318 |
* The string representation of the vector is returned. |
| 1319 |
* |
| 1320 |
* ---------------------------------------------------------------------- |
| 1321 |
*/ |
| 1322 |
/*ARGSUSED*/ |
| 1323 |
static char * |
| 1324 |
CoordinatesToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 1325 |
ClientData clientData; /* Not used. */ |
| 1326 |
Tk_Window tkwin; /* Not used. */ |
| 1327 |
char *widgRec; /* Marker record */ |
| 1328 |
int offset; /* Not used. */ |
| 1329 |
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */ |
| 1330 |
{ |
| 1331 |
Marker *markerPtr = (Marker *)widgRec; |
| 1332 |
Tcl_Interp *interp; |
| 1333 |
Tcl_DString dString; |
| 1334 |
char *result; |
| 1335 |
register int i; |
| 1336 |
register Point2D *p; |
| 1337 |
|
| 1338 |
if (markerPtr->nWorldPts < 1) { |
| 1339 |
return ""; |
| 1340 |
} |
| 1341 |
interp = markerPtr->graphPtr->interp; |
| 1342 |
|
| 1343 |
Tcl_DStringInit(&dString); |
| 1344 |
p = markerPtr->worldPts; |
| 1345 |
for (i = 0; i < markerPtr->nWorldPts; i++) { |
| 1346 |
Tcl_DStringAppendElement(&dString, PrintCoordinate(interp, p->x)); |
| 1347 |
Tcl_DStringAppendElement(&dString, PrintCoordinate(interp, p->y)); |
| 1348 |
p++; |
| 1349 |
} |
| 1350 |
result = Tcl_DStringValue(&dString); |
| 1351 |
|
| 1352 |
/* |
| 1353 |
* If memory wasn't allocated for the dynamic string, do it here (it's |
| 1354 |
* currently on the stack), so that Tcl can free it normally. |
| 1355 |
*/ |
| 1356 |
if (result == dString.staticSpace) { |
| 1357 |
result = Blt_Strdup(result); |
| 1358 |
} |
| 1359 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 1360 |
return result; |
| 1361 |
} |
| 1362 |
|
| 1363 |
/* |
| 1364 |
* ---------------------------------------------------------------------- |
| 1365 |
* |
| 1366 |
* HMap -- |
| 1367 |
* |
| 1368 |
* Map the given graph coordinate value to its axis, returning a |
| 1369 |
* window position. |
| 1370 |
* |
| 1371 |
* Results: |
| 1372 |
* Returns a floating point number representing the window |
| 1373 |
* coordinate position on the given axis. |
| 1374 |
* |
| 1375 |
* ---------------------------------------------------------------------- |
| 1376 |
*/ |
| 1377 |
static double |
| 1378 |
HMap(graphPtr, axisPtr, x) |
| 1379 |
Graph *graphPtr; |
| 1380 |
Axis *axisPtr; |
| 1381 |
double x; |
| 1382 |
{ |
| 1383 |
register double norm; |
| 1384 |
|
| 1385 |
if (x == DBL_MAX) { |
| 1386 |
norm = 1.0; |
| 1387 |
} else if (x == -DBL_MAX) { |
| 1388 |
norm = 0.0; |
| 1389 |
} else { |
| 1390 |
if (axisPtr->logScale) { |
| 1391 |
if (x > 0.0) { |
| 1392 |
x = log10(x); |
| 1393 |
} else if (x < 0.0) { |
| 1394 |
x = 0.0; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
norm = NORMALIZE(axisPtr, x); |
| 1398 |
} |
| 1399 |
if (axisPtr->descending) { |
| 1400 |
norm = 1.0 - norm; |
| 1401 |
} |
| 1402 |
/* Horizontal transformation */ |
| 1403 |
return ((norm * graphPtr->hRange) + graphPtr->hOffset); |
| 1404 |
} |
| 1405 |
|
| 1406 |
/* |
| 1407 |
* ---------------------------------------------------------------------- |
| 1408 |
* |
| 1409 |
* VMap -- |
| 1410 |
* |
| 1411 |
* Map the given graph coordinate value to its axis, returning a |
| 1412 |
* window position. |
| 1413 |
* |
| 1414 |
* Results: |
| 1415 |
* Returns a double precision number representing the window |
| 1416 |
* coordinate position on the given axis. |
| 1417 |
* |
| 1418 |
* ---------------------------------------------------------------------- |
| 1419 |
*/ |
| 1420 |
static double |
| 1421 |
VMap(graphPtr, axisPtr, y) |
| 1422 |
Graph *graphPtr; |
| 1423 |
Axis *axisPtr; |
| 1424 |
double y; |
| 1425 |
{ |
| 1426 |
register double norm; |
| 1427 |
|
| 1428 |
if (y == DBL_MAX) { |
| 1429 |
norm = 1.0; |
| 1430 |
} else if (y == -DBL_MAX) { |
| 1431 |
norm = 0.0; |
| 1432 |
} else { |
| 1433 |
if (axisPtr->logScale) { |
| 1434 |
if (y > 0.0) { |
| 1435 |
y = log10(y); |
| 1436 |
} else if (y < 0.0) { |
| 1437 |
y = 0.0; |
| 1438 |
} |
| 1439 |
} |
| 1440 |
norm = NORMALIZE(axisPtr, y); |
| 1441 |
} |
| 1442 |
if (axisPtr->descending) { |
| 1443 |
norm = 1.0 - norm; |
| 1444 |
} |
| 1445 |
/* Vertical transformation */ |
| 1446 |
return (((1.0 - norm) * graphPtr->vRange) + graphPtr->vOffset); |
| 1447 |
} |
| 1448 |
|
| 1449 |
/* |
| 1450 |
* ---------------------------------------------------------------------- |
| 1451 |
* |
| 1452 |
* MapPoint -- |
| 1453 |
* |
| 1454 |
* Maps the given graph x,y coordinate values to a window position. |
| 1455 |
* |
| 1456 |
* Results: |
| 1457 |
* Returns a XPoint structure containing the window coordinates |
| 1458 |
* of the given graph x,y coordinate. |
| 1459 |
* |
| 1460 |
* ---------------------------------------------------------------------- |
| 1461 |
*/ |
| 1462 |
static Point2D |
| 1463 |
MapPoint(graphPtr, pointPtr, axesPtr) |
| 1464 |
Graph *graphPtr; |
| 1465 |
Point2D *pointPtr; /* Graph X-Y coordinate. */ |
| 1466 |
Axis2D *axesPtr; /* Specifies which axes to use */ |
| 1467 |
{ |
| 1468 |
Point2D result; |
| 1469 |
|
| 1470 |
if (graphPtr->inverted) { |
| 1471 |
result.x = HMap(graphPtr, axesPtr->y, pointPtr->y); |
| 1472 |
result.y = VMap(graphPtr, axesPtr->x, pointPtr->x); |
| 1473 |
} else { |
| 1474 |
result.x = HMap(graphPtr, axesPtr->x, pointPtr->x); |
| 1475 |
result.y = VMap(graphPtr, axesPtr->y, pointPtr->y); |
| 1476 |
} |
| 1477 |
return result; /* Result is screen coordinate. */ |
| 1478 |
} |
| 1479 |
|
| 1480 |
static Marker * |
| 1481 |
CreateMarker(graphPtr, name, classUid) |
| 1482 |
Graph *graphPtr; |
| 1483 |
char *name; |
| 1484 |
Blt_Uid classUid; |
| 1485 |
{ |
| 1486 |
Marker *markerPtr; |
| 1487 |
|
| 1488 |
/* Create the new marker based upon the given type */ |
| 1489 |
if (classUid == bltBitmapMarkerUid) { |
| 1490 |
markerPtr = CreateBitmapMarker(); /* bitmap */ |
| 1491 |
} else if (classUid == bltLineMarkerUid) { |
| 1492 |
markerPtr = CreateLineMarker(); /* line */ |
| 1493 |
} else if (classUid == bltImageMarkerUid) { |
| 1494 |
markerPtr = CreateImageMarker(); /* image */ |
| 1495 |
} else if (classUid == bltTextMarkerUid) { |
| 1496 |
markerPtr = CreateTextMarker(); /* text */ |
| 1497 |
} else if (classUid == bltPolygonMarkerUid) { |
| 1498 |
markerPtr = CreatePolygonMarker(); /* polygon */ |
| 1499 |
} else if (classUid == bltWindowMarkerUid) { |
| 1500 |
markerPtr = CreateWindowMarker(); /* window */ |
| 1501 |
} else { |
| 1502 |
return NULL; |
| 1503 |
} |
| 1504 |
assert(markerPtr); |
| 1505 |
markerPtr->graphPtr = graphPtr; |
| 1506 |
markerPtr->hidden = markerPtr->drawUnder = FALSE; |
| 1507 |
markerPtr->flags |= MAP_ITEM; |
| 1508 |
markerPtr->name = Blt_Strdup(name); |
| 1509 |
markerPtr->classUid = classUid; |
| 1510 |
return markerPtr; |
| 1511 |
} |
| 1512 |
|
| 1513 |
static void |
| 1514 |
DestroyMarker(markerPtr) |
| 1515 |
Marker *markerPtr; |
| 1516 |
{ |
| 1517 |
Graph *graphPtr = markerPtr->graphPtr; |
| 1518 |
|
| 1519 |
if (markerPtr->drawUnder) { |
| 1520 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 1521 |
} |
| 1522 |
/* Free the resources allocated for the particular type of marker */ |
| 1523 |
(*markerPtr->classPtr->freeProc) (graphPtr, markerPtr); |
| 1524 |
if (markerPtr->worldPts != NULL) { |
| 1525 |
Blt_Free(markerPtr->worldPts); |
| 1526 |
} |
| 1527 |
Blt_DeleteBindings(graphPtr->bindTable, markerPtr); |
| 1528 |
Tk_FreeOptions(markerPtr->classPtr->configSpecs, (char *)markerPtr, |
| 1529 |
graphPtr->display, 0); |
| 1530 |
if (markerPtr->hashPtr != NULL) { |
| 1531 |
Blt_DeleteHashEntry(&graphPtr->markers.table, markerPtr->hashPtr); |
| 1532 |
} |
| 1533 |
if (markerPtr->linkPtr != NULL) { |
| 1534 |
Blt_ChainDeleteLink(graphPtr->markers.displayList, markerPtr->linkPtr); |
| 1535 |
} |
| 1536 |
if (markerPtr->name != NULL) { |
| 1537 |
Blt_Free(markerPtr->name); |
| 1538 |
} |
| 1539 |
if (markerPtr->elemName != NULL) { |
| 1540 |
Blt_Free(markerPtr->elemName); |
| 1541 |
} |
| 1542 |
if (markerPtr->tags != NULL) { |
| 1543 |
Blt_Free(markerPtr->tags); |
| 1544 |
} |
| 1545 |
Blt_Free(markerPtr); |
| 1546 |
} |
| 1547 |
|
| 1548 |
/* |
| 1549 |
* ---------------------------------------------------------------------- |
| 1550 |
* |
| 1551 |
* ConfigureBitmapMarker -- |
| 1552 |
* |
| 1553 |
* This procedure is called to process an argv/argc list, plus |
| 1554 |
* the Tk option database, in order to configure (or reconfigure) |
| 1555 |
* a bitmap marker. |
| 1556 |
* |
| 1557 |
* Results: |
| 1558 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 1559 |
* interp->result contains an error message. |
| 1560 |
* |
| 1561 |
* Side effects: |
| 1562 |
* Configuration information, such as bitmap pixmap, colors, |
| 1563 |
* rotation, etc. get set for markerPtr; old resources get freed, |
| 1564 |
* if there were any. The marker is eventually redisplayed. |
| 1565 |
* |
| 1566 |
* ---------------------------------------------------------------------- |
| 1567 |
*/ |
| 1568 |
/* ARGSUSED */ |
| 1569 |
static int |
| 1570 |
ConfigureBitmapMarker(markerPtr) |
| 1571 |
Marker *markerPtr; |
| 1572 |
{ |
| 1573 |
Graph *graphPtr = markerPtr->graphPtr; |
| 1574 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1575 |
GC newGC; |
| 1576 |
XGCValues gcValues; |
| 1577 |
unsigned long gcMask; |
| 1578 |
|
| 1579 |
if (bmPtr->srcBitmap == None) { |
| 1580 |
return TCL_OK; |
| 1581 |
} |
| 1582 |
bmPtr->theta = FMOD(bmPtr->rotate, 360.0); |
| 1583 |
if (bmPtr->theta < 0.0) { |
| 1584 |
bmPtr->theta += 360.0; |
| 1585 |
} |
| 1586 |
gcMask = 0; |
| 1587 |
if (bmPtr->outlineColor != NULL) { |
| 1588 |
gcMask |= GCForeground; |
| 1589 |
gcValues.foreground = bmPtr->outlineColor->pixel; |
| 1590 |
} |
| 1591 |
if (bmPtr->fillColor != NULL) { |
| 1592 |
gcValues.background = bmPtr->fillColor->pixel; |
| 1593 |
gcMask |= GCBackground; |
| 1594 |
} else { |
| 1595 |
gcValues.clip_mask = bmPtr->srcBitmap; |
| 1596 |
gcMask |= GCClipMask; |
| 1597 |
} |
| 1598 |
|
| 1599 |
/* Note that while this is a "shared" GC, we're going to change |
| 1600 |
* the clip origin right before the bitmap is drawn anyways. This |
| 1601 |
* assumes that any drawing code using this GC (with GCClipMask |
| 1602 |
* set) is going to want to set the clip origin anyways. */ |
| 1603 |
newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); |
| 1604 |
if (bmPtr->gc != NULL) { |
| 1605 |
Tk_FreeGC(graphPtr->display, bmPtr->gc); |
| 1606 |
} |
| 1607 |
bmPtr->gc = newGC; |
| 1608 |
|
| 1609 |
/* Create background GC color */ |
| 1610 |
|
| 1611 |
if (bmPtr->fillColor != NULL) { |
| 1612 |
gcValues.foreground = bmPtr->fillColor->pixel; |
| 1613 |
newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); |
| 1614 |
if (bmPtr->fillGC != NULL) { |
| 1615 |
Tk_FreeGC(graphPtr->display, bmPtr->fillGC); |
| 1616 |
} |
| 1617 |
bmPtr->fillGC = newGC; |
| 1618 |
} |
| 1619 |
bmPtr->flags |= MAP_ITEM; |
| 1620 |
if (bmPtr->drawUnder) { |
| 1621 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 1622 |
} |
| 1623 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 1624 |
return TCL_OK; |
| 1625 |
} |
| 1626 |
|
| 1627 |
/* |
| 1628 |
* ---------------------------------------------------------------------- |
| 1629 |
* |
| 1630 |
* MapBitmapMarker -- |
| 1631 |
* |
| 1632 |
* This procedure gets called each time the layout of the graph |
| 1633 |
* changes. The x, y window coordinates of the bitmap marker are |
| 1634 |
* saved in the marker structure. |
| 1635 |
* |
| 1636 |
* Additionly, if no background color was specified, the |
| 1637 |
* GCTileStipXOrigin and GCTileStipYOrigin attributes are set in |
| 1638 |
* the private GC. |
| 1639 |
* |
| 1640 |
* Results: |
| 1641 |
* None. |
| 1642 |
* |
| 1643 |
* Side effects: |
| 1644 |
* Window coordinates are saved and if no background color was |
| 1645 |
* set, the GC stipple origins are changed to calculated window |
| 1646 |
* coordinates. |
| 1647 |
* |
| 1648 |
* ---------------------------------------------------------------------- |
| 1649 |
*/ |
| 1650 |
static void |
| 1651 |
MapBitmapMarker(markerPtr) |
| 1652 |
Marker *markerPtr; |
| 1653 |
{ |
| 1654 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1655 |
Extents2D exts; |
| 1656 |
Graph *graphPtr = markerPtr->graphPtr; |
| 1657 |
Point2D anchorPos; |
| 1658 |
Point2D corner1, corner2; |
| 1659 |
int destWidth, destHeight; |
| 1660 |
int srcWidth, srcHeight; |
| 1661 |
register int i; |
| 1662 |
|
| 1663 |
if (bmPtr->srcBitmap == None) { |
| 1664 |
return; |
| 1665 |
} |
| 1666 |
if (bmPtr->destBitmap != None) { |
| 1667 |
Tk_FreePixmap(graphPtr->display, bmPtr->destBitmap); |
| 1668 |
bmPtr->destBitmap = None; |
| 1669 |
} |
| 1670 |
/* |
| 1671 |
* Collect the coordinates. The number of coordinates will determine |
| 1672 |
* the calculations to be made. |
| 1673 |
* |
| 1674 |
* x1 y1 A single pair of X-Y coordinates. They represent |
| 1675 |
* the anchor position of the bitmap. |
| 1676 |
* |
| 1677 |
* x1 y1 x2 y2 Two pairs of X-Y coordinates. They represent |
| 1678 |
* two opposite corners of a bounding rectangle. The |
| 1679 |
* bitmap is possibly rotated and scaled to fit into |
| 1680 |
* this box. |
| 1681 |
* |
| 1682 |
*/ |
| 1683 |
Tk_SizeOfBitmap(graphPtr->display, bmPtr->srcBitmap, &srcWidth, |
| 1684 |
&srcHeight); |
| 1685 |
corner1 = MapPoint(graphPtr, bmPtr->worldPts, &bmPtr->axes); |
| 1686 |
if (bmPtr->nWorldPts > 1) { |
| 1687 |
double hold; |
| 1688 |
|
| 1689 |
corner2 = MapPoint(graphPtr, bmPtr->worldPts + 1, &bmPtr->axes); |
| 1690 |
/* Flip the corners if necessary */ |
| 1691 |
if (corner1.x > corner2.x) { |
| 1692 |
hold = corner1.x, corner1.x = corner2.x, corner2.x = hold; |
| 1693 |
} |
| 1694 |
if (corner1.y > corner2.y) { |
| 1695 |
hold = corner1.y, corner1.y = corner2.y, corner2.y = hold; |
| 1696 |
} |
| 1697 |
} else { |
| 1698 |
corner2.x = corner1.x + srcWidth - 1; |
| 1699 |
corner2.y = corner1.y + srcHeight - 1; |
| 1700 |
} |
| 1701 |
destWidth = (int)(corner2.x - corner1.x) + 1; |
| 1702 |
destHeight = (int)(corner2.y - corner1.y) + 1; |
| 1703 |
|
| 1704 |
if (bmPtr->nWorldPts == 1) { |
| 1705 |
anchorPos = Blt_TranslatePoint(&corner1, destWidth, destHeight, |
| 1706 |
bmPtr->anchor); |
| 1707 |
} else { |
| 1708 |
anchorPos = corner1; |
| 1709 |
} |
| 1710 |
anchorPos.x += bmPtr->xOffset; |
| 1711 |
anchorPos.y += bmPtr->yOffset; |
| 1712 |
|
| 1713 |
/* Check if the bitmap sits at least partially in the plot area. */ |
| 1714 |
exts.left = anchorPos.x; |
| 1715 |
exts.top = anchorPos.y; |
| 1716 |
exts.right = anchorPos.x + destWidth - 1; |
| 1717 |
exts.bottom = anchorPos.y + destHeight - 1; |
| 1718 |
|
| 1719 |
bmPtr->clipped = BoxesDontOverlap(graphPtr, &exts); |
| 1720 |
if (bmPtr->clipped) { |
| 1721 |
return; /* Bitmap is offscreen. Don't generate |
| 1722 |
* rotated or scaled bitmaps. */ |
| 1723 |
} |
| 1724 |
|
| 1725 |
/* |
| 1726 |
* Scale the bitmap if necessary. It's a little tricky because we |
| 1727 |
* only want to scale what's visible on the screen, not the entire |
| 1728 |
* bitmap. |
| 1729 |
*/ |
| 1730 |
if ((bmPtr->theta != 0.0) || (destWidth != srcWidth) || |
| 1731 |
(destHeight != srcHeight)) { |
| 1732 |
int regionWidth, regionHeight; |
| 1733 |
Region2D region; /* Indicates the portion of the scaled |
| 1734 |
* bitmap that we want to display. */ |
| 1735 |
double left, right, top, bottom; |
| 1736 |
|
| 1737 |
/* |
| 1738 |
* Determine the region of the bitmap visible in the plot area. |
| 1739 |
*/ |
| 1740 |
left = MAX(graphPtr->left, exts.left); |
| 1741 |
right = MIN(graphPtr->right, exts.right); |
| 1742 |
top = MAX(graphPtr->top, exts.top); |
| 1743 |
bottom = MIN(graphPtr->bottom, exts.bottom); |
| 1744 |
|
| 1745 |
region.left = region.top = 0; |
| 1746 |
if (graphPtr->left > exts.left) { |
| 1747 |
region.left = (int)(graphPtr->left - exts.left); |
| 1748 |
} |
| 1749 |
if (graphPtr->top > exts.top) { |
| 1750 |
region.top = (int)(graphPtr->top - exts.top); |
| 1751 |
} |
| 1752 |
regionWidth = (int)(right - left) + 1; |
| 1753 |
regionHeight = (int)(bottom - top) + 1; |
| 1754 |
region.right = region.left + (int)(right - left); |
| 1755 |
region.bottom = region.top + (int)(bottom - top); |
| 1756 |
|
| 1757 |
anchorPos.x = left; |
| 1758 |
anchorPos.y = top; |
| 1759 |
bmPtr->destBitmap = Blt_ScaleRotateBitmapRegion(graphPtr->tkwin, |
| 1760 |
bmPtr->srcBitmap, srcWidth, srcHeight, |
| 1761 |
region.left, region.top, regionWidth, regionHeight, |
| 1762 |
destWidth, destHeight, bmPtr->theta); |
| 1763 |
bmPtr->destWidth = regionWidth; |
| 1764 |
bmPtr->destHeight = regionHeight; |
| 1765 |
} else { |
| 1766 |
bmPtr->destWidth = srcWidth; |
| 1767 |
bmPtr->destHeight = srcHeight; |
| 1768 |
bmPtr->destBitmap = None; |
| 1769 |
} |
| 1770 |
bmPtr->anchorPos = anchorPos; |
| 1771 |
{ |
| 1772 |
double xScale, yScale; |
| 1773 |
double tx, ty; |
| 1774 |
double rotWidth, rotHeight; |
| 1775 |
Point2D polygon[5]; |
| 1776 |
int n; |
| 1777 |
|
| 1778 |
/* |
| 1779 |
* Compute a polygon to represent the background area of the bitmap. |
| 1780 |
* This is needed for backgrounds of arbitrarily rotated bitmaps. |
| 1781 |
* We also use it to print a background in PostScript. |
| 1782 |
*/ |
| 1783 |
Blt_GetBoundingBox(srcWidth, srcHeight, bmPtr->theta, &rotWidth, |
| 1784 |
&rotHeight, polygon); |
| 1785 |
xScale = (double)destWidth / rotWidth; |
| 1786 |
yScale = (double)destHeight / rotHeight; |
| 1787 |
|
| 1788 |
/* |
| 1789 |
* Adjust each point of the polygon. Both scale it to the new size |
| 1790 |
* and translate it to the actual screen position of the bitmap. |
| 1791 |
*/ |
| 1792 |
tx = exts.left + destWidth * 0.5; |
| 1793 |
ty = exts.top + destHeight * 0.5; |
| 1794 |
for (i = 0; i < 4; i++) { |
| 1795 |
polygon[i].x = (polygon[i].x * xScale) + tx; |
| 1796 |
polygon[i].y = (polygon[i].y * yScale) + ty; |
| 1797 |
} |
| 1798 |
Blt_GraphExtents(graphPtr, &exts); |
| 1799 |
n = Blt_PolyRectClip(&exts, polygon, 4, bmPtr->outline); |
| 1800 |
assert(n <= MAX_OUTLINE_POINTS); |
| 1801 |
if (n < 3) { |
| 1802 |
memcpy(&bmPtr->outline, polygon, sizeof(Point2D) * 4); |
| 1803 |
bmPtr->nOutlinePts = 4; |
| 1804 |
} else { |
| 1805 |
bmPtr->nOutlinePts = n; |
| 1806 |
} |
| 1807 |
} |
| 1808 |
} |
| 1809 |
|
| 1810 |
/* |
| 1811 |
* ---------------------------------------------------------------------- |
| 1812 |
* |
| 1813 |
* PointInBitmapMarker -- |
| 1814 |
* |
| 1815 |
* Indicates if the given point is over the bitmap marker. The |
| 1816 |
* area of the bitmap is the rectangle. |
| 1817 |
* |
| 1818 |
* Results: |
| 1819 |
* Returns 1 is the point is over the bitmap marker, 0 otherwise. |
| 1820 |
* |
| 1821 |
* ---------------------------------------------------------------------- |
| 1822 |
*/ |
| 1823 |
static int |
| 1824 |
PointInBitmapMarker(markerPtr, samplePtr) |
| 1825 |
Marker *markerPtr; |
| 1826 |
Point2D *samplePtr; |
| 1827 |
{ |
| 1828 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1829 |
|
| 1830 |
if (bmPtr->srcBitmap == None) { |
| 1831 |
return 0; |
| 1832 |
} |
| 1833 |
if (bmPtr->theta != 0.0) { |
| 1834 |
Point2D points[MAX_OUTLINE_POINTS]; |
| 1835 |
register int i; |
| 1836 |
|
| 1837 |
/* |
| 1838 |
* Generate the bounding polygon (isolateral) for the bitmap |
| 1839 |
* and see if the point is inside of it. |
| 1840 |
*/ |
| 1841 |
for (i = 0; i < bmPtr->nOutlinePts; i++) { |
| 1842 |
points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x; |
| 1843 |
points[i].y = bmPtr->outline[i].y + bmPtr->anchorPos.y; |
| 1844 |
} |
| 1845 |
return Blt_PointInPolygon(samplePtr, points, bmPtr->nOutlinePts); |
| 1846 |
} |
| 1847 |
return ((samplePtr->x >= bmPtr->anchorPos.x) && |
| 1848 |
(samplePtr->x < (bmPtr->anchorPos.x + bmPtr->destWidth)) && |
| 1849 |
(samplePtr->y >= bmPtr->anchorPos.y) && |
| 1850 |
(samplePtr->y < (bmPtr->anchorPos.y + bmPtr->destHeight))); |
| 1851 |
} |
| 1852 |
|
| 1853 |
|
| 1854 |
/* |
| 1855 |
* ---------------------------------------------------------------------- |
| 1856 |
* |
| 1857 |
* RegionInBitmapMarker -- |
| 1858 |
* |
| 1859 |
* ---------------------------------------------------------------------- |
| 1860 |
*/ |
| 1861 |
static int |
| 1862 |
RegionInBitmapMarker(markerPtr, extsPtr, enclosed) |
| 1863 |
Marker *markerPtr; |
| 1864 |
Extents2D *extsPtr; |
| 1865 |
int enclosed; |
| 1866 |
{ |
| 1867 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1868 |
|
| 1869 |
if (bmPtr->nWorldPts < 1) { |
| 1870 |
return FALSE; |
| 1871 |
} |
| 1872 |
if (bmPtr->theta != 0.0) { |
| 1873 |
Point2D points[MAX_OUTLINE_POINTS]; |
| 1874 |
register int i; |
| 1875 |
|
| 1876 |
/* |
| 1877 |
* Generate the bounding polygon (isolateral) for the bitmap |
| 1878 |
* and see if the point is inside of it. |
| 1879 |
*/ |
| 1880 |
for (i = 0; i < bmPtr->nOutlinePts; i++) { |
| 1881 |
points[i].x = bmPtr->outline[i].x + bmPtr->anchorPos.x; |
| 1882 |
points[i].y = bmPtr->outline[i].y + bmPtr->anchorPos.y; |
| 1883 |
} |
| 1884 |
return Blt_RegionInPolygon(extsPtr, points, bmPtr->nOutlinePts, |
| 1885 |
enclosed); |
| 1886 |
} |
| 1887 |
if (enclosed) { |
| 1888 |
return ((bmPtr->anchorPos.x >= extsPtr->left) && |
| 1889 |
(bmPtr->anchorPos.y >= extsPtr->top) && |
| 1890 |
((bmPtr->anchorPos.x + bmPtr->destWidth) <= extsPtr->right) && |
| 1891 |
((bmPtr->anchorPos.y + bmPtr->destHeight) <= extsPtr->bottom)); |
| 1892 |
} |
| 1893 |
return !((bmPtr->anchorPos.x >= extsPtr->right) || |
| 1894 |
(bmPtr->anchorPos.y >= extsPtr->bottom) || |
| 1895 |
((bmPtr->anchorPos.x + bmPtr->destWidth) <= extsPtr->left) || |
| 1896 |
((bmPtr->anchorPos.y + bmPtr->destHeight) <= extsPtr->top)); |
| 1897 |
} |
| 1898 |
|
| 1899 |
/* |
| 1900 |
* ---------------------------------------------------------------------- |
| 1901 |
* |
| 1902 |
* DrawBitmapMarker -- |
| 1903 |
* |
| 1904 |
* Draws the bitmap marker that have a transparent of filled |
| 1905 |
* background. |
| 1906 |
* |
| 1907 |
* Results: |
| 1908 |
* None. |
| 1909 |
* |
| 1910 |
* Side effects: |
| 1911 |
* GC stipple origins are changed to current window coordinates. |
| 1912 |
* Commands are output to X to draw the marker in its current |
| 1913 |
* mode. |
| 1914 |
* |
| 1915 |
* ---------------------------------------------------------------------- |
| 1916 |
*/ |
| 1917 |
static void |
| 1918 |
DrawBitmapMarker(markerPtr, drawable) |
| 1919 |
Marker *markerPtr; |
| 1920 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 1921 |
{ |
| 1922 |
Graph *graphPtr = markerPtr->graphPtr; |
| 1923 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1924 |
double theta; |
| 1925 |
Pixmap bitmap; |
| 1926 |
|
| 1927 |
bitmap = GETBITMAP(bmPtr); |
| 1928 |
if ((bitmap == None) || (bmPtr->destWidth < 1) || (bmPtr->destHeight < 1)) { |
| 1929 |
return; |
| 1930 |
} |
| 1931 |
theta = FMOD(bmPtr->theta, (double)90.0); |
| 1932 |
if ((bmPtr->fillColor == NULL) || (theta != 0.0)) { |
| 1933 |
|
| 1934 |
/* |
| 1935 |
* If the bitmap is rotated and a filled background is |
| 1936 |
* required, then a filled polygon is drawn before the |
| 1937 |
* bitmap. |
| 1938 |
*/ |
| 1939 |
|
| 1940 |
if (bmPtr->fillColor != NULL) { |
| 1941 |
int i; |
| 1942 |
XPoint polygon[MAX_OUTLINE_POINTS]; |
| 1943 |
|
| 1944 |
for (i = 0; i < bmPtr->nOutlinePts; i++) { |
| 1945 |
polygon[i].x = (short int)bmPtr->outline[i].x; |
| 1946 |
polygon[i].y = (short int)bmPtr->outline[i].y; |
| 1947 |
} |
| 1948 |
XFillPolygon(graphPtr->display, drawable, bmPtr->fillGC, |
| 1949 |
polygon, bmPtr->nOutlinePts, Convex, CoordModeOrigin); |
| 1950 |
} |
| 1951 |
XSetClipMask(graphPtr->display, bmPtr->gc, bitmap); |
| 1952 |
XSetClipOrigin(graphPtr->display, bmPtr->gc, (int)bmPtr->anchorPos.x, |
| 1953 |
(int)bmPtr->anchorPos.y); |
| 1954 |
} else { |
| 1955 |
XSetClipMask(graphPtr->display, bmPtr->gc, None); |
| 1956 |
XSetClipOrigin(graphPtr->display, bmPtr->gc, 0, 0); |
| 1957 |
} |
| 1958 |
XCopyPlane(graphPtr->display, bitmap, drawable, bmPtr->gc, 0, 0, |
| 1959 |
bmPtr->destWidth, bmPtr->destHeight, (int)bmPtr->anchorPos.x, |
| 1960 |
(int)bmPtr->anchorPos.y, 1); |
| 1961 |
} |
| 1962 |
|
| 1963 |
/* |
| 1964 |
* ---------------------------------------------------------------------- |
| 1965 |
* |
| 1966 |
* BitmapMarkerToPostScript -- |
| 1967 |
* |
| 1968 |
* Generates PostScript to print a bitmap marker. |
| 1969 |
* |
| 1970 |
* Results: |
| 1971 |
* None. |
| 1972 |
* |
| 1973 |
* ---------------------------------------------------------------------- |
| 1974 |
*/ |
| 1975 |
static void |
| 1976 |
BitmapMarkerToPostScript(markerPtr, psToken) |
| 1977 |
Marker *markerPtr; /* Marker to be printed */ |
| 1978 |
PsToken psToken; |
| 1979 |
{ |
| 1980 |
Graph *graphPtr = markerPtr->graphPtr; |
| 1981 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 1982 |
Pixmap bitmap; |
| 1983 |
|
| 1984 |
bitmap = GETBITMAP(bmPtr); |
| 1985 |
if (bitmap == None) { |
| 1986 |
return; |
| 1987 |
} |
| 1988 |
if (bmPtr->fillColor != NULL) { |
| 1989 |
Blt_BackgroundToPostScript(psToken, bmPtr->fillColor); |
| 1990 |
Blt_PolygonToPostScript(psToken, bmPtr->outline, 4); |
| 1991 |
} |
| 1992 |
Blt_ForegroundToPostScript(psToken, bmPtr->outlineColor); |
| 1993 |
|
| 1994 |
Blt_FormatToPostScript(psToken, |
| 1995 |
" gsave\n %g %g translate\n %d %d scale\n", |
| 1996 |
bmPtr->anchorPos.x, bmPtr->anchorPos.y + bmPtr->destHeight, |
| 1997 |
bmPtr->destWidth, -bmPtr->destHeight); |
| 1998 |
Blt_FormatToPostScript(psToken, " %d %d true [%d 0 0 %d 0 %d] {", |
| 1999 |
bmPtr->destWidth, bmPtr->destHeight, bmPtr->destWidth, |
| 2000 |
-bmPtr->destHeight, bmPtr->destHeight); |
| 2001 |
Blt_BitmapDataToPostScript(psToken, graphPtr->display, bitmap, |
| 2002 |
bmPtr->destWidth, bmPtr->destHeight); |
| 2003 |
Blt_AppendToPostScript(psToken, " } imagemask\n", |
| 2004 |
"grestore\n", (char *)NULL); |
| 2005 |
} |
| 2006 |
|
| 2007 |
/* |
| 2008 |
* ---------------------------------------------------------------------- |
| 2009 |
* |
| 2010 |
* FreeBitmapMarker -- |
| 2011 |
* |
| 2012 |
* Releases the memory and attributes of the bitmap marker. |
| 2013 |
* |
| 2014 |
* Results: |
| 2015 |
* None. |
| 2016 |
* |
| 2017 |
* Side effects: |
| 2018 |
* Bitmap attributes (GCs, colors, bitmap, etc) get destroyed. |
| 2019 |
* Memory is released, X resources are freed, and the graph is |
| 2020 |
* redrawn. |
| 2021 |
* |
| 2022 |
* ---------------------------------------------------------------------- |
| 2023 |
*/ |
| 2024 |
static void |
| 2025 |
FreeBitmapMarker(graphPtr, markerPtr) |
| 2026 |
Graph *graphPtr; |
| 2027 |
Marker *markerPtr; |
| 2028 |
{ |
| 2029 |
BitmapMarker *bmPtr = (BitmapMarker *)markerPtr; |
| 2030 |
|
| 2031 |
if (bmPtr->gc != NULL) { |
| 2032 |
Tk_FreeGC(graphPtr->display, bmPtr->gc); |
| 2033 |
} |
| 2034 |
if (bmPtr->fillGC != NULL) { |
| 2035 |
Tk_FreeGC(graphPtr->display, bmPtr->fillGC); |
| 2036 |
} |
| 2037 |
if (bmPtr->destBitmap != None) { |
| 2038 |
Tk_FreePixmap(graphPtr->display, bmPtr->destBitmap); |
| 2039 |
} |
| 2040 |
} |
| 2041 |
|
| 2042 |
/* |
| 2043 |
* ---------------------------------------------------------------------- |
| 2044 |
* |
| 2045 |
* CreateBitmapMarker -- |
| 2046 |
* |
| 2047 |
* Allocate memory and initialize methods for the new bitmap marker. |
| 2048 |
* |
| 2049 |
* Results: |
| 2050 |
* The pointer to the newly allocated marker structure is returned. |
| 2051 |
* |
| 2052 |
* Side effects: |
| 2053 |
* Memory is allocated for the bitmap marker structure. |
| 2054 |
* |
| 2055 |
* ---------------------------------------------------------------------- |
| 2056 |
*/ |
| 2057 |
static Marker * |
| 2058 |
CreateBitmapMarker() |
| 2059 |
{ |
| 2060 |
BitmapMarker *bmPtr; |
| 2061 |
|
| 2062 |
bmPtr = Blt_Calloc(1, sizeof(BitmapMarker)); |
| 2063 |
if (bmPtr != NULL) { |
| 2064 |
bmPtr->classPtr = &bitmapMarkerClass; |
| 2065 |
} |
| 2066 |
return (Marker *)bmPtr; |
| 2067 |
} |
| 2068 |
|
| 2069 |
/* |
| 2070 |
*---------------------------------------------------------------------- |
| 2071 |
* |
| 2072 |
* ImageChangedProc |
| 2073 |
* |
| 2074 |
* |
| 2075 |
* Results: |
| 2076 |
* None. |
| 2077 |
* |
| 2078 |
*---------------------------------------------------------------------- |
| 2079 |
*/ |
| 2080 |
/* ARGSUSED */ |
| 2081 |
static void |
| 2082 |
ImageChangedProc(clientData, x, y, width, height, imageWidth, imageHeight) |
| 2083 |
ClientData clientData; |
| 2084 |
int x, y, width, height; /* Not used. */ |
| 2085 |
int imageWidth, imageHeight; /* Not used. */ |
| 2086 |
{ |
| 2087 |
ImageMarker *imPtr = clientData; |
| 2088 |
Tk_PhotoHandle photo; |
| 2089 |
|
| 2090 |
photo = Blt_FindPhoto(imPtr->graphPtr->interp, imPtr->imageName); |
| 2091 |
if (photo != NULL) { |
| 2092 |
if (imPtr->srcImage != NULL) { |
| 2093 |
Blt_FreeColorImage(imPtr->srcImage); |
| 2094 |
} |
| 2095 |
/* Convert the latest incarnation of the photo image back to a |
| 2096 |
* color image that we can scale. */ |
| 2097 |
imPtr->srcImage = Blt_PhotoToColorImage(photo); |
| 2098 |
} |
| 2099 |
imPtr->graphPtr->flags |= REDRAW_BACKING_STORE; |
| 2100 |
imPtr->flags |= MAP_ITEM; |
| 2101 |
Blt_EventuallyRedrawGraph(imPtr->graphPtr); |
| 2102 |
} |
| 2103 |
|
| 2104 |
/* |
| 2105 |
* ---------------------------------------------------------------------- |
| 2106 |
* |
| 2107 |
* ConfigureImageMarker -- |
| 2108 |
* |
| 2109 |
* This procedure is called to process an argv/argc list, plus |
| 2110 |
* the Tk option database, in order to configure (or reconfigure) |
| 2111 |
* a image marker. |
| 2112 |
* |
| 2113 |
* Results: |
| 2114 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 2115 |
* interp->result contains an error message. |
| 2116 |
* |
| 2117 |
* Side effects: |
| 2118 |
* Configuration information, such as image pixmap, colors, |
| 2119 |
* rotation, etc. get set for markerPtr; old resources get freed, |
| 2120 |
* if there were any. The marker is eventually redisplayed. |
| 2121 |
* |
| 2122 |
* ---------------------------------------------------------------------- |
| 2123 |
*/ |
| 2124 |
static int |
| 2125 |
ConfigureImageMarker(markerPtr) |
| 2126 |
Marker *markerPtr; |
| 2127 |
{ |
| 2128 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2129 |
Graph *graphPtr = markerPtr->graphPtr; |
| 2130 |
|
| 2131 |
if (Blt_ConfigModified(markerPtr->classPtr->configSpecs, graphPtr->interp, "-image", |
| 2132 |
(char *)NULL)) { |
| 2133 |
Tcl_Interp *interp = graphPtr->interp; |
| 2134 |
|
| 2135 |
if (imPtr->tkImage != NULL) { |
| 2136 |
Tk_FreeImage(imPtr->tkImage); |
| 2137 |
imPtr->tkImage = NULL; |
| 2138 |
} |
| 2139 |
if (imPtr->imageName[0] != '\0') { |
| 2140 |
GC newGC; |
| 2141 |
Tk_PhotoHandle photo; |
| 2142 |
|
| 2143 |
imPtr->tkImage = Tk_GetImage(interp, graphPtr->tkwin, |
| 2144 |
imPtr->imageName, ImageChangedProc, imPtr); |
| 2145 |
if (imPtr->tkImage == NULL) { |
| 2146 |
Blt_Free(imPtr->imageName); |
| 2147 |
imPtr->imageName = NULL; |
| 2148 |
return TCL_ERROR; |
| 2149 |
} |
| 2150 |
photo = Blt_FindPhoto(interp, imPtr->imageName); |
| 2151 |
if (photo != NULL) { |
| 2152 |
if (imPtr->srcImage != NULL) { |
| 2153 |
Blt_FreeColorImage(imPtr->srcImage); |
| 2154 |
} |
| 2155 |
/* Convert the photo into a color image */ |
| 2156 |
imPtr->srcImage = Blt_PhotoToColorImage(photo); |
| 2157 |
} |
| 2158 |
newGC = Tk_GetGC(graphPtr->tkwin, 0L, (XGCValues *)NULL); |
| 2159 |
if (imPtr->gc != NULL) { |
| 2160 |
Tk_FreeGC(graphPtr->display, imPtr->gc); |
| 2161 |
} |
| 2162 |
imPtr->gc = newGC; |
| 2163 |
} |
| 2164 |
} |
| 2165 |
imPtr->flags |= MAP_ITEM; |
| 2166 |
if (imPtr->drawUnder) { |
| 2167 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 2168 |
} |
| 2169 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 2170 |
return TCL_OK; |
| 2171 |
} |
| 2172 |
|
| 2173 |
/* |
| 2174 |
* ---------------------------------------------------------------------- |
| 2175 |
* |
| 2176 |
* MapImageMarker -- |
| 2177 |
* |
| 2178 |
* This procedure gets called each time the layout of the graph |
| 2179 |
* changes. The x, y window coordinates of the image marker are |
| 2180 |
* saved in the marker structure. |
| 2181 |
* |
| 2182 |
* Additionly, if no background color was specified, the |
| 2183 |
* GCTileStipXOrigin and GCTileStipYOrigin attributes are set in |
| 2184 |
* the private GC. |
| 2185 |
* |
| 2186 |
* Results: |
| 2187 |
* None. |
| 2188 |
* |
| 2189 |
* Side effects: |
| 2190 |
* Window coordinates are saved and if no background color was * |
| 2191 |
* set, the GC stipple origins are changed to calculated window |
| 2192 |
* coordinates. |
| 2193 |
* |
| 2194 |
* ---------------------------------------------------------------------- |
| 2195 |
*/ |
| 2196 |
static void |
| 2197 |
MapImageMarker(markerPtr) |
| 2198 |
Marker *markerPtr; |
| 2199 |
{ |
| 2200 |
Extents2D exts; |
| 2201 |
Graph *graphPtr; |
| 2202 |
ImageMarker *imPtr; |
| 2203 |
Point2D anchorPos; |
| 2204 |
Point2D corner1, corner2; |
| 2205 |
int scaledWidth, scaledHeight; |
| 2206 |
int srcWidth, srcHeight; |
| 2207 |
|
| 2208 |
imPtr = (ImageMarker *)markerPtr; |
| 2209 |
if (imPtr->tkImage == NULL) { |
| 2210 |
return; |
| 2211 |
} |
| 2212 |
graphPtr = imPtr->graphPtr; |
| 2213 |
corner1 = MapPoint(graphPtr, imPtr->worldPts, &imPtr->axes); |
| 2214 |
if (imPtr->srcImage == NULL) { |
| 2215 |
/* |
| 2216 |
* Don't scale or rotate non-photo images. |
| 2217 |
*/ |
| 2218 |
Tk_SizeOfImage(imPtr->tkImage, &srcWidth, &srcHeight); |
| 2219 |
imPtr->width = srcWidth; |
| 2220 |
imPtr->height = srcHeight; |
| 2221 |
imPtr->anchorPos = Blt_TranslatePoint(&corner1, |
| 2222 |
srcWidth, srcHeight, imPtr->anchor); |
| 2223 |
imPtr->anchorPos.x += imPtr->xOffset; |
| 2224 |
imPtr->anchorPos.y += imPtr->yOffset; |
| 2225 |
exts.left = imPtr->anchorPos.x; |
| 2226 |
exts.top = imPtr->anchorPos.y; |
| 2227 |
exts.right = exts.left + srcWidth - 1; |
| 2228 |
exts.bottom = exts.top + srcHeight - 1; |
| 2229 |
imPtr->clipped = BoxesDontOverlap(graphPtr, &exts); |
| 2230 |
return; |
| 2231 |
} |
| 2232 |
|
| 2233 |
imPtr->width = srcWidth = Blt_ColorImageWidth(imPtr->srcImage); |
| 2234 |
imPtr->height = srcHeight = Blt_ColorImageHeight(imPtr->srcImage); |
| 2235 |
if ((srcWidth == 0) && (srcHeight == 0)) { |
| 2236 |
imPtr->clipped = TRUE; |
| 2237 |
return; /* Empty image. */ |
| 2238 |
} |
| 2239 |
if (imPtr->nWorldPts > 1) { |
| 2240 |
double hold; |
| 2241 |
|
| 2242 |
corner2 = MapPoint(graphPtr, imPtr->worldPts + 1, &imPtr->axes); |
| 2243 |
/* Flip the corners if necessary */ |
| 2244 |
if (corner1.x > corner2.x) { |
| 2245 |
hold = corner1.x, corner1.x = corner2.x, corner2.x = hold; |
| 2246 |
} |
| 2247 |
if (corner1.y > corner2.y) { |
| 2248 |
hold = corner1.y, corner1.y = corner2.y, corner2.y = hold; |
| 2249 |
} |
| 2250 |
} else { |
| 2251 |
corner2.x = corner1.x + srcWidth - 1; |
| 2252 |
corner2.y = corner1.y + srcHeight - 1; |
| 2253 |
} |
| 2254 |
scaledWidth = (int)(corner2.x - corner1.x) + 1; |
| 2255 |
scaledHeight = (int)(corner2.y - corner1.y) + 1; |
| 2256 |
|
| 2257 |
if (imPtr->nWorldPts == 1) { |
| 2258 |
anchorPos = Blt_TranslatePoint(&corner1, scaledWidth, scaledHeight, |
| 2259 |
imPtr->anchor); |
| 2260 |
} else { |
| 2261 |
anchorPos = corner1; |
| 2262 |
} |
| 2263 |
anchorPos.x += imPtr->xOffset; |
| 2264 |
anchorPos.y += imPtr->yOffset; |
| 2265 |
|
| 2266 |
/* Check if the image sits at least partially in the plot area. */ |
| 2267 |
exts.left = anchorPos.x; |
| 2268 |
exts.top = anchorPos.y; |
| 2269 |
exts.right = anchorPos.x + scaledWidth - 1; |
| 2270 |
exts.bottom = anchorPos.y + scaledHeight - 1; |
| 2271 |
|
| 2272 |
imPtr->clipped = BoxesDontOverlap(graphPtr, &exts); |
| 2273 |
if (imPtr->clipped) { |
| 2274 |
return; /* Image is offscreen. Don't generate |
| 2275 |
* rotated or scaled images. */ |
| 2276 |
} |
| 2277 |
if ((scaledWidth != srcWidth) || (scaledHeight != srcHeight)) { |
| 2278 |
Tk_PhotoHandle photo; |
| 2279 |
Blt_ColorImage destImage; |
| 2280 |
int x, y, width, height; |
| 2281 |
int left, right, top, bottom; |
| 2282 |
|
| 2283 |
/* Determine the region of the subimage inside of the |
| 2284 |
* destination image. */ |
| 2285 |
left = MAX((int)exts.left, graphPtr->left); |
| 2286 |
top = MAX((int)exts.top, graphPtr->top); |
| 2287 |
right = MIN((int)exts.right, graphPtr->right); |
| 2288 |
bottom = MIN((int)exts.bottom, graphPtr->bottom); |
| 2289 |
|
| 2290 |
/* Reset image location and coordinates to that of the region */ |
| 2291 |
anchorPos.x = left; |
| 2292 |
anchorPos.y = top; |
| 2293 |
|
| 2294 |
x = y = 0; |
| 2295 |
if (graphPtr->left > (int)exts.left) { |
| 2296 |
x = graphPtr->left - (int)exts.left; |
| 2297 |
} |
| 2298 |
if (graphPtr->top > (int)exts.top) { |
| 2299 |
y = graphPtr->top - (int)exts.top; |
| 2300 |
} |
| 2301 |
width = (int)(right - left + 1); |
| 2302 |
height = (int)(bottom - top + 1); |
| 2303 |
|
| 2304 |
destImage = Blt_ResizeColorSubimage(imPtr->srcImage, x, y, width, |
| 2305 |
height, scaledWidth, scaledHeight); |
| 2306 |
#ifdef notyet |
| 2307 |
/* Now convert the color image into a pixmap */ |
| 2308 |
if (imPtr->pixmap != None) { |
| 2309 |
Blt_FreeColorTable(imPtr->colorTable); |
| 2310 |
Tk_FreePixmap(Tk_Display(graphPtr->tkwin), imPtr->pixmap); |
| 2311 |
imPtr->colorTable = NULL; |
| 2312 |
} |
| 2313 |
imPtr->pixmap = Blt_ColorImageToPixmap(graphPtr->interp, |
| 2314 |
graphPtr->tkwin, destImage, &imPtr->colorTable); |
| 2315 |
#else |
| 2316 |
imPtr->pixmap = None; |
| 2317 |
if (imPtr->tmpImage == NULL) { |
| 2318 |
imPtr->tmpImage = Blt_CreateTemporaryImage(graphPtr->interp, |
| 2319 |
graphPtr->tkwin, imPtr); |
| 2320 |
if (imPtr->tmpImage == NULL) { |
| 2321 |
return; |
| 2322 |
} |
| 2323 |
} |
| 2324 |
/* Put the scaled colorimage into the photo. */ |
| 2325 |
photo = Blt_FindPhoto(graphPtr->interp, |
| 2326 |
Blt_NameOfImage(imPtr->tmpImage)); |
| 2327 |
Blt_ColorImageToPhoto(destImage, photo); |
| 2328 |
#endif |
| 2329 |
Blt_FreeColorImage(destImage); |
| 2330 |
imPtr->width = width; |
| 2331 |
imPtr->height = height; |
| 2332 |
} |
| 2333 |
imPtr->anchorPos = anchorPos; |
| 2334 |
} |
| 2335 |
|
| 2336 |
/* |
| 2337 |
* ---------------------------------------------------------------------- |
| 2338 |
* |
| 2339 |
* PointInWindowMarker -- |
| 2340 |
* |
| 2341 |
* Indicates if the given point is over the window marker. The |
| 2342 |
* area of the window is the rectangle. |
| 2343 |
* |
| 2344 |
* Results: |
| 2345 |
* Returns 1 is the point is over the window marker, 0 otherwise. |
| 2346 |
* |
| 2347 |
* ---------------------------------------------------------------------- |
| 2348 |
*/ |
| 2349 |
static int |
| 2350 |
PointInImageMarker(markerPtr, samplePtr) |
| 2351 |
Marker *markerPtr; |
| 2352 |
Point2D *samplePtr; |
| 2353 |
{ |
| 2354 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2355 |
|
| 2356 |
return ((samplePtr->x >= imPtr->anchorPos.x) && |
| 2357 |
(samplePtr->x < (imPtr->anchorPos.x + imPtr->width)) && |
| 2358 |
(samplePtr->y >= imPtr->anchorPos.y) && |
| 2359 |
(samplePtr->y < (imPtr->anchorPos.y + imPtr->height))); |
| 2360 |
} |
| 2361 |
|
| 2362 |
/* |
| 2363 |
* ---------------------------------------------------------------------- |
| 2364 |
* |
| 2365 |
* RegionInImageMarker -- |
| 2366 |
* |
| 2367 |
* ---------------------------------------------------------------------- |
| 2368 |
*/ |
| 2369 |
static int |
| 2370 |
RegionInImageMarker(markerPtr, extsPtr, enclosed) |
| 2371 |
Marker *markerPtr; |
| 2372 |
Extents2D *extsPtr; |
| 2373 |
int enclosed; |
| 2374 |
{ |
| 2375 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2376 |
|
| 2377 |
if (imPtr->nWorldPts < 1) { |
| 2378 |
return FALSE; |
| 2379 |
} |
| 2380 |
if (enclosed) { |
| 2381 |
return ((imPtr->anchorPos.x >= extsPtr->left) && |
| 2382 |
(imPtr->anchorPos.y >= extsPtr->top) && |
| 2383 |
((imPtr->anchorPos.x + imPtr->width) <= extsPtr->right) && |
| 2384 |
((imPtr->anchorPos.y + imPtr->height) <= extsPtr->bottom)); |
| 2385 |
} |
| 2386 |
return !((imPtr->anchorPos.x >= extsPtr->right) || |
| 2387 |
(imPtr->anchorPos.y >= extsPtr->bottom) || |
| 2388 |
((imPtr->anchorPos.x + imPtr->width) <= extsPtr->left) || |
| 2389 |
((imPtr->anchorPos.y + imPtr->height) <= extsPtr->top)); |
| 2390 |
} |
| 2391 |
|
| 2392 |
/* |
| 2393 |
* ---------------------------------------------------------------------- |
| 2394 |
* |
| 2395 |
* DrawImageMarker -- |
| 2396 |
* |
| 2397 |
* This procedure is invoked to draw a image marker. |
| 2398 |
* |
| 2399 |
* Results: |
| 2400 |
* None. |
| 2401 |
* |
| 2402 |
* Side effects: |
| 2403 |
* GC stipple origins are changed to current window coordinates. |
| 2404 |
* Commands are output to X to draw the marker in its current mode. |
| 2405 |
* |
| 2406 |
* ---------------------------------------------------------------------- |
| 2407 |
*/ |
| 2408 |
static void |
| 2409 |
DrawImageMarker(markerPtr, drawable) |
| 2410 |
Marker *markerPtr; |
| 2411 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 2412 |
{ |
| 2413 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2414 |
int width, height; |
| 2415 |
|
| 2416 |
if ((imPtr->tkImage == NULL) || (Tk_ImageIsDeleted(imPtr->tkImage))) { |
| 2417 |
return; |
| 2418 |
} |
| 2419 |
if (imPtr->pixmap == None) { |
| 2420 |
Pixmap pixmap; |
| 2421 |
Tk_Image tkImage; |
| 2422 |
|
| 2423 |
tkImage = (imPtr->tmpImage != NULL) ? imPtr->tmpImage : imPtr->tkImage; |
| 2424 |
Tk_SizeOfImage(tkImage, &width, &height); |
| 2425 |
/* pixmap = Tk_ImageGetPhotoPixmap(tkImage); */ |
| 2426 |
pixmap = None; |
| 2427 |
if (pixmap == None) { /* May not be a "photo" image. */ |
| 2428 |
Tk_RedrawImage(tkImage, 0, 0, width, height, drawable, |
| 2429 |
(int)imPtr->anchorPos.x, (int)imPtr->anchorPos.y); |
| 2430 |
} else { |
| 2431 |
XCopyArea(imPtr->graphPtr->display, pixmap, drawable, |
| 2432 |
imPtr->gc, 0, 0, width, height, (int)imPtr->anchorPos.x, |
| 2433 |
(int)imPtr->anchorPos.y); |
| 2434 |
} |
| 2435 |
} else { |
| 2436 |
XCopyArea(imPtr->graphPtr->display, imPtr->pixmap, drawable, |
| 2437 |
imPtr->gc, 0, 0, imPtr->width, imPtr->height, |
| 2438 |
(int)imPtr->anchorPos.x, (int)imPtr->anchorPos.y); |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
/* |
| 2443 |
* ---------------------------------------------------------------------- |
| 2444 |
* |
| 2445 |
* ImageMarkerToPostScript -- |
| 2446 |
* |
| 2447 |
* This procedure is invoked to print a image marker. |
| 2448 |
* |
| 2449 |
* Results: |
| 2450 |
* None. |
| 2451 |
* |
| 2452 |
* ---------------------------------------------------------------------- |
| 2453 |
*/ |
| 2454 |
static void |
| 2455 |
ImageMarkerToPostScript(markerPtr, psToken) |
| 2456 |
Marker *markerPtr; /* Marker to be printed */ |
| 2457 |
PsToken psToken; |
| 2458 |
{ |
| 2459 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2460 |
char *imageName; |
| 2461 |
Tk_PhotoHandle photo; |
| 2462 |
|
| 2463 |
if ((imPtr->tkImage == NULL) || (Tk_ImageIsDeleted(imPtr->tkImage))) { |
| 2464 |
return; /* Image doesn't exist anymore */ |
| 2465 |
} |
| 2466 |
imageName = (imPtr->tmpImage == NULL) |
| 2467 |
? Blt_NameOfImage(imPtr->tkImage) : Blt_NameOfImage(imPtr->tmpImage); |
| 2468 |
photo = Blt_FindPhoto(markerPtr->graphPtr->interp, imageName); |
| 2469 |
if (photo == NULL) { |
| 2470 |
return; /* Image isn't a photo image */ |
| 2471 |
} |
| 2472 |
Blt_PhotoToPostScript(psToken, photo, imPtr->anchorPos.x, |
| 2473 |
imPtr->anchorPos.y); |
| 2474 |
} |
| 2475 |
|
| 2476 |
/* |
| 2477 |
* ---------------------------------------------------------------------- |
| 2478 |
* |
| 2479 |
* FreeImageMarker -- |
| 2480 |
* |
| 2481 |
* Destroys the structure containing the attributes of the image |
| 2482 |
* marker. |
| 2483 |
* |
| 2484 |
* Results: |
| 2485 |
* None. |
| 2486 |
* |
| 2487 |
* Side effects: |
| 2488 |
* Image attributes (GCs, colors, image, etc) get destroyed. |
| 2489 |
* Memory is released, X resources are freed, and the graph is |
| 2490 |
* redrawn. |
| 2491 |
* |
| 2492 |
* ---------------------------------------------------------------------- |
| 2493 |
*/ |
| 2494 |
static void |
| 2495 |
FreeImageMarker(graphPtr, markerPtr) |
| 2496 |
Graph *graphPtr; |
| 2497 |
Marker *markerPtr; |
| 2498 |
{ |
| 2499 |
ImageMarker *imPtr = (ImageMarker *)markerPtr; |
| 2500 |
|
| 2501 |
if (imPtr->pixmap != None) { |
| 2502 |
Tk_FreePixmap(graphPtr->display, imPtr->pixmap); |
| 2503 |
} |
| 2504 |
if (imPtr->tkImage != NULL) { |
| 2505 |
Tk_FreeImage(imPtr->tkImage); |
| 2506 |
} |
| 2507 |
if (imPtr->tmpImage != NULL) { |
| 2508 |
Blt_DestroyTemporaryImage(graphPtr->interp, imPtr->tmpImage); |
| 2509 |
} |
| 2510 |
if (imPtr->srcImage != NULL) { |
| 2511 |
Blt_FreeColorImage(imPtr->srcImage); |
| 2512 |
} |
| 2513 |
if (imPtr->gc != NULL) { |
| 2514 |
Tk_FreeGC(graphPtr->display, imPtr->gc); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
/* |
| 2519 |
* ---------------------------------------------------------------------- |
| 2520 |
* |
| 2521 |
* CreateImageMarker -- |
| 2522 |
* |
| 2523 |
* Allocate memory and initialize methods for the new image marker. |
| 2524 |
* |
| 2525 |
* Results: |
| 2526 |
* The pointer to the newly allocated marker structure is returned. |
| 2527 |
* |
| 2528 |
* Side effects: |
| 2529 |
* Memory is allocated for the image marker structure. |
| 2530 |
* |
| 2531 |
* ---------------------------------------------------------------------- |
| 2532 |
*/ |
| 2533 |
static Marker * |
| 2534 |
CreateImageMarker() |
| 2535 |
{ |
| 2536 |
ImageMarker *imPtr; |
| 2537 |
|
| 2538 |
imPtr = Blt_Calloc(1, sizeof(ImageMarker)); |
| 2539 |
if (imPtr != NULL) { |
| 2540 |
imPtr->classPtr = &imageMarkerClass; |
| 2541 |
} |
| 2542 |
return (Marker *)imPtr; |
| 2543 |
} |
| 2544 |
|
| 2545 |
/* |
| 2546 |
* ---------------------------------------------------------------------- |
| 2547 |
* |
| 2548 |
* ConfigureTextMarker -- |
| 2549 |
* |
| 2550 |
* This procedure is called to process an argv/argc list, plus |
| 2551 |
* the Tk option database, in order to configure (or |
| 2552 |
* reconfigure) a text marker. |
| 2553 |
* |
| 2554 |
* Results: |
| 2555 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 2556 |
* interp->result contains an error message. |
| 2557 |
* |
| 2558 |
* Side effects: |
| 2559 |
* Configuration information, such as text string, colors, font, |
| 2560 |
* etc. get set for markerPtr; old resources get freed, if there |
| 2561 |
* were any. The marker is eventually redisplayed. |
| 2562 |
* |
| 2563 |
* ---------------------------------------------------------------------- |
| 2564 |
*/ |
| 2565 |
static int |
| 2566 |
ConfigureTextMarker(markerPtr) |
| 2567 |
Marker *markerPtr; |
| 2568 |
{ |
| 2569 |
Graph *graphPtr = markerPtr->graphPtr; |
| 2570 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2571 |
GC newGC; |
| 2572 |
XGCValues gcValues; |
| 2573 |
unsigned long gcMask; |
| 2574 |
|
| 2575 |
tmPtr->style.theta = FMOD(tmPtr->style.theta, 360.0); |
| 2576 |
if (tmPtr->style.theta < 0.0) { |
| 2577 |
tmPtr->style.theta += 360.0; |
| 2578 |
} |
| 2579 |
newGC = NULL; |
| 2580 |
if (tmPtr->fillColor != NULL) { |
| 2581 |
gcMask = GCForeground; |
| 2582 |
gcValues.foreground = tmPtr->fillColor->pixel; |
| 2583 |
newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); |
| 2584 |
} |
| 2585 |
if (tmPtr->fillGC != NULL) { |
| 2586 |
Tk_FreeGC(graphPtr->display, tmPtr->fillGC); |
| 2587 |
} |
| 2588 |
tmPtr->fillGC = newGC; |
| 2589 |
Blt_ResetTextStyle(graphPtr->tkwin, &tmPtr->style); |
| 2590 |
|
| 2591 |
if (Blt_ConfigModified(tmPtr->classPtr->configSpecs, graphPtr->interp, "-text", |
| 2592 |
(char *)NULL)) { |
| 2593 |
if (tmPtr->textPtr != NULL) { |
| 2594 |
Blt_Free(tmPtr->textPtr); |
| 2595 |
tmPtr->textPtr = NULL; |
| 2596 |
} |
| 2597 |
tmPtr->width = tmPtr->height = 0; |
| 2598 |
if (tmPtr->string != NULL) { |
| 2599 |
register int i; |
| 2600 |
double rotWidth, rotHeight; |
| 2601 |
|
| 2602 |
tmPtr->textPtr = Blt_GetTextLayout(tmPtr->string, &tmPtr->style); |
| 2603 |
Blt_GetBoundingBox(tmPtr->textPtr->width, tmPtr->textPtr->height, |
| 2604 |
tmPtr->style.theta, &rotWidth, &rotHeight, tmPtr->outline); |
| 2605 |
tmPtr->width = ROUND(rotWidth); |
| 2606 |
tmPtr->height = ROUND(rotHeight); |
| 2607 |
for (i = 0; i < 4; i++) { |
| 2608 |
tmPtr->outline[i].x += ROUND(rotWidth * 0.5); |
| 2609 |
tmPtr->outline[i].y += ROUND(rotHeight * 0.5); |
| 2610 |
} |
| 2611 |
tmPtr->outline[4].x = tmPtr->outline[0].x; |
| 2612 |
tmPtr->outline[4].y = tmPtr->outline[0].y; |
| 2613 |
} |
| 2614 |
} |
| 2615 |
tmPtr->flags |= MAP_ITEM; |
| 2616 |
if (tmPtr->drawUnder) { |
| 2617 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 2618 |
} |
| 2619 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 2620 |
return TCL_OK; |
| 2621 |
} |
| 2622 |
|
| 2623 |
/* |
| 2624 |
* ---------------------------------------------------------------------- |
| 2625 |
* |
| 2626 |
* MapTextMarker -- |
| 2627 |
* |
| 2628 |
* Calculate the layout position for a text marker. Positional |
| 2629 |
* information is saved in the marker. If the text is rotated, |
| 2630 |
* a bitmap containing the text is created. |
| 2631 |
* |
| 2632 |
* Results: |
| 2633 |
* None. |
| 2634 |
* |
| 2635 |
* Side effects: |
| 2636 |
* If no background color has been specified, the GC stipple |
| 2637 |
* origins are changed to current window coordinates. For both |
| 2638 |
* rotated and non-rotated text, if any old bitmap is leftover, |
| 2639 |
* it is freed. |
| 2640 |
* |
| 2641 |
* ---------------------------------------------------------------------- |
| 2642 |
*/ |
| 2643 |
static void |
| 2644 |
MapTextMarker(markerPtr) |
| 2645 |
Marker *markerPtr; |
| 2646 |
{ |
| 2647 |
Graph *graphPtr = markerPtr->graphPtr; |
| 2648 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2649 |
Extents2D exts; |
| 2650 |
Point2D anchorPos; |
| 2651 |
|
| 2652 |
if (tmPtr->string == NULL) { |
| 2653 |
return; |
| 2654 |
} |
| 2655 |
anchorPos = MapPoint(graphPtr, tmPtr->worldPts, &tmPtr->axes); |
| 2656 |
anchorPos = Blt_TranslatePoint(&anchorPos, tmPtr->width, tmPtr->height, |
| 2657 |
tmPtr->anchor); |
| 2658 |
anchorPos.x += tmPtr->xOffset; |
| 2659 |
anchorPos.y += tmPtr->yOffset; |
| 2660 |
/* |
| 2661 |
* Determine the bounding box of the text and test to see if it |
| 2662 |
* is at least partially contained within the plotting area. |
| 2663 |
*/ |
| 2664 |
exts.left = anchorPos.x; |
| 2665 |
exts.top = anchorPos.y; |
| 2666 |
exts.right = anchorPos.x + tmPtr->width - 1; |
| 2667 |
exts.bottom = anchorPos.y + tmPtr->height - 1; |
| 2668 |
tmPtr->clipped = BoxesDontOverlap(graphPtr, &exts); |
| 2669 |
tmPtr->anchorPos = anchorPos; |
| 2670 |
|
| 2671 |
} |
| 2672 |
|
| 2673 |
static int |
| 2674 |
PointInTextMarker(markerPtr, samplePtr) |
| 2675 |
Marker *markerPtr; |
| 2676 |
Point2D *samplePtr; |
| 2677 |
{ |
| 2678 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2679 |
|
| 2680 |
if (tmPtr->string == NULL) { |
| 2681 |
return 0; |
| 2682 |
} |
| 2683 |
if (tmPtr->style.theta != 0.0) { |
| 2684 |
Point2D points[5]; |
| 2685 |
register int i; |
| 2686 |
|
| 2687 |
/* |
| 2688 |
* Figure out the bounding polygon (isolateral) for the text |
| 2689 |
* and see if the point is inside of it. |
| 2690 |
*/ |
| 2691 |
|
| 2692 |
for (i = 0; i < 5; i++) { |
| 2693 |
points[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x; |
| 2694 |
points[i].y = tmPtr->outline[i].y + tmPtr->anchorPos.y; |
| 2695 |
} |
| 2696 |
return Blt_PointInPolygon(samplePtr, points, 5); |
| 2697 |
} |
| 2698 |
return ((samplePtr->x >= tmPtr->anchorPos.x) && |
| 2699 |
(samplePtr->x < (tmPtr->anchorPos.x + tmPtr->width)) && |
| 2700 |
(samplePtr->y >= tmPtr->anchorPos.y) && |
| 2701 |
(samplePtr->y < (tmPtr->anchorPos.y + tmPtr->height))); |
| 2702 |
} |
| 2703 |
|
| 2704 |
/* |
| 2705 |
* ---------------------------------------------------------------------- |
| 2706 |
* |
| 2707 |
* RegionInTextMarker -- |
| 2708 |
* |
| 2709 |
* ---------------------------------------------------------------------- |
| 2710 |
*/ |
| 2711 |
static int |
| 2712 |
RegionInTextMarker(markerPtr, extsPtr, enclosed) |
| 2713 |
Marker *markerPtr; |
| 2714 |
Extents2D *extsPtr; |
| 2715 |
int enclosed; |
| 2716 |
{ |
| 2717 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2718 |
|
| 2719 |
if (tmPtr->nWorldPts < 1) { |
| 2720 |
return FALSE; |
| 2721 |
} |
| 2722 |
if (tmPtr->style.theta != 0.0) { |
| 2723 |
Point2D points[5]; |
| 2724 |
register int i; |
| 2725 |
|
| 2726 |
/* |
| 2727 |
* Generate the bounding polygon (isolateral) for the bitmap |
| 2728 |
* and see if the point is inside of it. |
| 2729 |
*/ |
| 2730 |
for (i = 0; i < 4; i++) { |
| 2731 |
points[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x; |
| 2732 |
points[i].y = tmPtr->outline[i].y + tmPtr->anchorPos.y; |
| 2733 |
} |
| 2734 |
return Blt_RegionInPolygon(extsPtr, points, 4, enclosed); |
| 2735 |
} |
| 2736 |
if (enclosed) { |
| 2737 |
return ((tmPtr->anchorPos.x >= extsPtr->left) && |
| 2738 |
(tmPtr->anchorPos.y >= extsPtr->top) && |
| 2739 |
((tmPtr->anchorPos.x + tmPtr->width) <= extsPtr->right) && |
| 2740 |
((tmPtr->anchorPos.y + tmPtr->height) <= extsPtr->bottom)); |
| 2741 |
} |
| 2742 |
return !((tmPtr->anchorPos.x >= extsPtr->right) || |
| 2743 |
(tmPtr->anchorPos.y >= extsPtr->bottom) || |
| 2744 |
((tmPtr->anchorPos.x + tmPtr->width) <= extsPtr->left) || |
| 2745 |
((tmPtr->anchorPos.y + tmPtr->height) <= extsPtr->top)); |
| 2746 |
} |
| 2747 |
|
| 2748 |
/* |
| 2749 |
* ---------------------------------------------------------------------- |
| 2750 |
* |
| 2751 |
* DrawTextMarker -- |
| 2752 |
* |
| 2753 |
* Draws the text marker on the graph. |
| 2754 |
* |
| 2755 |
* Results: |
| 2756 |
* None. |
| 2757 |
* |
| 2758 |
* Side effects: |
| 2759 |
* Commands are output to X to draw the marker in its current |
| 2760 |
* mode. |
| 2761 |
* |
| 2762 |
* ---------------------------------------------------------------------- |
| 2763 |
*/ |
| 2764 |
static void |
| 2765 |
DrawTextMarker(markerPtr, drawable) |
| 2766 |
Marker *markerPtr; |
| 2767 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 2768 |
{ |
| 2769 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2770 |
Graph *graphPtr = markerPtr->graphPtr; |
| 2771 |
|
| 2772 |
if (tmPtr->string == NULL) { |
| 2773 |
return; |
| 2774 |
} |
| 2775 |
if (tmPtr->fillGC != NULL) { |
| 2776 |
XPoint pointArr[4]; |
| 2777 |
register int i; |
| 2778 |
|
| 2779 |
/* |
| 2780 |
* Simulate the rotated background of the bitmap by |
| 2781 |
* filling a bounding polygon with the background color. |
| 2782 |
*/ |
| 2783 |
for (i = 0; i < 4; i++) { |
| 2784 |
pointArr[i].x = (short int) |
| 2785 |
(tmPtr->outline[i].x + tmPtr->anchorPos.x); |
| 2786 |
pointArr[i].y = (short int) |
| 2787 |
(tmPtr->outline[i].y + tmPtr->anchorPos.y); |
| 2788 |
} |
| 2789 |
XFillPolygon(graphPtr->display, drawable, tmPtr->fillGC, pointArr, 4, |
| 2790 |
Convex, CoordModeOrigin); |
| 2791 |
} |
| 2792 |
if (tmPtr->style.color != NULL) { |
| 2793 |
Blt_DrawTextLayout(graphPtr->tkwin, drawable, tmPtr->textPtr, |
| 2794 |
&tmPtr->style, (int)tmPtr->anchorPos.x, (int)tmPtr->anchorPos.y); |
| 2795 |
} |
| 2796 |
} |
| 2797 |
|
| 2798 |
/* |
| 2799 |
* ---------------------------------------------------------------------- |
| 2800 |
* |
| 2801 |
* TextMarkerToPostScript -- |
| 2802 |
* |
| 2803 |
* Outputs PostScript commands to draw a text marker at a given |
| 2804 |
* x,y coordinate, rotation, anchor, and font. |
| 2805 |
* |
| 2806 |
* Results: |
| 2807 |
* None. |
| 2808 |
* |
| 2809 |
* Side effects: |
| 2810 |
* PostScript font and color settings are changed. |
| 2811 |
* |
| 2812 |
* ---------------------------------------------------------------------- |
| 2813 |
*/ |
| 2814 |
static void |
| 2815 |
TextMarkerToPostScript(markerPtr, psToken) |
| 2816 |
Marker *markerPtr; |
| 2817 |
PsToken psToken; |
| 2818 |
{ |
| 2819 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2820 |
|
| 2821 |
if (tmPtr->string == NULL) { |
| 2822 |
return; |
| 2823 |
} |
| 2824 |
if (tmPtr->fillGC != NULL) { |
| 2825 |
Point2D polygon[4]; |
| 2826 |
register int i; |
| 2827 |
|
| 2828 |
/* |
| 2829 |
* Simulate the rotated background of the bitmap by |
| 2830 |
* filling a bounding polygon with the background color. |
| 2831 |
*/ |
| 2832 |
for (i = 0; i < 4; i++) { |
| 2833 |
polygon[i].x = tmPtr->outline[i].x + tmPtr->anchorPos.x; |
| 2834 |
polygon[i].y = tmPtr->outline[i].y + tmPtr->anchorPos.y; |
| 2835 |
} |
| 2836 |
Blt_BackgroundToPostScript(psToken, tmPtr->fillColor); |
| 2837 |
Blt_PolygonToPostScript(psToken, polygon, 4); |
| 2838 |
} |
| 2839 |
Blt_TextToPostScript(psToken, tmPtr->string, &tmPtr->style, |
| 2840 |
tmPtr->anchorPos.x, tmPtr->anchorPos.y); |
| 2841 |
} |
| 2842 |
|
| 2843 |
/* |
| 2844 |
* ---------------------------------------------------------------------- |
| 2845 |
* |
| 2846 |
* FreeTextMarker -- |
| 2847 |
* |
| 2848 |
* Destroys the structure containing the attributes of the text |
| 2849 |
* marker. |
| 2850 |
* |
| 2851 |
* Results: |
| 2852 |
* None. |
| 2853 |
* |
| 2854 |
* Side effects: |
| 2855 |
* Text attributes (GCs, colors, stipple, font, etc) get destroyed. |
| 2856 |
* Memory is released, X resources are freed, and the graph is |
| 2857 |
* redrawn. |
| 2858 |
* |
| 2859 |
* ---------------------------------------------------------------------- |
| 2860 |
*/ |
| 2861 |
static void |
| 2862 |
FreeTextMarker(graphPtr, markerPtr) |
| 2863 |
Graph *graphPtr; |
| 2864 |
Marker *markerPtr; |
| 2865 |
{ |
| 2866 |
TextMarker *tmPtr = (TextMarker *)markerPtr; |
| 2867 |
|
| 2868 |
Blt_FreeTextStyle(graphPtr->display, &tmPtr->style); |
| 2869 |
if (tmPtr->textPtr != NULL) { |
| 2870 |
Blt_Free(tmPtr->textPtr); |
| 2871 |
} |
| 2872 |
} |
| 2873 |
|
| 2874 |
/* |
| 2875 |
* ---------------------------------------------------------------------- |
| 2876 |
* |
| 2877 |
* CreateTextMarker -- |
| 2878 |
* |
| 2879 |
* Allocate memory and initialize methods for the new text marker. |
| 2880 |
* |
| 2881 |
* Results: |
| 2882 |
* The pointer to the newly allocated marker structure is returned. |
| 2883 |
* |
| 2884 |
* Side effects: |
| 2885 |
* Memory is allocated for the text marker structure. |
| 2886 |
* |
| 2887 |
* ---------------------------------------------------------------------- |
| 2888 |
*/ |
| 2889 |
static Marker * |
| 2890 |
CreateTextMarker() |
| 2891 |
{ |
| 2892 |
TextMarker *tmPtr; |
| 2893 |
|
| 2894 |
tmPtr = Blt_Calloc(1, sizeof(TextMarker)); |
| 2895 |
assert(tmPtr); |
| 2896 |
|
| 2897 |
tmPtr->classPtr = &textMarkerClass; |
| 2898 |
Blt_InitTextStyle(&tmPtr->style); |
| 2899 |
tmPtr->style.anchor = TK_ANCHOR_NW; |
| 2900 |
tmPtr->style.padLeft = tmPtr->style.padRight = 4; |
| 2901 |
tmPtr->style.padTop = tmPtr->style.padBottom = 4; |
| 2902 |
|
| 2903 |
return (Marker *)tmPtr; |
| 2904 |
} |
| 2905 |
|
| 2906 |
|
| 2907 |
static void ChildEventProc _ANSI_ARGS_((ClientData clientData, |
| 2908 |
XEvent *eventPtr)); |
| 2909 |
static void ChildGeometryProc _ANSI_ARGS_((ClientData clientData, |
| 2910 |
Tk_Window tkwin)); |
| 2911 |
|
| 2912 |
static void ChildCustodyProc _ANSI_ARGS_((ClientData clientData, |
| 2913 |
Tk_Window tkwin)); |
| 2914 |
|
| 2915 |
static Tk_GeomMgr winMarkerMgrInfo = |
| 2916 |
{ |
| 2917 |
"graph", /* Name of geometry manager used by winfo */ |
| 2918 |
ChildGeometryProc, /* Procedure to for new geometry requests */ |
| 2919 |
ChildCustodyProc, /* Procedure when window is taken away */ |
| 2920 |
}; |
| 2921 |
|
| 2922 |
/* |
| 2923 |
* ---------------------------------------------------------------------- |
| 2924 |
* |
| 2925 |
* ConfigureWindowMarker -- |
| 2926 |
* |
| 2927 |
* This procedure is called to process an argv/argc list, plus |
| 2928 |
* the Tk option database, in order to configure (or reconfigure) |
| 2929 |
* a window marker. |
| 2930 |
* |
| 2931 |
* Results: |
| 2932 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 2933 |
* interp->result contains an error message. |
| 2934 |
* |
| 2935 |
* Side effects: |
| 2936 |
* Configuration information, such as window pathname, placement, |
| 2937 |
* etc. get set for markerPtr; old resources get freed, if there |
| 2938 |
* were any. The marker is eventually redisplayed. |
| 2939 |
* |
| 2940 |
* ---------------------------------------------------------------------- |
| 2941 |
*/ |
| 2942 |
static int |
| 2943 |
ConfigureWindowMarker(markerPtr) |
| 2944 |
Marker *markerPtr; |
| 2945 |
{ |
| 2946 |
Graph *graphPtr = markerPtr->graphPtr; |
| 2947 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 2948 |
Tk_Window tkwin; |
| 2949 |
|
| 2950 |
if (wmPtr->pathName == NULL) { |
| 2951 |
return TCL_OK; |
| 2952 |
} |
| 2953 |
tkwin = Tk_NameToWindow(graphPtr->interp, wmPtr->pathName, |
| 2954 |
graphPtr->tkwin); |
| 2955 |
if (tkwin == NULL) { |
| 2956 |
return TCL_ERROR; |
| 2957 |
} |
| 2958 |
if (Tk_Parent(tkwin) != graphPtr->tkwin) { |
| 2959 |
Tcl_AppendResult(graphPtr->interp, "\"", wmPtr->pathName, |
| 2960 |
"\" is not a child of \"", Tk_PathName(graphPtr->tkwin), "\"", |
| 2961 |
(char *)NULL); |
| 2962 |
return TCL_ERROR; |
| 2963 |
} |
| 2964 |
if (tkwin != wmPtr->tkwin) { |
| 2965 |
if (wmPtr->tkwin != NULL) { |
| 2966 |
Tk_DeleteEventHandler(wmPtr->tkwin, StructureNotifyMask, |
| 2967 |
ChildEventProc, wmPtr); |
| 2968 |
Tk_ManageGeometry(wmPtr->tkwin, (Tk_GeomMgr *) 0, (ClientData)0); |
| 2969 |
Tk_UnmapWindow(wmPtr->tkwin); |
| 2970 |
} |
| 2971 |
Tk_CreateEventHandler(tkwin, StructureNotifyMask, ChildEventProc, |
| 2972 |
wmPtr); |
| 2973 |
Tk_ManageGeometry(tkwin, &winMarkerMgrInfo, wmPtr); |
| 2974 |
} |
| 2975 |
wmPtr->tkwin = tkwin; |
| 2976 |
|
| 2977 |
wmPtr->flags |= MAP_ITEM; |
| 2978 |
if (wmPtr->drawUnder) { |
| 2979 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 2980 |
} |
| 2981 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 2982 |
return TCL_OK; |
| 2983 |
} |
| 2984 |
|
| 2985 |
/* |
| 2986 |
* ---------------------------------------------------------------------- |
| 2987 |
* |
| 2988 |
* MapWindowMarker -- |
| 2989 |
* |
| 2990 |
* Calculate the layout position for a window marker. Positional |
| 2991 |
* information is saved in the marker. |
| 2992 |
* |
| 2993 |
* Results: |
| 2994 |
* None. |
| 2995 |
* |
| 2996 |
* ---------------------------------------------------------------------- |
| 2997 |
*/ |
| 2998 |
static void |
| 2999 |
MapWindowMarker(markerPtr) |
| 3000 |
Marker *markerPtr; |
| 3001 |
{ |
| 3002 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3003 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3004 |
Extents2D exts; |
| 3005 |
int width, height; |
| 3006 |
|
| 3007 |
if (wmPtr->tkwin == (Tk_Window)NULL) { |
| 3008 |
return; |
| 3009 |
} |
| 3010 |
wmPtr->anchorPos = MapPoint(graphPtr, wmPtr->worldPts, &wmPtr->axes); |
| 3011 |
|
| 3012 |
width = Tk_ReqWidth(wmPtr->tkwin); |
| 3013 |
height = Tk_ReqHeight(wmPtr->tkwin); |
| 3014 |
if (wmPtr->reqWidth > 0) { |
| 3015 |
width = wmPtr->reqWidth; |
| 3016 |
} |
| 3017 |
if (wmPtr->reqHeight > 0) { |
| 3018 |
height = wmPtr->reqHeight; |
| 3019 |
} |
| 3020 |
wmPtr->anchorPos = Blt_TranslatePoint(&wmPtr->anchorPos, width, height, |
| 3021 |
wmPtr->anchor); |
| 3022 |
wmPtr->anchorPos.x += wmPtr->xOffset; |
| 3023 |
wmPtr->anchorPos.y += wmPtr->yOffset; |
| 3024 |
wmPtr->width = width; |
| 3025 |
wmPtr->height = height; |
| 3026 |
|
| 3027 |
/* |
| 3028 |
* Determine the bounding box of the window and test to see if it |
| 3029 |
* is at least partially contained within the plotting area. |
| 3030 |
*/ |
| 3031 |
exts.left = wmPtr->anchorPos.x; |
| 3032 |
exts.top = wmPtr->anchorPos.y; |
| 3033 |
exts.right = wmPtr->anchorPos.x + wmPtr->width - 1; |
| 3034 |
exts.bottom = wmPtr->anchorPos.y + wmPtr->height - 1; |
| 3035 |
wmPtr->clipped = BoxesDontOverlap(graphPtr, &exts); |
| 3036 |
} |
| 3037 |
|
| 3038 |
/* |
| 3039 |
* ---------------------------------------------------------------------- |
| 3040 |
* |
| 3041 |
* PointInWindowMarker -- |
| 3042 |
* |
| 3043 |
* ---------------------------------------------------------------------- |
| 3044 |
*/ |
| 3045 |
static int |
| 3046 |
PointInWindowMarker(markerPtr, samplePtr) |
| 3047 |
Marker *markerPtr; |
| 3048 |
Point2D *samplePtr; |
| 3049 |
{ |
| 3050 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3051 |
|
| 3052 |
return ((samplePtr->x >= wmPtr->anchorPos.x) && |
| 3053 |
(samplePtr->x < (wmPtr->anchorPos.x + wmPtr->width)) && |
| 3054 |
(samplePtr->y >= wmPtr->anchorPos.y) && |
| 3055 |
(samplePtr->y < (wmPtr->anchorPos.y + wmPtr->height))); |
| 3056 |
} |
| 3057 |
|
| 3058 |
/* |
| 3059 |
* ---------------------------------------------------------------------- |
| 3060 |
* |
| 3061 |
* RegionInWindowMarker -- |
| 3062 |
* |
| 3063 |
* ---------------------------------------------------------------------- |
| 3064 |
*/ |
| 3065 |
static int |
| 3066 |
RegionInWindowMarker(markerPtr, extsPtr, enclosed) |
| 3067 |
Marker *markerPtr; |
| 3068 |
Extents2D *extsPtr; |
| 3069 |
int enclosed; |
| 3070 |
{ |
| 3071 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3072 |
|
| 3073 |
if (wmPtr->nWorldPts < 1) { |
| 3074 |
return FALSE; |
| 3075 |
} |
| 3076 |
if (enclosed) { |
| 3077 |
return ((wmPtr->anchorPos.x >= extsPtr->left) && |
| 3078 |
(wmPtr->anchorPos.y >= extsPtr->top) && |
| 3079 |
((wmPtr->anchorPos.x + wmPtr->width) <= extsPtr->right) && |
| 3080 |
((wmPtr->anchorPos.y + wmPtr->height) <= extsPtr->bottom)); |
| 3081 |
} |
| 3082 |
return !((wmPtr->anchorPos.x >= extsPtr->right) || |
| 3083 |
(wmPtr->anchorPos.y >= extsPtr->bottom) || |
| 3084 |
((wmPtr->anchorPos.x + wmPtr->width) <= extsPtr->left) || |
| 3085 |
((wmPtr->anchorPos.y + wmPtr->height) <= extsPtr->top)); |
| 3086 |
} |
| 3087 |
|
| 3088 |
/* |
| 3089 |
* ---------------------------------------------------------------------- |
| 3090 |
* |
| 3091 |
* DrawWindowMarker -- |
| 3092 |
* |
| 3093 |
* ---------------------------------------------------------------------- |
| 3094 |
*/ |
| 3095 |
/*ARGSUSED*/ |
| 3096 |
static void |
| 3097 |
DrawWindowMarker(markerPtr, drawable) |
| 3098 |
Marker *markerPtr; |
| 3099 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 3100 |
{ |
| 3101 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3102 |
|
| 3103 |
if (wmPtr->tkwin == NULL) { |
| 3104 |
return; |
| 3105 |
} |
| 3106 |
if ((wmPtr->height != Tk_Height(wmPtr->tkwin)) || |
| 3107 |
(wmPtr->width != Tk_Width(wmPtr->tkwin)) || |
| 3108 |
((int)wmPtr->anchorPos.x != Tk_X(wmPtr->tkwin)) || |
| 3109 |
((int)wmPtr->anchorPos.y != Tk_Y(wmPtr->tkwin))) { |
| 3110 |
Tk_MoveResizeWindow(wmPtr->tkwin, (int)wmPtr->anchorPos.x, |
| 3111 |
(int)wmPtr->anchorPos.y, wmPtr->width, wmPtr->height); |
| 3112 |
} |
| 3113 |
if (!Tk_IsMapped(wmPtr->tkwin)) { |
| 3114 |
Tk_MapWindow(wmPtr->tkwin); |
| 3115 |
} |
| 3116 |
} |
| 3117 |
|
| 3118 |
/* |
| 3119 |
* ---------------------------------------------------------------------- |
| 3120 |
* |
| 3121 |
* WindowMarkerToPostScript -- |
| 3122 |
* |
| 3123 |
* ---------------------------------------------------------------------- |
| 3124 |
*/ |
| 3125 |
static void |
| 3126 |
WindowMarkerToPostScript(markerPtr, psToken) |
| 3127 |
Marker *markerPtr; |
| 3128 |
PsToken psToken; |
| 3129 |
{ |
| 3130 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3131 |
|
| 3132 |
if (wmPtr->tkwin == NULL) { |
| 3133 |
return; |
| 3134 |
} |
| 3135 |
if (Tk_IsMapped(wmPtr->tkwin)) { |
| 3136 |
Blt_WindowToPostScript(psToken, wmPtr->tkwin, wmPtr->anchorPos.x, |
| 3137 |
wmPtr->anchorPos.y); |
| 3138 |
} |
| 3139 |
} |
| 3140 |
|
| 3141 |
/* |
| 3142 |
* ---------------------------------------------------------------------- |
| 3143 |
* |
| 3144 |
* FreeWindowMarker -- |
| 3145 |
* |
| 3146 |
* Destroys the structure containing the attributes of the window |
| 3147 |
* marker. |
| 3148 |
* |
| 3149 |
* Results: |
| 3150 |
* None. |
| 3151 |
* |
| 3152 |
* Side effects: |
| 3153 |
* Window is destroyed and removed from the screen. |
| 3154 |
* |
| 3155 |
* ---------------------------------------------------------------------- |
| 3156 |
*/ |
| 3157 |
/*ARGSUSED*/ |
| 3158 |
static void |
| 3159 |
FreeWindowMarker(graphPtr, markerPtr) |
| 3160 |
Graph *graphPtr; |
| 3161 |
Marker *markerPtr; |
| 3162 |
{ |
| 3163 |
WindowMarker *wmPtr = (WindowMarker *)markerPtr; |
| 3164 |
|
| 3165 |
if (wmPtr->tkwin != NULL) { |
| 3166 |
Tk_DeleteEventHandler(wmPtr->tkwin, StructureNotifyMask, |
| 3167 |
ChildEventProc, wmPtr); |
| 3168 |
Tk_ManageGeometry(wmPtr->tkwin, (Tk_GeomMgr *) 0, (ClientData)0); |
| 3169 |
Tk_DestroyWindow(wmPtr->tkwin); |
| 3170 |
} |
| 3171 |
} |
| 3172 |
|
| 3173 |
/* |
| 3174 |
* ---------------------------------------------------------------------- |
| 3175 |
* |
| 3176 |
* CreateWindowMarker -- |
| 3177 |
* |
| 3178 |
* Allocate memory and initialize methods for the new window marker. |
| 3179 |
* |
| 3180 |
* Results: |
| 3181 |
* The pointer to the newly allocated marker structure is returned. |
| 3182 |
* |
| 3183 |
* Side effects: |
| 3184 |
* Memory is allocated for the window marker structure. |
| 3185 |
* |
| 3186 |
* ---------------------------------------------------------------------- |
| 3187 |
*/ |
| 3188 |
static Marker * |
| 3189 |
CreateWindowMarker() |
| 3190 |
{ |
| 3191 |
WindowMarker *wmPtr; |
| 3192 |
|
| 3193 |
wmPtr = Blt_Calloc(1, sizeof(WindowMarker)); |
| 3194 |
if (wmPtr != NULL) { |
| 3195 |
wmPtr->classPtr = &windowMarkerClass; |
| 3196 |
} |
| 3197 |
return (Marker *)wmPtr; |
| 3198 |
} |
| 3199 |
|
| 3200 |
/* |
| 3201 |
* ---------------------------------------------------------------------- |
| 3202 |
* |
| 3203 |
* ChildEventProc -- |
| 3204 |
* |
| 3205 |
* This procedure is invoked whenever StructureNotify events |
| 3206 |
* occur for a window that's managed as part of a graph window |
| 3207 |
* marker. This procedure's only purpose is to clean up when |
| 3208 |
* windows are deleted. |
| 3209 |
* |
| 3210 |
* Results: |
| 3211 |
* None. |
| 3212 |
* |
| 3213 |
* Side effects: |
| 3214 |
* The window is disassociated from the window item when it is |
| 3215 |
* deleted. |
| 3216 |
* |
| 3217 |
* ---------------------------------------------------------------------- |
| 3218 |
*/ |
| 3219 |
static void |
| 3220 |
ChildEventProc(clientData, eventPtr) |
| 3221 |
ClientData clientData; /* Pointer to record describing window item. */ |
| 3222 |
XEvent *eventPtr; /* Describes what just happened. */ |
| 3223 |
{ |
| 3224 |
WindowMarker *wmPtr = clientData; |
| 3225 |
|
| 3226 |
if (eventPtr->type == DestroyNotify) { |
| 3227 |
wmPtr->tkwin = NULL; |
| 3228 |
} |
| 3229 |
} |
| 3230 |
|
| 3231 |
/* |
| 3232 |
* ---------------------------------------------------------------------- |
| 3233 |
* |
| 3234 |
* ChildGeometryProc -- |
| 3235 |
* |
| 3236 |
* This procedure is invoked whenever a window that's associated |
| 3237 |
* with a window item changes its requested dimensions. |
| 3238 |
* |
| 3239 |
* Results: |
| 3240 |
* None. |
| 3241 |
* |
| 3242 |
* Side effects: |
| 3243 |
* The size and location on the window of the window may change, |
| 3244 |
* depending on the options specified for the window item. |
| 3245 |
* |
| 3246 |
* ---------------------------------------------------------------------- |
| 3247 |
*/ |
| 3248 |
/* ARGSUSED */ |
| 3249 |
static void |
| 3250 |
ChildGeometryProc(clientData, tkwin) |
| 3251 |
ClientData clientData; /* Pointer to record for window item. */ |
| 3252 |
Tk_Window tkwin; /* Window that changed its desired size. */ |
| 3253 |
{ |
| 3254 |
WindowMarker *wmPtr = clientData; |
| 3255 |
|
| 3256 |
if (wmPtr->reqWidth == 0) { |
| 3257 |
wmPtr->width = Tk_ReqWidth(tkwin); |
| 3258 |
} |
| 3259 |
if (wmPtr->reqHeight == 0) { |
| 3260 |
wmPtr->height = Tk_ReqHeight(tkwin); |
| 3261 |
} |
| 3262 |
} |
| 3263 |
|
| 3264 |
/* |
| 3265 |
* ---------------------------------------------------------------------- |
| 3266 |
* |
| 3267 |
* ChildCustodyProc -- |
| 3268 |
* |
| 3269 |
* This procedure is invoked when an embedded window has been |
| 3270 |
* stolen by another geometry manager. The information and |
| 3271 |
* memory associated with the widget is released. |
| 3272 |
* |
| 3273 |
* Results: |
| 3274 |
* None. |
| 3275 |
* |
| 3276 |
* Side effects: |
| 3277 |
* Arranges for the graph to be redrawn without the embedded |
| 3278 |
* widget at the next idle point. |
| 3279 |
* |
| 3280 |
* ---------------------------------------------------------------------- |
| 3281 |
*/ |
| 3282 |
/* ARGSUSED */ |
| 3283 |
static void |
| 3284 |
ChildCustodyProc(clientData, tkwin) |
| 3285 |
ClientData clientData; /* Window marker to be destroyed. */ |
| 3286 |
Tk_Window tkwin; /* Not used. */ |
| 3287 |
{ |
| 3288 |
Marker *markerPtr = clientData; |
| 3289 |
Graph *graphPtr; |
| 3290 |
|
| 3291 |
graphPtr = markerPtr->graphPtr; |
| 3292 |
DestroyMarker(markerPtr); |
| 3293 |
/* |
| 3294 |
* Not really needed. We should get an Expose event when the |
| 3295 |
* child window is unmapped. |
| 3296 |
*/ |
| 3297 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 3298 |
} |
| 3299 |
|
| 3300 |
/* |
| 3301 |
* ---------------------------------------------------------------------- |
| 3302 |
* |
| 3303 |
* MapLineMarker -- |
| 3304 |
* |
| 3305 |
* Calculate the layout position for a line marker. Positional |
| 3306 |
* information is saved in the marker. The line positions are |
| 3307 |
* stored in an array of points (malloc'ed). |
| 3308 |
* |
| 3309 |
* Results: |
| 3310 |
* None. |
| 3311 |
* |
| 3312 |
* ---------------------------------------------------------------------- |
| 3313 |
*/ |
| 3314 |
static void |
| 3315 |
MapLineMarker(markerPtr) |
| 3316 |
Marker *markerPtr; |
| 3317 |
{ |
| 3318 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3319 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3320 |
Point2D *srcPtr, *endPtr; |
| 3321 |
Segment2D *segments, *segPtr; |
| 3322 |
Point2D p, q, next; |
| 3323 |
Extents2D exts; |
| 3324 |
|
| 3325 |
lmPtr->nSegments = 0; |
| 3326 |
if (lmPtr->segments != NULL) { |
| 3327 |
Blt_Free(lmPtr->segments); |
| 3328 |
} |
| 3329 |
if (lmPtr->nWorldPts < 2) { |
| 3330 |
return; /* Too few points */ |
| 3331 |
} |
| 3332 |
Blt_GraphExtents(graphPtr, &exts); |
| 3333 |
|
| 3334 |
/* |
| 3335 |
* Allow twice the number of world coordinates. The line will |
| 3336 |
* represented as series of line segments, not one continous |
| 3337 |
* polyline. This is because clipping against the plot area may |
| 3338 |
* chop the line into several disconnected segments. |
| 3339 |
*/ |
| 3340 |
segments = Blt_Malloc(lmPtr->nWorldPts * sizeof(Segment2D)); |
| 3341 |
srcPtr = lmPtr->worldPts; |
| 3342 |
p = MapPoint(graphPtr, srcPtr, &lmPtr->axes); |
| 3343 |
p.x += lmPtr->xOffset; |
| 3344 |
p.y += lmPtr->yOffset; |
| 3345 |
|
| 3346 |
segPtr = segments; |
| 3347 |
for (srcPtr++, endPtr = lmPtr->worldPts + lmPtr->nWorldPts; |
| 3348 |
srcPtr < endPtr; srcPtr++) { |
| 3349 |
next = MapPoint(graphPtr, srcPtr, &lmPtr->axes); |
| 3350 |
next.x += lmPtr->xOffset; |
| 3351 |
next.y += lmPtr->yOffset; |
| 3352 |
q = next; |
| 3353 |
if (Blt_LineRectClip(&exts, &p, &q)) { |
| 3354 |
segPtr->p = p; |
| 3355 |
segPtr->q = q; |
| 3356 |
segPtr++; |
| 3357 |
} |
| 3358 |
p = next; |
| 3359 |
} |
| 3360 |
lmPtr->nSegments = segPtr - segments; |
| 3361 |
lmPtr->segments = segments; |
| 3362 |
lmPtr->clipped = (lmPtr->nSegments == 0); |
| 3363 |
} |
| 3364 |
|
| 3365 |
static int |
| 3366 |
PointInLineMarker(markerPtr, samplePtr) |
| 3367 |
Marker *markerPtr; |
| 3368 |
Point2D *samplePtr; |
| 3369 |
{ |
| 3370 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3371 |
|
| 3372 |
return Blt_PointInSegments(samplePtr, lmPtr->segments, lmPtr->nSegments, |
| 3373 |
(double)lmPtr->graphPtr->halo); |
| 3374 |
} |
| 3375 |
|
| 3376 |
/* |
| 3377 |
* ---------------------------------------------------------------------- |
| 3378 |
* |
| 3379 |
* RegionInLineMarker -- |
| 3380 |
* |
| 3381 |
* ---------------------------------------------------------------------- |
| 3382 |
*/ |
| 3383 |
static int |
| 3384 |
RegionInLineMarker(markerPtr, extsPtr, enclosed) |
| 3385 |
Marker *markerPtr; |
| 3386 |
Extents2D *extsPtr; |
| 3387 |
int enclosed; |
| 3388 |
{ |
| 3389 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3390 |
|
| 3391 |
if (lmPtr->nWorldPts < 2) { |
| 3392 |
return FALSE; |
| 3393 |
} |
| 3394 |
if (enclosed) { |
| 3395 |
Point2D p; |
| 3396 |
Point2D *pointPtr, *endPtr; |
| 3397 |
|
| 3398 |
for (pointPtr = lmPtr->worldPts, |
| 3399 |
endPtr = lmPtr->worldPts + lmPtr->nWorldPts; |
| 3400 |
pointPtr < endPtr; pointPtr++) { |
| 3401 |
p = MapPoint(lmPtr->graphPtr, pointPtr, &lmPtr->axes); |
| 3402 |
if ((p.x < extsPtr->left) && (p.x > extsPtr->right) && |
| 3403 |
(p.y < extsPtr->top) && (p.y > extsPtr->bottom)) { |
| 3404 |
return FALSE; |
| 3405 |
} |
| 3406 |
} |
| 3407 |
return TRUE; /* All points inside bounding box. */ |
| 3408 |
} else { |
| 3409 |
Point2D p, q; |
| 3410 |
int count; |
| 3411 |
Point2D *pointPtr, *endPtr; |
| 3412 |
|
| 3413 |
count = 0; |
| 3414 |
for (pointPtr = lmPtr->worldPts, |
| 3415 |
endPtr = lmPtr->worldPts + (lmPtr->nWorldPts - 1); |
| 3416 |
pointPtr < endPtr; pointPtr++) { |
| 3417 |
p = MapPoint(lmPtr->graphPtr, pointPtr, &lmPtr->axes); |
| 3418 |
q = MapPoint(lmPtr->graphPtr, pointPtr + 1, &lmPtr->axes); |
| 3419 |
if (Blt_LineRectClip(extsPtr, &p, &q)) { |
| 3420 |
count++; |
| 3421 |
} |
| 3422 |
} |
| 3423 |
return (count > 0); /* At least 1 segment passes through region. */ |
| 3424 |
} |
| 3425 |
} |
| 3426 |
|
| 3427 |
/* |
| 3428 |
* ---------------------------------------------------------------------- |
| 3429 |
* |
| 3430 |
* DrawLineMarker -- |
| 3431 |
* |
| 3432 |
* ---------------------------------------------------------------------- |
| 3433 |
*/ |
| 3434 |
static void |
| 3435 |
DrawLineMarker(markerPtr, drawable) |
| 3436 |
Marker *markerPtr; |
| 3437 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 3438 |
{ |
| 3439 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3440 |
|
| 3441 |
if (lmPtr->nSegments > 0) { |
| 3442 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3443 |
|
| 3444 |
Blt_Draw2DSegments(graphPtr->display, drawable, lmPtr->gc, |
| 3445 |
lmPtr->segments, lmPtr->nSegments); |
| 3446 |
if (lmPtr->xor) { /* Toggle the drawing state */ |
| 3447 |
lmPtr->xorState = (lmPtr->xorState == 0); |
| 3448 |
} |
| 3449 |
} |
| 3450 |
} |
| 3451 |
|
| 3452 |
/* |
| 3453 |
* ---------------------------------------------------------------------- |
| 3454 |
* |
| 3455 |
* ConfigureLineMarker -- |
| 3456 |
* |
| 3457 |
* This procedure is called to process an argv/argc list, plus |
| 3458 |
* the Tk option database, in order to configure (or reconfigure) |
| 3459 |
* a line marker. |
| 3460 |
* |
| 3461 |
* Results: |
| 3462 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 3463 |
* interp->result contains an error message. |
| 3464 |
* |
| 3465 |
* Side effects: |
| 3466 |
* Configuration information, such as line width, colors, dashes, |
| 3467 |
* etc. get set for markerPtr; old resources get freed, if there |
| 3468 |
* were any. The marker is eventually redisplayed. |
| 3469 |
* |
| 3470 |
* ---------------------------------------------------------------------- |
| 3471 |
*/ |
| 3472 |
/*ARGSUSED*/ |
| 3473 |
static int |
| 3474 |
ConfigureLineMarker(markerPtr) |
| 3475 |
Marker *markerPtr; |
| 3476 |
{ |
| 3477 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3478 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3479 |
GC newGC; |
| 3480 |
XGCValues gcValues; |
| 3481 |
unsigned long gcMask; |
| 3482 |
Drawable drawable; |
| 3483 |
|
| 3484 |
drawable = Tk_WindowId(graphPtr->tkwin); |
| 3485 |
gcMask = (GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle); |
| 3486 |
if (lmPtr->outlineColor != NULL) { |
| 3487 |
gcMask |= GCForeground; |
| 3488 |
gcValues.foreground = lmPtr->outlineColor->pixel; |
| 3489 |
} |
| 3490 |
if (lmPtr->fillColor != NULL) { |
| 3491 |
gcMask |= GCBackground; |
| 3492 |
gcValues.background = lmPtr->fillColor->pixel; |
| 3493 |
} |
| 3494 |
gcValues.cap_style = lmPtr->capStyle; |
| 3495 |
gcValues.join_style = lmPtr->joinStyle; |
| 3496 |
gcValues.line_width = LineWidth(lmPtr->lineWidth); |
| 3497 |
gcValues.line_style = LineSolid; |
| 3498 |
if (LineIsDashed(lmPtr->dashes)) { |
| 3499 |
gcValues.line_style = |
| 3500 |
(gcMask & GCBackground) ? LineDoubleDash : LineOnOffDash; |
| 3501 |
} |
| 3502 |
if (lmPtr->xor) { |
| 3503 |
unsigned long pixel; |
| 3504 |
gcValues.function = GXxor; |
| 3505 |
|
| 3506 |
gcMask |= GCFunction; |
| 3507 |
if (graphPtr->plotBg == NULL) { |
| 3508 |
pixel = WhitePixelOfScreen(Tk_Screen(graphPtr->tkwin)); |
| 3509 |
} else { |
| 3510 |
pixel = graphPtr->plotBg->pixel; |
| 3511 |
} |
| 3512 |
if (gcMask & GCBackground) { |
| 3513 |
gcValues.background ^= pixel; |
| 3514 |
} |
| 3515 |
gcValues.foreground ^= pixel; |
| 3516 |
if (drawable != None) { |
| 3517 |
DrawLineMarker(markerPtr, drawable); |
| 3518 |
} |
| 3519 |
} |
| 3520 |
newGC = Blt_GetPrivateGC(graphPtr->tkwin, gcMask, &gcValues); |
| 3521 |
if (lmPtr->gc != NULL) { |
| 3522 |
Blt_FreePrivateGC(graphPtr->display, lmPtr->gc); |
| 3523 |
} |
| 3524 |
if (LineIsDashed(lmPtr->dashes)) { |
| 3525 |
Blt_SetDashes(graphPtr->display, newGC, &lmPtr->dashes); |
| 3526 |
} |
| 3527 |
lmPtr->gc = newGC; |
| 3528 |
if (lmPtr->xor) { |
| 3529 |
if (drawable != None) { |
| 3530 |
MapLineMarker(markerPtr); |
| 3531 |
DrawLineMarker(markerPtr, drawable); |
| 3532 |
} |
| 3533 |
return TCL_OK; |
| 3534 |
} |
| 3535 |
lmPtr->flags |= MAP_ITEM; |
| 3536 |
if (lmPtr->drawUnder) { |
| 3537 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 3538 |
} |
| 3539 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 3540 |
return TCL_OK; |
| 3541 |
} |
| 3542 |
|
| 3543 |
/* |
| 3544 |
* ---------------------------------------------------------------------- |
| 3545 |
* |
| 3546 |
* LineMarkerToPostScript -- |
| 3547 |
* |
| 3548 |
* Prints postscript commands to display the connect line. |
| 3549 |
* Dashed lines need to be handled specially, especially if a |
| 3550 |
* background color is designated. |
| 3551 |
* |
| 3552 |
* Results: |
| 3553 |
* None. |
| 3554 |
* |
| 3555 |
* Side effects: |
| 3556 |
* PostScript output commands are saved in the interpreter |
| 3557 |
* (infoPtr->interp) result field. |
| 3558 |
* |
| 3559 |
* ---------------------------------------------------------------------- |
| 3560 |
*/ |
| 3561 |
static void |
| 3562 |
LineMarkerToPostScript(markerPtr, psToken) |
| 3563 |
Marker *markerPtr; |
| 3564 |
PsToken psToken; |
| 3565 |
{ |
| 3566 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3567 |
|
| 3568 |
if (lmPtr->nSegments > 0) { |
| 3569 |
Blt_LineAttributesToPostScript(psToken, lmPtr->outlineColor, |
| 3570 |
lmPtr->lineWidth, &lmPtr->dashes, lmPtr->capStyle, |
| 3571 |
lmPtr->joinStyle); |
| 3572 |
if ((LineIsDashed(lmPtr->dashes)) && (lmPtr->fillColor != NULL)) { |
| 3573 |
Blt_AppendToPostScript(psToken, "/DashesProc {\n gsave\n ", |
| 3574 |
(char *)NULL); |
| 3575 |
Blt_BackgroundToPostScript(psToken, lmPtr->fillColor); |
| 3576 |
Blt_AppendToPostScript(psToken, " ", (char *)NULL); |
| 3577 |
Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL); |
| 3578 |
Blt_AppendToPostScript(psToken, |
| 3579 |
"stroke\n", |
| 3580 |
" grestore\n", |
| 3581 |
"} def\n", (char *)NULL); |
| 3582 |
} else { |
| 3583 |
Blt_AppendToPostScript(psToken, "/DashesProc {} def\n", |
| 3584 |
(char *)NULL); |
| 3585 |
} |
| 3586 |
Blt_2DSegmentsToPostScript(psToken, lmPtr->segments, lmPtr->nSegments); |
| 3587 |
} |
| 3588 |
} |
| 3589 |
|
| 3590 |
/* |
| 3591 |
* ---------------------------------------------------------------------- |
| 3592 |
* |
| 3593 |
* FreeLineMarker -- |
| 3594 |
* |
| 3595 |
* Destroys the structure and attributes of a line marker. |
| 3596 |
* |
| 3597 |
* Results: |
| 3598 |
* None. |
| 3599 |
* |
| 3600 |
* Side effects: |
| 3601 |
* Line attributes (GCs, colors, stipple, etc) get released. |
| 3602 |
* Memory is deallocated, X resources are freed. |
| 3603 |
* |
| 3604 |
* ---------------------------------------------------------------------- |
| 3605 |
*/ |
| 3606 |
static void |
| 3607 |
FreeLineMarker(graphPtr, markerPtr) |
| 3608 |
Graph *graphPtr; |
| 3609 |
Marker *markerPtr; |
| 3610 |
{ |
| 3611 |
LineMarker *lmPtr = (LineMarker *)markerPtr; |
| 3612 |
|
| 3613 |
if (lmPtr->gc != NULL) { |
| 3614 |
Blt_FreePrivateGC(graphPtr->display, lmPtr->gc); |
| 3615 |
} |
| 3616 |
if (lmPtr->segments != NULL) { |
| 3617 |
Blt_Free(lmPtr->segments); |
| 3618 |
} |
| 3619 |
} |
| 3620 |
|
| 3621 |
|
| 3622 |
/* |
| 3623 |
* ---------------------------------------------------------------------- |
| 3624 |
* |
| 3625 |
* CreateLineMarker -- |
| 3626 |
* |
| 3627 |
* Allocate memory and initialize methods for a new line marker. |
| 3628 |
* |
| 3629 |
* Results: |
| 3630 |
* The pointer to the newly allocated marker structure is returned. |
| 3631 |
* |
| 3632 |
* Side effects: |
| 3633 |
* Memory is allocated for the line marker structure. |
| 3634 |
* |
| 3635 |
* ---------------------------------------------------------------------- |
| 3636 |
*/ |
| 3637 |
static Marker * |
| 3638 |
CreateLineMarker() |
| 3639 |
{ |
| 3640 |
LineMarker *lmPtr; |
| 3641 |
|
| 3642 |
lmPtr = Blt_Calloc(1, sizeof(LineMarker)); |
| 3643 |
if (lmPtr != NULL) { |
| 3644 |
lmPtr->classPtr = &lineMarkerClass; |
| 3645 |
lmPtr->xor = FALSE; |
| 3646 |
lmPtr->capStyle = CapButt; |
| 3647 |
lmPtr->joinStyle = JoinMiter; |
| 3648 |
} |
| 3649 |
return (Marker *)lmPtr; |
| 3650 |
} |
| 3651 |
|
| 3652 |
/* |
| 3653 |
* ---------------------------------------------------------------------- |
| 3654 |
* |
| 3655 |
* MapPolygonMarker -- |
| 3656 |
* |
| 3657 |
* Calculate the layout position for a polygon marker. Positional |
| 3658 |
* information is saved in the polygon in an array of points |
| 3659 |
* (malloc'ed). |
| 3660 |
* |
| 3661 |
* Results: |
| 3662 |
* None. |
| 3663 |
* |
| 3664 |
* ---------------------------------------------------------------------- |
| 3665 |
*/ |
| 3666 |
static void |
| 3667 |
MapPolygonMarker(markerPtr) |
| 3668 |
Marker *markerPtr; |
| 3669 |
{ |
| 3670 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3671 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3672 |
Point2D *srcPtr, *destPtr, *endPtr; |
| 3673 |
Point2D *screenPts; |
| 3674 |
Extents2D exts; |
| 3675 |
int nScreenPts; |
| 3676 |
|
| 3677 |
if (pmPtr->outlinePts != NULL) { |
| 3678 |
Blt_Free(pmPtr->outlinePts); |
| 3679 |
pmPtr->outlinePts = NULL; |
| 3680 |
pmPtr->nOutlinePts = 0; |
| 3681 |
} |
| 3682 |
if (pmPtr->fillPts != NULL) { |
| 3683 |
Blt_Free(pmPtr->fillPts); |
| 3684 |
pmPtr->fillPts = NULL; |
| 3685 |
pmPtr->nFillPts = 0; |
| 3686 |
} |
| 3687 |
if (pmPtr->screenPts != NULL) { |
| 3688 |
Blt_Free(pmPtr->screenPts); |
| 3689 |
pmPtr->screenPts = NULL; |
| 3690 |
} |
| 3691 |
if (pmPtr->nWorldPts < 3) { |
| 3692 |
return; /* Too few points */ |
| 3693 |
} |
| 3694 |
|
| 3695 |
/* |
| 3696 |
* Allocate and fill a temporary array to hold the screen |
| 3697 |
* coordinates of the polygon. |
| 3698 |
*/ |
| 3699 |
nScreenPts = pmPtr->nWorldPts + 1; |
| 3700 |
screenPts = Blt_Malloc((nScreenPts + 1) * sizeof(Point2D)); |
| 3701 |
endPtr = pmPtr->worldPts + pmPtr->nWorldPts; |
| 3702 |
destPtr = screenPts; |
| 3703 |
for (srcPtr = pmPtr->worldPts; srcPtr < endPtr; srcPtr++) { |
| 3704 |
*destPtr = MapPoint(graphPtr, srcPtr, &pmPtr->axes); |
| 3705 |
destPtr->x += pmPtr->xOffset; |
| 3706 |
destPtr->y += pmPtr->yOffset; |
| 3707 |
destPtr++; |
| 3708 |
} |
| 3709 |
*destPtr = screenPts[0]; |
| 3710 |
|
| 3711 |
Blt_GraphExtents(graphPtr, &exts); |
| 3712 |
pmPtr->clipped = TRUE; |
| 3713 |
if (pmPtr->fill.fgColor != NULL) { /* Polygon fill required. */ |
| 3714 |
Point2D *fillPts; |
| 3715 |
int n; |
| 3716 |
|
| 3717 |
fillPts = Blt_Malloc(sizeof(Point2D) * nScreenPts * 3); |
| 3718 |
assert(fillPts); |
| 3719 |
n = Blt_PolyRectClip(&exts, screenPts, pmPtr->nWorldPts, fillPts); |
| 3720 |
if (n < 3) { |
| 3721 |
Blt_Free(fillPts); |
| 3722 |
} else { |
| 3723 |
pmPtr->nFillPts = n; |
| 3724 |
pmPtr->fillPts = fillPts; |
| 3725 |
pmPtr->clipped = FALSE; |
| 3726 |
} |
| 3727 |
} |
| 3728 |
if ((pmPtr->outline.fgColor != NULL) && (pmPtr->lineWidth > 0)) { |
| 3729 |
Segment2D *outlinePts; |
| 3730 |
register Segment2D *segPtr; |
| 3731 |
/* |
| 3732 |
* Generate line segments representing the polygon outline. |
| 3733 |
* The resulting outline may or may not be closed from |
| 3734 |
* viewport clipping. |
| 3735 |
*/ |
| 3736 |
outlinePts = Blt_Malloc(nScreenPts * sizeof(Segment2D)); |
| 3737 |
if (outlinePts == NULL) { |
| 3738 |
return; /* Can't allocate point array */ |
| 3739 |
} |
| 3740 |
/* |
| 3741 |
* Note that this assumes that the point array contains an |
| 3742 |
* extra point that closes the polygon. |
| 3743 |
*/ |
| 3744 |
segPtr = outlinePts; |
| 3745 |
for (srcPtr = screenPts, endPtr = screenPts + (nScreenPts - 1); |
| 3746 |
srcPtr < endPtr; srcPtr++) { |
| 3747 |
segPtr->p = srcPtr[0]; |
| 3748 |
segPtr->q = srcPtr[1]; |
| 3749 |
if (Blt_LineRectClip(&exts, &segPtr->p, &segPtr->q)) { |
| 3750 |
segPtr++; |
| 3751 |
} |
| 3752 |
} |
| 3753 |
pmPtr->nOutlinePts = segPtr - outlinePts; |
| 3754 |
pmPtr->outlinePts = outlinePts; |
| 3755 |
if (pmPtr->nOutlinePts > 0) { |
| 3756 |
pmPtr->clipped = FALSE; |
| 3757 |
} |
| 3758 |
} |
| 3759 |
pmPtr->screenPts = screenPts; |
| 3760 |
} |
| 3761 |
|
| 3762 |
static int |
| 3763 |
PointInPolygonMarker(markerPtr, samplePtr) |
| 3764 |
Marker *markerPtr; |
| 3765 |
Point2D *samplePtr; |
| 3766 |
{ |
| 3767 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3768 |
|
| 3769 |
if ((pmPtr->nWorldPts >= 3) && (pmPtr->screenPts != NULL)) { |
| 3770 |
return Blt_PointInPolygon(samplePtr, pmPtr->screenPts, |
| 3771 |
pmPtr->nWorldPts + 1); |
| 3772 |
} |
| 3773 |
return FALSE; |
| 3774 |
} |
| 3775 |
|
| 3776 |
/* |
| 3777 |
* ---------------------------------------------------------------------- |
| 3778 |
* |
| 3779 |
* RegionInPolygonMarker -- |
| 3780 |
* |
| 3781 |
* ---------------------------------------------------------------------- |
| 3782 |
*/ |
| 3783 |
static int |
| 3784 |
RegionInPolygonMarker(markerPtr, extsPtr, enclosed) |
| 3785 |
Marker *markerPtr; |
| 3786 |
Extents2D *extsPtr; |
| 3787 |
int enclosed; |
| 3788 |
{ |
| 3789 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3790 |
|
| 3791 |
if ((pmPtr->nWorldPts >= 3) && (pmPtr->screenPts != NULL)) { |
| 3792 |
return Blt_RegionInPolygon(extsPtr, pmPtr->screenPts, pmPtr->nWorldPts, |
| 3793 |
enclosed); |
| 3794 |
} |
| 3795 |
return FALSE; |
| 3796 |
} |
| 3797 |
|
| 3798 |
static void |
| 3799 |
DrawPolygonMarker(markerPtr, drawable) |
| 3800 |
Marker *markerPtr; |
| 3801 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 3802 |
{ |
| 3803 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3804 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3805 |
|
| 3806 |
/* Draw polygon fill region */ |
| 3807 |
if ((pmPtr->nFillPts > 0) && (pmPtr->fill.fgColor != NULL)) { |
| 3808 |
XPoint *destPtr, *pointArr; |
| 3809 |
Point2D *srcPtr, *endPtr; |
| 3810 |
|
| 3811 |
pointArr = Blt_Malloc(pmPtr->nFillPts * sizeof(XPoint)); |
| 3812 |
if (pointArr == NULL) { |
| 3813 |
return; |
| 3814 |
} |
| 3815 |
destPtr = pointArr; |
| 3816 |
for (srcPtr = pmPtr->fillPts, |
| 3817 |
endPtr = pmPtr->fillPts + pmPtr->nFillPts; srcPtr < endPtr; |
| 3818 |
srcPtr++) { |
| 3819 |
destPtr->x = (short int)srcPtr->x; |
| 3820 |
destPtr->y = (short int)srcPtr->y; |
| 3821 |
destPtr++; |
| 3822 |
} |
| 3823 |
XFillPolygon(graphPtr->display, drawable, pmPtr->fillGC, |
| 3824 |
pointArr, pmPtr->nFillPts, Complex, CoordModeOrigin); |
| 3825 |
Blt_Free(pointArr); |
| 3826 |
} |
| 3827 |
/* and then the outline */ |
| 3828 |
if ((pmPtr->nOutlinePts > 0) && (pmPtr->lineWidth > 0) && |
| 3829 |
(pmPtr->outline.fgColor != NULL)) { |
| 3830 |
Blt_Draw2DSegments(graphPtr->display, drawable, pmPtr->outlineGC, |
| 3831 |
pmPtr->outlinePts, pmPtr->nOutlinePts); |
| 3832 |
} |
| 3833 |
} |
| 3834 |
|
| 3835 |
|
| 3836 |
static void |
| 3837 |
PolygonMarkerToPostScript(markerPtr, psToken) |
| 3838 |
Marker *markerPtr; |
| 3839 |
PsToken psToken; |
| 3840 |
{ |
| 3841 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3842 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3843 |
|
| 3844 |
if (pmPtr->fill.fgColor != NULL) { |
| 3845 |
|
| 3846 |
/* |
| 3847 |
* Options: fg bg |
| 3848 |
* Draw outline only. |
| 3849 |
* x Draw solid or stipple. |
| 3850 |
* x x Draw solid or stipple. |
| 3851 |
*/ |
| 3852 |
|
| 3853 |
/* Create a path to use for both the polygon and its outline. */ |
| 3854 |
Blt_PathToPostScript(psToken, pmPtr->fillPts, pmPtr->nFillPts); |
| 3855 |
Blt_AppendToPostScript(psToken, "closepath\n", (char *)NULL); |
| 3856 |
|
| 3857 |
/* If the background fill color was specified, draw the |
| 3858 |
* polygon in a solid fashion with that color. */ |
| 3859 |
if (pmPtr->fill.bgColor != NULL) { |
| 3860 |
Blt_BackgroundToPostScript(psToken, pmPtr->fill.bgColor); |
| 3861 |
Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL); |
| 3862 |
} |
| 3863 |
Blt_ForegroundToPostScript(psToken, pmPtr->fill.fgColor); |
| 3864 |
if (pmPtr->stipple != None) { |
| 3865 |
/* Draw the stipple in the foreground color. */ |
| 3866 |
Blt_StippleToPostScript(psToken, graphPtr->display, |
| 3867 |
pmPtr->stipple); |
| 3868 |
} else { |
| 3869 |
Blt_AppendToPostScript(psToken, "Fill\n", (char *)NULL); |
| 3870 |
} |
| 3871 |
} |
| 3872 |
|
| 3873 |
/* Draw the outline in the foreground color. */ |
| 3874 |
if ((pmPtr->lineWidth > 0) && (pmPtr->outline.fgColor != NULL)) { |
| 3875 |
|
| 3876 |
/* Set up the line attributes. */ |
| 3877 |
Blt_LineAttributesToPostScript(psToken, pmPtr->outline.fgColor, |
| 3878 |
pmPtr->lineWidth, &pmPtr->dashes, pmPtr->capStyle, |
| 3879 |
pmPtr->joinStyle); |
| 3880 |
|
| 3881 |
/* |
| 3882 |
* Define on-the-fly a PostScript macro "DashesProc" that |
| 3883 |
* will be executed for each call to the Polygon drawing |
| 3884 |
* routine. If the line isn't dashed, simply make this an |
| 3885 |
* empty definition. |
| 3886 |
*/ |
| 3887 |
if ((pmPtr->outline.bgColor != NULL) && (LineIsDashed(pmPtr->dashes))) { |
| 3888 |
Blt_AppendToPostScript(psToken, |
| 3889 |
"/DashesProc {\n", |
| 3890 |
"gsave\n ", (char *)NULL); |
| 3891 |
Blt_BackgroundToPostScript(psToken, pmPtr->outline.bgColor); |
| 3892 |
Blt_AppendToPostScript(psToken, " ", (char *)NULL); |
| 3893 |
Blt_LineDashesToPostScript(psToken, (Blt_Dashes *)NULL); |
| 3894 |
Blt_AppendToPostScript(psToken, |
| 3895 |
"stroke\n", |
| 3896 |
" grestore\n", |
| 3897 |
"} def\n", (char *)NULL); |
| 3898 |
} else { |
| 3899 |
Blt_AppendToPostScript(psToken, "/DashesProc {} def\n", |
| 3900 |
(char *)NULL); |
| 3901 |
} |
| 3902 |
Blt_2DSegmentsToPostScript(psToken, pmPtr->outlinePts, |
| 3903 |
pmPtr->nOutlinePts); |
| 3904 |
} |
| 3905 |
} |
| 3906 |
|
| 3907 |
/* |
| 3908 |
* ---------------------------------------------------------------------- |
| 3909 |
* |
| 3910 |
* ConfigurePolygonMarker -- |
| 3911 |
* |
| 3912 |
* This procedure is called to process an argv/argc list, plus |
| 3913 |
* the Tk option database, in order to configure (or reconfigure) |
| 3914 |
* a polygon marker. |
| 3915 |
* |
| 3916 |
* Results: |
| 3917 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 3918 |
* interp->result contains an error message. |
| 3919 |
* |
| 3920 |
* Side effects: |
| 3921 |
* Configuration information, such as polygon color, dashes, |
| 3922 |
* fillstyle, etc. get set for markerPtr; old resources get |
| 3923 |
* freed, if there were any. The marker is eventually |
| 3924 |
* redisplayed. |
| 3925 |
* |
| 3926 |
* ---------------------------------------------------------------------- |
| 3927 |
*/ |
| 3928 |
/*ARGSUSED*/ |
| 3929 |
static int |
| 3930 |
ConfigurePolygonMarker(markerPtr) |
| 3931 |
Marker *markerPtr; |
| 3932 |
{ |
| 3933 |
Graph *graphPtr = markerPtr->graphPtr; |
| 3934 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 3935 |
GC newGC; |
| 3936 |
XGCValues gcValues; |
| 3937 |
unsigned long gcMask; |
| 3938 |
Drawable drawable; |
| 3939 |
|
| 3940 |
drawable = Tk_WindowId(graphPtr->tkwin); |
| 3941 |
gcMask = (GCLineWidth | GCLineStyle); |
| 3942 |
if (pmPtr->outline.fgColor != NULL) { |
| 3943 |
gcMask |= GCForeground; |
| 3944 |
gcValues.foreground = pmPtr->outline.fgColor->pixel; |
| 3945 |
} |
| 3946 |
if (pmPtr->outline.bgColor != NULL) { |
| 3947 |
gcMask |= GCBackground; |
| 3948 |
gcValues.background = pmPtr->outline.bgColor->pixel; |
| 3949 |
} |
| 3950 |
gcMask |= (GCCapStyle | GCJoinStyle); |
| 3951 |
gcValues.cap_style = pmPtr->capStyle; |
| 3952 |
gcValues.join_style = pmPtr->joinStyle; |
| 3953 |
gcValues.line_style = LineSolid; |
| 3954 |
gcValues.dash_offset = 0; |
| 3955 |
gcValues.line_width = LineWidth(pmPtr->lineWidth); |
| 3956 |
if (LineIsDashed(pmPtr->dashes)) { |
| 3957 |
gcValues.line_style = (pmPtr->outline.bgColor == NULL) |
| 3958 |
? LineOnOffDash : LineDoubleDash; |
| 3959 |
} |
| 3960 |
if (pmPtr->xor) { |
| 3961 |
unsigned long pixel; |
| 3962 |
gcValues.function = GXxor; |
| 3963 |
|
| 3964 |
gcMask |= GCFunction; |
| 3965 |
if (graphPtr->plotBg == NULL) { |
| 3966 |
/* The graph's color option may not have been set yet */ |
| 3967 |
pixel = WhitePixelOfScreen(Tk_Screen(graphPtr->tkwin)); |
| 3968 |
} else { |
| 3969 |
pixel = graphPtr->plotBg->pixel; |
| 3970 |
} |
| 3971 |
if (gcMask & GCBackground) { |
| 3972 |
gcValues.background ^= pixel; |
| 3973 |
} |
| 3974 |
gcValues.foreground ^= pixel; |
| 3975 |
if (drawable != None) { |
| 3976 |
DrawPolygonMarker(markerPtr, drawable); |
| 3977 |
} |
| 3978 |
} |
| 3979 |
newGC = Blt_GetPrivateGC(graphPtr->tkwin, gcMask, &gcValues); |
| 3980 |
if (LineIsDashed(pmPtr->dashes)) { |
| 3981 |
Blt_SetDashes(graphPtr->display, newGC, &pmPtr->dashes); |
| 3982 |
} |
| 3983 |
if (pmPtr->outlineGC != NULL) { |
| 3984 |
Blt_FreePrivateGC(graphPtr->display, pmPtr->outlineGC); |
| 3985 |
} |
| 3986 |
pmPtr->outlineGC = newGC; |
| 3987 |
|
| 3988 |
gcMask = 0; |
| 3989 |
if (pmPtr->fill.fgColor != NULL) { |
| 3990 |
gcMask |= GCForeground; |
| 3991 |
gcValues.foreground = pmPtr->fill.fgColor->pixel; |
| 3992 |
} |
| 3993 |
if (pmPtr->fill.bgColor != NULL) { |
| 3994 |
gcMask |= GCBackground; |
| 3995 |
gcValues.background = pmPtr->fill.bgColor->pixel; |
| 3996 |
} |
| 3997 |
if (pmPtr->stipple != None) { |
| 3998 |
gcValues.stipple = pmPtr->stipple; |
| 3999 |
gcValues.fill_style = (pmPtr->fill.bgColor != NULL) |
| 4000 |
? FillOpaqueStippled : FillStippled; |
| 4001 |
gcMask |= (GCStipple | GCFillStyle); |
| 4002 |
} |
| 4003 |
newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues); |
| 4004 |
if (pmPtr->fillGC != NULL) { |
| 4005 |
Tk_FreeGC(graphPtr->display, pmPtr->fillGC); |
| 4006 |
} |
| 4007 |
pmPtr->fillGC = newGC; |
| 4008 |
|
| 4009 |
if ((gcMask == 0) && !(graphPtr->flags & RESET_AXES) && (pmPtr->xor)) { |
| 4010 |
if (drawable != None) { |
| 4011 |
MapPolygonMarker(markerPtr); |
| 4012 |
DrawPolygonMarker(markerPtr, drawable); |
| 4013 |
} |
| 4014 |
return TCL_OK; |
| 4015 |
} |
| 4016 |
pmPtr->flags |= MAP_ITEM; |
| 4017 |
if (pmPtr->drawUnder) { |
| 4018 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 4019 |
} |
| 4020 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 4021 |
return TCL_OK; |
| 4022 |
} |
| 4023 |
|
| 4024 |
/* |
| 4025 |
* ---------------------------------------------------------------------- |
| 4026 |
* |
| 4027 |
* FreePolygonMarker -- |
| 4028 |
* |
| 4029 |
* Release memory and resources allocated for the polygon element. |
| 4030 |
* |
| 4031 |
* Results: |
| 4032 |
* None. |
| 4033 |
* |
| 4034 |
* Side effects: |
| 4035 |
* Everything associated with the polygon element is freed up. |
| 4036 |
* |
| 4037 |
* ---------------------------------------------------------------------- |
| 4038 |
*/ |
| 4039 |
static void |
| 4040 |
FreePolygonMarker(graphPtr, markerPtr) |
| 4041 |
Graph *graphPtr; |
| 4042 |
Marker *markerPtr; |
| 4043 |
{ |
| 4044 |
PolygonMarker *pmPtr = (PolygonMarker *)markerPtr; |
| 4045 |
|
| 4046 |
if (pmPtr->fillGC != NULL) { |
| 4047 |
Tk_FreeGC(graphPtr->display, pmPtr->fillGC); |
| 4048 |
} |
| 4049 |
if (pmPtr->outlineGC != NULL) { |
| 4050 |
Blt_FreePrivateGC(graphPtr->display, pmPtr->outlineGC); |
| 4051 |
} |
| 4052 |
if (pmPtr->fillPts != NULL) { |
| 4053 |
Blt_Free(pmPtr->fillPts); |
| 4054 |
} |
| 4055 |
if (pmPtr->outlinePts != NULL) { |
| 4056 |
Blt_Free(pmPtr->outlinePts); |
| 4057 |
} |
| 4058 |
if (pmPtr->screenPts != NULL) { |
| 4059 |
Blt_Free(pmPtr->screenPts); |
| 4060 |
} |
| 4061 |
Blt_FreeColorPair(&pmPtr->outline); |
| 4062 |
Blt_FreeColorPair(&pmPtr->fill); |
| 4063 |
} |
| 4064 |
|
| 4065 |
/* |
| 4066 |
* ---------------------------------------------------------------------- |
| 4067 |
* |
| 4068 |
* CreatePolygonMarker -- |
| 4069 |
* |
| 4070 |
* Allocate memory and initialize methods for the new polygon |
| 4071 |
* marker. |
| 4072 |
* |
| 4073 |
* Results: |
| 4074 |
* The pointer to the newly allocated marker structure is |
| 4075 |
* returned. |
| 4076 |
* |
| 4077 |
* Side effects: |
| 4078 |
* Memory is allocated for the polygon marker structure. |
| 4079 |
* |
| 4080 |
* ---------------------------------------------------------------------- |
| 4081 |
*/ |
| 4082 |
static Marker * |
| 4083 |
CreatePolygonMarker() |
| 4084 |
{ |
| 4085 |
PolygonMarker *pmPtr; |
| 4086 |
|
| 4087 |
pmPtr = Blt_Calloc(1, sizeof(PolygonMarker)); |
| 4088 |
if (pmPtr != NULL) { |
| 4089 |
pmPtr->classPtr = &polygonMarkerClass; |
| 4090 |
pmPtr->capStyle = CapButt; |
| 4091 |
pmPtr->joinStyle = JoinMiter; |
| 4092 |
|
| 4093 |
} |
| 4094 |
return (Marker *)pmPtr; |
| 4095 |
} |
| 4096 |
|
| 4097 |
static int |
| 4098 |
NameToMarker(graphPtr, name, markerPtrPtr) |
| 4099 |
Graph *graphPtr; |
| 4100 |
char *name; |
| 4101 |
Marker **markerPtrPtr; |
| 4102 |
{ |
| 4103 |
Blt_HashEntry *hPtr; |
| 4104 |
|
| 4105 |
hPtr = Blt_FindHashEntry(&graphPtr->markers.table, name); |
| 4106 |
if (hPtr != NULL) { |
| 4107 |
*markerPtrPtr = (Marker *)Blt_GetHashValue(hPtr); |
| 4108 |
return TCL_OK; |
| 4109 |
} |
| 4110 |
Tcl_AppendResult(graphPtr->interp, "can't find marker \"", name, |
| 4111 |
"\" in \"", Tk_PathName(graphPtr->tkwin), (char *)NULL); |
| 4112 |
return TCL_ERROR; |
| 4113 |
} |
| 4114 |
|
| 4115 |
|
| 4116 |
static int |
| 4117 |
RenameMarker(graphPtr, markerPtr, oldName, newName) |
| 4118 |
Graph *graphPtr; |
| 4119 |
Marker *markerPtr; |
| 4120 |
char *oldName, *newName; |
| 4121 |
{ |
| 4122 |
int isNew; |
| 4123 |
Blt_HashEntry *hPtr; |
| 4124 |
|
| 4125 |
/* Rename the marker only if no marker already exists by that name */ |
| 4126 |
hPtr = Blt_CreateHashEntry(&graphPtr->markers.table, newName, &isNew); |
| 4127 |
if (!isNew) { |
| 4128 |
Tcl_AppendResult(graphPtr->interp, "can't rename marker: \"", newName, |
| 4129 |
"\" already exists", (char *)NULL); |
| 4130 |
return TCL_ERROR; |
| 4131 |
} |
| 4132 |
markerPtr->name = Blt_Strdup(newName); |
| 4133 |
markerPtr->hashPtr = hPtr; |
| 4134 |
Blt_SetHashValue(hPtr, (char *)markerPtr); |
| 4135 |
|
| 4136 |
/* Delete the old hash entry */ |
| 4137 |
hPtr = Blt_FindHashEntry(&graphPtr->markers.table, oldName); |
| 4138 |
Blt_DeleteHashEntry(&graphPtr->markers.table, hPtr); |
| 4139 |
if (oldName != NULL) { |
| 4140 |
Blt_Free(oldName); |
| 4141 |
} |
| 4142 |
return TCL_OK; |
| 4143 |
} |
| 4144 |
|
| 4145 |
/* |
| 4146 |
* ---------------------------------------------------------------------- |
| 4147 |
* |
| 4148 |
* NamesOp -- |
| 4149 |
* |
| 4150 |
* Returns a list of marker identifiers in interp->result; |
| 4151 |
* |
| 4152 |
* Results: |
| 4153 |
* The return value is a standard Tcl result. |
| 4154 |
* |
| 4155 |
* ---------------------------------------------------------------------- |
| 4156 |
*/ |
| 4157 |
static int |
| 4158 |
NamesOp(graphPtr, interp, argc, argv) |
| 4159 |
Graph *graphPtr; |
| 4160 |
Tcl_Interp *interp; |
| 4161 |
int argc; |
| 4162 |
char **argv; |
| 4163 |
{ |
| 4164 |
Marker *markerPtr; |
| 4165 |
Blt_ChainLink *linkPtr; |
| 4166 |
register int i; |
| 4167 |
|
| 4168 |
Tcl_ResetResult(interp); |
| 4169 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList); |
| 4170 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4171 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4172 |
if (argc == 3) { |
| 4173 |
Tcl_AppendElement(interp, markerPtr->name); |
| 4174 |
continue; |
| 4175 |
} |
| 4176 |
for (i = 3; i < argc; i++) { |
| 4177 |
if (Tcl_StringMatch(markerPtr->name, argv[i])) { |
| 4178 |
Tcl_AppendElement(interp, markerPtr->name); |
| 4179 |
break; |
| 4180 |
} |
| 4181 |
} |
| 4182 |
} |
| 4183 |
return TCL_OK; |
| 4184 |
} |
| 4185 |
|
| 4186 |
ClientData |
| 4187 |
Blt_MakeMarkerTag(graphPtr, tagName) |
| 4188 |
Graph *graphPtr; |
| 4189 |
char *tagName; |
| 4190 |
{ |
| 4191 |
Blt_HashEntry *hPtr; |
| 4192 |
int isNew; |
| 4193 |
|
| 4194 |
hPtr = Blt_CreateHashEntry(&graphPtr->markers.tagTable, tagName, &isNew); |
| 4195 |
assert(hPtr); |
| 4196 |
return Blt_GetHashKey(&graphPtr->markers.tagTable, hPtr); |
| 4197 |
} |
| 4198 |
|
| 4199 |
/* |
| 4200 |
*---------------------------------------------------------------------- |
| 4201 |
* |
| 4202 |
* BindOp -- |
| 4203 |
* |
| 4204 |
* .g element bind elemName sequence command |
| 4205 |
* |
| 4206 |
*---------------------------------------------------------------------- |
| 4207 |
*/ |
| 4208 |
/*ARGSUSED*/ |
| 4209 |
static int |
| 4210 |
BindOp(graphPtr, interp, argc, argv) |
| 4211 |
Graph *graphPtr; |
| 4212 |
Tcl_Interp *interp; |
| 4213 |
int argc; |
| 4214 |
char **argv; |
| 4215 |
{ |
| 4216 |
if (argc == 3) { |
| 4217 |
Blt_HashEntry *hPtr; |
| 4218 |
Blt_HashSearch cursor; |
| 4219 |
char *tag; |
| 4220 |
|
| 4221 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->markers.tagTable, &cursor); |
| 4222 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4223 |
tag = Blt_GetHashKey(&graphPtr->markers.tagTable, hPtr); |
| 4224 |
Tcl_AppendElement(interp, tag); |
| 4225 |
} |
| 4226 |
return TCL_OK; |
| 4227 |
} |
| 4228 |
return Blt_ConfigureBindings(interp, graphPtr->bindTable, |
| 4229 |
Blt_MakeMarkerTag(graphPtr, argv[3]), argc - 4, argv + 4); |
| 4230 |
} |
| 4231 |
|
| 4232 |
/* |
| 4233 |
* ---------------------------------------------------------------------- |
| 4234 |
* |
| 4235 |
* CgetOp -- |
| 4236 |
* |
| 4237 |
* ---------------------------------------------------------------------- |
| 4238 |
*/ |
| 4239 |
/*ARGSUSED*/ |
| 4240 |
static int |
| 4241 |
CgetOp(graphPtr, interp, argc, argv) |
| 4242 |
Graph *graphPtr; |
| 4243 |
Tcl_Interp *interp; |
| 4244 |
int argc; |
| 4245 |
char **argv; |
| 4246 |
{ |
| 4247 |
Marker *markerPtr; |
| 4248 |
|
| 4249 |
if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) { |
| 4250 |
return TCL_ERROR; |
| 4251 |
} |
| 4252 |
if (Tk_ConfigureValue(interp, graphPtr->tkwin, |
| 4253 |
markerPtr->classPtr->configSpecs, (char *)markerPtr, argv[4], 0) |
| 4254 |
!= TCL_OK) { |
| 4255 |
return TCL_ERROR; |
| 4256 |
} |
| 4257 |
return TCL_OK; |
| 4258 |
} |
| 4259 |
|
| 4260 |
/* |
| 4261 |
* ---------------------------------------------------------------------- |
| 4262 |
* |
| 4263 |
* ConfigureOp -- |
| 4264 |
* |
| 4265 |
* Results: |
| 4266 |
* The return value is a standard Tcl result. |
| 4267 |
* |
| 4268 |
* Side Effects: |
| 4269 |
* |
| 4270 |
* ---------------------------------------------------------------------- |
| 4271 |
*/ |
| 4272 |
static int |
| 4273 |
ConfigureOp(graphPtr, interp, argc, argv) |
| 4274 |
Graph *graphPtr; |
| 4275 |
Tcl_Interp *interp; |
| 4276 |
int argc; |
| 4277 |
char **argv; |
| 4278 |
{ |
| 4279 |
Marker *markerPtr; |
| 4280 |
int flags = TK_CONFIG_ARGV_ONLY; |
| 4281 |
char *oldName; |
| 4282 |
int nNames, nOpts; |
| 4283 |
char **options; |
| 4284 |
register int i; |
| 4285 |
int under; |
| 4286 |
|
| 4287 |
/* Figure out where the option value pairs begin */ |
| 4288 |
argc -= 3; |
| 4289 |
argv += 3; |
| 4290 |
for (i = 0; i < argc; i++) { |
| 4291 |
if (argv[i][0] == '-') { |
| 4292 |
break; |
| 4293 |
} |
| 4294 |
if (NameToMarker(graphPtr, argv[i], &markerPtr) != TCL_OK) { |
| 4295 |
return TCL_ERROR; |
| 4296 |
} |
| 4297 |
} |
| 4298 |
nNames = i; /* Number of element names specified */ |
| 4299 |
nOpts = argc - i; /* Number of options specified */ |
| 4300 |
options = argv + nNames; /* Start of options in argv */ |
| 4301 |
|
| 4302 |
for (i = 0; i < nNames; i++) { |
| 4303 |
NameToMarker(graphPtr, argv[i], &markerPtr); |
| 4304 |
if (nOpts == 0) { |
| 4305 |
return Tk_ConfigureInfo(interp, graphPtr->tkwin, |
| 4306 |
markerPtr->classPtr->configSpecs, (char *)markerPtr, |
| 4307 |
(char *)NULL, flags); |
| 4308 |
} else if (nOpts == 1) { |
| 4309 |
return Tk_ConfigureInfo(interp, graphPtr->tkwin, |
| 4310 |
markerPtr->classPtr->configSpecs, (char *)markerPtr, |
| 4311 |
options[0], flags); |
| 4312 |
} |
| 4313 |
/* Save the old marker. */ |
| 4314 |
oldName = markerPtr->name; |
| 4315 |
under = markerPtr->drawUnder; |
| 4316 |
if (Tk_ConfigureWidget(interp, graphPtr->tkwin, |
| 4317 |
markerPtr->classPtr->configSpecs, nOpts, options, |
| 4318 |
(char *)markerPtr, flags) != TCL_OK) { |
| 4319 |
return TCL_ERROR; |
| 4320 |
} |
| 4321 |
if (oldName != markerPtr->name) { |
| 4322 |
if (RenameMarker(graphPtr, markerPtr, oldName, markerPtr->name) |
| 4323 |
!= TCL_OK) { |
| 4324 |
markerPtr->name = oldName; |
| 4325 |
return TCL_ERROR; |
| 4326 |
} |
| 4327 |
} |
| 4328 |
if ((*markerPtr->classPtr->configProc) (markerPtr) != TCL_OK) { |
| 4329 |
return TCL_ERROR; |
| 4330 |
} |
| 4331 |
if (markerPtr->drawUnder != under) { |
| 4332 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 4333 |
} |
| 4334 |
} |
| 4335 |
return TCL_OK; |
| 4336 |
} |
| 4337 |
|
| 4338 |
/* |
| 4339 |
* ---------------------------------------------------------------------- |
| 4340 |
* |
| 4341 |
* CreateOp -- |
| 4342 |
* |
| 4343 |
* This procedure creates and initializes a new marker. |
| 4344 |
* |
| 4345 |
* Results: |
| 4346 |
* The return value is a pointer to a structure describing |
| 4347 |
* the new element. If an error occurred, then the return |
| 4348 |
* value is NULL and an error message is left in interp->result. |
| 4349 |
* |
| 4350 |
* Side effects: |
| 4351 |
* Memory is allocated, etc. |
| 4352 |
* |
| 4353 |
* ---------------------------------------------------------------------- |
| 4354 |
*/ |
| 4355 |
static int |
| 4356 |
CreateOp(graphPtr, interp, argc, argv) |
| 4357 |
Graph *graphPtr; |
| 4358 |
Tcl_Interp *interp; |
| 4359 |
int argc; |
| 4360 |
char **argv; |
| 4361 |
{ |
| 4362 |
Marker *markerPtr; |
| 4363 |
Blt_HashEntry *hPtr; |
| 4364 |
int isNew; |
| 4365 |
Blt_Uid classUid; |
| 4366 |
register int i; |
| 4367 |
char *name; |
| 4368 |
char string[200]; |
| 4369 |
unsigned int length; |
| 4370 |
char c; |
| 4371 |
|
| 4372 |
c = argv[3][0]; |
| 4373 |
/* Create the new marker based upon the given type */ |
| 4374 |
if ((c == 't') && (strcmp(argv[3], "text") == 0)) { |
| 4375 |
classUid = bltTextMarkerUid; |
| 4376 |
} else if ((c == 'l') && (strcmp(argv[3], "line") == 0)) { |
| 4377 |
classUid = bltLineMarkerUid; |
| 4378 |
} else if ((c == 'p') && (strcmp(argv[3], "polygon") == 0)) { |
| 4379 |
classUid = bltPolygonMarkerUid; |
| 4380 |
} else if ((c == 'i') && (strcmp(argv[3], "image") == 0)) { |
| 4381 |
classUid = bltImageMarkerUid; |
| 4382 |
} else if ((c == 'b') && (strcmp(argv[3], "bitmap") == 0)) { |
| 4383 |
classUid = bltBitmapMarkerUid; |
| 4384 |
} else if ((c == 'w') && (strcmp(argv[3], "window") == 0)) { |
| 4385 |
classUid = bltWindowMarkerUid; |
| 4386 |
} else { |
| 4387 |
Tcl_AppendResult(interp, "unknown marker type \"", argv[3], |
| 4388 |
"\": should be \"text\", \"line\", \"polygon\", \"bitmap\", \"image\", or \ |
| 4389 |
\"window\"", (char *)NULL); |
| 4390 |
return TCL_ERROR; |
| 4391 |
} |
| 4392 |
/* Scan for "-name" option. We need it for the component name */ |
| 4393 |
name = NULL; |
| 4394 |
for (i = 4; i < argc; i += 2) { |
| 4395 |
length = strlen(argv[i]); |
| 4396 |
if ((length > 1) && (strncmp(argv[i], "-name", length) == 0)) { |
| 4397 |
name = argv[i + 1]; |
| 4398 |
break; |
| 4399 |
} |
| 4400 |
} |
| 4401 |
/* If no name was given for the marker, make up one. */ |
| 4402 |
if (name == NULL) { |
| 4403 |
sprintf(string, "marker%d", graphPtr->nextMarkerId++); |
| 4404 |
name = string; |
| 4405 |
} else if (name[0] == '-') { |
| 4406 |
Tcl_AppendResult(interp, "name of marker \"", name, |
| 4407 |
"\" can't start with a '-'", (char *)NULL); |
| 4408 |
return TCL_ERROR; |
| 4409 |
} |
| 4410 |
markerPtr = CreateMarker(graphPtr, name, classUid); |
| 4411 |
if (Blt_ConfigureWidgetComponent(interp, graphPtr->tkwin, name, |
| 4412 |
markerPtr->classUid, markerPtr->classPtr->configSpecs, |
| 4413 |
argc - 4, argv + 4, (char *)markerPtr, 0) != TCL_OK) { |
| 4414 |
DestroyMarker(markerPtr); |
| 4415 |
return TCL_ERROR; |
| 4416 |
} |
| 4417 |
if ((*markerPtr->classPtr->configProc) (markerPtr) != TCL_OK) { |
| 4418 |
DestroyMarker(markerPtr); |
| 4419 |
return TCL_ERROR; |
| 4420 |
} |
| 4421 |
hPtr = Blt_CreateHashEntry(&graphPtr->markers.table, name, &isNew); |
| 4422 |
if (!isNew) { |
| 4423 |
Marker *oldMarkerPtr; |
| 4424 |
/* |
| 4425 |
* Marker by the same name already exists. Delete the old |
| 4426 |
* marker and it's list entry. But save the hash entry. |
| 4427 |
*/ |
| 4428 |
oldMarkerPtr = (Marker *)Blt_GetHashValue(hPtr); |
| 4429 |
oldMarkerPtr->hashPtr = NULL; |
| 4430 |
DestroyMarker(oldMarkerPtr); |
| 4431 |
} |
| 4432 |
Blt_SetHashValue(hPtr, markerPtr); |
| 4433 |
markerPtr->hashPtr = hPtr; |
| 4434 |
markerPtr->linkPtr = |
| 4435 |
Blt_ChainAppend(graphPtr->markers.displayList, markerPtr); |
| 4436 |
if (markerPtr->drawUnder) { |
| 4437 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 4438 |
} |
| 4439 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 4440 |
Tcl_SetResult(interp, name, TCL_VOLATILE); |
| 4441 |
return TCL_OK; |
| 4442 |
} |
| 4443 |
|
| 4444 |
/* |
| 4445 |
* ---------------------------------------------------------------------- |
| 4446 |
* |
| 4447 |
* DeleteOp -- |
| 4448 |
* |
| 4449 |
* Deletes the marker given by markerId. |
| 4450 |
* |
| 4451 |
* Results: |
| 4452 |
* The return value is a standard Tcl result. |
| 4453 |
* |
| 4454 |
* Side Effects: |
| 4455 |
* Graph will be redrawn to reflect the new display list. |
| 4456 |
* |
| 4457 |
* ---------------------------------------------------------------------- |
| 4458 |
*/ |
| 4459 |
/*ARGSUSED*/ |
| 4460 |
static int |
| 4461 |
DeleteOp(graphPtr, interp, argc, argv) |
| 4462 |
Graph *graphPtr; |
| 4463 |
Tcl_Interp *interp; /* Not used. */ |
| 4464 |
int argc; |
| 4465 |
char **argv; |
| 4466 |
{ |
| 4467 |
Marker *markerPtr; |
| 4468 |
register int i; |
| 4469 |
|
| 4470 |
for (i = 3; i < argc; i++) { |
| 4471 |
if (NameToMarker(graphPtr, argv[i], &markerPtr) == TCL_OK) { |
| 4472 |
DestroyMarker(markerPtr); |
| 4473 |
} |
| 4474 |
} |
| 4475 |
Tcl_ResetResult(interp); |
| 4476 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 4477 |
return TCL_OK; |
| 4478 |
} |
| 4479 |
|
| 4480 |
/* |
| 4481 |
*---------------------------------------------------------------------- |
| 4482 |
* |
| 4483 |
* GetOp -- |
| 4484 |
* |
| 4485 |
* Find the legend entry from the given argument. The argument |
| 4486 |
* can be either a screen position "@x,y" or the name of an |
| 4487 |
* element. |
| 4488 |
* |
| 4489 |
* I don't know how useful it is to test with the name of an |
| 4490 |
* element. |
| 4491 |
* |
| 4492 |
* Results: |
| 4493 |
* A standard Tcl result. |
| 4494 |
* |
| 4495 |
* Side Effects: |
| 4496 |
* Graph will be redrawn to reflect the new legend attributes. |
| 4497 |
* |
| 4498 |
*---------------------------------------------------------------------- |
| 4499 |
*/ |
| 4500 |
/*ARGSUSED*/ |
| 4501 |
static int |
| 4502 |
GetOp(graphPtr, interp, argc, argv) |
| 4503 |
Graph *graphPtr; |
| 4504 |
Tcl_Interp *interp; |
| 4505 |
int argc; /* Not used. */ |
| 4506 |
char *argv[]; |
| 4507 |
{ |
| 4508 |
register Marker *markerPtr; |
| 4509 |
|
| 4510 |
if ((argv[3][0] == 'c') && (strcmp(argv[3], "current") == 0)) { |
| 4511 |
markerPtr = (Marker *)Blt_GetCurrentItem(graphPtr->bindTable); |
| 4512 |
/* Report only on markers. */ |
| 4513 |
if (markerPtr == NULL) { |
| 4514 |
return TCL_OK; |
| 4515 |
} |
| 4516 |
if ((markerPtr->classUid == bltBitmapMarkerUid) || |
| 4517 |
(markerPtr->classUid == bltLineMarkerUid) || |
| 4518 |
(markerPtr->classUid == bltWindowMarkerUid) || |
| 4519 |
(markerPtr->classUid == bltPolygonMarkerUid) || |
| 4520 |
(markerPtr->classUid == bltTextMarkerUid) || |
| 4521 |
(markerPtr->classUid == bltImageMarkerUid)) { |
| 4522 |
Tcl_SetResult(interp, markerPtr->name, TCL_VOLATILE); |
| 4523 |
} |
| 4524 |
} |
| 4525 |
return TCL_OK; |
| 4526 |
} |
| 4527 |
|
| 4528 |
/* |
| 4529 |
* ---------------------------------------------------------------------- |
| 4530 |
* |
| 4531 |
* RelinkOp -- |
| 4532 |
* |
| 4533 |
* Reorders the marker (given by the first name) before/after |
| 4534 |
* the another marker (given by the second name) in the |
| 4535 |
* marker display list. If no second name is given, the |
| 4536 |
* marker is placed at the beginning/end of the list. |
| 4537 |
* |
| 4538 |
* Results: |
| 4539 |
* A standard Tcl result. |
| 4540 |
* |
| 4541 |
* Side Effects: |
| 4542 |
* Graph will be redrawn to reflect the new display list. |
| 4543 |
* |
| 4544 |
* ---------------------------------------------------------------------- |
| 4545 |
*/ |
| 4546 |
/*ARGSUSED*/ |
| 4547 |
static int |
| 4548 |
RelinkOp(graphPtr, interp, argc, argv) |
| 4549 |
Graph *graphPtr; |
| 4550 |
Tcl_Interp *interp; /* Not used. */ |
| 4551 |
int argc; |
| 4552 |
char **argv; |
| 4553 |
{ |
| 4554 |
Blt_ChainLink *linkPtr, *placePtr; |
| 4555 |
Marker *markerPtr; |
| 4556 |
|
| 4557 |
/* Find the marker to be raised or lowered. */ |
| 4558 |
if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) { |
| 4559 |
return TCL_ERROR; |
| 4560 |
} |
| 4561 |
/* Right now it's assumed that all markers are always in the |
| 4562 |
display list. */ |
| 4563 |
linkPtr = markerPtr->linkPtr; |
| 4564 |
Blt_ChainUnlinkLink(graphPtr->markers.displayList, markerPtr->linkPtr); |
| 4565 |
|
| 4566 |
placePtr = NULL; |
| 4567 |
if (argc == 5) { |
| 4568 |
if (NameToMarker(graphPtr, argv[4], &markerPtr) != TCL_OK) { |
| 4569 |
return TCL_ERROR; |
| 4570 |
} |
| 4571 |
placePtr = markerPtr->linkPtr; |
| 4572 |
} |
| 4573 |
|
| 4574 |
/* Link the marker at its new position. */ |
| 4575 |
if (argv[2][0] == 'a') { |
| 4576 |
Blt_ChainLinkAfter(graphPtr->markers.displayList, linkPtr, placePtr); |
| 4577 |
} else { |
| 4578 |
Blt_ChainLinkBefore(graphPtr->markers.displayList, linkPtr, placePtr); |
| 4579 |
} |
| 4580 |
if (markerPtr->drawUnder) { |
| 4581 |
graphPtr->flags |= REDRAW_BACKING_STORE; |
| 4582 |
} |
| 4583 |
Blt_EventuallyRedrawGraph(graphPtr); |
| 4584 |
return TCL_OK; |
| 4585 |
} |
| 4586 |
|
| 4587 |
|
| 4588 |
/* |
| 4589 |
* ---------------------------------------------------------------------- |
| 4590 |
* |
| 4591 |
* FindOp -- |
| 4592 |
* |
| 4593 |
* Returns if marker by a given ID currently exists. |
| 4594 |
* |
| 4595 |
* Results: |
| 4596 |
* A standard Tcl result. |
| 4597 |
* |
| 4598 |
* ---------------------------------------------------------------------- |
| 4599 |
*/ |
| 4600 |
/*ARGSUSED*/ |
| 4601 |
static int |
| 4602 |
FindOp(graphPtr, interp, argc, argv) |
| 4603 |
Graph *graphPtr; |
| 4604 |
Tcl_Interp *interp; |
| 4605 |
int argc; |
| 4606 |
char **argv; |
| 4607 |
{ |
| 4608 |
Blt_ChainLink *linkPtr; |
| 4609 |
Extents2D exts; |
| 4610 |
Marker *markerPtr; |
| 4611 |
int mode; |
| 4612 |
int left, right, top, bottom; |
| 4613 |
int enclosed; |
| 4614 |
|
| 4615 |
#define FIND_ENCLOSED (1<<0) |
| 4616 |
#define FIND_OVERLAPPING (1<<1) |
| 4617 |
if (strcmp(argv[3], "enclosed") == 0) { |
| 4618 |
mode = FIND_ENCLOSED; |
| 4619 |
} else if (strcmp(argv[3], "overlapping") == 0) { |
| 4620 |
mode = FIND_OVERLAPPING; |
| 4621 |
} else { |
| 4622 |
Tcl_AppendResult(interp, "bad search type \"", argv[3], |
| 4623 |
": should be \"enclosed\", or \"overlapping\"", (char *)NULL); |
| 4624 |
return TCL_ERROR; |
| 4625 |
} |
| 4626 |
|
| 4627 |
if ((Tcl_GetInt(interp, argv[4], &left) != TCL_OK) || |
| 4628 |
(Tcl_GetInt(interp, argv[5], &top) != TCL_OK) || |
| 4629 |
(Tcl_GetInt(interp, argv[6], &right) != TCL_OK) || |
| 4630 |
(Tcl_GetInt(interp, argv[7], &bottom) != TCL_OK)) { |
| 4631 |
return TCL_ERROR; |
| 4632 |
} |
| 4633 |
if (left < right) { |
| 4634 |
exts.left = (double)left; |
| 4635 |
exts.right = (double)right; |
| 4636 |
} else { |
| 4637 |
exts.left = (double)right; |
| 4638 |
exts.right = (double)left; |
| 4639 |
} |
| 4640 |
if (top < bottom) { |
| 4641 |
exts.top = (double)top; |
| 4642 |
exts.bottom = (double)bottom; |
| 4643 |
} else { |
| 4644 |
exts.top = (double)bottom; |
| 4645 |
exts.bottom = (double)top; |
| 4646 |
} |
| 4647 |
enclosed = (mode == FIND_ENCLOSED); |
| 4648 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList); |
| 4649 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4650 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4651 |
if (markerPtr->hidden) { |
| 4652 |
continue; |
| 4653 |
} |
| 4654 |
if (markerPtr->elemName != NULL) { |
| 4655 |
Blt_HashEntry *hPtr; |
| 4656 |
|
| 4657 |
hPtr = Blt_FindHashEntry(&graphPtr->elements.table, |
| 4658 |
markerPtr->elemName); |
| 4659 |
if (hPtr != NULL) { |
| 4660 |
Element *elemPtr; |
| 4661 |
|
| 4662 |
elemPtr = (Element *)Blt_GetHashValue(hPtr); |
| 4663 |
if (elemPtr->hidden) { |
| 4664 |
continue; |
| 4665 |
} |
| 4666 |
} |
| 4667 |
} |
| 4668 |
if ((*markerPtr->classPtr->regionProc)(markerPtr, &exts, enclosed)) { |
| 4669 |
Tcl_SetResult(interp, markerPtr->name, TCL_VOLATILE); |
| 4670 |
return TCL_OK; |
| 4671 |
} |
| 4672 |
} |
| 4673 |
Tcl_SetResult(interp, "", TCL_VOLATILE); |
| 4674 |
return TCL_OK; |
| 4675 |
} |
| 4676 |
|
| 4677 |
/* |
| 4678 |
* ---------------------------------------------------------------------- |
| 4679 |
* |
| 4680 |
* ExistsOp -- |
| 4681 |
* |
| 4682 |
* Returns if marker by a given ID currently exists. |
| 4683 |
* |
| 4684 |
* Results: |
| 4685 |
* A standard Tcl result. |
| 4686 |
* |
| 4687 |
* ---------------------------------------------------------------------- |
| 4688 |
*/ |
| 4689 |
/*ARGSUSED*/ |
| 4690 |
static int |
| 4691 |
ExistsOp(graphPtr, interp, argc, argv) |
| 4692 |
Graph *graphPtr; |
| 4693 |
Tcl_Interp *interp; |
| 4694 |
int argc; |
| 4695 |
char **argv; |
| 4696 |
{ |
| 4697 |
Blt_HashEntry *hPtr; |
| 4698 |
|
| 4699 |
hPtr = Blt_FindHashEntry(&graphPtr->markers.table, argv[3]); |
| 4700 |
Blt_SetBooleanResult(interp, (hPtr != NULL)); |
| 4701 |
return TCL_OK; |
| 4702 |
} |
| 4703 |
|
| 4704 |
/* |
| 4705 |
* ---------------------------------------------------------------------- |
| 4706 |
* |
| 4707 |
* TypeOp -- |
| 4708 |
* |
| 4709 |
* Returns a symbolic name for the type of the marker whose ID is |
| 4710 |
* given. |
| 4711 |
* |
| 4712 |
* Results: |
| 4713 |
* A standard Tcl result. interp->result will contain the symbolic |
| 4714 |
* type of the marker. |
| 4715 |
* |
| 4716 |
* ---------------------------------------------------------------------- |
| 4717 |
*/ |
| 4718 |
/*ARGSUSED*/ |
| 4719 |
static int |
| 4720 |
TypeOp(graphPtr, interp, argc, argv) |
| 4721 |
Graph *graphPtr; |
| 4722 |
Tcl_Interp *interp; |
| 4723 |
int argc; |
| 4724 |
char **argv; |
| 4725 |
{ |
| 4726 |
Marker *markerPtr; |
| 4727 |
|
| 4728 |
if (NameToMarker(graphPtr, argv[3], &markerPtr) != TCL_OK) { |
| 4729 |
return TCL_ERROR; |
| 4730 |
} |
| 4731 |
Tcl_SetResult(interp, markerPtr->classUid, TCL_STATIC); |
| 4732 |
return TCL_OK; |
| 4733 |
} |
| 4734 |
|
| 4735 |
/* Public routines */ |
| 4736 |
|
| 4737 |
/* |
| 4738 |
* ---------------------------------------------------------------------- |
| 4739 |
* |
| 4740 |
* Blt_MarkerOp -- |
| 4741 |
* |
| 4742 |
* This procedure is invoked to process the Tcl command |
| 4743 |
* that corresponds to a widget managed by this module. |
| 4744 |
* See the user documentation for details on what it does. |
| 4745 |
* |
| 4746 |
* Results: |
| 4747 |
* A standard Tcl result. |
| 4748 |
* |
| 4749 |
* Side effects: |
| 4750 |
* See the user documentation. |
| 4751 |
* |
| 4752 |
* ---------------------------------------------------------------------- |
| 4753 |
*/ |
| 4754 |
|
| 4755 |
static Blt_OpSpec markerOps[] = |
| 4756 |
{ |
| 4757 |
{"after", 1, (Blt_Op)RelinkOp, 4, 5, "marker ?afterMarker?",}, |
| 4758 |
{"before", 2, (Blt_Op)RelinkOp, 4, 5, "marker ?beforeMarker?",}, |
| 4759 |
{"bind", 2, (Blt_Op)BindOp, 3, 6, "marker sequence command",}, |
| 4760 |
{"cget", 2, (Blt_Op)CgetOp, 5, 5, "marker option",}, |
| 4761 |
{"configure", 2, (Blt_Op)ConfigureOp, 4, 0, |
| 4762 |
"marker ?marker?... ?option value?...",}, |
| 4763 |
{"create", 2, (Blt_Op)CreateOp, 4, 0, |
| 4764 |
"type ?option value?...",}, |
| 4765 |
{"delete", 1, (Blt_Op)DeleteOp, 3, 0, "?marker?...",}, |
| 4766 |
{"exists", 1, (Blt_Op)ExistsOp, 4, 4, "marker",}, |
| 4767 |
{"find", 1, (Blt_Op)FindOp, 8, 8, "enclosed|overlapping x1 y1 x2 y2",}, |
| 4768 |
{"get", 1, (Blt_Op)GetOp, 4, 4, "name",}, |
| 4769 |
{"names", 1, (Blt_Op)NamesOp, 3, 0, "?pattern?...",}, |
| 4770 |
{"type", 1, (Blt_Op)TypeOp, 4, 4, "marker",}, |
| 4771 |
}; |
| 4772 |
static int nMarkerOps = sizeof(markerOps) / sizeof(Blt_OpSpec); |
| 4773 |
|
| 4774 |
/*ARGSUSED*/ |
| 4775 |
int |
| 4776 |
Blt_MarkerOp(graphPtr, interp, argc, argv) |
| 4777 |
Graph *graphPtr; |
| 4778 |
Tcl_Interp *interp; /* Not used. */ |
| 4779 |
int argc; |
| 4780 |
char **argv; |
| 4781 |
{ |
| 4782 |
Blt_Op proc; |
| 4783 |
int result; |
| 4784 |
|
| 4785 |
proc = Blt_GetOp(interp, nMarkerOps, markerOps, BLT_OP_ARG2, argc, argv,0); |
| 4786 |
if (proc == NULL) { |
| 4787 |
return TCL_ERROR; |
| 4788 |
} |
| 4789 |
result = (*proc) (graphPtr, interp, argc, argv); |
| 4790 |
return result; |
| 4791 |
} |
| 4792 |
|
| 4793 |
/* |
| 4794 |
* ------------------------------------------------------------------------- |
| 4795 |
* |
| 4796 |
* Blt_MarkersToPostScript -- |
| 4797 |
* |
| 4798 |
* ------------------------------------------------------------------------- |
| 4799 |
*/ |
| 4800 |
void |
| 4801 |
Blt_MarkersToPostScript(graphPtr, psToken, under) |
| 4802 |
Graph *graphPtr; |
| 4803 |
PsToken psToken; |
| 4804 |
int under; |
| 4805 |
{ |
| 4806 |
Blt_ChainLink *linkPtr; |
| 4807 |
register Marker *markerPtr; |
| 4808 |
|
| 4809 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList); |
| 4810 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4811 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4812 |
if ((markerPtr->classPtr->postscriptProc == NULL) || |
| 4813 |
(markerPtr->nWorldPts == 0)) { |
| 4814 |
continue; |
| 4815 |
} |
| 4816 |
if (markerPtr->drawUnder != under) { |
| 4817 |
continue; |
| 4818 |
} |
| 4819 |
if (markerPtr->hidden) { |
| 4820 |
continue; |
| 4821 |
} |
| 4822 |
if (markerPtr->elemName != NULL) { |
| 4823 |
Blt_HashEntry *hPtr; |
| 4824 |
|
| 4825 |
hPtr = Blt_FindHashEntry(&graphPtr->elements.table, |
| 4826 |
markerPtr->elemName); |
| 4827 |
if (hPtr != NULL) { |
| 4828 |
Element *elemPtr; |
| 4829 |
|
| 4830 |
elemPtr = (Element *)Blt_GetHashValue(hPtr); |
| 4831 |
if (elemPtr->hidden) { |
| 4832 |
continue; |
| 4833 |
} |
| 4834 |
} |
| 4835 |
} |
| 4836 |
Blt_AppendToPostScript(psToken, "\n% Marker \"", markerPtr->name, |
| 4837 |
"\" is a ", markerPtr->classUid, " marker\n", (char *)NULL); |
| 4838 |
(*markerPtr->classPtr->postscriptProc) (markerPtr, psToken); |
| 4839 |
} |
| 4840 |
} |
| 4841 |
|
| 4842 |
/* |
| 4843 |
* ------------------------------------------------------------------------- |
| 4844 |
* |
| 4845 |
* Blt_DrawMarkers -- |
| 4846 |
* |
| 4847 |
* Calls the individual drawing routines (based on marker type) |
| 4848 |
* for each marker in the display list. |
| 4849 |
* |
| 4850 |
* A marker will not be drawn if |
| 4851 |
* |
| 4852 |
* 1) An element linked to the marker (indicated by elemName) |
| 4853 |
* is currently hidden. |
| 4854 |
* |
| 4855 |
* 2) No coordinates have been specified for the marker. |
| 4856 |
* |
| 4857 |
* 3) The marker is requesting to be drawn at a different level |
| 4858 |
* (above/below the elements) from the current mode. |
| 4859 |
* |
| 4860 |
* 4) The marker is configured as hidden (-hide option). |
| 4861 |
* |
| 4862 |
* 5) The marker isn't visible in the current viewport |
| 4863 |
* (i.e. clipped). |
| 4864 |
* |
| 4865 |
* Results: |
| 4866 |
* None |
| 4867 |
* |
| 4868 |
* Side Effects: |
| 4869 |
* Markers are drawn into the drawable (pixmap) which will eventually |
| 4870 |
* be displayed in the graph window. |
| 4871 |
* |
| 4872 |
* ------------------------------------------------------------------------- |
| 4873 |
*/ |
| 4874 |
void |
| 4875 |
Blt_DrawMarkers(graphPtr, drawable, under) |
| 4876 |
Graph *graphPtr; |
| 4877 |
Drawable drawable; /* Pixmap or window to draw into */ |
| 4878 |
int under; |
| 4879 |
{ |
| 4880 |
Blt_ChainLink *linkPtr; |
| 4881 |
Marker *markerPtr; |
| 4882 |
|
| 4883 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList); |
| 4884 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4885 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4886 |
|
| 4887 |
if ((markerPtr->nWorldPts == 0) || |
| 4888 |
(markerPtr->drawUnder != under) || |
| 4889 |
(markerPtr->hidden) || |
| 4890 |
(markerPtr->clipped)) { |
| 4891 |
continue; |
| 4892 |
} |
| 4893 |
if (markerPtr->elemName != NULL) { |
| 4894 |
Blt_HashEntry *hPtr; |
| 4895 |
|
| 4896 |
/* Look up the named element and see if it's hidden */ |
| 4897 |
hPtr = Blt_FindHashEntry(&graphPtr->elements.table, |
| 4898 |
markerPtr->elemName); |
| 4899 |
if (hPtr != NULL) { |
| 4900 |
Element *elemPtr; |
| 4901 |
|
| 4902 |
elemPtr = (Element *)Blt_GetHashValue(hPtr); |
| 4903 |
if (elemPtr->hidden) { |
| 4904 |
continue; |
| 4905 |
} |
| 4906 |
} |
| 4907 |
} |
| 4908 |
|
| 4909 |
(*markerPtr->classPtr->drawProc) (markerPtr, drawable); |
| 4910 |
} |
| 4911 |
} |
| 4912 |
|
| 4913 |
void |
| 4914 |
Blt_MapMarkers(graphPtr) |
| 4915 |
Graph *graphPtr; |
| 4916 |
{ |
| 4917 |
Blt_ChainLink *linkPtr; |
| 4918 |
Marker *markerPtr; |
| 4919 |
|
| 4920 |
for (linkPtr = Blt_ChainFirstLink(graphPtr->markers.displayList); |
| 4921 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4922 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4923 |
if ((markerPtr->nWorldPts == 0) || (markerPtr->hidden)) { |
| 4924 |
continue; |
| 4925 |
} |
| 4926 |
if ((graphPtr->flags & MAP_ALL) || (markerPtr->flags & MAP_ITEM)) { |
| 4927 |
(*markerPtr->classPtr->mapProc) (markerPtr); |
| 4928 |
markerPtr->flags &= ~MAP_ITEM; |
| 4929 |
} |
| 4930 |
} |
| 4931 |
} |
| 4932 |
|
| 4933 |
|
| 4934 |
void |
| 4935 |
Blt_DestroyMarkers(graphPtr) |
| 4936 |
Graph *graphPtr; |
| 4937 |
{ |
| 4938 |
Blt_HashEntry *hPtr; |
| 4939 |
Blt_HashSearch cursor; |
| 4940 |
Marker *markerPtr; |
| 4941 |
|
| 4942 |
for (hPtr = Blt_FirstHashEntry(&graphPtr->markers.table, &cursor); |
| 4943 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 4944 |
markerPtr = (Marker *)Blt_GetHashValue(hPtr); |
| 4945 |
/* |
| 4946 |
* Dereferencing the pointer to the hash table prevents the |
| 4947 |
* hash table entry from being automatically deleted. |
| 4948 |
*/ |
| 4949 |
markerPtr->hashPtr = NULL; |
| 4950 |
DestroyMarker(markerPtr); |
| 4951 |
} |
| 4952 |
Blt_DeleteHashTable(&graphPtr->markers.table); |
| 4953 |
Blt_DeleteHashTable(&graphPtr->markers.tagTable); |
| 4954 |
Blt_ChainDestroy(graphPtr->markers.displayList); |
| 4955 |
} |
| 4956 |
|
| 4957 |
Marker * |
| 4958 |
Blt_NearestMarker(graphPtr, x, y, under) |
| 4959 |
Graph *graphPtr; |
| 4960 |
int x, y; /* Screen coordinates */ |
| 4961 |
int under; |
| 4962 |
{ |
| 4963 |
Blt_ChainLink *linkPtr; |
| 4964 |
Marker *markerPtr; |
| 4965 |
Point2D point; |
| 4966 |
|
| 4967 |
point.x = (double)x; |
| 4968 |
point.y = (double)y; |
| 4969 |
for (linkPtr = Blt_ChainLastLink(graphPtr->markers.displayList); |
| 4970 |
linkPtr != NULL; linkPtr = Blt_ChainPrevLink(linkPtr)) { |
| 4971 |
markerPtr = Blt_ChainGetValue(linkPtr); |
| 4972 |
/* |
| 4973 |
* Don't consider markers that are pending to be mapped. Even |
| 4974 |
* if the marker has already been mapped, the coordinates |
| 4975 |
* could be invalid now. Better to pick no marker than the |
| 4976 |
* wrong marker. |
| 4977 |
*/ |
| 4978 |
if ((markerPtr->drawUnder == under) && (markerPtr->nWorldPts > 0) && |
| 4979 |
((markerPtr->flags & MAP_ITEM) == 0) && |
| 4980 |
(!markerPtr->hidden) && (markerPtr->state == STATE_NORMAL)) { |
| 4981 |
if ((*markerPtr->classPtr->pointProc) (markerPtr, &point)) { |
| 4982 |
return markerPtr; |
| 4983 |
} |
| 4984 |
} |
| 4985 |
} |
| 4986 |
return NULL; |
| 4987 |
} |