| 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 |
#include "bltInt.h" |
| 28 |
#include "bltChain.h" |
| 29 |
#include "bltHash.h" |
| 30 |
#include "bltImage.h" |
| 31 |
#include <X11/Xutil.h> |
| 32 |
|
| 33 |
#include "bltTile.h" |
| 34 |
|
| 35 |
#define TILE_THREAD_KEY "BLT Tile Data" |
| 36 |
#define TILE_MAGIC ((unsigned int) 0x46170277) |
| 37 |
|
| 38 |
typedef struct { |
| 39 |
Blt_HashTable tileTable; |
| 40 |
|
| 41 |
Tcl_Interp *interp; |
| 42 |
} TileInterpData; |
| 43 |
|
| 44 |
typedef struct { |
| 45 |
char *name; |
| 46 |
Display *display; |
| 47 |
int flags; |
| 48 |
Tcl_Interp *interp; |
| 49 |
Blt_HashEntry *hashPtr; |
| 50 |
Blt_HashTable *tablePtr; |
| 51 |
|
| 52 |
Pixmap pixmap; |
| 53 |
Pixmap mask; |
| 54 |
|
| 55 |
GC gc; |
| 56 |
Tk_Image tkImage; |
| 57 |
Blt_Chain *clients; |
| 58 |
int width, height; |
| 59 |
} Tile; |
| 60 |
|
| 61 |
#define NOTIFY_PENDING 1 |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
#define FIXED_TS_ORIGIN 2 |
| 68 |
#define TILE_ALPHA 4 |
| 69 |
|
| 70 |
typedef struct Blt_TileClientStruct { |
| 71 |
unsigned int magic; |
| 72 |
Tk_Window tkwin; |
| 73 |
int xOrigin, yOrigin; |
| 74 |
|
| 75 |
Blt_TileChangedProc *notifyProc; |
| 76 |
|
| 77 |
ClientData clientData; |
| 78 |
|
| 79 |
Tile *tilePtr; |
| 80 |
Blt_ChainLink *linkPtr; |
| 81 |
|
| 82 |
} TileClient; |
| 83 |
|
| 84 |
typedef struct { |
| 85 |
Display *display; |
| 86 |
Tk_Uid nameId; |
| 87 |
int depth; |
| 88 |
} TileKey; |
| 89 |
|
| 90 |
static TileInterpData *GetTileInterpData _ANSI_ARGS_((Tcl_Interp *interp)); |
| 91 |
|
| 92 |
static Tcl_IdleProc UpdateTile; |
| 93 |
static Tk_ImageChangedProc ImageChangedProc; |
| 94 |
static Tcl_InterpDeleteProc TileInterpDeleteProc; |
| 95 |
|
| 96 |
static void DestroyClient _ANSI_ARGS_((TileClient *clientPtr)); |
| 97 |
static void DestroyTile _ANSI_ARGS_((Tile *tilePtr)); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
static void |
| 114 |
RedrawTile(tkwin, tilePtr) |
| 115 |
Tk_Window tkwin; |
| 116 |
Tile *tilePtr; |
| 117 |
{ |
| 118 |
GC newGC; |
| 119 |
Tk_PhotoHandle photo; |
| 120 |
XGCValues gcValues; |
| 121 |
int width, height; |
| 122 |
unsigned int gcMask; |
| 123 |
|
| 124 |
Tk_SizeOfImage(tilePtr->tkImage, &width, &height); |
| 125 |
if (height<=0 || width<=0) return; |
| 126 |
|
| 127 |
Tk_MakeWindowExist(tkwin); |
| 128 |
if ((width != tilePtr->width) || (height != tilePtr->height)) { |
| 129 |
Pixmap pixmap; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin), width, |
| 139 |
height, Tk_Depth(tkwin)); |
| 140 |
if (tilePtr->pixmap != None) { |
| 141 |
Tk_FreePixmap(Tk_Display(tkwin), tilePtr->pixmap); |
| 142 |
} |
| 143 |
tilePtr->pixmap = pixmap; |
| 144 |
} |
| 145 |
Tk_RedrawImage(tilePtr->tkImage, 0, 0, width, height, tilePtr->pixmap, |
| 146 |
0, 0); |
| 147 |
|
| 148 |
gcMask = (GCTile | GCFillStyle); |
| 149 |
gcValues.fill_style = FillTiled; |
| 150 |
gcValues.tile = tilePtr->pixmap; |
| 151 |
newGC = Tk_GetGC(tkwin, gcMask, &gcValues); |
| 152 |
if (tilePtr->gc != NULL) { |
| 153 |
Tk_FreeGC(Tk_Display(tkwin), tilePtr->gc); |
| 154 |
} |
| 155 |
tilePtr->gc = newGC; |
| 156 |
tilePtr->width = width; |
| 157 |
tilePtr->height = height; |
| 158 |
|
| 159 |
if (tilePtr->mask != None) { |
| 160 |
#ifdef WIN32 |
| 161 |
Tk_FreePixmap(Tk_Display(tkwin), tilePtr->mask); |
| 162 |
#else |
| 163 |
XFreePixmap(Tk_Display(tkwin), tilePtr->mask); |
| 164 |
#endif |
| 165 |
tilePtr->mask = None; |
| 166 |
} |
| 167 |
photo = Blt_FindPhoto(tilePtr->interp, |
| 168 |
Blt_NameOfImage(tilePtr->tkImage)); |
| 169 |
if (photo != NULL) { |
| 170 |
Tk_PhotoImageBlock src; |
| 171 |
|
| 172 |
Tk_PhotoGetImage(photo, &src); |
| 173 |
if ((src.offset[3] < src.pixelSize) && (src.offset[3] >= 0)) { |
| 174 |
tilePtr->mask = Blt_PhotoImageMask(tkwin, src); |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
static void |
| 192 |
UpdateTile(clientData) |
| 193 |
ClientData clientData; |
| 194 |
{ |
| 195 |
Tile *tilePtr = (Tile *)clientData; |
| 196 |
TileClient *clientPtr; |
| 197 |
Blt_ChainLink *linkPtr; |
| 198 |
|
| 199 |
tilePtr->flags &= ~NOTIFY_PENDING; |
| 200 |
if (Tk_ImageIsDeleted(tilePtr->tkImage)) { |
| 201 |
if (tilePtr->pixmap != None) { |
| 202 |
Tk_FreePixmap(tilePtr->display, tilePtr->pixmap); |
| 203 |
} |
| 204 |
tilePtr->pixmap = None; |
| 205 |
} else { |
| 206 |
|
| 207 |
linkPtr = Blt_ChainFirstLink(tilePtr->clients); |
| 208 |
clientPtr = Blt_ChainGetValue(linkPtr); |
| 209 |
RedrawTile(clientPtr->tkwin, tilePtr); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
for (linkPtr = Blt_ChainFirstLink(tilePtr->clients); linkPtr != NULL; |
| 215 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 216 |
clientPtr = Blt_ChainGetValue(linkPtr); |
| 217 |
if (clientPtr->notifyProc != NULL) { |
| 218 |
(*clientPtr->notifyProc) (clientPtr->clientData, clientPtr); |
| 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 |
static void |
| 244 |
ImageChangedProc(clientData, x, y, width, height, imageWidth, imageHeight) |
| 245 |
ClientData clientData; |
| 246 |
int x, y, width, height; |
| 247 |
int imageWidth, imageHeight; |
| 248 |
{ |
| 249 |
Tile *tilePtr = (Tile *) clientData; |
| 250 |
|
| 251 |
if (!(tilePtr->flags & NOTIFY_PENDING)) { |
| 252 |
Tcl_DoWhenIdle(UpdateTile, tilePtr); |
| 253 |
tilePtr->flags |= NOTIFY_PENDING; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
static void |
| 271 |
DestroyTile(Tile *tilePtr) |
| 272 |
{ |
| 273 |
Blt_ChainLink *linkPtr; |
| 274 |
TileClient *clientPtr; |
| 275 |
|
| 276 |
if (tilePtr->flags & NOTIFY_PENDING) { |
| 277 |
Tcl_CancelIdleCall(UpdateTile, tilePtr); |
| 278 |
} |
| 279 |
for (linkPtr = Blt_ChainFirstLink(tilePtr->clients); linkPtr != NULL; |
| 280 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 281 |
clientPtr = Blt_ChainGetValue(linkPtr); |
| 282 |
Blt_Free(clientPtr); |
| 283 |
} |
| 284 |
Blt_ChainDestroy(tilePtr->clients); |
| 285 |
|
| 286 |
if (tilePtr->hashPtr != NULL) { |
| 287 |
Blt_DeleteHashEntry(tilePtr->tablePtr, tilePtr->hashPtr); |
| 288 |
} |
| 289 |
if (tilePtr->pixmap != None) { |
| 290 |
Tk_FreePixmap(tilePtr->display, tilePtr->pixmap); |
| 291 |
} |
| 292 |
Tk_FreeImage(tilePtr->tkImage); |
| 293 |
|
| 294 |
if (tilePtr->gc != NULL) { |
| 295 |
Tk_FreeGC(tilePtr->display, tilePtr->gc); |
| 296 |
} |
| 297 |
if (tilePtr->name != NULL) { |
| 298 |
Blt_Free(tilePtr->name); |
| 299 |
} |
| 300 |
Blt_Free(tilePtr); |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
static Tile * |
| 323 |
CreateTile( |
| 324 |
Tcl_Interp *interp, |
| 325 |
Tk_Window tkwin, |
| 326 |
char *imageName) |
| 327 |
{ |
| 328 |
Tile *tilePtr; |
| 329 |
Tk_Image tkImage; |
| 330 |
|
| 331 |
tilePtr = Blt_Calloc(1, sizeof(Tile)); |
| 332 |
assert(tilePtr); |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
tkImage = Tk_GetImage(interp, tkwin, imageName, ImageChangedProc, |
| 337 |
tilePtr); |
| 338 |
if (tkImage == NULL) { |
| 339 |
Blt_Free(tilePtr); |
| 340 |
return NULL; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
tilePtr->display = Tk_Display(tkwin); |
| 347 |
tilePtr->interp = interp; |
| 348 |
tilePtr->name = Blt_Strdup(imageName); |
| 349 |
tilePtr->clients = Blt_ChainCreate(); |
| 350 |
tilePtr->tkImage = tkImage; |
| 351 |
if (strchr(imageName, '!')) { |
| 352 |
tilePtr->flags |= FIXED_TS_ORIGIN; |
| 353 |
} |
| 354 |
if (strchr(imageName, '|')) { |
| 355 |
tilePtr->flags |= TILE_ALPHA; |
| 356 |
} |
| 357 |
RedrawTile(tkwin, tilePtr); |
| 358 |
return tilePtr; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
static void |
| 376 |
DestroyClient(TileClient *clientPtr) |
| 377 |
{ |
| 378 |
Tile *tilePtr; |
| 379 |
tilePtr = clientPtr->tilePtr; |
| 380 |
|
| 381 |
|
| 382 |
if (clientPtr->linkPtr != NULL) { |
| 383 |
Blt_ChainDeleteLink(tilePtr->clients, clientPtr->linkPtr); |
| 384 |
} |
| 385 |
if (Blt_ChainGetLength(tilePtr->clients) == 0) { |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
DestroyTile(tilePtr); |
| 391 |
} |
| 392 |
Blt_Free(clientPtr); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
static TileClient * |
| 414 |
CreateClient( |
| 415 |
Tcl_Interp *interp, |
| 416 |
Tk_Window tkwin, |
| 417 |
char *name) |
| 418 |
{ |
| 419 |
TileClient *clientPtr; |
| 420 |
Tile *tilePtr; |
| 421 |
TileInterpData *dataPtr; |
| 422 |
Blt_HashEntry *hPtr; |
| 423 |
int isNew; |
| 424 |
TileKey key; |
| 425 |
|
| 426 |
dataPtr = GetTileInterpData(interp); |
| 427 |
|
| 428 |
key.nameId = Tk_GetUid(name); |
| 429 |
key.display = Tk_Display(tkwin); |
| 430 |
key.depth = Tk_Depth(tkwin); |
| 431 |
hPtr = Blt_CreateHashEntry(&dataPtr->tileTable, (char *)&key, &isNew); |
| 432 |
if (isNew) { |
| 433 |
tilePtr = CreateTile(interp, tkwin, name); |
| 434 |
if (tilePtr == NULL) { |
| 435 |
Blt_DeleteHashEntry(&(dataPtr->tileTable), hPtr); |
| 436 |
return NULL; |
| 437 |
} |
| 438 |
tilePtr->hashPtr = hPtr; |
| 439 |
tilePtr->tablePtr = &(dataPtr->tileTable); |
| 440 |
Blt_SetHashValue(hPtr, tilePtr); |
| 441 |
} else { |
| 442 |
tilePtr = Blt_GetHashValue(hPtr); |
| 443 |
} |
| 444 |
clientPtr = Blt_Calloc(1, sizeof(TileClient)); |
| 445 |
assert(clientPtr); |
| 446 |
|
| 447 |
|
| 448 |
clientPtr->magic = TILE_MAGIC; |
| 449 |
clientPtr->tkwin = tkwin; |
| 450 |
clientPtr->linkPtr = Blt_ChainAppend(tilePtr->clients, clientPtr); |
| 451 |
clientPtr->tilePtr = tilePtr; |
| 452 |
return clientPtr; |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
static void |
| 473 |
TileInterpDeleteProc( |
| 474 |
ClientData clientData, |
| 475 |
Tcl_Interp *interp) |
| 476 |
{ |
| 477 |
TileInterpData *dataPtr = clientData; |
| 478 |
Blt_HashEntry *hPtr; |
| 479 |
Blt_HashSearch cursor; |
| 480 |
Tile *tilePtr; |
| 481 |
|
| 482 |
for (hPtr = Blt_FirstHashEntry(&(dataPtr->tileTable), &cursor); |
| 483 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 484 |
tilePtr = Blt_GetHashValue(hPtr); |
| 485 |
tilePtr->hashPtr = NULL; |
| 486 |
DestroyTile(tilePtr); |
| 487 |
} |
| 488 |
Blt_DeleteHashTable(&(dataPtr->tileTable)); |
| 489 |
Tcl_DeleteAssocData(interp, TILE_THREAD_KEY); |
| 490 |
Blt_Free(dataPtr); |
| 491 |
} |
| 492 |
|
| 493 |
static TileInterpData * |
| 494 |
GetTileInterpData(interp) |
| 495 |
Tcl_Interp *interp; |
| 496 |
{ |
| 497 |
TileInterpData *dataPtr; |
| 498 |
Tcl_InterpDeleteProc *proc; |
| 499 |
|
| 500 |
dataPtr = (TileInterpData *) |
| 501 |
Tcl_GetAssocData(interp, TILE_THREAD_KEY, &proc); |
| 502 |
if (dataPtr == NULL) { |
| 503 |
dataPtr = Blt_Malloc(sizeof(TileInterpData)); |
| 504 |
assert(dataPtr); |
| 505 |
dataPtr->interp = interp; |
| 506 |
Tcl_SetAssocData(interp, TILE_THREAD_KEY, TileInterpDeleteProc, |
| 507 |
dataPtr); |
| 508 |
Blt_InitHashTable(&(dataPtr->tileTable), sizeof(TileKey)/sizeof(int)); |
| 509 |
} |
| 510 |
return dataPtr; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
int |
| 532 |
Blt_GetTile( |
| 533 |
Tcl_Interp *interp, |
| 534 |
Tk_Window tkwin, |
| 535 |
char *imageName, |
| 536 |
Blt_Tile *tokenPtr) |
| 537 |
{ |
| 538 |
TileClient *clientPtr; |
| 539 |
|
| 540 |
clientPtr = CreateClient(interp, tkwin, imageName); |
| 541 |
if (clientPtr == NULL) { |
| 542 |
return TCL_ERROR; |
| 543 |
} |
| 544 |
*tokenPtr = clientPtr; |
| 545 |
return TCL_OK; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
void |
| 566 |
Blt_FreeTile(TileClient *clientPtr) |
| 567 |
{ |
| 568 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 569 |
return; |
| 570 |
} |
| 571 |
DestroyClient(clientPtr); |
| 572 |
} |
| 573 |
|
| 574 |
void |
| 575 |
Blt_FixedTile(TileClient *clientPtr) |
| 576 |
{ |
| 577 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 578 |
return; |
| 579 |
} |
| 580 |
clientPtr->tilePtr->flags |= FIXED_TS_ORIGIN; |
| 581 |
} |
| 582 |
|
| 583 |
int |
| 584 |
Blt_TileFlags(TileClient *clientPtr) |
| 585 |
{ |
| 586 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 587 |
return 0; |
| 588 |
} |
| 589 |
return clientPtr->tilePtr->flags; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
char * |
| 610 |
Blt_NameOfTile(TileClient *clientPtr) |
| 611 |
{ |
| 612 |
if (clientPtr == NULL) { |
| 613 |
return ""; |
| 614 |
} |
| 615 |
if (clientPtr->magic != TILE_MAGIC) { |
| 616 |
return "not a tile"; |
| 617 |
} |
| 618 |
return clientPtr->tilePtr->name; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
Pixmap |
| 635 |
Blt_PixmapOfTile(TileClient *clientPtr) |
| 636 |
{ |
| 637 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 638 |
return None; |
| 639 |
} |
| 640 |
return clientPtr->tilePtr->pixmap; |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
int |
| 645 |
Blt_HasTile( TileClient *clientPtr) |
| 646 |
{ |
| 647 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 648 |
return 0; |
| 649 |
} |
| 650 |
if (clientPtr->tilePtr->width <= 1) return 0; |
| 651 |
if (clientPtr->tilePtr->height <= 1) return 0; |
| 652 |
return 1; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
void |
| 669 |
Blt_SizeOfTile( |
| 670 |
TileClient *clientPtr, |
| 671 |
int *widthPtr, |
| 672 |
int *heightPtr) |
| 673 |
{ |
| 674 |
if ((clientPtr == NULL) || (clientPtr->magic != TILE_MAGIC)) { |
| 675 |
*widthPtr = *heightPtr = 0; |
| 676 |
return; |
| 677 |
} |
| 678 |
*widthPtr = clientPtr->tilePtr->width; |
| 679 |
*heightPtr = clientPtr->tilePtr->height; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
void |
| 700 |
Blt_SetTileChangedProc( |
| 701 |
TileClient *clientPtr, |
| 702 |
Blt_TileChangedProc *notifyProc, |
| 703 |
ClientData clientData) |
| 704 |
{ |
| 705 |
if ((clientPtr != NULL) && (clientPtr->magic == TILE_MAGIC)) { |
| 706 |
clientPtr->notifyProc = notifyProc; |
| 707 |
clientPtr->clientData = clientData; |
| 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 |
void |
| 733 |
Blt_SetTileOrigin( |
| 734 |
Tk_Window tkwin, |
| 735 |
TileClient *clientPtr, |
| 736 |
int x, int y) |
| 737 |
{ |
| 738 |
while (!Tk_IsTopLevel(tkwin)) { |
| 739 |
if (Tk_IsBgTileTop(tkwin)) break; |
| 740 |
x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width; |
| 741 |
y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width; |
| 742 |
tkwin = Tk_Parent(tkwin); |
| 743 |
} |
| 744 |
if (clientPtr->tilePtr->gc) { |
| 745 |
XSetTSOrigin(Tk_Display(tkwin), clientPtr->tilePtr->gc, -x, -y); |
| 746 |
} |
| 747 |
clientPtr->xOrigin = -x; |
| 748 |
clientPtr->yOrigin = -y; |
| 749 |
} |
| 750 |
|
| 751 |
void |
| 752 |
Blt_SetTSOrigin( |
| 753 |
Tk_Window tkwin, |
| 754 |
TileClient *clientPtr, |
| 755 |
int x, int y) |
| 756 |
{ |
| 757 |
if (clientPtr->tilePtr->gc) { |
| 758 |
XSetTSOrigin(Tk_Display(tkwin), clientPtr->tilePtr->gc, x, y); |
| 759 |
} |
| 760 |
clientPtr->xOrigin = x; |
| 761 |
clientPtr->yOrigin = y; |
| 762 |
} |
| 763 |
|
| 764 |
#ifdef WIN32 |
| 765 |
static int tkpWinRopModes[] = |
| 766 |
{ |
| 767 |
R2_BLACK, |
| 768 |
R2_MASKPEN, |
| 769 |
R2_MASKPENNOT, |
| 770 |
R2_COPYPEN, |
| 771 |
R2_MASKNOTPEN, |
| 772 |
R2_NOT, |
| 773 |
R2_XORPEN, |
| 774 |
R2_MERGEPEN, |
| 775 |
R2_NOTMERGEPEN, |
| 776 |
R2_NOTXORPEN, |
| 777 |
R2_NOT, |
| 778 |
R2_MERGEPENNOT, |
| 779 |
R2_NOTCOPYPEN, |
| 780 |
R2_MERGENOTPEN, |
| 781 |
R2_NOTMASKPEN, |
| 782 |
R2_WHITE |
| 783 |
}; |
| 784 |
#define MASKPAT 0x00E20746 |
| 785 |
#define COPYFG 0x00CA0749 |
| 786 |
#define COPYBG 0x00AC0744 |
| 787 |
|
| 788 |
static void |
| 789 |
TileRegion( |
| 790 |
HDC srcDC, |
| 791 |
HDC destDC, |
| 792 |
HDC maskDC, |
| 793 |
|
| 794 |
TileClient *clientPtr, |
| 795 |
int x, int y, |
| 796 |
int width, int height) |
| 797 |
{ |
| 798 |
Tile *tilePtr = clientPtr->tilePtr; |
| 799 |
int destX, destY; |
| 800 |
int destWidth, destHeight; |
| 801 |
int srcX, srcY; |
| 802 |
int startX, startY; |
| 803 |
int delta; |
| 804 |
int left, top, right, bottom; |
| 805 |
|
| 806 |
startX = x; |
| 807 |
if (x < clientPtr->xOrigin) { |
| 808 |
delta = (clientPtr->xOrigin - x) % tilePtr->width; |
| 809 |
if (delta > 0) { |
| 810 |
startX -= (tilePtr->width - delta); |
| 811 |
} |
| 812 |
} else if (x > clientPtr->xOrigin) { |
| 813 |
delta = (x - clientPtr->xOrigin) % tilePtr->width; |
| 814 |
if (delta > 0) { |
| 815 |
startX -= delta; |
| 816 |
} |
| 817 |
} |
| 818 |
startY = y; |
| 819 |
if (y < clientPtr->yOrigin) { |
| 820 |
delta = (clientPtr->yOrigin - y) % tilePtr->height; |
| 821 |
if (delta > 0) { |
| 822 |
startY -= (tilePtr->height - delta); |
| 823 |
} |
| 824 |
} else if (y >= clientPtr->yOrigin) { |
| 825 |
delta = (y - clientPtr->yOrigin) % tilePtr->height; |
| 826 |
if (delta > 0) { |
| 827 |
startY -= delta; |
| 828 |
} |
| 829 |
} |
| 830 |
#ifdef notdef |
| 831 |
PurifyPrintf("tile is (%d,%d,%d,%d)\n", |
| 832 |
clientPtr->xOrigin, clientPtr->yOrigin, |
| 833 |
tilePtr->width, tilePtr->height); |
| 834 |
PurifyPrintf("region is (%d,%d,%d,%d)\n", x, y, width, height); |
| 835 |
PurifyPrintf("starting at %d,%d\n", startX, startY); |
| 836 |
#endif |
| 837 |
left = x; |
| 838 |
right = x + width; |
| 839 |
top = y; |
| 840 |
bottom = y + height; |
| 841 |
for (y = startY; y < bottom; y += tilePtr->height) { |
| 842 |
srcY = 0; |
| 843 |
destY = y; |
| 844 |
destHeight = tilePtr->height; |
| 845 |
if (y < top) { |
| 846 |
srcY = (top - y); |
| 847 |
destHeight = tilePtr->height - srcY; |
| 848 |
destY = top; |
| 849 |
} |
| 850 |
if ((destY + destHeight) > bottom) { |
| 851 |
destHeight = (bottom - destY); |
| 852 |
} |
| 853 |
for (x = startX; x < right; x += tilePtr->width) { |
| 854 |
srcX = 0; |
| 855 |
destX = x; |
| 856 |
destWidth = tilePtr->width; |
| 857 |
if (x < left) { |
| 858 |
srcX = (left - x); |
| 859 |
destWidth = tilePtr->width - srcX; |
| 860 |
destX = left; |
| 861 |
} |
| 862 |
if ((destX + destWidth) > right) { |
| 863 |
destWidth = (right - destX); |
| 864 |
} |
| 865 |
#ifdef notdef |
| 866 |
PurifyPrintf("drawing pattern (%d,%d,%d,%d) at %d,%d\n", |
| 867 |
srcX , srcY, destWidth, destHeight, destX, destY); |
| 868 |
#endif |
| 869 |
if (tilePtr->mask != None) { |
| 870 |
#ifdef notdef |
| 871 |
HDC maskDC; |
| 872 |
TkWinDCState maskState; |
| 873 |
|
| 874 |
maskDC = TkWinGetDrawableDC(tilePtr->display, |
| 875 |
tilePtr->mask, &maskState); |
| 876 |
SetBkColor(destDC, RGB(255, 255, 255)); |
| 877 |
SetTextColor(destDC, RGB(0, 0, 0)); |
| 878 |
#endif |
| 879 |
BitBlt(destDC, destX, destY, destWidth, destHeight, maskDC, |
| 880 |
0, 0, SRCAND); |
| 881 |
BitBlt(destDC, destX, destY, destWidth, destHeight, srcDC, |
| 882 |
srcX, srcY, SRCPAINT); |
| 883 |
#ifdef notdef |
| 884 |
TkWinReleaseDrawableDC(tilePtr->mask, maskDC, &maskState); |
| 885 |
#endif |
| 886 |
} else { |
| 887 |
BitBlt(destDC, destX, destY, destWidth, destHeight, |
| 888 |
srcDC, srcX, srcY, SRCCOPY); |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
void |
| 895 |
Blt_TilePolygon( |
| 896 |
Tk_Window tkwin, |
| 897 |
Drawable drawable, |
| 898 |
TileClient *clientPtr, |
| 899 |
XPoint pointArr[], |
| 900 |
int nPoints) |
| 901 |
{ |
| 902 |
HBITMAP oldBitmap; |
| 903 |
HDC hDC, memDC; |
| 904 |
HRGN hRgn; |
| 905 |
POINT *p, *winPts; |
| 906 |
Region2D bbox; |
| 907 |
Tile *tilePtr; |
| 908 |
TkWinDCState state; |
| 909 |
TkWinDrawable *twdPtr; |
| 910 |
XPoint *endPtr, *pointPtr; |
| 911 |
int fillMode; |
| 912 |
int width, height; |
| 913 |
|
| 914 |
if (drawable == None) { |
| 915 |
return; |
| 916 |
} |
| 917 |
tilePtr = clientPtr->tilePtr; |
| 918 |
if (tilePtr->gc == NULL) return; |
| 919 |
|
| 920 |
|
| 921 |
bbox.left = bbox.right = pointArr[0].x; |
| 922 |
bbox.top = bbox.bottom = pointArr[0].y; |
| 923 |
|
| 924 |
endPtr = pointArr + nPoints; |
| 925 |
for (pointPtr = pointArr; pointPtr < endPtr; pointPtr++) { |
| 926 |
if (pointPtr->x < bbox.left) { |
| 927 |
bbox.left = pointPtr->x; |
| 928 |
} |
| 929 |
if (pointPtr->x > bbox.right) { |
| 930 |
bbox.right = pointPtr->x; |
| 931 |
} |
| 932 |
if (pointPtr->y < bbox.top) { |
| 933 |
bbox.top = pointPtr->y; |
| 934 |
} |
| 935 |
if (pointPtr->y > bbox.bottom) { |
| 936 |
bbox.bottom = pointPtr->y; |
| 937 |
} |
| 938 |
} |
| 939 |
width = bbox.right - bbox.left + 1; |
| 940 |
height = bbox.bottom - bbox.top + 1; |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
p = winPts = Blt_Malloc(sizeof(POINT) * nPoints); |
| 945 |
for (pointPtr = pointArr; pointPtr < endPtr; pointPtr++) { |
| 946 |
p->x = pointPtr->x - bbox.left; |
| 947 |
p->y = pointPtr->y - bbox.top; |
| 948 |
p++; |
| 949 |
} |
| 950 |
|
| 951 |
hDC = TkWinGetDrawableDC(Tk_Display(tkwin), drawable, &state); |
| 952 |
SetROP2(hDC, tkpWinRopModes[tilePtr->gc->function]); |
| 953 |
fillMode = (tilePtr->gc->fill_rule == EvenOddRule) ? ALTERNATE : WINDING; |
| 954 |
|
| 955 |
LPtoDP(hDC, winPts, nPoints); |
| 956 |
hRgn = CreatePolygonRgn(winPts, nPoints, fillMode); |
| 957 |
SelectClipRgn(hDC, hRgn); |
| 958 |
OffsetClipRgn(hDC, bbox.left, bbox.top); |
| 959 |
Blt_Free(winPts); |
| 960 |
|
| 961 |
twdPtr = (TkWinDrawable *)tilePtr->pixmap; |
| 962 |
memDC = CreateCompatibleDC(hDC); |
| 963 |
oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle); |
| 964 |
|
| 965 |
if (tilePtr->flags & FIXED_TS_ORIGIN) { |
| 966 |
Blt_SetTSOrigin(tkwin, clientPtr, Tk_X(tkwin), Tk_Y(tkwin)); |
| 967 |
} |
| 968 |
|
| 969 |
|
| 970 |
if (tilePtr->mask != None) { |
| 971 |
TkWinDCState maskState; |
| 972 |
HDC maskDC; |
| 973 |
|
| 974 |
maskDC = TkWinGetDrawableDC(tilePtr->display, tilePtr->mask, |
| 975 |
&maskState); |
| 976 |
SetBkColor(hDC, RGB(255, 255, 255)); |
| 977 |
SetTextColor(hDC, RGB(0, 0, 0)); |
| 978 |
TileRegion(memDC, hDC, maskDC, clientPtr, bbox.left, bbox.top, width, |
| 979 |
height); |
| 980 |
TkWinReleaseDrawableDC(tilePtr->mask, maskDC, &maskState); |
| 981 |
} else { |
| 982 |
TileRegion(memDC, hDC, NULL, clientPtr, bbox.left, bbox.top, width, |
| 983 |
height); |
| 984 |
} |
| 985 |
SelectBitmap(memDC, oldBitmap); |
| 986 |
DeleteDC(memDC); |
| 987 |
SelectClipRgn(hDC, NULL); |
| 988 |
DeleteRgn(hRgn); |
| 989 |
TkWinReleaseDrawableDC(drawable, hDC, &state); |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
void |
| 994 |
Blt_TileRectangle( |
| 995 |
Tk_Window tkwin, |
| 996 |
Drawable drawable, |
| 997 |
TileClient *clientPtr, |
| 998 |
int x, int y, |
| 999 |
unsigned int width, |
| 1000 |
unsigned int height) |
| 1001 |
{ |
| 1002 |
HBITMAP oldBitmap; |
| 1003 |
HDC hDC, memDC; |
| 1004 |
Tile *tilePtr; |
| 1005 |
TkWinDCState state; |
| 1006 |
TkWinDrawable *twdPtr; |
| 1007 |
|
| 1008 |
if (drawable == None) { |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
tilePtr = clientPtr->tilePtr; |
| 1012 |
if (tilePtr->gc == NULL) return; |
| 1013 |
if (tilePtr->flags & FIXED_TS_ORIGIN) { |
| 1014 |
Blt_SetTSOrigin(tkwin, clientPtr, x, y); |
| 1015 |
|
| 1016 |
} |
| 1017 |
hDC = TkWinGetDrawableDC(Tk_Display(tkwin), drawable, &state); |
| 1018 |
SetROP2(hDC, tkpWinRopModes[tilePtr->gc->function]); |
| 1019 |
|
| 1020 |
twdPtr = (TkWinDrawable *)tilePtr->pixmap; |
| 1021 |
memDC = CreateCompatibleDC(hDC); |
| 1022 |
oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle); |
| 1023 |
|
| 1024 |
|
| 1025 |
if (tilePtr->mask != None) { |
| 1026 |
TkWinDCState maskState; |
| 1027 |
HDC maskDC; |
| 1028 |
|
| 1029 |
maskDC = TkWinGetDrawableDC(tilePtr->display, tilePtr->mask, |
| 1030 |
&maskState); |
| 1031 |
SetBkColor(hDC, RGB(255, 255, 255)); |
| 1032 |
SetTextColor(hDC, RGB(0, 0, 0)); |
| 1033 |
TileRegion(memDC, hDC, maskDC, clientPtr, x, y, width, height); |
| 1034 |
TkWinReleaseDrawableDC(tilePtr->mask, maskDC, &maskState); |
| 1035 |
} else { |
| 1036 |
TileRegion(memDC, hDC, NULL, clientPtr, x, y, width, height); |
| 1037 |
} |
| 1038 |
SelectBitmap(memDC, oldBitmap); |
| 1039 |
DeleteDC(memDC); |
| 1040 |
TkWinReleaseDrawableDC(drawable, hDC, &state); |
| 1041 |
} |
| 1042 |
|
| 1043 |
void |
| 1044 |
Blt_TileRectangles( |
| 1045 |
Tk_Window tkwin, |
| 1046 |
Drawable drawable, |
| 1047 |
TileClient *clientPtr, |
| 1048 |
XRectangle rectArr[], |
| 1049 |
int nRectangles) |
| 1050 |
{ |
| 1051 |
HBITMAP oldBitmap; |
| 1052 |
HDC hDC, memDC; |
| 1053 |
Tile *tilePtr; |
| 1054 |
TkWinDCState state; |
| 1055 |
TkWinDrawable *twdPtr; |
| 1056 |
XRectangle *rectPtr, *endPtr; |
| 1057 |
|
| 1058 |
if (drawable == None) { |
| 1059 |
return; |
| 1060 |
} |
| 1061 |
tilePtr = clientPtr->tilePtr; |
| 1062 |
if (tilePtr->gc == NULL) return; |
| 1063 |
hDC = TkWinGetDrawableDC(Tk_Display(tkwin), drawable, &state); |
| 1064 |
SetROP2(hDC, tkpWinRopModes[tilePtr->gc->function]); |
| 1065 |
|
| 1066 |
twdPtr = (TkWinDrawable *)tilePtr->pixmap; |
| 1067 |
memDC = CreateCompatibleDC(hDC); |
| 1068 |
oldBitmap = SelectBitmap(memDC, twdPtr->bitmap.handle); |
| 1069 |
|
| 1070 |
endPtr = rectArr + nRectangles; |
| 1071 |
|
| 1072 |
if (tilePtr->mask != None) { |
| 1073 |
TkWinDCState maskState; |
| 1074 |
HDC maskDC; |
| 1075 |
|
| 1076 |
maskDC = TkWinGetDrawableDC(tilePtr->display, tilePtr->mask, |
| 1077 |
&maskState); |
| 1078 |
SetBkColor(hDC, RGB(255, 255, 255)); |
| 1079 |
SetTextColor(hDC, RGB(0, 0, 0)); |
| 1080 |
for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) { |
| 1081 |
TileRegion(memDC, hDC, maskDC, clientPtr, (int)rectPtr->x, |
| 1082 |
(int)rectPtr->y, (int)rectPtr->width, (int)rectPtr->height); |
| 1083 |
} |
| 1084 |
TkWinReleaseDrawableDC(tilePtr->mask, maskDC, &maskState); |
| 1085 |
} else { |
| 1086 |
for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) { |
| 1087 |
TileRegion(memDC, hDC, NULL, clientPtr, (int)rectPtr->x, |
| 1088 |
(int)rectPtr->y, (int)rectPtr->width, (int)rectPtr->height); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
SelectBitmap(memDC, oldBitmap); |
| 1092 |
DeleteDC(memDC); |
| 1093 |
TkWinReleaseDrawableDC(drawable, hDC, &state); |
| 1094 |
} |
| 1095 |
|
| 1096 |
#else |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
static Pixmap |
| 1113 |
RectangleMask(display, drawable, x, y, width, height, mask, xOrigin, yOrigin) |
| 1114 |
Display *display; |
| 1115 |
Drawable drawable; |
| 1116 |
int x, y; |
| 1117 |
unsigned int width, height; |
| 1118 |
Pixmap mask; |
| 1119 |
int xOrigin, yOrigin; |
| 1120 |
{ |
| 1121 |
GC gc; |
| 1122 |
Pixmap bitmap; |
| 1123 |
XGCValues gcValues; |
| 1124 |
unsigned long gcMask; |
| 1125 |
|
| 1126 |
bitmap = Tk_GetPixmap(display, drawable, width, height, 1); |
| 1127 |
gcMask = (GCForeground | GCBackground | GCFillStyle | |
| 1128 |
GCTileStipXOrigin | GCTileStipYOrigin | GCStipple); |
| 1129 |
gcValues.foreground = 0x1; |
| 1130 |
gcValues.background = 0x0; |
| 1131 |
gcValues.fill_style = FillOpaqueStippled; |
| 1132 |
gcValues.ts_x_origin = xOrigin - x; |
| 1133 |
gcValues.ts_y_origin = yOrigin - y; |
| 1134 |
gcValues.stipple = mask; |
| 1135 |
gc = XCreateGC(display, bitmap, gcMask, &gcValues); |
| 1136 |
XFillRectangle(display, bitmap, gc, 0, 0, width, height); |
| 1137 |
Blt_FreePrivateGC(display, gc); |
| 1138 |
return bitmap; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
void |
| 1159 |
Blt_TileRectangle( |
| 1160 |
Tk_Window tkwin, |
| 1161 |
Drawable drawable, |
| 1162 |
TileClient *clientPtr, |
| 1163 |
int x, int y, |
| 1164 |
unsigned int width, |
| 1165 |
unsigned int height) |
| 1166 |
{ |
| 1167 |
Tile *tilePtr; |
| 1168 |
Display *display; |
| 1169 |
|
| 1170 |
if (height==0 || width == 0) return; |
| 1171 |
display = Tk_Display(tkwin); |
| 1172 |
tilePtr = clientPtr->tilePtr; |
| 1173 |
if (tilePtr->gc == NULL) return; |
| 1174 |
if (tilePtr->flags & FIXED_TS_ORIGIN) { |
| 1175 |
XSetTSOrigin(display, clientPtr->tilePtr->gc, x, y); |
| 1176 |
} |
| 1177 |
if (clientPtr->tilePtr->mask != None) { |
| 1178 |
Pixmap mask; |
| 1179 |
|
| 1180 |
mask = RectangleMask(display, drawable, x, y, width, height, |
| 1181 |
tilePtr->mask, clientPtr->xOrigin, clientPtr->yOrigin); |
| 1182 |
XSetClipMask(display, tilePtr->gc, mask); |
| 1183 |
XSetClipOrigin(display, tilePtr->gc, x, y); |
| 1184 |
XFillRectangle(display, drawable, tilePtr->gc, x, y, width, height); |
| 1185 |
XSetClipMask(display, tilePtr->gc, None); |
| 1186 |
XSetClipOrigin(display, tilePtr->gc, 0, 0); |
| 1187 |
Tk_FreePixmap(display, mask); |
| 1188 |
} else { |
| 1189 |
XFillRectangle(display, drawable, tilePtr->gc, x, y, width, height); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
void |
| 1211 |
Blt_TileRectangles( |
| 1212 |
Tk_Window tkwin, |
| 1213 |
Drawable drawable, |
| 1214 |
TileClient *clientPtr, |
| 1215 |
XRectangle rectArr[], |
| 1216 |
int nRectangles) |
| 1217 |
{ |
| 1218 |
Tile *tilePtr; |
| 1219 |
|
| 1220 |
tilePtr = clientPtr->tilePtr; |
| 1221 |
if (tilePtr->gc == NULL) return; |
| 1222 |
if (tilePtr->mask != None) { |
| 1223 |
XRectangle *rectPtr, *endPtr; |
| 1224 |
|
| 1225 |
endPtr = rectArr + nRectangles; |
| 1226 |
for (rectPtr = rectArr; rectPtr < endPtr; rectPtr++) { |
| 1227 |
Blt_TileRectangle(tkwin, drawable, clientPtr, rectPtr->x, |
| 1228 |
rectPtr->y, rectPtr->width, rectPtr->height); |
| 1229 |
} |
| 1230 |
} else { |
| 1231 |
XFillRectangles(Tk_Display(tkwin), drawable, tilePtr->gc, rectArr, |
| 1232 |
nRectangles); |
| 1233 |
} |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
static Pixmap |
| 1251 |
PolygonMask(display, pointArr, nPoints, regionPtr, mask, xOrigin, yOrigin) |
| 1252 |
Display *display; |
| 1253 |
XPoint *pointArr; |
| 1254 |
int nPoints; |
| 1255 |
Region2D *regionPtr; |
| 1256 |
Pixmap mask; |
| 1257 |
int xOrigin, yOrigin; |
| 1258 |
{ |
| 1259 |
unsigned int width, height; |
| 1260 |
Pixmap bitmap; |
| 1261 |
GC gc; |
| 1262 |
XPoint *destArr; |
| 1263 |
register XPoint *srcPtr, *destPtr, *endPtr; |
| 1264 |
|
| 1265 |
width = regionPtr->right - regionPtr->left + 1; |
| 1266 |
height = regionPtr->bottom - regionPtr->top + 1; |
| 1267 |
bitmap = |
| 1268 |
Tk_GetPixmap(display, DefaultRootWindow(display), width, height, 1); |
| 1269 |
|
| 1270 |
destArr = Blt_Malloc(sizeof(XPoint) * nPoints); |
| 1271 |
endPtr = destArr + nPoints; |
| 1272 |
srcPtr = pointArr; |
| 1273 |
for (destPtr = destArr; destPtr < endPtr; destPtr++) { |
| 1274 |
destPtr->x = srcPtr->x - regionPtr->left; |
| 1275 |
destPtr->y = srcPtr->y - regionPtr->top; |
| 1276 |
srcPtr++; |
| 1277 |
} |
| 1278 |
gc = XCreateGC(display, bitmap, 0, NULL); |
| 1279 |
XFillRectangle(display, bitmap, gc, 0, 0, width, height); |
| 1280 |
XSetForeground(display, gc, 0x01); |
| 1281 |
XSetFillStyle(display, gc, FillStippled); |
| 1282 |
XSetTSOrigin(display, gc, xOrigin - regionPtr->left, |
| 1283 |
yOrigin - regionPtr->top); |
| 1284 |
XSetStipple(display, gc, mask); |
| 1285 |
XFillPolygon(display, bitmap, gc, destArr, nPoints, Complex, |
| 1286 |
CoordModeOrigin); |
| 1287 |
XFreeGC(display, gc); |
| 1288 |
Blt_Free(destArr); |
| 1289 |
return bitmap; |
| 1290 |
} |
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
void |
| 1310 |
Blt_TilePolygon( |
| 1311 |
Tk_Window tkwin, |
| 1312 |
Drawable drawable, |
| 1313 |
TileClient *clientPtr, |
| 1314 |
XPoint pointArr[], |
| 1315 |
int nPoints) |
| 1316 |
{ |
| 1317 |
Tile *tilePtr; |
| 1318 |
Display *display; |
| 1319 |
|
| 1320 |
display = Tk_Display(tkwin); |
| 1321 |
tilePtr = clientPtr->tilePtr; |
| 1322 |
if (tilePtr->gc == NULL) return; |
| 1323 |
if (tilePtr->mask != None) { |
| 1324 |
XPoint *pointPtr, *endPtr; |
| 1325 |
Region2D region; |
| 1326 |
Pixmap mask; |
| 1327 |
|
| 1328 |
if (tilePtr->flags & FIXED_TS_ORIGIN) { |
| 1329 |
Blt_SetTSOrigin(tkwin, clientPtr, Tk_X(tkwin), Tk_Y(tkwin)); |
| 1330 |
} |
| 1331 |
|
| 1332 |
pointPtr = pointArr; |
| 1333 |
region.left = region.right = pointPtr->x; |
| 1334 |
region.top = region.bottom = pointPtr->y; |
| 1335 |
|
| 1336 |
endPtr = pointArr + nPoints; |
| 1337 |
for (pointPtr = pointArr; pointPtr < endPtr; pointPtr++) { |
| 1338 |
if (region.left > pointPtr->x) { |
| 1339 |
region.left = pointPtr->x; |
| 1340 |
} else if (region.right < pointPtr->x) { |
| 1341 |
region.right = pointPtr->x; |
| 1342 |
} |
| 1343 |
if (region.top > pointPtr->y) { |
| 1344 |
region.top = pointPtr->y; |
| 1345 |
} else if (region.bottom < pointPtr->y) { |
| 1346 |
region.bottom = pointPtr->y; |
| 1347 |
} |
| 1348 |
} |
| 1349 |
mask = PolygonMask(display, pointArr, nPoints, ®ion, |
| 1350 |
tilePtr->mask, clientPtr->xOrigin, clientPtr->yOrigin); |
| 1351 |
XSetClipMask(display, tilePtr->gc, mask); |
| 1352 |
XSetClipOrigin(display, tilePtr->gc, region.left, region.top); |
| 1353 |
XFillPolygon(display, drawable, tilePtr->gc, pointArr, |
| 1354 |
nPoints, Complex, CoordModeOrigin); |
| 1355 |
XSetClipMask(display, tilePtr->gc, None); |
| 1356 |
XSetClipOrigin(display, tilePtr->gc, 0, 0); |
| 1357 |
Tk_FreePixmap(display, mask); |
| 1358 |
} else { |
| 1359 |
XFillPolygon(display, drawable, tilePtr->gc, pointArr, |
| 1360 |
nPoints, Complex, CoordModeOrigin); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
#endif |
| 1364 |
|
| 1365 |
void |
| 1366 |
Blt_Fill3DRectangleTile(tkwin, drawable, border, x, y, width, height, borderWidth, |
| 1367 |
relief, tilePtr, scrollTile, flags) |
| 1368 |
Tk_Window tkwin; |
| 1369 |
Drawable drawable; |
| 1370 |
Tk_3DBorder border; |
| 1371 |
int x, y, width, height; |
| 1372 |
int borderWidth; |
| 1373 |
|
| 1374 |
int relief; |
| 1375 |
|
| 1376 |
TileClient *tilePtr; |
| 1377 |
int scrollTile; |
| 1378 |
int flags; |
| 1379 |
{ |
| 1380 |
|
| 1381 |
if (Blt_HasTile(tilePtr)==0 || (flags&1)) { |
| 1382 |
Blt_Fill3DRectangle(tkwin, drawable, border, x, y, width, height, borderWidth, relief); |
| 1383 |
return; |
| 1384 |
} |
| 1385 |
if (border && (tilePtr->tilePtr->flags & TILE_ALPHA)) { |
| 1386 |
Blt_Fill3DRectangle(tkwin, drawable, border, x, y, width, height, borderWidth, relief); |
| 1387 |
} |
| 1388 |
Blt_SetTileOrigin(tkwin, tilePtr, x, 0); |
| 1389 |
if (scrollTile) { |
| 1390 |
Blt_SetTSOrigin(tkwin, tilePtr, x, y); |
| 1391 |
} else { |
| 1392 |
Blt_SetTileOrigin(tkwin, tilePtr, x, 0); |
| 1393 |
} |
| 1394 |
Blt_TileRectangle(tkwin, drawable, tilePtr, x, y, width, height); |
| 1395 |
Blt_Draw3DRectangle(tkwin, drawable, border, x, y, width, height, |
| 1396 |
borderWidth, relief); |
| 1397 |
} |