1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
|
/*------------------------------------------------------*/
/* Graphics routines for qrouter */
/*------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <tk.h>
#include "qrouter.h"
#include "qconfig.h"
#include "node.h"
#include "maze.h"
#include "lef.h"
/*------------------------------*/
/* Type declarations */
/*------------------------------*/
static void load_font(XFontStruct **);
static void createGC(Window, GC *, XFontStruct *);
/*----------------------------------*/
/* Global variables for X11 drawing */
/*----------------------------------*/
XFontStruct *font_info;
Pixmap buffer = (Pixmap)0;
Display *dpy;
Window win;
Colormap cmap;
GC gc;
Dimension width, height;
#define SHORTSPAN 10
#define LONGSPAN 127
int spacing;
int bluepix, greenpix, redpix, cyanpix, orangepix, goldpix;
int blackpix, whitepix, graypix, ltgraypix, yellowpix;
int magentapix, purplepix, greenyellowpix;
int brownvector[SHORTSPAN];
int bluevector[LONGSPAN];
/*--------------------------------------------------------------*/
/* Highlight a position on the graph. Do this on the actual */
/* screen, not the buffer. */
/*--------------------------------------------------------------*/
void highlight(int x, int y) {
int i, xspc, yspc, hspc;
PROUTE *Pr;
// If Obs2[] at x, y is a source or dest, don't highlight
// Do this only for layer 0; it doesn't have to be rigorous.
for (i = 0; i < Num_layers; i++) {
Pr = &OBS2VAL(x, y, i);
if (Pr->flags & (PR_SOURCE | PR_TARGET)) return;
}
hspc = spacing >> 1;
if (hspc == 0) hspc = 1;
xspc = (x + 1) * spacing - hspc;
yspc = height - (y + 1) * spacing - hspc;
XSetForeground(dpy, gc, yellowpix);
XFillRectangle(dpy, win, gc, xspc, yspc, spacing, spacing);
XFlush(dpy);
}
/*--------------------------------------*/
/* Highlight source (in magenta) */
/*--------------------------------------*/
void highlight_source() {
int xspc, yspc, hspc;
int i, x, y;
PROUTE *Pr;
if (Obs2[0] == NULL) return;
// Determine the number of routes per width and height, if
// it has not yet been computed
hspc = spacing >> 1;
if (hspc == 0) hspc = 1;
// Draw source pins as magenta squares
XSetForeground(dpy, gc, magentapix);
for (i = 0; i < Num_layers; i++) {
for (x = 0; x < NumChannelsX[i]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[i]; y++) {
Pr = &OBS2VAL(x, y, i);
if (Pr->flags & PR_SOURCE) {
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, win, gc, xspc, yspc,
spacing, spacing);
}
}
}
}
XFlush(dpy);
}
/*--------------------------------------*/
/* Highlight destination (in purple) */
/*--------------------------------------*/
void highlight_dest() {
int xspc, yspc, hspc, dspc;
int i, x, y;
PROUTE *Pr;
if (Obs2[0] == NULL) return;
// Determine the number of routes per width and height, if
// it has not yet been computed
dspc = spacing + 4; // Make target more visible
hspc = dspc >> 1;
// Draw destination pins as purple squares
XSetForeground(dpy, gc, purplepix);
for (i = 0; i < Num_layers; i++) {
for (x = 0; x < NumChannelsX[i]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[i]; y++) {
Pr = &OBS2VAL(x, y, i);
if (Pr->flags & PR_TARGET) {
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, win, gc, xspc, yspc,
dspc, dspc);
}
}
}
}
XFlush(dpy);
}
/*----------------------------------------------*/
/* Highlight all the search starting points */
/*----------------------------------------------*/
void highlight_starts(POINT glist) {
int xspc, yspc, hspc;
POINT gpoint;
// Determine the number of routes per width and height, if
// it has not yet been computed
hspc = spacing >> 1;
XSetForeground(dpy, gc, greenyellowpix);
for (gpoint = glist; gpoint; gpoint = gpoint->next) {
xspc = (gpoint->x1 + 1) * spacing - hspc;
yspc = height - (gpoint->y1 + 1) * spacing - hspc;
XFillRectangle(dpy, win, gc, xspc, yspc, spacing, spacing);
}
XFlush(dpy);
}
/*--------------------------------------*/
/* Highlight mask (in tan) */
/*--------------------------------------*/
void highlight_mask(void) {
int xspc, yspc, hspc;
int x, y;
if (RMask == NULL) return;
// Determine the number of routes per width and height, if
// it has not yet been computed
hspc = spacing >> 1;
// Draw destination pins as tan squares
for (x = 0; x < NumChannelsX[0]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[0]; y++) {
XSetForeground(dpy, gc, brownvector[RMASK(x, y)]);
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, win, gc, xspc, yspc, spacing, spacing);
}
}
XFlush(dpy);
}
/*----------------------------------------------*/
/* Draw a map of obstructions and pins */
/*----------------------------------------------*/
static void
map_obstruction()
{
int xspc, yspc, hspc;
int i, x, y;
hspc = spacing >> 1;
// Draw obstructions as light gray squares
XSetForeground(dpy, gc, ltgraypix);
for (i = 0; i < Num_layers; i++) {
for (x = 0; x < NumChannelsX[i]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[i]; y++) {
if (OBSVAL(x, y, i) & NO_NET) {
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, buffer, gc, xspc, yspc,
spacing, spacing);
}
}
}
}
// Draw pins as gray squares
XSetForeground(dpy, gc, graypix);
for (i = 0; i < Pinlayers; i++) {
for (x = 0; x < NumChannelsX[i]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[i]; y++) {
if (NODEIPTR(x, y, i) != NULL) {
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, buffer, gc, xspc, yspc,
spacing, spacing);
}
}
}
}
}
/*----------------------------------------------*/
/* Draw a map of actual route congestion */
/*----------------------------------------------*/
static void
map_congestion()
{
int xspc, yspc, hspc;
int i, x, y, n, norm;
u_char *Congestion;
u_char value, maxval;
hspc = spacing >> 1;
Congestion = (u_char *)calloc(NumChannelsX[0] * NumChannelsY[0],
sizeof(u_char));
// Analyze Obs[] array for congestion
for (i = 0; i < Num_layers; i++) {
for (x = 0; x < NumChannelsX[i]; x++) {
for (y = 0; y < NumChannelsY[i]; y++) {
value = (u_char)0;
n = OBSVAL(x, y, i);
if (n & ROUTED_NET) value++;
if (n & BLOCKED_MASK) value++;
if (n & NO_NET) value++;
if (n & PINOBSTRUCTMASK) value++;
CONGEST(x, y) += value;
}
}
}
maxval = 0;
for (x = 0; x < NumChannelsX[0]; x++) {
for (y = 0; y < NumChannelsY[0]; y++) {
value = CONGEST(x, y);
if (value > maxval) maxval = value;
}
}
norm = (LONGSPAN - 1) / maxval;
// Draw destination pins as blue squares
for (x = 0; x < NumChannelsX[0]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[0]; y++) {
XSetForeground(dpy, gc, bluevector[norm * CONGEST(x, y)]);
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, buffer, gc, xspc, yspc, spacing, spacing);
}
}
// Cleanup
free(Congestion);
}
/*----------------------------------------------------------------------*/
/* Draw a map of route congestion estimated from net bounding boxes */
/*----------------------------------------------------------------------*/
static void
map_estimate()
{
NET net;
int xspc, yspc, hspc;
int i, x, y, nwidth, nheight, area, length, value;
float density, *Congestion, norm, maxval;
hspc = spacing >> 1;
Congestion = (float *)calloc(NumChannelsX[0] * NumChannelsY[0],
sizeof(float));
// Use net bounding boxes to estimate congestion
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
nwidth = (net->xmax - net->xmin + 1);
nheight = (net->ymax - net->ymin + 1);
area = nwidth * nheight;
if (nwidth > nheight) {
length = nwidth + (nheight >> 1) * net->numnodes;
}
else {
length = nheight + (nwidth >> 1) * net->numnodes;
}
density = (float)length / (float)area;
for (x = net->xmin; x < net->xmax; x++)
for (y = net->ymin; y < net->ymax; y++)
CONGEST(x, y) += density;
}
maxval = 0.0;
for (x = 0; x < NumChannelsX[0]; x++) {
for (y = 0; y < NumChannelsY[0]; y++) {
density = CONGEST(x, y);
if (density > maxval) maxval = density;
}
}
norm = (float)(LONGSPAN - 1) / maxval;
// Draw destination pins as blue squares
for (x = 0; x < NumChannelsX[0]; x++) {
xspc = (x + 1) * spacing - hspc;
for (y = 0; y < NumChannelsY[0]; y++) {
value = (int)(norm * CONGEST(x, y));
XSetForeground(dpy, gc, bluevector[value]);
yspc = height - (y + 1) * spacing - hspc;
XFillRectangle(dpy, buffer, gc, xspc, yspc, spacing, spacing);
}
}
// Cleanup
free(Congestion);
}
/*--------------------------------------*/
/* Draw one net on the display */
/*--------------------------------------*/
void draw_net(NET net, u_char single, int *lastlayer) {
int layer;
SEG seg;
ROUTE rt;
if (dpy == NULL) return;
// Draw all nets, much like "emit_routes" does when writing
// routes to the DEF file.
rt = net->routes;
if (single && rt)
for (rt = net->routes; rt->next; rt = rt->next);
for (; rt; rt = rt->next) {
for (seg = rt->segments; seg; seg = seg->next) {
layer = seg->layer;
if (layer != *lastlayer) {
*lastlayer = layer;
switch(layer) {
case 0:
XSetForeground(dpy, gc, bluepix);
break;
case 1:
XSetForeground(dpy, gc, redpix);
break;
case 2:
XSetForeground(dpy, gc, cyanpix);
break;
case 3:
XSetForeground(dpy, gc, goldpix);
break;
default:
XSetForeground(dpy, gc, greenpix);
break;
}
}
XDrawLine(dpy, buffer, gc, spacing * (seg->x1 + 1),
height - spacing * (seg->y1 + 1),
spacing * (seg->x2 + 1),
height - spacing * (seg->y2 + 1));
if (single)
XDrawLine(dpy, win, gc, spacing * (seg->x1 + 1),
height - spacing * (seg->y1 + 1),
spacing * (seg->x2 + 1),
height - spacing * (seg->y2 + 1));
}
}
if (single) {
// The following line to be removed
XCopyArea(dpy, buffer, win, gc, 0, 0, width, height, 0, 0);
XFlush(dpy);
}
}
/*--------------------------------------*/
/* Draw one unrouted net on the display */
/*--------------------------------------*/
static void
draw_net_nodes(NET net) {
NODE node;
SEG bboxlist = NULL; /* bbox list of all the nodes in the net */
SEG lastbbox, bboxit;
DPOINT tap;
int first, w, h, n;
/* Compute bbox for each node and draw it */
for (node = net->netnodes, n = 0; node != NULL; node = node->next, n++) {
if (bboxlist == NULL) {
lastbbox = bboxlist = (SEG)malloc(sizeof(struct seg_));
}
else {
lastbbox->next = (SEG)malloc(sizeof(struct seg_));
lastbbox = lastbbox->next;
}
lastbbox->next = NULL;
for (tap = node->taps, first = TRUE;
tap != NULL;
tap = tap->next, first = FALSE) {
if (first) {
lastbbox->x1 = lastbbox->x2 = tap->gridx;
lastbbox->y1 = lastbbox->y2 = tap->gridy;
}
else {
lastbbox->x1 = MIN(lastbbox->x1, tap->gridx);
lastbbox->x2 = MAX(lastbbox->x2, tap->gridx);
lastbbox->y1 = MIN(lastbbox->y1, tap->gridy);
lastbbox->y2 = MAX(lastbbox->y2, tap->gridy);
}
}
/* Convert to X coordinates */
lastbbox->x1 = spacing * (lastbbox->x1 + 1);
lastbbox->y1 = height - spacing * (lastbbox->y1 + 1);
lastbbox->x2 = spacing * (lastbbox->x2 + 1);
lastbbox->y2 = height - spacing * (lastbbox->y2 + 1);
/* Draw the bbox */
w = lastbbox->x2 - lastbbox->x1;
h = lastbbox->y1 - lastbbox->y2;
XDrawRectangle(dpy, buffer, gc,
lastbbox->x1, lastbbox->y1, w, h
);
}
/* if net->numnodes == 1 don't draw a wire */
if (n == 2) {
XDrawLine(
dpy, buffer, gc,
(bboxlist->x1 + bboxlist->x2)/2, (bboxlist->y1 + bboxlist->y2)/2,
(lastbbox->x1 + lastbbox->x2)/2, (lastbbox->y1 + lastbbox->y2)/2
);
}
else if (n > 2) {
/* Compute center point */
POINT midpoint = (POINT)malloc(sizeof(struct point_));
midpoint->x1 = midpoint->y1 = 0;
for (bboxit = bboxlist; bboxit != NULL; bboxit = bboxit->next) {
midpoint->x1 += (bboxit->x1 + bboxit->x2)/2;
midpoint->y1 += (bboxit->y1 + bboxit->y2)/2;
}
midpoint->x1 /= n;
midpoint->y1 /= n;
for (bboxit = bboxlist; bboxit != NULL; bboxit = bboxit->next) {
XDrawLine(
dpy, buffer, gc,
midpoint->x1, midpoint->y1,
(bboxit->x1 + bboxit->x2)/2, (bboxit->y1 + bboxit->y2)/2
);
}
free(midpoint);
}
for (bboxit = bboxlist; bboxit != NULL; bboxit = lastbbox) {
lastbbox = bboxit->next;
free(bboxit);
}
}
/*--------------------------------------*/
/* Graphical display of the layout */
/*--------------------------------------*/
void draw_layout() {
int lastlayer;
int i;
NET net;
if (dpy == NULL) return;
else if (buffer == (Pixmap)NULL) return;
XSetForeground(dpy, gc, whitepix);
XFillRectangle(dpy, buffer, gc, 0, 0, width, height);
// Check if a netlist even exists
if (Obs[0] == NULL) {
XCopyArea(dpy, buffer, win, gc, 0, 0, width, height, 0, 0);
return;
}
switch (mapType & MAP_MASK) {
case MAP_OBSTRUCT:
map_obstruction();
break;
case MAP_CONGEST:
map_congestion();
break;
case MAP_ESTIMATE:
map_estimate();
break;
}
// Draw all nets, much like "emit_routes" does when writing
// routes to the DEF file.
if ((mapType & DRAW_ROUTES) != 0) {
lastlayer = -1;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
draw_net(net, FALSE, &lastlayer);
}
}
// Draw unrouted nets
if ((mapType & DRAW_UNROUTED) != 0) {
XSetForeground(dpy, gc, blackpix);
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (strcmp(net->netname, gndnet) != 0
&& strcmp(net->netname, vddnet) != 0
&&net->routes == NULL) {
draw_net_nodes(net);
}
}
}
/* Copy double-buffer onto display window */
XCopyArea(dpy, buffer, win, gc, 0, 0, width, height, 0, 0);
}
/*--------------------------------------*/
/* GUI initialization */
/*--------------------------------------*/
int GUI_init(Tcl_Interp *interp)
{
Tk_Window tkwind, tktop;
static char *qrouterdrawdefault = ".qrouter";
char *qrouterdrawwin;
XColor cvcolor, cvexact;
int i;
float frac;
tktop = Tk_MainWindow(interp);
if (tktop == NULL) {
tcl_printf(stderr, "No Top-level Tk window available. . .\n");
return TCL_ERROR;
}
qrouterdrawwin = (char *)Tcl_GetVar(interp, "drawwindow", TCL_GLOBAL_ONLY);
if (qrouterdrawwin == NULL)
qrouterdrawwin = qrouterdrawdefault;
tkwind = Tk_NameToWindow(interp, qrouterdrawwin, tktop);
if (tkwind == NULL) {
tcl_printf(stderr, "The Tk window hierarchy must be rooted at "
".qrouter or $drawwindow must point to the drawing window\n");
return TCL_ERROR;
}
Tk_MapWindow(tkwind);
dpy = Tk_Display(tkwind);
win = Tk_WindowId(tkwind);
cmap = DefaultColormap (dpy, Tk_ScreenNumber(tkwind));
load_font(&font_info);
/* create GC for text and drawing */
createGC(win, &gc, font_info);
/* Initialize colors */
XAllocNamedColor(dpy, cmap, "blue", &cvcolor, &cvexact);
bluepix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "cyan", &cvcolor, &cvexact);
cyanpix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "green", &cvcolor, &cvexact);
greenpix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "red", &cvcolor, &cvexact);
redpix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "orange", &cvcolor, &cvexact);
orangepix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "gold", &cvcolor, &cvexact);
goldpix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "gray70", &cvcolor, &cvexact);
ltgraypix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "gray50", &cvcolor, &cvexact);
graypix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "yellow", &cvcolor, &cvexact);
yellowpix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "purple", &cvcolor, &cvexact);
purplepix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "magenta", &cvcolor, &cvexact);
magentapix = cvcolor.pixel;
XAllocNamedColor(dpy, cmap, "GreenYellow", &cvcolor, &cvexact);
greenyellowpix = cvcolor.pixel;
blackpix = BlackPixel(dpy,DefaultScreen(dpy));
whitepix = WhitePixel(dpy,DefaultScreen(dpy));
cvcolor.flags = DoRed | DoGreen | DoBlue;
for (i = 0; i < SHORTSPAN; i++) {
frac = (float)i / (float)(SHORTSPAN - 1);
/* gamma correction */
frac = pow(frac, 0.5);
cvcolor.green = (int)(53970 * frac);
cvcolor.blue = (int)(46260 * frac);
cvcolor.red = (int)(35980 * frac);
XAllocColor(dpy, cmap, &cvcolor);
brownvector[i] = cvcolor.pixel;
}
cvcolor.green = 0;
cvcolor.red = 0;
for (i = 0; i < LONGSPAN; i++) {
frac = (float)i / (float)(LONGSPAN - 1);
/* gamma correction */
frac = pow(frac, 0.5);
cvcolor.blue = (int)(65535 * frac);
XAllocColor(dpy, cmap, &cvcolor);
bluevector[i] = cvcolor.pixel;
}
return TCL_OK; /* proceed to interpreter */
}
/*----------------------------------------------------------------*/
static void
load_font(XFontStruct **font_info)
{
char *fontname = "9x15";
/* Load font and get font information structure. */
if ((*font_info = XLoadQueryFont (dpy,fontname)) == NULL) {
(void) Fprintf (stderr, "Cannot open 9x15 font\n");
// exit(1);
}
}
/*----------------------------------------------------------------*/
static void
createGC(Window win, GC *gc, XFontStruct *font_info)
{
unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */
XGCValues values;
unsigned int line_width = 1;
int line_style = LineSolid;
int cap_style = CapRound;
int join_style = JoinRound;
/* Create default Graphics Context */
*gc = XCreateGC(dpy, win, valuemask, &values);
/* specify font */
if (font_info != NULL)
XSetFont(dpy, *gc, font_info->fid);
/* specify black foreground since default window background is
* white and default foreground is undefined. */
XSetForeground(dpy, *gc, blackpix);
/* set line, fill attributes */
XSetLineAttributes(dpy, *gc, line_width, line_style,
cap_style, join_style);
XSetFillStyle(dpy, *gc, FillSolid);
XSetArcMode(dpy, *gc, ArcPieSlice);
}
/*----------------------------------------------------------------*/
void expose(Tk_Window tkwind)
{
if (Tk_WindowId(tkwind) == 0) return;
if (dpy == NULL) return;
draw_layout();
}
/*----------------------------------------------------------------*/
int redraw(ClientData clientData, Tcl_Interp *interp, int objc,
Tcl_Obj *objv[])
{
draw_layout();
return TCL_OK;
}
/*------------------------------------------------------*/
/* Call to recalculate the spacing if NumChannelsX[0] */
/* or NumChannelsY[0] changes. */
/* */
/* Return 1 if the spacing changed, 0 otherwise. */
/*------------------------------------------------------*/
int recalc_spacing()
{
int xspc, yspc;
int oldspacing = spacing;
xspc = width / (NumChannelsX[0] + 1);
yspc = height / (NumChannelsY[0] + 1);
spacing = (xspc < yspc) ? xspc : yspc;
if (spacing == 0) spacing = 1;
return (spacing == oldspacing) ? 0 : 1;
}
/*----------------------------------------------------------------*/
void resize(Tk_Window tkwind, int locwidth, int locheight)
{
if ((locwidth == 0) || (locheight == 0)) return;
if (buffer != (Pixmap)0)
XFreePixmap (Tk_Display(tkwind), buffer);
if (Tk_WindowId(tkwind) == 0)
Tk_MapWindow(tkwind);
buffer = XCreatePixmap (Tk_Display(tkwind), Tk_WindowId(tkwind),
locwidth, locheight, DefaultDepthOfScreen(Tk_Screen(tkwind)));
width = locwidth;
height = locheight;
recalc_spacing();
if (dpy) draw_layout();
}
/*----------------------------------------------------------------*/
|