| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <stdio.h> |
| 19 |
#include <stdlib.h> |
| 20 |
#include <string.h> |
| 21 |
#include <assert.h> |
| 22 |
|
| 23 |
#include <X11/Xlib.h> |
| 24 |
#include <X11/Xutil.h> |
| 25 |
#include <X11/keysym.h> |
| 26 |
#include <X11/Xatom.h> |
| 27 |
|
| 28 |
#define CD printf("%d: %d %d %d %d\n", __LINE__, ex, ey, ew, eh) |
| 29 |
#undef CD |
| 30 |
#define CD |
| 31 |
|
| 32 |
#include "imagelib.h" |
| 33 |
#include "table.h" |
| 34 |
#include "cards.h" |
| 35 |
#include "xwin.h" |
| 36 |
#include "funcs.h" |
| 37 |
|
| 38 |
#define TRACE_EVENTS 0 |
| 39 |
#define TRACE_PICTURES 0 |
| 40 |
#define TRACE_INVALIDATE 0 |
| 41 |
|
| 42 |
#define DBLCLICK_TIME 800 |
| 43 |
#define DBLCLICK_MOVE 5 |
| 44 |
|
| 45 |
|
| 46 |
int table_width=0, table_height=0, table_type; |
| 47 |
int display_width, display_height; |
| 48 |
|
| 49 |
static Picture *centered_pic = 0; |
| 50 |
|
| 51 |
static int ex=0, ey=0, ew=0, eh=0; |
| 52 |
|
| 53 |
static int graphics_disabled = 1; |
| 54 |
|
| 55 |
OptionDesc *app_options; |
| •56 |
extern OptionDesc *xwin_options; |
| 57 |
static OptionDesc *options[5]; |
| 58 |
|
| 59 |
static OptionDesc ace_options[] = { |
| 60 |
{ "-width", OPTION_INTEGER, &table_width }, |
| 61 |
{ "-height", OPTION_INTEGER, &table_height }, |
| 62 |
{ 0, 0, 0 } |
| 63 |
}; |
| 64 |
|
| 65 |
static FunctionMapping flist[] = { |
| 66 |
{ "click", &click_cb }, |
| 67 |
{ "drag", &drag_cb }, |
| 68 |
{ "redraw", &redraw_cb }, |
| 69 |
{ "init", &init_cb }, |
| 70 |
{ "drop", &drop_cb }, |
| 71 |
{ "key", &key_cb }, |
| 72 |
{ "resize", &resize_cb }, |
| 73 |
{ "double_click", &double_click_cb }, |
| 74 |
{ 0, 0 } |
| 75 |
}; |
| 76 |
|
| 77 |
extern image_list cards_imagelib[]; |
| 78 |
static image_list card_images[]; |
| 79 |
|
| 80 |
void |
| 81 |
init_ace(int argc, char **argv, FunctionMapping *funcs) |
| 82 |
{ |
| 83 |
int i = 0, o, a, errors=0; |
| 84 |
|
| 85 |
register_imagelib(cards_imagelib); |
| 86 |
register_imagelib(card_images); |
| 87 |
|
| 88 |
if (app_options) |
| 89 |
options[i++] = app_options; |
| 90 |
if (xwin_options) |
| 91 |
options[i++] = xwin_options; |
| 92 |
options[i++] = ace_options; |
| 93 |
options[i++] = 0; |
| 94 |
|
| 95 |
for (i=0; funcs[i].name; i++) |
| 96 |
for (a=0; flist[a].name; a++) |
| 97 |
if (strcmp(funcs[i].name, flist[a].name) == 0) |
| 98 |
*(void **)flist[a].function = funcs[i].function; |
| 99 |
|
| 100 |
for (a=1; a<argc; a++) |
| 101 |
{ |
| 102 |
int found = 0; |
| 103 |
if (argv[a][0] != '-') |
| 104 |
break; |
| 105 |
for (i=0; options[i]; i++) |
| 106 |
for (o=0; options[i][o].option; o++) |
| 107 |
if (strcmp (options[i][o].option, argv[a]) == 0) |
| 108 |
{ |
| 109 |
found = 1; |
| 110 |
if (options[i][o].type != OPTION_BOOLEAN && a == argc-1) |
| 111 |
{ |
| 112 |
fprintf(stderr, "Option `%s' takes an argument\n", argv[a]); |
| 113 |
errors++; |
| 114 |
continue; |
| 115 |
} |
| 116 |
switch (options[i][o].type) |
| 117 |
{ |
| 118 |
case OPTION_BOOLEAN: |
| 119 |
*(int *)(options[i][o].ptr) = 1; |
| 120 |
break; |
| 121 |
case OPTION_STRING: |
| 122 |
*(char **)(options[i][o].ptr) = argv[a+1]; |
| 123 |
a++; |
| 124 |
break; |
| 125 |
case OPTION_INTEGER: |
| 126 |
*(int *)(options[i][o].ptr) = strtol(argv[a+1], 0, 0); |
| 127 |
a++; |
| 128 |
break; |
| 129 |
} |
| 130 |
} |
| 131 |
if (!found) |
| 132 |
{ |
| 133 |
fprintf(stderr, "Unrecognized option `%s'\n", argv[a]); |
| 134 |
errors++; |
| 135 |
} |
| 136 |
} |
| 137 |
if (errors) |
| 138 |
exit(errors); |
| 139 |
|
| 140 |
i = 1; |
| 141 |
while (a < argc) |
| 142 |
argv[i++] = argv[a++]; |
| 143 |
argv[i] = 0; |
| 144 |
|
| 145 |
if (xwin_init(argc, argv)) |
| 146 |
exit(1); |
| 147 |
} |
| 148 |
|
| 149 |
void |
| 150 |
init_table(int width, int height) |
| 151 |
{ |
| 152 |
|
| 153 |
if (width > display_width) |
| 154 |
width = display_width; |
| 155 |
if (height > display_height) |
| 156 |
height = display_height; |
| 157 |
|
| 158 |
ew = width; |
| 159 |
eh = height; |
| 160 |
|
| 161 |
table_width = width; |
| 162 |
table_height = height; |
| 163 |
|
| 164 |
xwin_create (width, height); |
| 165 |
} |
| 166 |
|
| 167 |
typedef struct PicRec { |
| 168 |
Pixmap pixmap; |
| 169 |
Pixmap mask; |
| 170 |
char **xpm_data; |
| 171 |
int image_table_index; |
| 172 |
} PicRec; |
| 173 |
|
| 174 |
int get_picture_default_width = CARD_WIDTH; |
| 175 |
int get_picture_default_height = CARD_HEIGHT; |
| 176 |
|
| 177 |
Picture * |
| 178 |
get_picture(char *name) |
| 179 |
{ |
| 180 |
image *img; |
| 181 |
img = get_image(name, get_picture_default_width, get_picture_default_height, 0); |
| 182 |
return (Picture *)img; |
| 183 |
} |
| 184 |
|
| 185 |
static int put_picture_flags = 0; |
| 186 |
|
| 187 |
void |
| 188 |
put_picture(Picture *picture, int dx, int dy, |
| 189 |
int x, int y, int w, int h) |
| 190 |
{ |
| 191 |
if (!picture) return; |
| 192 |
if (graphics_disabled) return; |
| 193 |
#if TRACE_PICTURES |
| 194 |
|
| 195 |
#endif |
| 196 |
|
| 197 |
if (dx+x < ex) |
| 198 |
{ |
| 199 |
w -= ex-(dx+x); |
| 200 |
x += ex-(dx+x); |
| 201 |
} |
| 202 |
if (dx+x+w > ex+ew) |
| 203 |
w = ex+ew - (dx+x); |
| 204 |
if (dy+y < ey) |
| 205 |
{ |
| 206 |
h -= ey-(dy+y); |
| 207 |
y += ey-(dy+y); |
| 208 |
} |
| 209 |
if (dy+y+h > ey+eh) |
| 210 |
h = ey+eh - (dy+y); |
| 211 |
#if TRACE_PICTURES |
| 212 |
printf("copy clip: x=%3d y=%3d w=%3d h=%3d (ex=%d ey=%d ew=%d eh=%d)\n", |
| 213 |
dx+x, dy+y, w, h, ex, ey, ew, eh); |
| 214 |
#endif |
| 215 |
if (w>0 && h>0) |
| 216 |
{ |
| 217 |
#if TRACE_PICTURES |
| 218 |
printf("copy aft: x=%3d y=%3d w=%3d h=%3d\n", dx+x, dy+y, w, h); |
| 219 |
#endif |
| 220 |
put_image ((image *)picture, x, y, w, h, display_image, dx, dy, put_picture_flags); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
void |
| 225 |
put_picture_inverted(Picture *picture, int dx, int dy, |
| 226 |
int x, int y, int w, int h) |
| 227 |
{ |
| 228 |
put_picture_flags = PUT_INVERTED; |
| 229 |
put_picture (picture, dx, dy, x, y, w, h); |
| 230 |
put_picture_flags = 0; |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
set_centered_pic(Picture *picture) |
| 235 |
{ |
| 236 |
int x, y, w=0, h=0; |
| 237 |
if (centered_pic) |
| 238 |
{ |
| 239 |
x = table_width/2-centered_pic->w/2; |
| 240 |
y = table_height/2-centered_pic->h/2; |
| 241 |
w = centered_pic->w; |
| 242 |
h = centered_pic->h; |
| 243 |
} |
| 244 |
centered_pic = picture; |
| 245 |
if (centered_pic) |
| 246 |
{ |
| 247 |
if (centered_pic->w > w) |
| 248 |
{ |
| 249 |
x = table_width/2-centered_pic->w/2; |
| 250 |
w = centered_pic->w; |
| 251 |
} |
| 252 |
if (centered_pic->h > h) |
| 253 |
{ |
| 254 |
y = table_height/2-centered_pic->h/2; |
| 255 |
h = centered_pic->h; |
| 256 |
} |
| 257 |
} |
| 258 |
if (! graphics_disabled) |
| 259 |
invalidate(x, y, w, h); |
| 260 |
} |
| 261 |
|
| 262 |
Picture * |
| 263 |
get_centered_pic() |
| 264 |
{ |
| 265 |
return centered_pic; |
| 266 |
} |
| 267 |
|
| 268 |
static void |
| 269 |
redraw_centered_pic() |
| 270 |
{ |
| 271 |
if (centered_pic) |
| 272 |
put_picture(centered_pic, table_width/2-centered_pic->w/2, |
| 273 |
table_height/2-centered_pic->h/2, |
| 274 |
0, 0, centered_pic->w, centered_pic->h); |
| 275 |
} |
| 276 |
|
| 277 |
#define CLEAR_CLIP ex = 0; ey = 0; ew = table_width; eh = table_height; xwin_noclip(); |
| 278 |
|
| 279 |
static int dcx, dcy, dct=0; |
| 280 |
static int drag_enabled=0; |
| 281 |
|
| 282 |
static void |
| 283 |
check_dclick(int x, int y, int t) |
| 284 |
{ |
| 285 |
if (t>dct+DBLCLICK_TIME) |
| 286 |
dct = t-2*DBLCLICK_TIME; |
| 287 |
if (x < dcx-DBLCLICK_MOVE || x>dcx+DBLCLICK_MOVE |
| 288 |
|| y < dcy-DBLCLICK_MOVE || y > dcy+DBLCLICK_MOVE) |
| 289 |
{ |
| 290 |
dct = t-2*DBLCLICK_TIME; |
| 291 |
drag_enabled = 1; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
int help_is_showing = 0; |
| 296 |
static void help_nothing() { help_is_showing = 0; } |
| 297 |
void (*help_redraw)(void) = help_nothing; |
| 298 |
void (*help_click)(int x, int y, int b) = help_nothing; |
| 299 |
void (*help_key)(int c, int x, int y) = help_nothing; |
| 300 |
|
| 301 |
static int no_resize = 0; |
| 302 |
void |
| 303 |
table_no_resize() |
| 304 |
{ |
| 305 |
no_resize = 1; |
| 306 |
} |
| 307 |
|
| 308 |
static int initted = 0; |
| 309 |
|
| 310 |
static void |
| 311 |
maybe_init() |
| 312 |
{ |
| 313 |
if (! initted) |
| 314 |
{ |
| 315 |
initted = 1; |
| 316 |
flush(); |
| 317 |
graphics_disabled = 1; |
| 318 |
init_cb(); |
| 319 |
graphics_disabled = 0; |
| 320 |
#if TRACE_EVENTS |
| 321 |
printf(" - done init\n"); |
| 322 |
#endif |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
void |
| 327 |
table_loop() |
| 328 |
{ |
| 329 |
int first_expose = 0; |
| 330 |
int click_button; |
| 331 |
|
| 332 |
while (1) |
| 333 |
{ |
| 334 |
XWin_Event event; |
| 335 |
xwin_nextevent(&event); |
| 336 |
|
| 337 |
if (!initted && (event.type != ev_expose && event.type != ev_resize)) |
| 338 |
continue; |
| 339 |
|
| 340 |
switch (event.type) |
| 341 |
{ |
| 342 |
case ev_resize: |
| 343 |
#if TRACE_EVENTS |
| 344 |
printf("resize: x=%3d y=%3d w=%3d h=%3d, no=%d\n", |
| 345 |
event.x, event.y, event.w, event.h, no_resize); |
| 346 |
#endif |
| 347 |
|
| 348 |
maybe_init(); |
| 349 |
|
| 350 |
if (no_resize) |
| 351 |
xwin_fixed_size(table_width, table_height); |
| 352 |
else |
| 353 |
{ |
| 354 |
graphics_disabled = 1; |
| 355 |
resize_cb(event.w, event.h); |
| 356 |
graphics_disabled = 0; |
| 357 |
if (no_resize) |
| 358 |
xwin_fixed_size(table_width, table_height); |
| 359 |
else |
| 360 |
{ |
| 361 |
table_width = event.w; |
| 362 |
table_height = event.h; |
| 363 |
if (first_expose) |
| 364 |
{ |
| 365 |
clear (0, 0, table_width, table_height); |
| 366 |
redraw_cb(); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
break; |
| 371 |
|
| 372 |
case ev_expose: |
| 373 |
first_expose = 1; |
| 374 |
ex = event.x; |
| 375 |
ey = event.y; |
| 376 |
ew = event.w; |
| 377 |
eh = event.h; |
| 378 |
#if TRACE_EVENTS |
| 379 |
printf("expose: x=%3d y=%3d w=%3d h=%3d\n", |
| 380 |
ex, ey, ew, eh); |
| 381 |
#endif |
| 382 |
CD; |
| 383 |
xwin_clip (ex, ey, ew, eh); |
| 384 |
clear(ex, ey, ew, eh); |
| 385 |
|
| 386 |
maybe_init(); |
| 387 |
|
| 388 |
ex = event.x; |
| 389 |
ey = event.y; |
| 390 |
ew = event.w; |
| 391 |
eh = event.h; |
| 392 |
CD; |
| 393 |
if (help_is_showing) |
| 394 |
help_redraw(); |
| 395 |
else |
| 396 |
redraw_cb(); |
| 397 |
redraw_centered_pic(); |
| 398 |
xwin_noclip(); |
| 399 |
#if TRACE_EVENTS |
| 400 |
printf(" - done expose\n"); |
| 401 |
#endif |
| 402 |
break; |
| 403 |
|
| 404 |
case ev_buttondown: |
| 405 |
CLEAR_CLIP; |
| 406 |
CD; |
| 407 |
#if TRACE_EVENTS |
| 408 |
printf("click: %d,%d %d\n", |
| 409 |
event.x, event.y, event.button); |
| 410 |
#endif |
| 411 |
click_button = event.button; |
| 412 |
check_dclick(event.x, event.y, event.time); |
| 413 |
if (help_is_showing) |
| 414 |
{ |
| 415 |
help_click(event.x, event.y, click_button); |
| 416 |
} |
| 417 |
else if (event.time - dct < DBLCLICK_TIME) |
| 418 |
{ |
| 419 |
double_click_cb(event.x, event.y, event.button); |
| 420 |
dct -= DBLCLICK_TIME; |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
click_cb(event.x, event.y, click_button); |
| 425 |
dcx = event.x; |
| 426 |
dcy = event.y; |
| 427 |
dct = event.time; |
| 428 |
} |
| 429 |
drag_enabled = 0; |
| 430 |
break; |
| 431 |
|
| 432 |
case ev_motion: |
| 433 |
CLEAR_CLIP; |
| 434 |
CD; |
| 435 |
check_dclick(event.x, event.y, event.time); |
| 436 |
if (drag_enabled && !help_is_showing) |
| 437 |
{ |
| 438 |
#if TRACE_EVENTS |
| 439 |
printf("drag: %d,%d %d\n", event.x, event.y, click_button); |
| 440 |
#endif |
| 441 |
drag_cb(event.x, event.y, click_button); |
| 442 |
} |
| 443 |
break; |
| 444 |
|
| 445 |
case ev_buttonup: |
| 446 |
CLEAR_CLIP; |
| 447 |
check_dclick(event.x, event.y, event.time); |
| 448 |
CD; |
| 449 |
#if TRACE_EVENTS |
| 450 |
printf("drop: %d,%d\n", event.x, event.y); |
| 451 |
#endif |
| 452 |
if (!help_is_showing) |
| 453 |
drop_cb(event.x, event.y, click_button); |
| 454 |
break; |
| 455 |
|
| 456 |
case ev_keypress: |
| 457 |
CLEAR_CLIP; |
| 458 |
CD; |
| 459 |
if (help_is_showing) |
| 460 |
help_key(event.key, event.x, event.y); |
| 461 |
else |
| 462 |
key_cb(event.key, event.x, event.y); |
| 463 |
break; |
| 464 |
|
| 465 |
case ev_quit: |
| 466 |
exit(0); |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
static void |
| 472 |
reset_clip() |
| 473 |
{ |
| 474 |
xwin_clip (ex, ey, ew, eh); |
| 475 |
} |
| 476 |
|
| 477 |
void |
| 478 |
clip(int x, int y, int w, int h) |
| 479 |
{ |
| 480 |
if (graphics_disabled) return; |
| 481 |
ex = x; |
| 482 |
ey = y; |
| 483 |
ew = w; |
| 484 |
eh = h; |
| 485 |
|
| 486 |
if (ew < 0) ew = 0; |
| 487 |
if (eh < 0) eh = 0; |
| 488 |
if (ex < 0) |
| 489 |
{ |
| 490 |
ew += ex; |
| 491 |
ex = 0; |
| 492 |
} |
| 493 |
if (ey < 0) |
| 494 |
{ |
| 495 |
eh += ey; |
| 496 |
ey = 0; |
| 497 |
} |
| 498 |
if (ex+ew > table_width) |
| 499 |
ew = table_width - ex; |
| 500 |
if (ey+eh > table_height) |
| 501 |
eh = table_height - ey; |
| 502 |
reset_clip(); |
| 503 |
} |
| 504 |
|
| 505 |
static int *clip_saves = 0; |
| 506 |
|
| 507 |
void |
| 508 |
clip_more(int x, int y, int w, int h) |
| 509 |
{ |
| 510 |
int *save = (int *)malloc (5*sizeof(int)); |
| 511 |
save[0] = (int)clip_saves; |
| 512 |
save[1] = ex; |
| 513 |
save[2] = ey; |
| 514 |
save[3] = ew; |
| 515 |
save[4] = eh; |
| 516 |
clip_saves = save; |
| 517 |
|
| 518 |
if (x+w > ex+ew) |
| 519 |
w = ex+ew - x; |
| 520 |
if (y+h > ey+eh) |
| 521 |
h = ey+eh - y; |
| 522 |
if (x < ex) |
| 523 |
{ |
| 524 |
w -= ex-x; |
| 525 |
x = ex; |
| 526 |
} |
| 527 |
if (y < ey) |
| 528 |
{ |
| 529 |
h -= ey-y; |
| 530 |
y = ey; |
| 531 |
} |
| 532 |
clip (x, y, w, h); |
| 533 |
} |
| 534 |
|
| 535 |
void |
| 536 |
unclip() |
| 537 |
{ |
| 538 |
int *ptr = clip_saves; |
| 539 |
if (!ptr) return; |
| 540 |
ex = clip_saves[1]; |
| 541 |
ey = clip_saves[1]; |
| 542 |
ew = clip_saves[1]; |
| 543 |
eh = clip_saves[1]; |
| 544 |
clip_saves = (int *)clip_saves[0]; |
| 545 |
free (clip_saves); |
| 546 |
xwin_noclip(); |
| 547 |
reset_clip(); |
| 548 |
} |
| 549 |
|
| 550 |
static void |
| 551 |
invalidate_sub(int x, int y, int w, int h) |
| 552 |
{ |
| 553 |
#if TRACE_INVALIDATE |
| 554 |
printf("inv_sub(%d, %d, %d, %d)\n", x, y, w, h); |
| 555 |
#endif |
| 556 |
ex = x; |
| 557 |
ey = y; |
| 558 |
ew = w; |
| 559 |
eh = h; |
| 560 |
CD; |
| 561 |
reset_clip(); |
| 562 |
clear(ex, ey, ew, eh); |
| 563 |
if (help_is_showing) |
| 564 |
help_redraw(); |
| 565 |
else |
| 566 |
redraw_cb(); |
| 567 |
redraw_centered_pic(); |
| 568 |
xwin_noclip(); |
| 569 |
} |
| 570 |
|
| 571 |
void |
| 572 |
invalidate(int x, int y, int w, int h) |
| 573 |
{ |
| 574 |
int ox = ex; |
| 575 |
int oy = ey; |
| 576 |
int ow = ew; |
| 577 |
int oh = eh; |
| 578 |
if (graphics_disabled) return; |
| 579 |
#if TRACE_INVALIDATE |
| 580 |
printf("invalidate(%d, %d, %d, %d)\n", x, y, w, h); |
| 581 |
#endif |
| 582 |
invalidate_sub(x, y, w, h); |
| 583 |
#if TRACE_INVALIDATE |
| 584 |
printf(" - done invalidate\n"); |
| 585 |
#endif |
| 586 |
ex = ox; |
| 587 |
ey = oy; |
| 588 |
ew = ow; |
| 589 |
eh = oh; |
| 590 |
reset_clip(); |
| 591 |
CD; |
| 592 |
} |
| 593 |
|
| 594 |
void |
| 595 |
invalidate_nc(int x, int y, int w, int h) |
| 596 |
{ |
| 597 |
int ox = ex; |
| 598 |
int oy = ey; |
| 599 |
int ow = ew; |
| 600 |
int oh = eh; |
| 601 |
if (graphics_disabled) return; |
| 602 |
#if TRACE_INVALIDATE |
| 603 |
printf("invalidate_nc(%d, %d, %d, %d)\n", x, y, w, h); |
| 604 |
#endif |
| 605 |
ex = x; |
| 606 |
ey = y; |
| 607 |
ew = w; |
| 608 |
eh = h; |
| 609 |
CD; |
| 610 |
reset_clip(); |
| 611 |
if (help_is_showing) |
| 612 |
help_redraw(); |
| 613 |
else |
| 614 |
redraw_cb(); |
| 615 |
redraw_centered_pic(); |
| 616 |
#if TRACE_INVALIDATE |
| 617 |
printf(" - done invalidate\n"); |
| 618 |
#endif |
| 619 |
ex = ox; |
| 620 |
ey = oy; |
| 621 |
ew = ow; |
| 622 |
eh = oh; |
| 623 |
reset_clip(); |
| 624 |
CD; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
void |
| 630 |
invalidate_exposure(int ox, int oy, int ow, int oh, |
| 631 |
int nx, int ny, int nw, int nh) |
| 632 |
{ |
| 633 |
int oex = ex; |
| 634 |
int oey = ey; |
| 635 |
int oew = ew; |
| 636 |
int oeh = eh; |
| 637 |
if (graphics_disabled) return; |
| 638 |
|
| 639 |
#if TRACE_INVALIDATE |
| 640 |
printf("invalidate_exposure(%d, %d, %d, %d - %d, %d, %d, %d)\n", |
| 641 |
ox, oy, ow, oh, nx, ny, nw, nh); |
| 642 |
#endif |
| 643 |
|
| 644 |
|
| 645 |
if (ox+ow <= nx || ox >= nx+nw || oy+oh <= ny || oy >= ny+nh) |
| 646 |
{ |
| 647 |
#if TRACE_INVALIDATE |
| 648 |
printf("- not overlapping\n"); |
| 649 |
#endif |
| 650 |
invalidate_sub(ox, oy, ow, oh); |
| 651 |
ex = oex; |
| 652 |
ey = oey; |
| 653 |
ew = oew; |
| 654 |
eh = oeh; |
| 655 |
CD; |
| 656 |
return; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
if (nx+nw < ox+ow) |
| 662 |
{ |
| 663 |
#if TRACE_INVALIDATE |
| 664 |
printf("- exposed on right\n"); |
| 665 |
#endif |
| 666 |
invalidate_sub(nx+nw, oy, (ox+ow)-(nx+nw), oh); |
| 667 |
ow = (nx+nw) - ox; |
| 668 |
} |
| 669 |
|
| 670 |
if (ox < nx) |
| 671 |
{ |
| 672 |
#if TRACE_INVALIDATE |
| 673 |
printf("- exposed on left\n"); |
| 674 |
#endif |
| 675 |
invalidate_sub(ox, oy, (nx-ox), oh); |
| 676 |
ow = (ox+ow) - nx; |
| 677 |
ox = nx; |
| 678 |
} |
| 679 |
|
| 680 |
if (ny+nh < oy+oh) |
| 681 |
{ |
| 682 |
#if TRACE_INVALIDATE |
| 683 |
printf("- exposed on bottom\n"); |
| 684 |
#endif |
| 685 |
invalidate_sub(ox, ny+nh, ow, (oy+oh)-(ny+nh)); |
| 686 |
oh = (ny+nh) - oy; |
| 687 |
} |
| 688 |
|
| 689 |
if (oy < ny) |
| 690 |
{ |
| 691 |
#if TRACE_INVALIDATE |
| 692 |
printf("- exposed on top\n"); |
| 693 |
#endif |
| 694 |
invalidate_sub(ox, oy, ow, (ny-oy)); |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
} |
| 699 |
ex = oex; |
| 700 |
ey = oey; |
| 701 |
ew = oew; |
| 702 |
eh = oeh; |
| 703 |
CD; |
| 704 |
|
| 705 |
#if TRACE_INVALIDATE |
| 706 |
printf("- done invalidate_exposure\n"); |
| 707 |
#endif |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
static int |
| 712 |
snap_one(int x, int step, int origin, int m, int *did_it) |
| 713 |
{ |
| 714 |
int offset, dx; |
| 715 |
|
| 716 |
x -= origin; |
| 717 |
dx = ((x+step/2) % step) - step/2; |
| 718 |
if (-m <= dx && dx <= m) |
| 719 |
{ |
| 720 |
x -= dx; |
| 721 |
*did_it = 1; |
| 722 |
} |
| 723 |
|
| 724 |
x += origin; |
| 725 |
return x; |
| 726 |
} |
| 727 |
|
| 728 |
void |
| 729 |
snap_to_grid(int *x, int *y, |
| 730 |
int step_x, int step_y, |
| 731 |
int origin_x, int origin_y, |
| 732 |
int max_distance) |
| 733 |
{ |
| 734 |
int sx, sy, snapx=0, snapy=0; |
| 735 |
sx = snap_one(*x, step_x, origin_x, max_distance, &snapx); |
| 736 |
sy = snap_one(*y, step_y, origin_y, max_distance, &snapy); |
| 737 |
if (snapx && snapy) |
| 738 |
{ |
| 739 |
*x = sx; |
| 740 |
*y = sy; |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
static char *suit_spots[] = { |
| 745 |
"15", |
| 746 |
"101:", |
| 747 |
"10151:", |
| 748 |
"00200:2:", |
| 749 |
"0020150:2:", |
| 750 |
"002005250:2:", |
| 751 |
"00201205250:2:", |
| 752 |
"0020032307270:2:", |
| 753 |
"002003231507270:2:", |
| 754 |
"00201104240626190:2:" |
| 755 |
}; |
| 756 |
|
| 757 |
static int spot_xx[] = { 0, 50, 100 }; |
| 758 |
static int spot_yy[] = { 0, 16, 25, 33, 36, 50, 63, 66, 75, 83, 100 }; |
| 759 |
|
| 760 |
static void |
| 761 |
card_synth2(image *rv) |
| 762 |
{ |
| 763 |
image *face_img, *img; |
| 764 |
int face, suit, color; |
| 765 |
static char face_chars[] = "a234567890jqk"; |
| 766 |
static char suit_chars[] = "cdsh"; |
| 767 |
int subw, subh, face_w, w; |
| 768 |
int width = rv->width, height = rv->height; |
| 769 |
image_list *list = rv->list; |
| 770 |
|
| 771 |
fill_image (rv, 0, 0, width, height, 255, 255, 255); |
| 772 |
|
| 773 |
face = strchr(face_chars, list->name[0]) - face_chars; |
| 774 |
suit = strchr(suit_chars, list->name[1]) - suit_chars; |
| 775 |
color = suit & 1; |
| 776 |
|
| 777 |
face_w = width*2/11; |
| 778 |
face_img = get_image("a-k", face_w*2, face_w*13, 0); |
| 779 |
face_w = face_img->width / face_img->list->across; |
| 780 |
|
| 781 |
if (face < 10 && width > 3*face_w) |
| 782 |
{ |
| 783 |
char *spots = suit_spots[face]; |
| 784 |
int sw, sh; |
| 785 |
if (face == 0) |
| 786 |
{ |
| 787 |
sw = width; |
| 788 |
sh = height; |
| 789 |
} |
| 790 |
else |
| 791 |
{ |
| 792 |
sw = (width - 2*face_w) / 3; |
| 793 |
sh = (height - 2*face_w) / 4; |
| 794 |
} |
| 795 |
if (face == 0 && suit == 2) |
| 796 |
img = get_image("penguin", sw, sh, GI_NOT_BIGGER); |
| 797 |
else |
| 798 |
img = get_image("suits", sw, sh*4, GI_NOT_BIGGER); |
| 799 |
if (img) |
| 800 |
{ |
| 801 |
int spw, sph, spoh, spow; |
| 802 |
sw = img->width / img->list->across; |
| 803 |
sh = img->height / img->list->down; |
| 804 |
spow = face_w + 2; |
| 805 |
spoh = face_w*3/4 + 2; |
| 806 |
spw = width - 2*spow - sw; |
| 807 |
sph = height - 2*spoh - sh; |
| 808 |
while (*spots) |
| 809 |
{ |
| 810 |
int sx = spot_xx[spots[0]-'0'] * spw / 100 + spow; |
| 811 |
int sy = spot_yy[spots[1]-'0'] * sph / 100 + spoh; |
| 812 |
put_subimage (img, 0, suit, rv, sx, sy, |
| 813 |
spot_yy[spots[1]-'0'] > 51 ? PUT_ROTATED : 0); |
| 814 |
spots += 2; |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
if (face >= 10 && width > 3*face_w) |
| 820 |
{ |
| 821 |
int wm = face_w+2; |
| 822 |
int hm = face_w*3/4+2; |
| 823 |
int w2 = width-2*wm; |
| 824 |
int h2 = height-2*hm; |
| 825 |
image *kqj, *simg; |
| 826 |
static char *portrait[] = {"jack", "queen", "king"}; |
| 827 |
|
| 828 |
fill_image (rv, wm, hm, w2, 1, 0, 0, 0); |
| 829 |
fill_image (rv, wm, hm, 1, h2, 0, 0, 0); |
| 830 |
fill_image (rv, wm, height-hm, w2, 1, 0, 0, 0); |
| 831 |
fill_image (rv, width-wm, hm, 1, h2, 0, 0, 0); |
| 832 |
|
| 833 |
simg = get_image("suits", w2/3, w2*4/3, 0); |
| 834 |
|
| 835 |
kqj = get_image(portrait[face-10], w2, h2/2, GI_NOT_BIGGER); |
| 836 |
if (!kqj) |
| 837 |
kqj = get_image(portrait[face-10], w2, h2, GI_NOT_BIGGER); |
| 838 |
|
| 839 |
if (simg) |
| 840 |
{ |
| 841 |
put_subimage (simg, 0, suit, rv, wm+2, hm+2, 0); |
| 842 |
put_subimage (simg, 0, suit, rv, width-wm-1-simg->width, height-hm-1-simg->height/4, PUT_ROTATED); |
| 843 |
} |
| 844 |
|
| 845 |
if (kqj && kqj->height <= h2/2) |
| 846 |
{ |
| 847 |
put_subimage (kqj, 0, 0, rv, width-wm-kqj->width, height/2-kqj->height, 0); |
| 848 |
put_subimage (kqj, 0, 0, rv, wm+1, (height+1)/2, PUT_ROTATED); |
| 849 |
} |
| 850 |
else if (kqj && kqj->height <= h2/2+3) |
| 851 |
{ |
| 852 |
put_subimage (kqj, 0, 0, rv, width-wm-kqj->width, hm+1, 0); |
| 853 |
put_subimage (kqj, 0, 0, rv, wm+1, height-hm-kqj->height, PUT_ROTATED); |
| 854 |
} |
| 855 |
else if (kqj) |
| 856 |
{ |
| 857 |
put_subimage (kqj, 0, 0, rv, (width+1-kqj->width)/2, (height+1-kqj->height)/2, 0); |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
fill_image (rv, 0, 0, width, 1, 0, 0, 0); |
| 862 |
fill_image (rv, 0, 0, 1, height, 0, 0, 0); |
| 863 |
fill_image (rv, 0, height-1, width, 1, 0, 0, 0); |
| 864 |
fill_image (rv, width-1, 0, 1, height, 0, 0, 0); |
| 865 |
|
| 866 |
put_subimage (face_img, color, face, rv, 1, 2, 0); |
| 867 |
subw = face_img->width / face_img->list->across; |
| 868 |
subh = face_img->height / face_img->list->down; |
| 869 |
if (width > subw*2+4) |
| 870 |
put_subimage (face_img, color, face, rv, width-1-subw, height-2-subh, PUT_ROTATED); |
| 871 |
|
| 872 |
img = get_image("suits", subw-2, (subw-2)*4, GI_NOT_BIGGER); |
| 873 |
put_subimage (img, 0, suit, rv, 1+subw/2-img->width/2, 4+subh, 0); |
| 874 |
if (width > subw*2+4) |
| 875 |
put_subimage (img, 0, suit, rv, |
| 876 |
width-1-subw/2-img->width/2, height-4-subh-img->height/img->list->down, |
| 877 |
PUT_ROTATED); |
| 878 |
} |
| 879 |
|
| 880 |
static image * |
| 881 |
card_synth(image_list *list, int type, int width, int height) |
| 882 |
{ |
| 883 |
image *rv; |
| 884 |
static int minw=0, minh=0; |
| 885 |
|
| 886 |
for (rv = list->subimage[type]; rv; rv=rv->next) |
| 887 |
if (rv->width == width && rv->height == height) |
| 888 |
return rv; |
| 889 |
|
| 890 |
if (minw == 0) |
| 891 |
{ |
| 892 |
image *val, *suit; |
| 893 |
int face_w = width*2/11; |
| 894 |
val = get_image("a-k", face_w*2, face_w*13, 0); |
| 895 |
suit = get_image("suits", 9, 9*4, 0); |
| 896 |
minw = val->width / val->list->across + 2; |
| 897 |
minh = val->height / val->list->down + suit->height / suit->list->down + 6; |
| 898 |
} |
| 899 |
|
| 900 |
if (width < minw) |
| 901 |
width = minw; |
| 902 |
if (height < minh) |
| 903 |
height = minh; |
| 904 |
|
| 905 |
rv = alloc_synth_image(list, width, height, type); |
| 906 |
rv->synth_func = card_synth2; |
| 907 |
return rv; |
| 908 |
} |
| 909 |
|
| 910 |
static void |
| 911 |
empty_synth2(image *img) |
| 912 |
{ |
| 913 |
fill_image (img, 0, 0, img->width, img->height, 0, 102, 0); |
| 914 |
fill_image (img, 0, img->height-1, img->width, 1, 0, 0, 0); |
| 915 |
fill_image (img, img->width-1, 0, 1, img->height, 0, 0, 0); |
| 916 |
fill_image (img, 0, 0, img->width, 1, 0, 204, 0); |
| 917 |
fill_image (img, 0, 0, 1, img->height, 0, 204, 0); |
| 918 |
} |
| 919 |
|
| 920 |
static image * |
| 921 |
empty_synth(image_list *list, int type, int width, int height) |
| 922 |
{ |
| 923 |
image *rv, *img; |
| 924 |
|
| 925 |
for (rv = list->subimage[type]; rv; rv=rv->next) |
| 926 |
if (rv->width == width && rv->height == height) |
| 927 |
return rv; |
| 928 |
|
| 929 |
rv = alloc_synth_image(list, width, height, type); |
| 930 |
rv->synth_func = empty_synth2; |
| 931 |
return rv; |
| 932 |
} |
| 933 |
|
| 934 |
static void |
| 935 |
back_synth2(image *img) |
| 936 |
{ |
| 937 |
image *tile = get_image ("back-tile", 1, 1, 0); |
| 938 |
int xo, yo, size; |
| 939 |
int x, y, l, r; |
| 940 |
int xs[6]; |
| 941 |
int x01, x23, x24, x25; |
| 942 |
|
| 943 |
for (x=0; x<img->width; x += tile->width) |
| 944 |
for (y=0; y<img->height; y += tile->height) |
| 945 |
put_image (tile, 0, 0, tile->width, tile->height, img, x, y, 0); |
| 946 |
fill_image (img, 0, img->height-1, img->width, 1, 0, 0, 0); |
| 947 |
fill_image (img, img->width-1, 0, 1, img->height, 0, 0, 0); |
| 948 |
fill_image (img, 0, 0, img->width, 1, 0, 0, 0); |
| 949 |
fill_image (img, 0, 0, 1, img->height, 0, 0, 0); |
| 950 |
|
| 951 |
if (img->width < img->height) |
| 952 |
size = img->width * 2/3; |
| 953 |
else |
| 954 |
size = img->height * 2/3; |
| 955 |
xo = (img->width - size) / 2; |
| 956 |
yo = (img->height - size) / 2; |
| 957 |
|
| 958 |
x = (size-1) * 203 / 256; |
| 959 |
x25 = size - 1 - x; |
| 960 |
x23 = x25 * 105 / 256; |
| 961 |
x24 = x25 - x23; |
| 962 |
|
| 963 |
x = (size-1) * 200 / 256; |
| 964 |
x01 = size - 1 - x; |
| 965 |
|
| 966 |
for (y=0; y<size; y++) |
| 967 |
{ |
| 968 |
xs[0] = y * 192/256; |
| 969 |
xs[1] = xs[0] + x01; |
| 970 |
xs[2] = (size-1-y) * 203/256; |
| 971 |
xs[3] = xs[2] + x23; |
| 972 |
xs[4] = xs[2] + x24; |
| 973 |
xs[5] = xs[2] + x25; |
| 974 |
|
| 975 |
l = (xs[0] < xs[2]) ? xs[0] : xs[2]; |
| 976 |
r = (xs[1] < xs[3]) ? xs[1] : xs[3]; |
| 977 |
fill_image (img, l+xo, y+yo, r-l+1, 1, 0, 0, 0); |
| 978 |
|
| 979 |
l = (xs[0] > xs[4]) ? xs[0] : xs[4]; |
| 980 |
r = (xs[1] > xs[5]) ? xs[1] : xs[5]; |
| 981 |
fill_image (img, l+xo, y+yo, r-l+1, 1, 0, 0, 0); |
| 982 |
} |
| 983 |
|
| 984 |
} |
| 985 |
|
| 986 |
static image * |
| 987 |
back_synth(image_list *list, int type, int width, int height) |
| 988 |
{ |
| 989 |
image *rv, *img; |
| 990 |
|
| 991 |
for (rv = list->subimage[type]; rv; rv=rv->next) |
| 992 |
if (rv->width == width && rv->height == height) |
| 993 |
return rv; |
| 994 |
|
| 995 |
rv = alloc_synth_image(list, width, height, type); |
| 996 |
rv->synth_func = back_synth2; |
| 997 |
return rv; |
| 998 |
} |
| 999 |
|
| 1000 |
static image_list card_images[] = { |
| 1001 |
{ "ac", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1002 |
{ "ad", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1003 |
{ "as", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1004 |
{ "ah", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1005 |
{ "2c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1006 |
{ "2d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1007 |
{ "2s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1008 |
{ "2h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1009 |
{ "3c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1010 |
{ "3d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1011 |
{ "3s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1012 |
{ "3h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1013 |
{ "4c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1014 |
{ "4d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1015 |
{ "4s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1016 |
{ "4h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1017 |
{ "5c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1018 |
{ "5d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1019 |
{ "5s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1020 |
{ "5h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1021 |
{ "6c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1022 |
{ "6d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1023 |
{ "6s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1024 |
{ "6h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1025 |
{ "7c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1026 |
{ "7d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1027 |
{ "7s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1028 |
{ "7h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1029 |
{ "8c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1030 |
{ "8d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1031 |
{ "8s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1032 |
{ "8h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1033 |
{ "9c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1034 |
{ "9d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1035 |
{ "9s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1036 |
{ "9h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1037 |
{ "0c", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1038 |
{ "0d", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1039 |
{ "0s", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1040 |
{ "0h", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1041 |
{ "jc", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1042 |
{ "jd", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1043 |
{ "js", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1044 |
{ "jh", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1045 |
{ "qc", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1046 |
{ "qd", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1047 |
{ "qs", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1048 |
{ "qh", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1049 |
{ "kc", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1050 |
{ "kd", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1051 |
{ "ks", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1052 |
{ "kh", 1, 1, {0,0,0}, 0, card_synth, 0 }, |
| 1053 |
{ "empty", 1, 1, {0,0,0}, 0, empty_synth, 0 }, |
| 1054 |
{ "back", 1, 1, {0,0,0}, 0, back_synth, 0 }, |
| 1055 |
{ 0 } |
| 1056 |
}; |
| 1057 |
|