| 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 |
#include "angband.h" |
| 58 |
#include "buildid.h" |
| 59 |
#include "cmds.h" |
| 60 |
#include "cave.h" |
| 61 |
#include "game-world.h" |
| 62 |
#include "grafmode.h" |
| 63 |
#include "init.h" |
| 64 |
#include "savefile.h" |
| 65 |
#include "ui-command.h" |
| 66 |
#include "ui-display.h" |
| 67 |
#include "ui-game.h" |
| 68 |
#include "ui-init.h" |
| 69 |
#include "ui-input.h" |
| 70 |
#include "ui-map.h" |
| 71 |
#include "ui-output.h" |
| 72 |
#include "ui-prefs.h" |
| 73 |
#include "win/win-menu.h" |
| 74 |
|
| 75 |
|
| 76 |
#if (WINVER < 0x0500) |
| 77 |
#define WINVER 0x0500 |
| 78 |
#endif |
| 79 |
|
| 80 |
#include <locale.h> |
| 81 |
|
| 82 |
#define uint unsigned int |
| 83 |
|
| 84 |
#if defined(WINDOWS) && !defined(USE_SDL) && !defined(USE_SDL2) |
| 85 |
|
| 86 |
#include "sound.h" |
| 87 |
#include "snd-win.h" |
| 88 |
|
| 89 |
#define HAS_CLEANUP |
| 90 |
|
| 91 |
#ifdef ALLOW_BORG |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
#define USE_SAVER |
| 97 |
|
| 98 |
#endif |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
#define STRICT |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
#define NOCOMM |
| 109 |
#define NOLOGERROR |
| 110 |
#define NOPROFILER |
| 111 |
#define NOLFILEIO |
| 112 |
#define NOOPENFILE |
| 113 |
#define NORESOURCE |
| 114 |
#define NOATOM |
| 115 |
#define NOLANGUAGE |
| 116 |
#define NOLSTRING |
| 117 |
#define NODBCS |
| 118 |
#define NOKEYBOARDINFO |
| 119 |
#define NOCOLOR |
| 120 |
#define NODRAWTEXT |
| 121 |
#define NOSCALABLEFONT |
| 122 |
#define NOMETAFILE |
| 123 |
#define NOSYSTEMPARAMSINFO |
| 124 |
#define NODEFERWINDOWPOS |
| 125 |
#define NOKEYSTATES |
| 126 |
#define NOWH |
| 127 |
#define NOCLIPBOARD |
| 128 |
#define NOICONS |
| 129 |
#define NOMDI |
| 130 |
#define NOHELP |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
#define WIN32_LEAN_AND_MEAN |
| 139 |
|
| 140 |
#define NOSERVICE |
| 141 |
#define NOKANJI |
| 142 |
#define NOMCX |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
#include <windows.h> |
| 148 |
#include <windowsx.h> |
| 149 |
|
| 150 |
#ifndef GetWindowLongPtr |
| 151 |
#define GetWindowLongPtr GetWindowLong |
| 152 |
#endif |
| 153 |
#ifndef SetWindowLongPtr |
| 154 |
#define SetWindowLongPtr SetWindowLong |
| 155 |
#endif |
| 156 |
#ifndef GWLP_USERDATA |
| 157 |
#define GWLP_USERDATA GWL_USERDATA |
| 158 |
#endif |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
#define MMNODRV |
| 164 |
#define MMNOWAVE |
| 165 |
#define MMNOMIDI |
| 166 |
#define MMNOAUX |
| 167 |
#define MMNOTIMER |
| 168 |
#define MMNOJOY |
| 169 |
|
| 170 |
#define MMNOMMIO |
| 171 |
#define MMNOMMSYSTEM |
| 172 |
|
| 173 |
#include <mmsystem.h> |
| 174 |
|
| 175 |
#include <commdlg.h> |
| 176 |
#include <shellapi.h> |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
#include "win/readdib.h" |
| 182 |
#include "win/scrnshot.h" |
| 183 |
|
| 184 |
#include <wingdi.h> |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
#define INVALID_FILE_NAME (DWORD)0xFFFFFFFF |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
#define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL) |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
#ifndef WS_EX_TOOLWINDOW |
| 200 |
# define WS_EX_TOOLWINDOW 0 |
| 201 |
#endif |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
#define VID_BLACK 0x00 |
| 207 |
#define VID_BLUE 0x01 |
| 208 |
#define VID_GREEN 0x02 |
| 209 |
#define VID_CYAN 0x03 |
| 210 |
#define VID_RED 0x04 |
| 211 |
#define VID_MAGENTA 0x05 |
| 212 |
#define VID_YELLOW 0x06 |
| 213 |
#define VID_WHITE 0x07 |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
#define VID_BRIGHT 0x08 |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
#define VUD_BLACK 0x00 |
| 224 |
#define VUD_BLUE 0x10 |
| 225 |
#define VUD_GREEN 0x20 |
| 226 |
#define VUD_CYAN 0x30 |
| 227 |
#define VUD_RED 0x40 |
| 228 |
#define VUD_MAGENTA 0x50 |
| 229 |
#define VUD_YELLOW 0x60 |
| 230 |
#define VUD_WHITE 0x70 |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
#define VUD_BRIGHT 0x80 |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
#define DEFAULT_FONT "8X12x.FON" |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
#include "win/win-term.h" |
| 254 |
|
| 255 |
bool use_graphics_nice; |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
static term_data data[MAX_TERM_DATA]; |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
static term_data *my_td; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
bool game_in_progress = false; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
bool initialized = false; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
static HANDLE multapp_file = INVALID_HANDLE_VALUE; |
| 287 |
static bool create_savefile_tracking_file(bool message_on_failure); |
| 288 |
static bool monitor_existing_savefile(void); |
| 289 |
static void monitor_new_savefile(game_event_type ev_type, |
| 290 |
game_event_data *ev_data, void *user); |
| 291 |
static void finish_monitoring_savefile(game_event_type ev_type, |
| 292 |
game_event_data *ev_data, void *user); |
| 293 |
|
| 294 |
|
| 295 |
size_t Term_mbstowcs_win(wchar_t* dest, const char* src, int n); |
| 296 |
int Term_wcsz_win(void); |
| 297 |
int Term_wctomb_win(char* s, wchar_t wchar); |
| 298 |
int Term_iswprint_win(wint_t wc); |
| 299 |
LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
bool paletted = false; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
bool colors16 = false; |
| 311 |
|
| 312 |
static bool low_priority = false; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
static HINSTANCE hInstance; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
static HBRUSH hbrYellow; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
static HICON hIcon; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
static HPALETTE hPal; |
| 333 |
|
| 334 |
|
| 335 |
#ifdef USE_SAVER |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
static HWND hwndSaver; |
| 341 |
|
| 342 |
static HANDLE screensaverSemaphore; |
| 343 |
|
| 344 |
static char saverfilename[1024]; |
| 345 |
|
| 346 |
static HMENU main_menu; |
| 347 |
|
| 348 |
#define MOUSE_SENS 10 |
| 349 |
|
| 350 |
#endif |
| 351 |
|
| 352 |
static bool screensaver_active = false; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
static bool can_use_graphics = false; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
static bool change_tilesize = false; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
static DIBINIT infGraph; |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
static DIBINIT infMask; |
| 374 |
|
| 375 |
static int overdraw = 0; |
| 376 |
static int overdrawmax = -1; |
| 377 |
|
| 378 |
static int alphablend = 0; |
| 379 |
static BLENDFUNCTION blendfn; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
static char *ini_file = NULL; |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
static const char *AppName = VERSION_NAME; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
static const char *AngList = "AngList"; |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
static COLORREF win_clr[MAX_COLORS]; |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
static uint8_t win_pal[MAX_COLORS] = |
| 412 |
{ |
| 413 |
VID_BLACK, |
| 414 |
VID_WHITE, |
| 415 |
VID_CYAN, |
| 416 |
VID_RED | VID_BRIGHT, |
| 417 |
VID_RED, |
| 418 |
VID_GREEN, |
| 419 |
VID_BLUE, |
| 420 |
VID_YELLOW, |
| 421 |
VID_BLACK | VID_BRIGHT, |
| 422 |
VID_CYAN | VID_BRIGHT, |
| 423 |
VID_MAGENTA, |
| 424 |
VID_YELLOW | VID_BRIGHT, |
| 425 |
VID_MAGENTA | VID_BRIGHT, |
| 426 |
VID_GREEN | VID_BRIGHT, |
| 427 |
VID_BLUE | VID_BRIGHT, |
| 428 |
VID_YELLOW |
| 429 |
}; |
| 430 |
|
| 431 |
|
| 432 |
static int gamma_correction; |
| 433 |
|
| 434 |
static void show_win_error(void) |
| 435 |
{ |
| 436 |
LPVOID lpMsgBuf; |
| 437 |
|
| 438 |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 439 |
NULL, GetLastError(), |
| 440 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 441 |
(LPTSTR) &lpMsgBuf, 0, NULL); |
| 442 |
|
| 443 |
MessageBox(NULL, lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION); |
| 444 |
|
| 445 |
LocalFree(lpMsgBuf); |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
static char *analyze_font(char *path, int *wp, int *hp) |
| 455 |
{ |
| 456 |
int wid, hgt; |
| 457 |
|
| 458 |
char *s, *p; |
| 459 |
|
| 460 |
|
| 461 |
p = path + strlen(path) - 1; |
| 462 |
|
| 463 |
|
| 464 |
while ((p >= path) && (*p != ':') && (*p != '\\')) --p; |
| 465 |
|
| 466 |
|
| 467 |
++p; |
| 468 |
|
| 469 |
|
| 470 |
for (s = p; *s; ++s) { |
| 471 |
|
| 472 |
if (islower((unsigned char)*s)) *s = toupper((unsigned char)*s); |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
s = strchr(p, 'X'); |
| 477 |
|
| 478 |
|
| 479 |
wid = atoi(p); |
| 480 |
|
| 481 |
|
| 482 |
hgt = s ? atoi(s+1) : 0; |
| 483 |
|
| 484 |
|
| 485 |
(*wp) = wid; |
| 486 |
(*hp) = hgt; |
| 487 |
|
| 488 |
|
| 489 |
return (p); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
static bool check_dir(const char *s) |
| 497 |
{ |
| 498 |
int i; |
| 499 |
char path[1024]; |
| 500 |
DWORD attrib; |
| 501 |
|
| 502 |
|
| 503 |
my_strcpy(path, s, sizeof(path)); |
| 504 |
|
| 505 |
|
| 506 |
i = strlen(path); |
| 507 |
|
| 508 |
|
| 509 |
if (i && (path[i-1] == '\\')) path[--i] = '\0'; |
| 510 |
|
| 511 |
|
| 512 |
attrib = GetFileAttributes(path); |
| 513 |
|
| 514 |
|
| 515 |
if (attrib == INVALID_FILE_NAME) return (false); |
| 516 |
|
| 517 |
|
| 518 |
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (false); |
| 519 |
|
| 520 |
|
| 521 |
return (true); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
static void validate_file(const char *s) |
| 529 |
{ |
| 530 |
|
| 531 |
if (!file_exists(s)) |
| 532 |
quit_fmt("Cannot find required file:\n%s", s); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
static void validate_dir(const char *s) |
| 540 |
{ |
| 541 |
|
| 542 |
if (!check_dir(s)) |
| 543 |
quit_fmt("Cannot find required directory:\n%s", s); |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
static void term_getsize(term_data *td) |
| 551 |
{ |
| 552 |
RECT rc; |
| 553 |
|
| 554 |
int wid, hgt; |
| 555 |
|
| 556 |
|
| 557 |
if (td->cols < 1) td->cols = 1; |
| 558 |
if (td->rows < 1) td->rows = 1; |
| 559 |
|
| 560 |
if (use_graphics_nice) { |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
const struct { int w, h; } multipliers[] = { |
| 567 |
{ 1, 1 }, |
| 568 |
{ 2, 1 }, |
| 569 |
{ 3, 1 }, |
| 570 |
{ 2, 2 }, |
| 571 |
{ 4, 2 }, |
| 572 |
{ 3, 3 }, |
| 573 |
{ 4, 4 }, |
| 574 |
{ 6, 3 }, |
| 575 |
{ 8, 4 }, |
| 576 |
{ 6, 6 }, |
| 577 |
{ 8, 8 }, |
| 578 |
{ 16, 8 }, |
| 579 |
{ 16, 16 }, |
| 580 |
}; |
| 581 |
long best; |
| 582 |
int ibest, i; |
| 583 |
|
| 584 |
if (current_graphics_mode && current_graphics_mode->grafID) { |
| 585 |
if (current_graphics_mode->file[0]) { |
| 586 |
char *end; |
| 587 |
td->tile_wid = strtol( |
| 588 |
current_graphics_mode->file,&end,10); |
| 589 |
td->tile_hgt = strtol(end+1,NULL,10); |
| 590 |
} else { |
| 591 |
td->tile_wid = |
| 592 |
current_graphics_mode->cell_width; |
| 593 |
td->tile_hgt = |
| 594 |
current_graphics_mode->cell_height; |
| 595 |
} |
| 596 |
if ((td->tile_wid == 0) || (td->tile_hgt == 0)) { |
| 597 |
td->tile_wid = |
| 598 |
current_graphics_mode->cell_width; |
| 599 |
td->tile_hgt = |
| 600 |
current_graphics_mode->cell_height; |
| 601 |
} |
| 602 |
if ((td->tile_wid == 0) || (td->tile_hgt == 0)) { |
| 603 |
td->tile_wid = td->font_wid; |
| 604 |
td->tile_hgt = td->font_hgt; |
| 605 |
} |
| 606 |
} else { |
| 607 |
|
| 608 |
td->tile_wid = td->font_wid; |
| 609 |
td->tile_hgt = td->font_hgt; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
if (td->tile_wid <= (2 * td->font_wid) / 3 |
| 618 |
|| td->tile_hgt <= (2 * td->font_wid) / 3) { |
| 619 |
int area_ratio = (int) (((long) td->font_wid |
| 620 |
* (long) td->font_hgt + ((long) td->tile_wid |
| 621 |
* (long) td->tile_hgt) / 2) |
| 622 |
/ ((long) td->tile_wid * (long) td->tile_hgt)); |
| 623 |
|
| 624 |
best = abs((long) td->font_wid * (long) td->font_hgt |
| 625 |
- (long) td->tile_wid * (long) td->tile_hgt); |
| 626 |
ibest = 1; |
| 627 |
i = 2; |
| 628 |
while (!best && (i - 1) * (i - 1) <= area_ratio) { |
| 629 |
int try_best = abs((long) td->font_wid |
| 630 |
* (long) td->font_hgt |
| 631 |
- ((long) td->tile_wid * i) |
| 632 |
* ((long) td->tile_hgt * i)); |
| 633 |
|
| 634 |
if (best > try_best) { |
| 635 |
best = try_best; |
| 636 |
ibest = i; |
| 637 |
} |
| 638 |
++i; |
| 639 |
} |
| 640 |
td->tile_wid *= i; |
| 641 |
td->tile_hgt *= i; |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
ibest = -1; |
| 650 |
best = (long) td->tile_wid * (long) td->tile_hgt; |
| 651 |
for (i = 0; i < (int) N_ELEMENTS(multipliers) && best; ++i) { |
| 652 |
uint sclw = td->font_wid * multipliers[i].w; |
| 653 |
uint sclh = td->font_hgt * multipliers[i].h; |
| 654 |
|
| 655 |
if (sclw <= td->tile_wid && sclh <= td->tile_hgt) { |
| 656 |
int try_best = abs( |
| 657 |
(long) td->tile_wid |
| 658 |
* (long) td->tile_hgt |
| 659 |
- (long) sclw * (long) sclh); |
| 660 |
|
| 661 |
if (best > try_best) { |
| 662 |
best = try_best; |
| 663 |
ibest = i; |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
if (ibest >= 0) { |
| 669 |
tile_width = multipliers[ibest].w; |
| 670 |
tile_height = multipliers[ibest].h; |
| 671 |
td->tile_wid /= tile_width; |
| 672 |
td->tile_hgt /= tile_height; |
| 673 |
} else { |
| 674 |
tile_width = 1; |
| 675 |
tile_height = 1; |
| 676 |
} |
| 677 |
|
| 678 |
if (td->tile_wid < td->font_wid) td->tile_wid = td->font_wid; |
| 679 |
if (td->tile_hgt < td->font_hgt) td->tile_hgt = td->font_hgt; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2; |
| 684 |
hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2; |
| 685 |
|
| 686 |
|
| 687 |
rc.left = 0; |
| 688 |
rc.right = rc.left + wid; |
| 689 |
rc.top = 0; |
| 690 |
rc.bottom = rc.top + hgt; |
| 691 |
|
| 692 |
|
| 693 |
AdjustWindowRectEx(&rc, td->dwStyle, true, td->dwExStyle); |
| 694 |
|
| 695 |
|
| 696 |
td->size_wid = rc.right - rc.left; |
| 697 |
td->size_hgt = rc.bottom - rc.top; |
| 698 |
|
| 699 |
|
| 700 |
if (!td->w) return; |
| 701 |
|
| 702 |
|
| 703 |
GetWindowRect(td->w, &rc); |
| 704 |
|
| 705 |
|
| 706 |
td->pos_x = rc.left; |
| 707 |
td->pos_y = rc.top; |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
static void save_prefs_aux(term_data *td, const char *sec_name) |
| 715 |
{ |
| 716 |
char buf[1024]; |
| 717 |
|
| 718 |
RECT rc; |
| 719 |
|
| 720 |
WINDOWPLACEMENT lpwndpl; |
| 721 |
|
| 722 |
|
| 723 |
if (!td->w) return; |
| 724 |
|
| 725 |
|
| 726 |
my_strcpy(buf, td->visible ? "1" : "0", sizeof(buf)); |
| 727 |
WritePrivateProfileStringA(sec_name, "Visible", buf, ini_file); |
| 728 |
|
| 729 |
|
| 730 |
my_strcpy(buf, td->font_file ? td->font_file : DEFAULT_FONT, sizeof(buf)); |
| 731 |
WritePrivateProfileStringA(sec_name, "Font", buf, ini_file); |
| 732 |
|
| 733 |
|
| 734 |
my_strcpy(buf, td->bizarre ? "1" : "0", sizeof(buf)); |
| 735 |
WritePrivateProfileStringA(sec_name, "Bizarre", buf, ini_file); |
| 736 |
|
| 737 |
|
| 738 |
strnfmt(buf, sizeof(buf), "%d", td->tile_wid); |
| 739 |
WritePrivateProfileStringA(sec_name, "TileWid", buf, ini_file); |
| 740 |
|
| 741 |
|
| 742 |
strnfmt(buf, sizeof(buf), "%d", td->tile_hgt); |
| 743 |
WritePrivateProfileStringA(sec_name, "TileHgt", buf, ini_file); |
| 744 |
|
| 745 |
|
| 746 |
strnfmt(buf, sizeof(buf), "%d", td->cols); |
| 747 |
WritePrivateProfileStringA(sec_name, "NumCols", buf, ini_file); |
| 748 |
|
| 749 |
|
| 750 |
strnfmt(buf, sizeof(buf), "%d", td->rows); |
| 751 |
WritePrivateProfileStringA(sec_name, "NumRows", buf, ini_file); |
| 752 |
|
| 753 |
|
| 754 |
lpwndpl.length = sizeof(WINDOWPLACEMENT); |
| 755 |
GetWindowPlacement(td->w, &lpwndpl); |
| 756 |
|
| 757 |
|
| 758 |
rc = lpwndpl.rcNormalPosition; |
| 759 |
|
| 760 |
|
| 761 |
if (lpwndpl.showCmd & SW_SHOWMAXIMIZED) |
| 762 |
td->maximized = true; |
| 763 |
else |
| 764 |
td->maximized = false; |
| 765 |
|
| 766 |
|
| 767 |
strnfmt(buf, sizeof(buf), "%ld", rc.left); |
| 768 |
WritePrivateProfileStringA(sec_name, "PositionX", buf, ini_file); |
| 769 |
|
| 770 |
|
| 771 |
strnfmt(buf, sizeof(buf), "%ld", rc.top); |
| 772 |
WritePrivateProfileStringA(sec_name, "PositionY", buf, ini_file); |
| 773 |
|
| 774 |
|
| 775 |
my_strcpy(buf, td->maximized ? "1" : "0", sizeof(buf)); |
| 776 |
WritePrivateProfileStringA(sec_name, "Maximized", buf, ini_file); |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
static void save_prefs(void) |
| 786 |
{ |
| 787 |
int i; |
| 788 |
|
| 789 |
char buf[128]; |
| 790 |
|
| 791 |
|
| 792 |
strnfmt(buf, sizeof(buf), "%d", arg_graphics); |
| 793 |
WritePrivateProfileStringA("Angband", "Graphics", buf, ini_file); |
| 794 |
|
| 795 |
|
| 796 |
my_strcpy(buf, arg_graphics_nice ? "1" : "0", sizeof(buf)); |
| 797 |
WritePrivateProfileStringA("Angband", "Graphics_Nice", buf, ini_file); |
| 798 |
|
| 799 |
|
| 800 |
strnfmt(buf, sizeof(buf), "%d", tile_width); |
| 801 |
WritePrivateProfileStringA("Angband", "TileWidth", buf, ini_file); |
| 802 |
|
| 803 |
|
| 804 |
strnfmt(buf, sizeof(buf), "%d", tile_height); |
| 805 |
WritePrivateProfileStringA("Angband", "TileHeight", buf, ini_file); |
| 806 |
|
| 807 |
|
| 808 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 809 |
term_data *td = &data[i]; |
| 810 |
|
| 811 |
strnfmt(buf, sizeof(buf), "Term-%d", i); |
| 812 |
|
| 813 |
save_prefs_aux(td, buf); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
static void load_prefs_aux(term_data *td, const char *sec_name) |
| 822 |
{ |
| 823 |
char tmp[1024]; |
| 824 |
|
| 825 |
int wid, hgt; |
| 826 |
|
| 827 |
|
| 828 |
td->visible = (GetPrivateProfileIntA(sec_name, "Visible", td->visible, |
| 829 |
ini_file) != 0); |
| 830 |
|
| 831 |
|
| 832 |
td->maximized = (GetPrivateProfileIntA(sec_name, "Maximized", |
| 833 |
td->maximized, ini_file) != 0); |
| 834 |
|
| 835 |
|
| 836 |
GetPrivateProfileStringA(sec_name, "Font", DEFAULT_FONT, tmp, 127, |
| 837 |
ini_file); |
| 838 |
|
| 839 |
|
| 840 |
td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", true, |
| 841 |
ini_file) != 0); |
| 842 |
|
| 843 |
|
| 844 |
td->font_want = string_make(analyze_font(tmp, &wid, &hgt)); |
| 845 |
|
| 846 |
|
| 847 |
td->tile_wid = GetPrivateProfileIntA(sec_name, "TileWid", wid, ini_file); |
| 848 |
td->tile_hgt = GetPrivateProfileIntA(sec_name, "TileHgt", hgt, ini_file); |
| 849 |
|
| 850 |
|
| 851 |
td->cols = GetPrivateProfileIntA(sec_name, "NumCols", td->cols, ini_file); |
| 852 |
td->rows = GetPrivateProfileIntA(sec_name, "NumRows", td->rows, ini_file); |
| 853 |
|
| 854 |
|
| 855 |
td->pos_x = GetPrivateProfileIntA(sec_name, "PositionX", td->pos_x, |
| 856 |
ini_file); |
| 857 |
td->pos_y = GetPrivateProfileIntA(sec_name, "PositionY", td->pos_y, |
| 858 |
ini_file); |
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
static void load_prefs(void) |
| 866 |
{ |
| 867 |
int i; |
| 868 |
|
| 869 |
char buf[1024]; |
| 870 |
bool first_start; |
| 871 |
|
| 872 |
if (file_exists(ini_file)) { |
| 873 |
first_start = false; |
| 874 |
} else { |
| 875 |
first_start = true; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
arg_graphics = GetPrivateProfileIntA("Angband", "Graphics", |
| 880 |
GRAPHICS_NONE, ini_file); |
| 881 |
|
| 882 |
|
| 883 |
arg_graphics_nice = GetPrivateProfileIntA("Angband", "Graphics_Nice", |
| 884 |
true, ini_file); |
| 885 |
|
| 886 |
|
| 887 |
tile_width = GetPrivateProfileIntA("Angband", "TileWidth", false, |
| 888 |
ini_file); |
| 889 |
|
| 890 |
|
| 891 |
tile_height = GetPrivateProfileIntA("Angband", "TileHeight", false, |
| 892 |
ini_file); |
| 893 |
|
| 894 |
|
| 895 |
arg_wizard = (GetPrivateProfileIntA("Angband", "Wizard", 0, ini_file) != 0); |
| 896 |
|
| 897 |
|
| 898 |
gamma_correction = GetPrivateProfileIntA("Angband", "Gamma", 0, ini_file); |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 903 |
term_data *td = &data[i]; |
| 904 |
|
| 905 |
strnfmt(buf, sizeof(buf), "Term-%d", i); |
| 906 |
|
| 907 |
load_prefs_aux(td, buf); |
| 908 |
} |
| 909 |
|
| 910 |
if (first_start) { |
| 911 |
default_layout_win(data,MAX_TERM_DATA); |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
if (data[0].cols < 80) data[0].cols = 80; |
| 916 |
if (data[0].rows < 24) data[0].rows = 24; |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
static int new_palette(void) |
| 932 |
{ |
| 933 |
HPALETTE hBmPal; |
| 934 |
HPALETTE hNewPal; |
| 935 |
HDC hdc; |
| 936 |
int i, nEntries; |
| 937 |
int pLogPalSize; |
| 938 |
LPLOGPALETTE pLogPal; |
| 939 |
LPPALETTEENTRY lppe; |
| 940 |
|
| 941 |
term_data *td; |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
if (!paletted) return (true); |
| 946 |
|
| 947 |
|
| 948 |
lppe = NULL; |
| 949 |
nEntries = 0; |
| 950 |
|
| 951 |
|
| 952 |
hBmPal = infGraph.hPalette; |
| 953 |
|
| 954 |
|
| 955 |
if (hBmPal) { |
| 956 |
lppe = mem_alloc(256 * sizeof(PALETTEENTRY)); |
| 957 |
nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe); |
| 958 |
if ((nEntries == 0) || (nEntries > 220)) { |
| 959 |
|
| 960 |
plog("Please switch to high- or true-color mode."); |
| 961 |
|
| 962 |
|
| 963 |
mem_free(lppe); |
| 964 |
|
| 965 |
|
| 966 |
return (false); |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY); |
| 972 |
|
| 973 |
|
| 974 |
pLogPal = (LPLOGPALETTE)mem_alloc(pLogPalSize); |
| 975 |
|
| 976 |
|
| 977 |
pLogPal->palVersion = 0x300; |
| 978 |
|
| 979 |
|
| 980 |
pLogPal->palNumEntries = nEntries + 16; |
| 981 |
|
| 982 |
|
| 983 |
for (i = 0; i < nEntries; i++) |
| 984 |
pLogPal->palPalEntry[i] = lppe[i]; |
| 985 |
|
| 986 |
|
| 987 |
for (i = 0; i < BASIC_COLORS; i++) { |
| 988 |
LPPALETTEENTRY p; |
| 989 |
|
| 990 |
|
| 991 |
p = &(pLogPal->palPalEntry[i+nEntries]); |
| 992 |
|
| 993 |
|
| 994 |
p->peRed = GetRValue(win_clr[i]); |
| 995 |
p->peGreen = GetGValue(win_clr[i]); |
| 996 |
p->peBlue = GetBValue(win_clr[i]); |
| 997 |
|
| 998 |
|
| 999 |
if (gamma_correction > 0) { |
| 1000 |
p->peRed = gamma_table[p->peRed]; |
| 1001 |
p->peGreen = gamma_table[p->peGreen]; |
| 1002 |
p->peBlue = gamma_table[p->peBlue]; |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
p->peFlags = PC_NOCOLLAPSE; |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
if (lppe) mem_free(lppe); |
| 1012 |
|
| 1013 |
|
| 1014 |
hNewPal = CreatePalette(pLogPal); |
| 1015 |
if (!hNewPal) quit("Cannot create palette!"); |
| 1016 |
|
| 1017 |
|
| 1018 |
mem_free(pLogPal); |
| 1019 |
|
| 1020 |
|
| 1021 |
td = &data[0]; |
| 1022 |
|
| 1023 |
|
| 1024 |
hdc = GetDC(td->w); |
| 1025 |
SelectPalette(hdc, hNewPal, 0); |
| 1026 |
i = RealizePalette(hdc); |
| 1027 |
ReleaseDC(td->w, hdc); |
| 1028 |
if (i == 0) quit("Cannot realize palette!"); |
| 1029 |
|
| 1030 |
|
| 1031 |
for (i = 1; i < MAX_TERM_DATA; i++) { |
| 1032 |
td = &data[i]; |
| 1033 |
|
| 1034 |
hdc = GetDC(td->w); |
| 1035 |
SelectPalette(hdc, hNewPal, 0); |
| 1036 |
ReleaseDC(td->w, hdc); |
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
if (hPal) DeleteObject(hPal); |
| 1041 |
|
| 1042 |
|
| 1043 |
hPal = hNewPal; |
| 1044 |
|
| 1045 |
|
| 1046 |
return (true); |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
static bool init_graphics(void) |
| 1054 |
{ |
| 1055 |
|
| 1056 |
char buf[1024]; |
| 1057 |
int wid, hgt; |
| 1058 |
const char *name; |
| 1059 |
const char *path; |
| 1060 |
graphics_mode *mode = NULL; |
| 1061 |
|
| 1062 |
if (arg_graphics) { |
| 1063 |
mode = get_graphics_mode(arg_graphics); |
| 1064 |
} |
| 1065 |
if (!mode) { |
| 1066 |
mode = get_graphics_mode(1); |
| 1067 |
} |
| 1068 |
if (mode) { |
| 1069 |
if (!mode->pref[0]) { |
| 1070 |
plog_fmt("invalid tile prefname '%s'", mode->menuname); |
| 1071 |
return false; |
| 1072 |
} |
| 1073 |
wid = mode->cell_width; |
| 1074 |
hgt = mode->cell_height; |
| 1075 |
if ((wid < 2) || (hgt < 2)) { |
| 1076 |
plog_fmt("invalid tile dimensions in tileset: '%s'", |
| 1077 |
mode->menuname); |
| 1078 |
return false; |
| 1079 |
} |
| 1080 |
|
| 1081 |
path = mode->path; |
| 1082 |
name = mode->file; |
| 1083 |
|
| 1084 |
overdraw = mode->overdrawRow; |
| 1085 |
overdrawmax = mode->overdrawMax; |
| 1086 |
alphablend = mode->alphablend; |
| 1087 |
|
| 1088 |
current_graphics_mode = mode; |
| 1089 |
} else { |
| 1090 |
plog("could not find graphics mode"); |
| 1091 |
return false; |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
path_build(buf, sizeof(buf), path, name); |
| 1096 |
|
| 1097 |
|
| 1098 |
if (alphablend) { |
| 1099 |
|
| 1100 |
if (strstr(name, "_pre")) { |
| 1101 |
|
| 1102 |
if (!ReadDIB2_PNG(data[0].w, buf, &infGraph, NULL, false)) { |
| 1103 |
plog_fmt("Cannot read file '%s'", name); |
| 1104 |
return false; |
| 1105 |
} |
| 1106 |
} else { |
| 1107 |
|
| 1108 |
|
| 1109 |
char *ext; |
| 1110 |
char modname[1024]; |
| 1111 |
bool have_space = 0; |
| 1112 |
my_strcpy(modname, buf, sizeof(modname)); |
| 1113 |
ext = strstr(modname, ".png"); |
| 1114 |
|
| 1115 |
if (ext && ((size_t)(ext - modname) |
| 1116 |
< sizeof(modname) - 9)) { |
| 1117 |
have_space = true; |
| 1118 |
my_strcpy(ext, "_pre.png", |
| 1119 |
sizeof(modname) - (ext - buf)); |
| 1120 |
if (!file_exists(modname)) { |
| 1121 |
|
| 1122 |
|
| 1123 |
ext = NULL; |
| 1124 |
} else if (file_newer(buf, modname)) { |
| 1125 |
|
| 1126 |
|
| 1127 |
ext = NULL; |
| 1128 |
} |
| 1129 |
} |
| 1130 |
if (ext && have_space) { |
| 1131 |
|
| 1132 |
if (!ReadDIB2_PNG(data[0].w, modname, &infGraph, NULL, false)) { |
| 1133 |
plog_fmt("Cannot read premultiplied version of file '%s'", |
| 1134 |
name); |
| 1135 |
return false; |
| 1136 |
} |
| 1137 |
} else { |
| 1138 |
|
| 1139 |
if (!ReadDIB2_PNG(data[0].w, buf, &infGraph, NULL, true)) { |
| 1140 |
plog_fmt("Cannot read file '%s'", name); |
| 1141 |
return false; |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
} |
| 1152 |
} |
| 1153 |
} else { |
| 1154 |
if (!ReadDIB2_PNG(data[0].w, buf, &infGraph, &infMask, false)) { |
| 1155 |
plog_fmt("Cannot read file '%s'", name); |
| 1156 |
return false; |
| 1157 |
} |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
infGraph.CellWidth = wid; |
| 1162 |
infGraph.CellHeight = hgt; |
| 1163 |
|
| 1164 |
|
| 1165 |
if (!new_palette()){ |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
plog("Cannot activate palette!"); |
| 1170 |
return (false); |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
can_use_graphics = arg_graphics; |
| 1175 |
|
| 1176 |
|
| 1177 |
return (can_use_graphics); |
| 1178 |
} |
| 1179 |
|
| 1180 |
#if defined(SOUND) && !defined(SOUND_SDL) && !defined(SOUND_SDL2) |
| 1181 |
|
| 1182 |
|
| 1183 |
enum { |
| 1184 |
WIN_NULL = 0, |
| 1185 |
WIN_MP3, |
| 1186 |
WIN_WAV |
| 1187 |
}; |
| 1188 |
|
| 1189 |
const struct sound_file_type supported_sound_files[] = { {".mp3", WIN_MP3}, |
| 1190 |
{".wav", WIN_WAV}, |
| 1191 |
{"", WIN_NULL} }; |
| 1192 |
|
| 1193 |
typedef struct |
| 1194 |
{ |
| 1195 |
int type; |
| 1196 |
MCI_OPEN_PARMS op; |
| 1197 |
char *filename; |
| 1198 |
} win_sample; |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
static bool load_sound_win(const char *filename, int ftyp, |
| 1204 |
struct sound_data *sd) |
| 1205 |
{ |
| 1206 |
win_sample *sample = NULL; |
| 1207 |
|
| 1208 |
sample = (win_sample *)(sd->plat_data); |
| 1209 |
|
| 1210 |
switch (ftyp) { |
| 1211 |
case WIN_MP3: |
| 1212 |
if (!sample) |
| 1213 |
sample = mem_zalloc(sizeof(*sample)); |
| 1214 |
|
| 1215 |
|
| 1216 |
if (!sample->op.wDeviceID) { |
| 1217 |
sample->op.dwCallback = 0; |
| 1218 |
sample->op.lpstrDeviceType = (char*)MCI_ALL_DEVICE_ID; |
| 1219 |
sample->op.lpstrElementName = filename; |
| 1220 |
sample->op.lpstrAlias = NULL; |
| 1221 |
|
| 1222 |
|
| 1223 |
mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_WAIT, (size_t)(&sample->op)); |
| 1224 |
} |
| 1225 |
|
| 1226 |
if (0 != sample->op.wDeviceID) { |
| 1227 |
sd->status = SOUND_ST_LOADED; |
| 1228 |
} else { |
| 1229 |
mem_free(sample); |
| 1230 |
sample = NULL; |
| 1231 |
} |
| 1232 |
break; |
| 1233 |
|
| 1234 |
case WIN_WAV: |
| 1235 |
if (!sample) |
| 1236 |
sample = mem_alloc(sizeof(*sample)); |
| 1237 |
|
| 1238 |
sample->filename = mem_zalloc(strlen(filename) + 1); |
| 1239 |
my_strcpy(sample->filename, filename, strlen(filename) + 1); |
| 1240 |
sd->status = SOUND_ST_LOADED; |
| 1241 |
break; |
| 1242 |
|
| 1243 |
default: |
| 1244 |
plog_fmt("Sound: Oops - Unsupported file type"); |
| 1245 |
break; |
| 1246 |
} |
| 1247 |
|
| 1248 |
if (sample) { |
| 1249 |
sample->type = ftyp; |
| 1250 |
} |
| 1251 |
sd->plat_data = (void *)sample; |
| 1252 |
|
| 1253 |
return (NULL != sample); |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
static bool play_sound_win(struct sound_data *sd) |
| 1260 |
{ |
| 1261 |
MCI_PLAY_PARMS pp; |
| 1262 |
|
| 1263 |
win_sample *sample = (win_sample *)(sd->plat_data); |
| 1264 |
|
| 1265 |
if (sample) { |
| 1266 |
switch (sample->type) { |
| 1267 |
case WIN_MP3: |
| 1268 |
if (sample->op.wDeviceID) { |
| 1269 |
|
| 1270 |
pp.dwCallback = 0; |
| 1271 |
pp.dwFrom = 0; |
| 1272 |
return (!mciSendCommand(sample->op.wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM, (size_t)&pp)); |
| 1273 |
} |
| 1274 |
break; |
| 1275 |
|
| 1276 |
case WIN_WAV: |
| 1277 |
if (sample->filename) |
| 1278 |
{ |
| 1279 |
|
| 1280 |
if (PlaySound(NULL, 0, SND_PURGE)) |
| 1281 |
|
| 1282 |
return PlaySound(sample->filename, 0, SND_FILENAME | SND_ASYNC); |
| 1283 |
} |
| 1284 |
break; |
| 1285 |
default: |
| 1286 |
|
| 1287 |
break; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
|
| 1291 |
return true; |
| 1292 |
} |
| 1293 |
|
| 1294 |
static bool unload_sound_win(struct sound_data *sd) |
| 1295 |
{ |
| 1296 |
win_sample *sample = (win_sample *)(sd->plat_data); |
| 1297 |
|
| 1298 |
if (sample) { |
| 1299 |
switch (sample->type) { |
| 1300 |
case WIN_MP3: |
| 1301 |
if (sample->op.wDeviceID) |
| 1302 |
mciSendCommand(sample->op.wDeviceID, MCI_CLOSE, MCI_WAIT, (size_t)(&sample->op)); |
| 1303 |
|
| 1304 |
break; |
| 1305 |
|
| 1306 |
case WIN_WAV: |
| 1307 |
mem_free(sample->filename); |
| 1308 |
break; |
| 1309 |
|
| 1310 |
default: |
| 1311 |
break; |
| 1312 |
} |
| 1313 |
|
| 1314 |
mem_free(sample); |
| 1315 |
sd->plat_data = NULL; |
| 1316 |
sd->status = SOUND_ST_UNKNOWN; |
| 1317 |
} |
| 1318 |
|
| 1319 |
return true; |
| 1320 |
} |
| 1321 |
|
| 1322 |
static bool open_audio_win(void) |
| 1323 |
{ |
| 1324 |
return true; |
| 1325 |
} |
| 1326 |
|
| 1327 |
static bool close_audio_win(void) |
| 1328 |
{ |
| 1329 |
return true; |
| 1330 |
} |
| 1331 |
|
| 1332 |
static const struct sound_file_type *supported_files_win(void) |
| 1333 |
{ |
| 1334 |
return supported_sound_files; |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
errr init_sound_win(struct sound_hooks *hooks, int argc, char **argv) |
| 1341 |
{ |
| 1342 |
hooks->open_audio_hook = open_audio_win; |
| 1343 |
hooks->supported_files_hook = supported_files_win; |
| 1344 |
hooks->close_audio_hook = close_audio_win; |
| 1345 |
hooks->load_sound_hook = load_sound_win; |
| 1346 |
hooks->unload_sound_hook = unload_sound_win; |
| 1347 |
hooks->play_sound_hook = play_sound_win; |
| 1348 |
|
| 1349 |
|
| 1350 |
return (0); |
| 1351 |
} |
| 1352 |
#endif |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
static void term_window_resize(const term_data *td) |
| 1359 |
{ |
| 1360 |
|
| 1361 |
if (!td->w) return; |
| 1362 |
|
| 1363 |
|
| 1364 |
SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, |
| 1365 |
SWP_NOMOVE | SWP_NOZORDER); |
| 1366 |
|
| 1367 |
|
| 1368 |
InvalidateRect(td->w, NULL, true); |
| 1369 |
} |
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
static void term_remove_font(const char *name) |
| 1376 |
{ |
| 1377 |
char buf[1024]; |
| 1378 |
|
| 1379 |
|
| 1380 |
my_strcpy(buf, ANGBAND_DIR_FONTS, sizeof(buf)); |
| 1381 |
my_strcat(buf, "\\", sizeof(buf)); |
| 1382 |
my_strcat(buf, name, sizeof(buf)); |
| 1383 |
|
| 1384 |
|
| 1385 |
RemoveFontResource(buf); |
| 1386 |
|
| 1387 |
|
| 1388 |
PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); |
| 1389 |
|
| 1390 |
return; |
| 1391 |
} |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
static errr term_force_font(term_data *td, const char *path) |
| 1404 |
{ |
| 1405 |
int i; |
| 1406 |
|
| 1407 |
int wid, hgt; |
| 1408 |
|
| 1409 |
char *base; |
| 1410 |
|
| 1411 |
char buf[1024]; |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
if (!path) return (1); |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
if (td->font_id) DeleteObject(td->font_id); |
| 1420 |
|
| 1421 |
|
| 1422 |
if (td->font_file) { |
| 1423 |
bool used = false; |
| 1424 |
|
| 1425 |
|
| 1426 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 1427 |
|
| 1428 |
if ((td != &data[i]) && (data[i].font_file) && |
| 1429 |
(streq(data[i].font_file, td->font_file))) { |
| 1430 |
used = true; |
| 1431 |
} |
| 1432 |
} |
| 1433 |
|
| 1434 |
|
| 1435 |
if (!used) term_remove_font(td->font_file); |
| 1436 |
|
| 1437 |
|
| 1438 |
string_free(td->font_file); |
| 1439 |
|
| 1440 |
|
| 1441 |
td->font_file = NULL; |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
my_strcpy(buf, path, sizeof(buf)); |
| 1448 |
|
| 1449 |
|
| 1450 |
base = analyze_font(buf, &wid, &hgt); |
| 1451 |
|
| 1452 |
|
| 1453 |
if (!suffix(base, ".FON")) return (1); |
| 1454 |
|
| 1455 |
|
| 1456 |
if (!file_exists(buf)) return (1); |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
if (!AddFontResourceEx(buf, FR_PRIVATE, 0)) return (1); |
| 1461 |
|
| 1462 |
|
| 1463 |
td->font_file = string_make(base); |
| 1464 |
|
| 1465 |
|
| 1466 |
base[strlen(base)-4] = '\0'; |
| 1467 |
|
| 1468 |
|
| 1469 |
td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0, |
| 1470 |
ANSI_CHARSET, OUT_DEFAULT_PRECIS, |
| 1471 |
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, |
| 1472 |
FIXED_PITCH | FF_DONTCARE, base); |
| 1473 |
|
| 1474 |
|
| 1475 |
if (!wid || !hgt) |
| 1476 |
{ |
| 1477 |
HDC hdcDesktop; |
| 1478 |
HFONT hfOld; |
| 1479 |
TEXTMETRIC tm; |
| 1480 |
|
| 1481 |
|
| 1482 |
hdcDesktop = GetDC(HWND_DESKTOP); |
| 1483 |
hfOld = SelectObject(hdcDesktop, td->font_id); |
| 1484 |
GetTextMetrics(hdcDesktop, &tm); |
| 1485 |
SelectObject(hdcDesktop, hfOld); |
| 1486 |
ReleaseDC(HWND_DESKTOP, hdcDesktop); |
| 1487 |
|
| 1488 |
|
| 1489 |
wid = tm.tmAveCharWidth; |
| 1490 |
hgt = tm.tmHeight; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
td->font_wid = wid; |
| 1495 |
td->font_hgt = hgt; |
| 1496 |
|
| 1497 |
|
| 1498 |
return (0); |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
static void term_change_font(term_data *td) |
| 1507 |
{ |
| 1508 |
OPENFILENAME ofn; |
| 1509 |
|
| 1510 |
char tmp[1024] = ""; |
| 1511 |
|
| 1512 |
|
| 1513 |
if (td->font_file) my_strcpy(tmp, td->font_file, sizeof(tmp)); |
| 1514 |
|
| 1515 |
|
| 1516 |
memset(&ofn, 0, sizeof(ofn)); |
| 1517 |
ofn.lStructSize = sizeof(ofn); |
| 1518 |
ofn.hwndOwner = data[0].w; |
| 1519 |
ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0"; |
| 1520 |
ofn.nFilterIndex = 1; |
| 1521 |
ofn.lpstrFile = tmp; |
| 1522 |
ofn.nMaxFile = 128; |
| 1523 |
ofn.lpstrInitialDir = ANGBAND_DIR_FONTS; |
| 1524 |
ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; |
| 1525 |
ofn.lpstrDefExt = "fon"; |
| 1526 |
|
| 1527 |
|
| 1528 |
if (GetOpenFileName(&ofn)) { |
| 1529 |
|
| 1530 |
bool tile_match_size = !use_graphics_nice |
| 1531 |
&& td->tile_wid == td->font_wid |
| 1532 |
&& td->tile_hgt == td->font_hgt; |
| 1533 |
|
| 1534 |
|
| 1535 |
if (term_force_font(td, tmp)) { |
| 1536 |
|
| 1537 |
path_build(tmp, sizeof(tmp), ANGBAND_DIR_FONTS, DEFAULT_FONT); |
| 1538 |
|
| 1539 |
|
| 1540 |
(void)term_force_font(td, tmp); |
| 1541 |
|
| 1542 |
|
| 1543 |
td->tile_wid = td->font_wid; |
| 1544 |
td->tile_hgt = td->font_hgt; |
| 1545 |
} |
| 1546 |
|
| 1547 |
|
| 1548 |
td->bizarre = true; |
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
if (!td->tile_wid || !td->tile_hgt || tile_match_size) { |
| 1555 |
td->tile_wid = td->font_wid; |
| 1556 |
td->tile_hgt = td->font_hgt; |
| 1557 |
} |
| 1558 |
|
| 1559 |
|
| 1560 |
term_getsize(td); |
| 1561 |
|
| 1562 |
|
| 1563 |
term_window_resize(td); |
| 1564 |
} |
| 1565 |
} |
| 1566 |
|
| 1567 |
|
| 1568 |
static void windows_map_aux(void); |
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
static void term_data_redraw(term_data *td) |
| 1575 |
{ |
| 1576 |
if (td->map_active) { |
| 1577 |
|
| 1578 |
windows_map_aux(); |
| 1579 |
} else { |
| 1580 |
|
| 1581 |
Term_activate(&td->t); |
| 1582 |
|
| 1583 |
|
| 1584 |
Term_redraw(); |
| 1585 |
|
| 1586 |
|
| 1587 |
Term_activate(term_screen); |
| 1588 |
} |
| 1589 |
} |
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
static void term_data_redraw_section(term_data *td, int x1, int y1, |
| 1596 |
int x2, int y2) |
| 1597 |
{ |
| 1598 |
|
| 1599 |
Term_activate(&td->t); |
| 1600 |
|
| 1601 |
|
| 1602 |
Term_redraw_section(x1, y1, x2, y2); |
| 1603 |
|
| 1604 |
|
| 1605 |
Term_activate(term_screen); |
| 1606 |
} |
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
#if 0 |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
static void Term_init_win(term *t) |
| 1623 |
{ |
| 1624 |
|
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
static void Term_nuke_win(term *t) |
| 1632 |
{ |
| 1633 |
|
| 1634 |
} |
| 1635 |
|
| 1636 |
#endif |
| 1637 |
|
| 1638 |
|
| 1639 |
static errr Term_pict_win(int x, int y, int n, |
| 1640 |
const int *ap, const wchar_t *cp, |
| 1641 |
const int *tap, const wchar_t *tcp); |
| 1642 |
static errr Term_pict_win_alpha(int x, int y, int n, |
| 1643 |
const int *ap, const wchar_t *cp, |
| 1644 |
const int *tap, const wchar_t *tcp); |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
static errr Term_xtra_win_react(void) |
| 1650 |
{ |
| 1651 |
int i; |
| 1652 |
|
| 1653 |
|
| 1654 |
term_data *td = &data[0]; |
| 1655 |
|
| 1656 |
|
| 1657 |
if (colors16) { |
| 1658 |
|
| 1659 |
for (i = 0; i < MAX_COLORS; i++) { |
| 1660 |
|
| 1661 |
win_pal[i] = angband_color_table[i][0]; |
| 1662 |
} |
| 1663 |
} else { |
| 1664 |
COLORREF code; |
| 1665 |
|
| 1666 |
uint8_t rv, gv, bv; |
| 1667 |
|
| 1668 |
bool change = false; |
| 1669 |
|
| 1670 |
|
| 1671 |
for (i = 0; i < MAX_COLORS; i++) { |
| 1672 |
|
| 1673 |
rv = angband_color_table[i][1]; |
| 1674 |
gv = angband_color_table[i][2]; |
| 1675 |
bv = angband_color_table[i][3]; |
| 1676 |
|
| 1677 |
if (gamma_correction > 0) { |
| 1678 |
rv = gamma_table[rv]; |
| 1679 |
gv = gamma_table[gv]; |
| 1680 |
bv = gamma_table[bv]; |
| 1681 |
} |
| 1682 |
|
| 1683 |
|
| 1684 |
code = PALETTERGB(rv, gv, bv); |
| 1685 |
|
| 1686 |
|
| 1687 |
if (win_clr[i] != code) { |
| 1688 |
|
| 1689 |
change = true; |
| 1690 |
|
| 1691 |
|
| 1692 |
win_clr[i] = code; |
| 1693 |
} |
| 1694 |
} |
| 1695 |
|
| 1696 |
|
| 1697 |
if (change) (void)new_palette(); |
| 1698 |
} |
| 1699 |
|
| 1700 |
|
| 1701 |
if (use_graphics_nice != arg_graphics_nice) { |
| 1702 |
|
| 1703 |
use_graphics_nice = arg_graphics_nice; |
| 1704 |
|
| 1705 |
|
| 1706 |
td->bizarre = true; |
| 1707 |
|
| 1708 |
|
| 1709 |
term_getsize(td); |
| 1710 |
|
| 1711 |
|
| 1712 |
term_window_resize(td); |
| 1713 |
} |
| 1714 |
|
| 1715 |
|
| 1716 |
if (use_graphics != arg_graphics) { |
| 1717 |
|
| 1718 |
FreeDIB(&infGraph); |
| 1719 |
FreeDIB(&infMask); |
| 1720 |
|
| 1721 |
|
| 1722 |
if (arg_graphics && !init_graphics()) { |
| 1723 |
|
| 1724 |
plog("Cannot initialize graphics!"); |
| 1725 |
|
| 1726 |
|
| 1727 |
arg_graphics = GRAPHICS_NONE; |
| 1728 |
} else { |
| 1729 |
if (alphablend || overdraw) { |
| 1730 |
td->t.pict_hook = Term_pict_win_alpha; |
| 1731 |
} else { |
| 1732 |
td->t.pict_hook = Term_pict_win; |
| 1733 |
} |
| 1734 |
} |
| 1735 |
td->t.dblh_hook = (overdraw) ? is_dh_tile : NULL; |
| 1736 |
|
| 1737 |
|
| 1738 |
current_graphics_mode = get_graphics_mode(arg_graphics); |
| 1739 |
|
| 1740 |
|
| 1741 |
use_graphics = arg_graphics; |
| 1742 |
|
| 1743 |
if (use_graphics_nice) { |
| 1744 |
|
| 1745 |
td->bizarre = true; |
| 1746 |
|
| 1747 |
|
| 1748 |
term_getsize(td); |
| 1749 |
|
| 1750 |
|
| 1751 |
term_window_resize(td); |
| 1752 |
} |
| 1753 |
|
| 1754 |
|
| 1755 |
if (character_dungeon) reset_visuals(true); |
| 1756 |
} |
| 1757 |
|
| 1758 |
|
| 1759 |
if (change_tilesize) { |
| 1760 |
|
| 1761 |
reset_visuals(true); |
| 1762 |
|
| 1763 |
|
| 1764 |
verify_panel(); |
| 1765 |
|
| 1766 |
|
| 1767 |
change_tilesize = false; |
| 1768 |
} |
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 1773 |
term *old = Term; |
| 1774 |
|
| 1775 |
td = &data[i]; |
| 1776 |
|
| 1777 |
|
| 1778 |
if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) { |
| 1779 |
|
| 1780 |
Term_activate(&td->t); |
| 1781 |
|
| 1782 |
|
| 1783 |
Term_resize(td->cols, td->rows); |
| 1784 |
|
| 1785 |
|
| 1786 |
Term_redraw(); |
| 1787 |
|
| 1788 |
|
| 1789 |
Term_activate(old); |
| 1790 |
} |
| 1791 |
} |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
return (0); |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
static errr Term_xtra_win_event(int v) |
| 1803 |
{ |
| 1804 |
MSG msg; |
| 1805 |
|
| 1806 |
|
| 1807 |
if (v) |
| 1808 |
{ |
| 1809 |
int i = 0; |
| 1810 |
while (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
| 1811 |
|
| 1812 |
|
| 1813 |
if (i == 0) idle_update(); |
| 1814 |
Sleep(20); |
| 1815 |
i = (i + 1) % 10; |
| 1816 |
} |
| 1817 |
TranslateMessage(&msg); |
| 1818 |
DispatchMessage(&msg); |
| 1819 |
} else if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
| 1820 |
TranslateMessage(&msg); |
| 1821 |
DispatchMessage(&msg); |
| 1822 |
} |
| 1823 |
|
| 1824 |
|
| 1825 |
return 0; |
| 1826 |
} |
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
static errr Term_xtra_win_flush(void) |
| 1833 |
{ |
| 1834 |
MSG msg; |
| 1835 |
|
| 1836 |
|
| 1837 |
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
| 1838 |
TranslateMessage(&msg); |
| 1839 |
DispatchMessage(&msg); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
return (0); |
| 1844 |
} |
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
static errr Term_xtra_win_clear(void) |
| 1853 |
{ |
| 1854 |
term_data *td = (term_data*)(Term->data); |
| 1855 |
|
| 1856 |
HDC hdc; |
| 1857 |
RECT rc; |
| 1858 |
HBRUSH brush; |
| 1859 |
|
| 1860 |
|
| 1861 |
GetClientRect(td->w, &rc); |
| 1862 |
|
| 1863 |
|
| 1864 |
hdc = GetDC(td->w); |
| 1865 |
brush = CreateSolidBrush((colors16) ? RGB(0, 0, 0) : win_clr[0]); |
| 1866 |
FillRect(hdc, &rc, brush); |
| 1867 |
DeleteObject(brush); |
| 1868 |
ReleaseDC(td->w, hdc); |
| 1869 |
|
| 1870 |
|
| 1871 |
return 0; |
| 1872 |
} |
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
static errr Term_xtra_win_noise(void) |
| 1879 |
{ |
| 1880 |
MessageBeep(MB_ICONASTERISK); |
| 1881 |
return (0); |
| 1882 |
} |
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
static int Term_xtra_win_delay(int v) |
| 1888 |
{ |
| 1889 |
|
| 1890 |
if (v > 0) Sleep(v); |
| 1891 |
|
| 1892 |
|
| 1893 |
return (0); |
| 1894 |
} |
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
static errr Term_xtra_win(int n, int v) |
| 1901 |
{ |
| 1902 |
|
| 1903 |
switch (n) |
| 1904 |
{ |
| 1905 |
|
| 1906 |
case TERM_XTRA_NOISE: |
| 1907 |
{ |
| 1908 |
return (Term_xtra_win_noise()); |
| 1909 |
} |
| 1910 |
|
| 1911 |
|
| 1912 |
case TERM_XTRA_BORED: |
| 1913 |
{ |
| 1914 |
return (Term_xtra_win_event(0)); |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
case TERM_XTRA_EVENT: |
| 1919 |
{ |
| 1920 |
return (Term_xtra_win_event(v)); |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
case TERM_XTRA_FLUSH: |
| 1925 |
{ |
| 1926 |
return (Term_xtra_win_flush()); |
| 1927 |
} |
| 1928 |
|
| 1929 |
|
| 1930 |
case TERM_XTRA_CLEAR: |
| 1931 |
{ |
| 1932 |
return (Term_xtra_win_clear()); |
| 1933 |
} |
| 1934 |
|
| 1935 |
|
| 1936 |
case TERM_XTRA_REACT: |
| 1937 |
{ |
| 1938 |
return (Term_xtra_win_react()); |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
case TERM_XTRA_DELAY: |
| 1943 |
{ |
| 1944 |
return (Term_xtra_win_delay(v)); |
| 1945 |
} |
| 1946 |
} |
| 1947 |
|
| 1948 |
|
| 1949 |
return 1; |
| 1950 |
} |
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
static errr Term_curs_win(int x, int y) |
| 1960 |
{ |
| 1961 |
term_data *td = (term_data*)(Term->data); |
| 1962 |
|
| 1963 |
RECT rc; |
| 1964 |
HDC hdc; |
| 1965 |
|
| 1966 |
int tile_wid, tile_hgt; |
| 1967 |
|
| 1968 |
if (td->map_active) { |
| 1969 |
tile_wid = td->map_tile_wid; |
| 1970 |
tile_hgt = td->map_tile_hgt; |
| 1971 |
} else { |
| 1972 |
tile_wid = td->tile_wid; |
| 1973 |
tile_hgt = td->tile_hgt; |
| 1974 |
} |
| 1975 |
|
| 1976 |
|
| 1977 |
rc.left = x * tile_wid + td->size_ow1; |
| 1978 |
rc.right = rc.left + tile_wid; |
| 1979 |
rc.top = y * tile_hgt + td->size_oh1; |
| 1980 |
rc.bottom = rc.top + tile_hgt; |
| 1981 |
|
| 1982 |
|
| 1983 |
hdc = GetDC(td->w); |
| 1984 |
FrameRect(hdc, &rc, hbrYellow); |
| 1985 |
ReleaseDC(td->w, hdc); |
| 1986 |
|
| 1987 |
|
| 1988 |
return 0; |
| 1989 |
} |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
static errr Term_bigcurs_win(int x, int y) |
| 1998 |
{ |
| 1999 |
term_data *td = (term_data*)(Term->data); |
| 2000 |
|
| 2001 |
RECT rc; |
| 2002 |
HDC hdc; |
| 2003 |
|
| 2004 |
int tile_wid, tile_hgt; |
| 2005 |
|
| 2006 |
if (td->map_active) { |
| 2007 |
|
| 2008 |
Term_curs_win(x, y); |
| 2009 |
return 0; |
| 2010 |
} else { |
| 2011 |
tile_wid = td->tile_wid; |
| 2012 |
tile_hgt = td->tile_hgt; |
| 2013 |
} |
| 2014 |
|
| 2015 |
|
| 2016 |
rc.left = x * tile_wid + td->size_ow1; |
| 2017 |
rc.right = rc.left + tile_width * tile_wid; |
| 2018 |
rc.top = y * tile_hgt + td->size_oh1; |
| 2019 |
rc.bottom = rc.top + tile_height * tile_hgt; |
| 2020 |
|
| 2021 |
|
| 2022 |
hdc = GetDC(td->w); |
| 2023 |
FrameRect(hdc, &rc, hbrYellow); |
| 2024 |
ReleaseDC(td->w, hdc); |
| 2025 |
|
| 2026 |
|
| 2027 |
return 0; |
| 2028 |
} |
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
static errr Term_wipe_win_helper(int x, int y, int nc, int nr, COLORREF c) |
| 2037 |
{ |
| 2038 |
term_data *td = (term_data*)(Term->data); |
| 2039 |
|
| 2040 |
HDC hdc; |
| 2041 |
RECT rc; |
| 2042 |
|
| 2043 |
|
| 2044 |
rc.left = x * td->tile_wid + td->size_ow1; |
| 2045 |
rc.right = rc.left + nc * td->tile_wid; |
| 2046 |
rc.top = y * td->tile_hgt + td->size_oh1; |
| 2047 |
rc.bottom = rc.top + nr * td->tile_hgt; |
| 2048 |
|
| 2049 |
hdc = GetDC(td->w); |
| 2050 |
SetBkColor(hdc, c); |
| 2051 |
SelectObject(hdc, td->font_id); |
| 2052 |
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); |
| 2053 |
ReleaseDC(td->w, hdc); |
| 2054 |
|
| 2055 |
|
| 2056 |
return 0; |
| 2057 |
} |
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
static errr Term_wipe_win(int x, int y, int n) |
| 2066 |
{ |
| 2067 |
return Term_wipe_win_helper(x, y, n, 1, |
| 2068 |
(colors16) ? RGB(0, 0, 0) : win_clr[0]); |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
static errr Term_text_win(int x, int y, int n, int a, const wchar_t *s) |
| 2084 |
{ |
| 2085 |
term_data *td = (term_data*)(Term->data); |
| 2086 |
RECT rc; |
| 2087 |
HDC hdc; |
| 2088 |
|
| 2089 |
|
| 2090 |
rc.left = x * td->tile_wid + td->size_ow1; |
| 2091 |
rc.right = rc.left + n * td->tile_wid; |
| 2092 |
rc.top = y * td->tile_hgt + td->size_oh1; |
| 2093 |
rc.bottom = rc.top + td->tile_hgt; |
| 2094 |
|
| 2095 |
|
| 2096 |
hdc = GetDC(td->w); |
| 2097 |
|
| 2098 |
|
| 2099 |
if (colors16) { |
| 2100 |
SetTextColor(hdc, PALETTEINDEX(win_pal[a % MAX_COLORS])); |
| 2101 |
|
| 2102 |
SetBkColor(hdc, RGB(0, 0, 0)); |
| 2103 |
} else { |
| 2104 |
if (paletted) |
| 2105 |
SetTextColor(hdc, win_clr[(a % MAX_COLORS) & 0x1F]); |
| 2106 |
else |
| 2107 |
SetTextColor(hdc, win_clr[a % MAX_COLORS]); |
| 2108 |
|
| 2109 |
|
| 2110 |
switch (a / MULT_BG) |
| 2111 |
{ |
| 2112 |
case BG_SAME: |
| 2113 |
|
| 2114 |
SetBkColor(hdc, win_clr[a % MAX_COLORS]); |
| 2115 |
break; |
| 2116 |
case BG_DARK: |
| 2117 |
|
| 2118 |
SetBkColor(hdc, win_clr[COLOUR_SHADE]); |
| 2119 |
break; |
| 2120 |
case BG_BLACK: |
| 2121 |
default: |
| 2122 |
|
| 2123 |
SetBkColor(hdc, win_clr[0]); |
| 2124 |
break; |
| 2125 |
} |
| 2126 |
} |
| 2127 |
|
| 2128 |
|
| 2129 |
SelectObject(hdc, td->font_id); |
| 2130 |
|
| 2131 |
|
| 2132 |
if (td->bizarre || |
| 2133 |
(td->tile_hgt != td->font_hgt) || |
| 2134 |
(td->tile_wid != td->font_wid)) { |
| 2135 |
int i; |
| 2136 |
|
| 2137 |
|
| 2138 |
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); |
| 2139 |
|
| 2140 |
|
| 2141 |
rc.left += ((td->tile_wid - td->font_wid) / 2); |
| 2142 |
rc.right = rc.left + td->font_wid; |
| 2143 |
rc.top += ((td->tile_hgt - td->font_hgt) / 2); |
| 2144 |
rc.bottom = rc.top + td->font_hgt; |
| 2145 |
|
| 2146 |
|
| 2147 |
for (i = 0; i < n; i++) { |
| 2148 |
|
| 2149 |
ExtTextOutW(hdc, rc.left, rc.top, 0, &rc, |
| 2150 |
s+i, 1, NULL); |
| 2151 |
|
| 2152 |
|
| 2153 |
rc.left += td->tile_wid; |
| 2154 |
rc.right += td->tile_wid; |
| 2155 |
} |
| 2156 |
} else { |
| 2157 |
|
| 2158 |
ExtTextOutW(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, |
| 2159 |
s, n, NULL); |
| 2160 |
} |
| 2161 |
|
| 2162 |
|
| 2163 |
ReleaseDC(td->w, hdc); |
| 2164 |
|
| 2165 |
|
| 2166 |
return 0; |
| 2167 |
} |
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
static errr Term_pict_win(int x, int y, int n, |
| 2184 |
const int *ap, const wchar_t *cp, |
| 2185 |
const int *tap, const wchar_t *tcp) |
| 2186 |
{ |
| 2187 |
term_data *td = (term_data*)(Term->data); |
| 2188 |
|
| 2189 |
int i; |
| 2190 |
int mw, mh; |
| 2191 |
int x1, y1, w1, h1; |
| 2192 |
int x2, y2, w2, h2, tw2, th2; |
| 2193 |
int x3, y3; |
| 2194 |
|
| 2195 |
HDC hdcMask; |
| 2196 |
HDC hdc; |
| 2197 |
HDC hdcSrc; |
| 2198 |
HBITMAP hbmSrcOld; |
| 2199 |
|
| 2200 |
|
| 2201 |
w1 = infGraph.CellWidth; |
| 2202 |
h1 = infGraph.CellHeight; |
| 2203 |
|
| 2204 |
|
| 2205 |
if (td->map_active) { |
| 2206 |
w2 = td->map_tile_wid; |
| 2207 |
h2 = td->map_tile_hgt; |
| 2208 |
mw = 1; |
| 2209 |
mh = 1; |
| 2210 |
} else { |
| 2211 |
w2 = td->tile_wid; |
| 2212 |
h2 = td->tile_hgt; |
| 2213 |
|
| 2214 |
|
| 2215 |
mw = tile_width; |
| 2216 |
mh = tile_height; |
| 2217 |
} |
| 2218 |
tw2 = mw * w2; |
| 2219 |
th2 = mh * h2; |
| 2220 |
|
| 2221 |
|
| 2222 |
Term_wipe_win_helper(x, y, n * mw, mh, RGB(0, 0, 0)); |
| 2223 |
|
| 2224 |
|
| 2225 |
x2 = x * w2 + td->size_ow1; |
| 2226 |
y2 = y * h2 + td->size_oh1; |
| 2227 |
|
| 2228 |
|
| 2229 |
hdc = GetDC(td->w); |
| 2230 |
|
| 2231 |
|
| 2232 |
hdcSrc = CreateCompatibleDC(hdc); |
| 2233 |
hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap); |
| 2234 |
|
| 2235 |
if (infMask.hBitmap) { |
| 2236 |
hdcMask = CreateCompatibleDC(hdc); |
| 2237 |
SelectObject(hdcMask, infMask.hBitmap); |
| 2238 |
} else { |
| 2239 |
hdcMask = NULL; |
| 2240 |
} |
| 2241 |
|
| 2242 |
|
| 2243 |
for (i = n-1; i >= 0; i--, x2 -= w2) { |
| 2244 |
int a = ap[i]; |
| 2245 |
wchar_t c = cp[i]; |
| 2246 |
|
| 2247 |
|
| 2248 |
int row = (a & 0x7F); |
| 2249 |
int col = (c & 0x7F); |
| 2250 |
|
| 2251 |
|
| 2252 |
x1 = col * w1; |
| 2253 |
y1 = row * h1; |
| 2254 |
|
| 2255 |
if (hdcMask) { |
| 2256 |
x3 = (tcp[i] & 0x7F) * w1; |
| 2257 |
y3 = (tap[i] & 0x7F) * h1; |
| 2258 |
|
| 2259 |
|
| 2260 |
if ((w1 == tw2) && (h1 == th2)) { |
| 2261 |
|
| 2262 |
BitBlt(hdc, x2, y2, tw2, th2, hdcSrc, x3, y3, SRCCOPY); |
| 2263 |
|
| 2264 |
|
| 2265 |
if ((x1 != x3) || (y1 != y3)) { |
| 2266 |
|
| 2267 |
BitBlt(hdc, x2, y2, tw2, th2, hdcMask, x1, y1, SRCAND); |
| 2268 |
|
| 2269 |
|
| 2270 |
BitBlt(hdc, x2, y2, tw2, th2, hdcSrc, x1, y1, SRCPAINT); |
| 2271 |
} |
| 2272 |
|
| 2273 |
|
| 2274 |
} else { |
| 2275 |
|
| 2276 |
SetStretchBltMode(hdc, COLORONCOLOR); |
| 2277 |
|
| 2278 |
|
| 2279 |
StretchBlt(hdc, x2, y2, tw2, th2, hdcSrc, x3, y3, w1, h1, |
| 2280 |
SRCCOPY); |
| 2281 |
|
| 2282 |
|
| 2283 |
if ((x1 != x3) || (y1 != y3)) { |
| 2284 |
|
| 2285 |
StretchBlt(hdc, x2, y2, tw2, th2, hdcMask, x1, y1, w1, h1, |
| 2286 |
SRCAND); |
| 2287 |
|
| 2288 |
|
| 2289 |
StretchBlt(hdc, x2, y2, tw2, th2, hdcSrc, x1, y1, w1, h1, |
| 2290 |
SRCPAINT); |
| 2291 |
} |
| 2292 |
} |
| 2293 |
} else { |
| 2294 |
|
| 2295 |
if ((w1 == tw2) && (h1 == th2)) { |
| 2296 |
|
| 2297 |
BitBlt(hdc, x2, y2, tw2, th2, hdcSrc, x1, y1, SRCCOPY); |
| 2298 |
|
| 2299 |
|
| 2300 |
} else { |
| 2301 |
|
| 2302 |
SetStretchBltMode(hdc, COLORONCOLOR); |
| 2303 |
|
| 2304 |
|
| 2305 |
StretchBlt(hdc, x2, y2, tw2, th2, hdcSrc, x1, y1, w1, h1, |
| 2306 |
SRCCOPY); |
| 2307 |
} |
| 2308 |
} |
| 2309 |
} |
| 2310 |
|
| 2311 |
|
| 2312 |
SelectObject(hdcSrc, hbmSrcOld); |
| 2313 |
DeleteDC(hdcSrc); |
| 2314 |
|
| 2315 |
if (hdcMask) { |
| 2316 |
|
| 2317 |
SelectObject(hdcMask, hbmSrcOld); |
| 2318 |
DeleteDC(hdcMask); |
| 2319 |
} |
| 2320 |
|
| 2321 |
|
| 2322 |
ReleaseDC(td->w, hdc); |
| 2323 |
|
| 2324 |
|
| 2325 |
return 0; |
| 2326 |
} |
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
size_t Term_mbstowcs_win(wchar_t *dest, const char *src, int n) |
| 2344 |
{ |
| 2345 |
int res; |
| 2346 |
int required; |
| 2347 |
wchar_t *tmp; |
| 2348 |
|
| 2349 |
if (dest) { |
| 2350 |
res = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, |
| 2351 |
dest, n); |
| 2352 |
if (res) |
| 2353 |
return (size_t)(res - 1); |
| 2354 |
else { |
| 2355 |
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
| 2356 |
required = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, |
| 2357 |
src, -1, NULL, 0); |
| 2358 |
tmp = malloc(required * sizeof(wchar_t)); |
| 2359 |
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, tmp, |
| 2360 |
required); |
| 2361 |
memcpy(dest, tmp, n * sizeof(wchar_t)); |
| 2362 |
free(tmp); |
| 2363 |
return n; |
| 2364 |
} else { |
| 2365 |
return (size_t)-1; |
| 2366 |
} |
| 2367 |
} |
| 2368 |
} else { |
| 2369 |
return (size_t)(MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, |
| 2370 |
src, -1, NULL, 0) - 1); |
| 2371 |
} |
| 2372 |
} |
| 2373 |
|
| 2374 |
int Term_wcsz_win(void) |
| 2375 |
{ |
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
return 4; |
| 2380 |
} |
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
int Term_wctomb_win(char *s, wchar_t wchar) |
| 2392 |
{ |
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
int n = WideCharToMultiByte(CP_UTF8, 0, &wchar, 1, s, Term_wcsz_win(), |
| 2400 |
NULL, NULL); |
| 2401 |
return (n > 0) ? n : -1; |
| 2402 |
} |
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
int Term_iswprint_win(wint_t wc) |
| 2413 |
{ |
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
return utf32_isprint((uint32_t) wc); |
| 2421 |
} |
| 2422 |
|
| 2423 |
|
| 2424 |
#ifndef AC_SRC_ALPHA |
| 2425 |
#define AC_SRC_ALPHA 0x01 |
| 2426 |
#endif |
| 2427 |
static errr Term_pict_win_alpha(int x, int y, int n, |
| 2428 |
const int *ap, const wchar_t *cp, |
| 2429 |
const int *tap, const wchar_t *tcp) |
| 2430 |
{ |
| 2431 |
term_data *td = (term_data*)(Term->data); |
| 2432 |
int dhrclip = (overdraw) ? |
| 2433 |
Term_get_first_tile_row(Term) + tile_height - 1 : 0; |
| 2434 |
int i; |
| 2435 |
int mw, mh; |
| 2436 |
int x1, y1, w1, h1; |
| 2437 |
int x2, y2, w2, h2, tw2, th2; |
| 2438 |
int x3, y3; |
| 2439 |
|
| 2440 |
HDC hdc; |
| 2441 |
HDC hdcSrc; |
| 2442 |
HBITMAP hbmSrcOld; |
| 2443 |
|
| 2444 |
|
| 2445 |
w1 = infGraph.CellWidth; |
| 2446 |
h1 = infGraph.CellHeight; |
| 2447 |
|
| 2448 |
|
| 2449 |
if (td->map_active) { |
| 2450 |
w2 = td->map_tile_wid; |
| 2451 |
h2 = td->map_tile_hgt; |
| 2452 |
mw = 1; |
| 2453 |
mh = 1; |
| 2454 |
} else { |
| 2455 |
w2 = td->tile_wid; |
| 2456 |
h2 = td->tile_hgt; |
| 2457 |
|
| 2458 |
|
| 2459 |
mw = tile_width; |
| 2460 |
mh = tile_height; |
| 2461 |
} |
| 2462 |
tw2 = mw * w2; |
| 2463 |
th2 = mh * h2; |
| 2464 |
|
| 2465 |
|
| 2466 |
Term_wipe_win_helper(x, y, n * mw, mh, RGB(0, 0, 0)); |
| 2467 |
|
| 2468 |
|
| 2469 |
x2 = x * w2 + td->size_ow1; |
| 2470 |
y2 = y * h2 + td->size_oh1; |
| 2471 |
|
| 2472 |
|
| 2473 |
hdc = GetDC(td->w); |
| 2474 |
|
| 2475 |
|
| 2476 |
hdcSrc = CreateCompatibleDC(hdc); |
| 2477 |
hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap); |
| 2478 |
|
| 2479 |
|
| 2480 |
for (i = n-1; i >= 0; i--, x2 -= w2) { |
| 2481 |
int a = ap[i]; |
| 2482 |
wchar_t c = cp[i]; |
| 2483 |
|
| 2484 |
|
| 2485 |
int row = (a & 0x7F); |
| 2486 |
int col = (c & 0x7F); |
| 2487 |
int trow = (tap[i] & 0x7F); |
| 2488 |
|
| 2489 |
|
| 2490 |
x1 = col * w1; |
| 2491 |
y1 = row * h1; |
| 2492 |
|
| 2493 |
x3 = (tcp[i] & 0x7F) * w1; |
| 2494 |
y3 = trow * h1; |
| 2495 |
|
| 2496 |
|
| 2497 |
SetStretchBltMode(hdc, COLORONCOLOR); |
| 2498 |
|
| 2499 |
|
| 2500 |
if ((w1 == tw2) && (h1 == th2)) { |
| 2501 |
|
| 2502 |
BitBlt(hdc, x2, y2, tw2, th2, hdcSrc, x3, y3, SRCCOPY); |
| 2503 |
} else { |
| 2504 |
|
| 2505 |
StretchBlt(hdc, x2, y2, tw2, th2, hdcSrc, x3, y3, w1, h1, SRCCOPY); |
| 2506 |
} |
| 2507 |
|
| 2508 |
if (overdraw && trow >= overdraw && y > dhrclip && |
| 2509 |
trow <= overdrawmax) { |
| 2510 |
AlphaBlend(hdc, x2, y2-th2, tw2, th2, hdcSrc, x3, y3-h1, w1, h1, |
| 2511 |
blendfn); |
| 2512 |
} |
| 2513 |
|
| 2514 |
|
| 2515 |
if ((x1 != x3) || (y1 != y3)) |
| 2516 |
{ |
| 2517 |
|
| 2518 |
if (overdraw && row >= overdraw && y > dhrclip && |
| 2519 |
row <= overdrawmax) { |
| 2520 |
AlphaBlend(hdc, x2, y2-th2, tw2, th2*2, hdcSrc, x1, y1-h1, w1, |
| 2521 |
h1*2, blendfn); |
| 2522 |
} else { |
| 2523 |
AlphaBlend(hdc, x2, y2, tw2, th2, hdcSrc, x1, y1, w1, h1, |
| 2524 |
blendfn); |
| 2525 |
} |
| 2526 |
} |
| 2527 |
} |
| 2528 |
|
| 2529 |
|
| 2530 |
SelectObject(hdcSrc, hbmSrcOld); |
| 2531 |
DeleteDC(hdcSrc); |
| 2532 |
|
| 2533 |
|
| 2534 |
ReleaseDC(td->w, hdc); |
| 2535 |
|
| 2536 |
|
| 2537 |
return 0; |
| 2538 |
} |
| 2539 |
|
| 2540 |
|
| 2541 |
static void windows_map_aux(void) |
| 2542 |
{ |
| 2543 |
term_data *td = &data[0]; |
| 2544 |
int a; |
| 2545 |
wchar_t c; |
| 2546 |
int x, min_x, max_x; |
| 2547 |
int y, min_y, max_y; |
| 2548 |
int ta; |
| 2549 |
wchar_t tc; |
| 2550 |
|
| 2551 |
td->map_tile_wid = (td->tile_wid * td->cols) / cave->width; |
| 2552 |
td->map_tile_hgt = (td->tile_hgt * td->rows) / cave->height; |
| 2553 |
|
| 2554 |
min_x = 0; |
| 2555 |
min_y = 0; |
| 2556 |
max_x = cave->width; |
| 2557 |
max_y = cave->height; |
| 2558 |
|
| 2559 |
|
| 2560 |
for (x = min_x; x < max_x; x++) { |
| 2561 |
for (y = min_y; y < max_y; y++) { |
| 2562 |
struct grid_data g; |
| 2563 |
|
| 2564 |
map_info(loc(x, y), &g); |
| 2565 |
grid_data_as_text(&g, &a, &c, &ta, &tc); |
| 2566 |
|
| 2567 |
|
| 2568 |
if (a & 0x80) |
| 2569 |
Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc); |
| 2570 |
} |
| 2571 |
} |
| 2572 |
|
| 2573 |
|
| 2574 |
Term_curs_win(player->grid.x - min_x, player->grid.y - min_y); |
| 2575 |
} |
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
static void windows_map(void) |
| 2582 |
{ |
| 2583 |
term_data *td = &data[0]; |
| 2584 |
ui_event ch; |
| 2585 |
|
| 2586 |
|
| 2587 |
if (!use_graphics) return; |
| 2588 |
|
| 2589 |
|
| 2590 |
initialized = false; |
| 2591 |
|
| 2592 |
|
| 2593 |
Term_xtra_win_clear(); |
| 2594 |
|
| 2595 |
td->map_active = true; |
| 2596 |
|
| 2597 |
|
| 2598 |
windows_map_aux(); |
| 2599 |
|
| 2600 |
|
| 2601 |
Term_inkey(&ch, true, true); |
| 2602 |
Term_flush(); |
| 2603 |
|
| 2604 |
|
| 2605 |
td->map_active = false; |
| 2606 |
|
| 2607 |
|
| 2608 |
Term_xtra_win_clear(); |
| 2609 |
Term_redraw(); |
| 2610 |
|
| 2611 |
|
| 2612 |
initialized = true; |
| 2613 |
} |
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
static void term_data_link(term_data *td) |
| 2627 |
{ |
| 2628 |
term *t = &td->t; |
| 2629 |
|
| 2630 |
|
| 2631 |
term_init(t, td->cols, td->rows, td->keys); |
| 2632 |
|
| 2633 |
|
| 2634 |
t->soft_cursor = true; |
| 2635 |
|
| 2636 |
|
| 2637 |
t->complex_input = true; |
| 2638 |
|
| 2639 |
|
| 2640 |
t->higher_pict = true; |
| 2641 |
|
| 2642 |
#if 0 |
| 2643 |
|
| 2644 |
t->init_hook = Term_init_win; |
| 2645 |
t->nuke_hook = Term_nuke_win; |
| 2646 |
#endif |
| 2647 |
|
| 2648 |
|
| 2649 |
t->xtra_hook = Term_xtra_win; |
| 2650 |
t->curs_hook = Term_curs_win; |
| 2651 |
t->bigcurs_hook = Term_bigcurs_win; |
| 2652 |
t->wipe_hook = Term_wipe_win; |
| 2653 |
t->text_hook = Term_text_win; |
| 2654 |
t->pict_hook = Term_pict_win; |
| 2655 |
t->dblh_hook = NULL; |
| 2656 |
|
| 2657 |
|
| 2658 |
t->data = td; |
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
static void init_windows(void) |
| 2672 |
{ |
| 2673 |
int i; |
| 2674 |
|
| 2675 |
term_data *td; |
| 2676 |
|
| 2677 |
char buf[1024]; |
| 2678 |
|
| 2679 |
WINDOWPLACEMENT lpwndpl; |
| 2680 |
|
| 2681 |
MENUITEMINFO mii; |
| 2682 |
HMENU hm; |
| 2683 |
graphics_mode *mode; |
| 2684 |
|
| 2685 |
|
| 2686 |
td = &data[0]; |
| 2687 |
memset(td, 0, sizeof(term_data)); |
| 2688 |
td->s = angband_term_name[0]; |
| 2689 |
td->keys = 1024; |
| 2690 |
td->rows = 24; |
| 2691 |
td->cols = 80; |
| 2692 |
td->visible = true; |
| 2693 |
td->size_ow1 = 2; |
| 2694 |
td->size_ow2 = 2; |
| 2695 |
td->size_oh1 = 2; |
| 2696 |
td->size_oh2 = 2; |
| 2697 |
td->pos_x = 30; |
| 2698 |
td->pos_y = 20; |
| 2699 |
|
| 2700 |
|
| 2701 |
for (i = 1; i < MAX_TERM_DATA; i++) { |
| 2702 |
td = &data[i]; |
| 2703 |
memset(td, 0, sizeof(term_data)); |
| 2704 |
td->s = angband_term_name[i]; |
| 2705 |
td->keys = 16; |
| 2706 |
td->rows = 24; |
| 2707 |
td->cols = 80; |
| 2708 |
td->visible = false; |
| 2709 |
td->size_ow1 = 1; |
| 2710 |
td->size_ow2 = 1; |
| 2711 |
td->size_oh1 = 1; |
| 2712 |
td->size_oh2 = 1; |
| 2713 |
td->pos_x = (7 - i) * 30; |
| 2714 |
td->pos_y = (7 - i) * 20; |
| 2715 |
} |
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
load_prefs(); |
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
td = &data[0]; |
| 2724 |
td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | |
| 2725 |
WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | |
| 2726 |
WS_VISIBLE); |
| 2727 |
if (td->maximized) td->dwStyle |= WS_MAXIMIZE; |
| 2728 |
td->dwExStyle = 0; |
| 2729 |
td->visible = true; |
| 2730 |
|
| 2731 |
|
| 2732 |
for (i = 1; i < MAX_TERM_DATA; i++) { |
| 2733 |
td = &data[i]; |
| 2734 |
td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_CAPTION); |
| 2735 |
td->dwExStyle = (WS_EX_TOOLWINDOW); |
| 2736 |
} |
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 2741 |
td = &data[i]; |
| 2742 |
|
| 2743 |
|
| 2744 |
path_build(buf, sizeof(buf), ANGBAND_DIR_FONTS, td->font_want); |
| 2745 |
|
| 2746 |
|
| 2747 |
if (term_force_font(td, buf)) { |
| 2748 |
|
| 2749 |
path_build(buf, sizeof(buf), ANGBAND_DIR_FONTS, DEFAULT_FONT); |
| 2750 |
|
| 2751 |
|
| 2752 |
(void)term_force_font(td, buf); |
| 2753 |
|
| 2754 |
|
| 2755 |
td->tile_wid = 8; |
| 2756 |
td->tile_hgt = 13; |
| 2757 |
|
| 2758 |
|
| 2759 |
td->bizarre = true; |
| 2760 |
} |
| 2761 |
|
| 2762 |
|
| 2763 |
term_getsize(td); |
| 2764 |
|
| 2765 |
|
| 2766 |
term_window_resize(td); |
| 2767 |
} |
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
for (i = MAX_TERM_DATA - 1; i >= 1; --i) { |
| 2772 |
td = &data[i]; |
| 2773 |
|
| 2774 |
my_td = td; |
| 2775 |
td->w = CreateWindowEx(td->dwExStyle, AngList, |
| 2776 |
td->s, td->dwStyle, |
| 2777 |
td->pos_x, td->pos_y, |
| 2778 |
td->size_wid, td->size_hgt, |
| 2779 |
HWND_DESKTOP, NULL, hInstance, NULL); |
| 2780 |
my_td = NULL; |
| 2781 |
if (!td->w) quit("Failed to create sub-window"); |
| 2782 |
|
| 2783 |
term_data_link(td); |
| 2784 |
angband_term[i] = &td->t; |
| 2785 |
|
| 2786 |
if (td->visible) { |
| 2787 |
td->size_hack = true; |
| 2788 |
ShowWindow(td->w, SW_SHOW); |
| 2789 |
td->size_hack = false; |
| 2790 |
|
| 2791 |
|
| 2792 |
SetActiveWindow(td->w); |
| 2793 |
|
| 2794 |
|
| 2795 |
lpwndpl.length = sizeof(WINDOWPLACEMENT); |
| 2796 |
lpwndpl.showCmd = SW_SHOWNORMAL; |
| 2797 |
lpwndpl.rcNormalPosition = (RECT) { td->pos_x, td->pos_y, |
| 2798 |
td->pos_x + td->size_wid, |
| 2799 |
td->pos_y + td->size_hgt }; |
| 2800 |
SetWindowPlacement(td->w, &lpwndpl); |
| 2801 |
|
| 2802 |
} |
| 2803 |
} |
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
td = &data[0]; |
| 2808 |
|
| 2809 |
|
| 2810 |
my_td = td; |
| 2811 |
td->w = CreateWindowEx(td->dwExStyle, AppName, |
| 2812 |
td->s, td->dwStyle, |
| 2813 |
td->pos_x, td->pos_y, |
| 2814 |
td->size_wid, td->size_hgt, |
| 2815 |
HWND_DESKTOP, NULL, hInstance, NULL); |
| 2816 |
my_td = NULL; |
| 2817 |
if (!td->w) quit_fmt("Failed to create %s window", VERSION_NAME); |
| 2818 |
|
| 2819 |
term_data_link(td); |
| 2820 |
term_screen = &td->t; |
| 2821 |
text_mbcs_hook = Term_mbstowcs_win; |
| 2822 |
text_wctomb_hook = Term_wctomb_win; |
| 2823 |
text_wcsz_hook = Term_wcsz_win; |
| 2824 |
text_iswprint_hook = Term_iswprint_win; |
| 2825 |
|
| 2826 |
|
| 2827 |
SetActiveWindow(td->w); |
| 2828 |
|
| 2829 |
|
| 2830 |
lpwndpl.length = sizeof(WINDOWPLACEMENT); |
| 2831 |
lpwndpl.showCmd = SW_SHOWNORMAL; |
| 2832 |
lpwndpl.rcNormalPosition = (RECT) { td->pos_x, td->pos_y, |
| 2833 |
td->pos_x + td->size_wid, |
| 2834 |
td->pos_y + td->size_hgt }; |
| 2835 |
SetWindowPlacement(td->w, &lpwndpl); |
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
if (gamma_correction > 0) |
| 2840 |
build_gamma_table(gamma_correction); |
| 2841 |
|
| 2842 |
|
| 2843 |
(void)new_palette(); |
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
hbrYellow = CreateSolidBrush(win_clr[COLOUR_YELLOW]); |
| 2848 |
|
| 2849 |
|
| 2850 |
hm = GetMenu(data[0].w); |
| 2851 |
mii.cbSize = sizeof(MENUITEMINFO); |
| 2852 |
mii.fMask = MIIM_ID | MIIM_TYPE; |
| 2853 |
mii.fType = MFT_STRING; |
| 2854 |
mode = graphics_modes; |
| 2855 |
while (mode) { |
| 2856 |
if (mode->grafID != GRAPHICS_NONE) { |
| 2857 |
mii.wID = mode->grafID + IDM_OPTIONS_GRAPHICS_NONE; |
| 2858 |
mii.dwTypeData = mode->menuname; |
| 2859 |
mii.cch = strlen(mode->menuname); |
| 2860 |
InsertMenuItem(hm,IDM_OPTIONS_GRAPHICS_NICE, false, &mii); |
| 2861 |
} |
| 2862 |
mode = mode->pNext; |
| 2863 |
} |
| 2864 |
|
| 2865 |
mii.fMask = MIIM_TYPE; |
| 2866 |
mii.fType = MFT_SEPARATOR; |
| 2867 |
mii.wID = 399; |
| 2868 |
mii.dwTypeData = 0; |
| 2869 |
mii.cch = 0; |
| 2870 |
InsertMenuItem(hm,IDM_OPTIONS_GRAPHICS_NICE, false, &mii); |
| 2871 |
|
| 2872 |
|
| 2873 |
blendfn.BlendOp = AC_SRC_OVER; |
| 2874 |
blendfn.BlendFlags = 0; |
| 2875 |
blendfn.AlphaFormat = AC_SRC_ALPHA; |
| 2876 |
blendfn.SourceConstantAlpha = 255; |
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
(void)Term_xtra_win_flush(); |
| 2881 |
} |
| 2882 |
|
| 2883 |
|
| 2884 |
#ifdef USE_SAVER |
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
static void stop_screensaver(void) |
| 2890 |
{ |
| 2891 |
if (screensaver) |
| 2892 |
SendMessage(data[0].w, WM_CLOSE, 0, 0); |
| 2893 |
else |
| 2894 |
SendMessage(data[0].w, WM_COMMAND, IDM_OPTIONS_SAVER, 0); |
| 2895 |
} |
| 2896 |
|
| 2897 |
#endif |
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
static void setup_menus(void) |
| 2904 |
{ |
| 2905 |
size_t i; |
| 2906 |
graphics_mode *mode; |
| 2907 |
|
| 2908 |
HMENU hm = GetMenu(data[0].w); |
| 2909 |
|
| 2910 |
#ifdef USE_SAVER |
| 2911 |
main_menu = hm; |
| 2912 |
#endif |
| 2913 |
|
| 2914 |
|
| 2915 |
EnableMenuItem(hm, IDM_FILE_NEW, |
| 2916 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2917 |
EnableMenuItem(hm, IDM_FILE_OPEN, |
| 2918 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2919 |
EnableMenuItem(hm, IDM_FILE_SAVE, |
| 2920 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2921 |
EnableMenuItem(hm, IDM_FILE_EXIT, |
| 2922 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2923 |
|
| 2924 |
EnableMenuItem(hm, IDM_WINDOW_OPT, |
| 2925 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2926 |
|
| 2927 |
|
| 2928 |
if (!character_generated) { |
| 2929 |
|
| 2930 |
EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED); |
| 2931 |
|
| 2932 |
|
| 2933 |
EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED); |
| 2934 |
} |
| 2935 |
|
| 2936 |
|
| 2937 |
if (game_in_progress && character_generated && inkey_flag) { |
| 2938 |
|
| 2939 |
EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED); |
| 2940 |
|
| 2941 |
EnableMenuItem(hm, IDM_WINDOW_OPT, MF_BYCOMMAND | MF_ENABLED); |
| 2942 |
} |
| 2943 |
|
| 2944 |
if (!game_in_progress || !character_generated || inkey_flag) { |
| 2945 |
|
| 2946 |
EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED); |
| 2947 |
} |
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 2952 |
EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, |
| 2953 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2954 |
|
| 2955 |
CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, |
| 2956 |
(data[i].visible ? MF_CHECKED : MF_UNCHECKED)); |
| 2957 |
|
| 2958 |
EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, |
| 2959 |
MF_BYCOMMAND | MF_ENABLED); |
| 2960 |
} |
| 2961 |
|
| 2962 |
|
| 2963 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 2964 |
EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, |
| 2965 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2966 |
|
| 2967 |
if (data[i].visible) { |
| 2968 |
EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, |
| 2969 |
MF_BYCOMMAND | MF_ENABLED); |
| 2970 |
} |
| 2971 |
} |
| 2972 |
|
| 2973 |
|
| 2974 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 2975 |
EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, |
| 2976 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2977 |
|
| 2978 |
CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, |
| 2979 |
(data[i].bizarre ? MF_CHECKED : MF_UNCHECKED)); |
| 2980 |
|
| 2981 |
if (data[i].visible) { |
| 2982 |
EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, |
| 2983 |
MF_BYCOMMAND | MF_ENABLED); |
| 2984 |
} |
| 2985 |
} |
| 2986 |
|
| 2987 |
|
| 2988 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 2989 |
EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, |
| 2990 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 2991 |
|
| 2992 |
if (data[i].visible) { |
| 2993 |
EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, |
| 2994 |
MF_BYCOMMAND | MF_ENABLED); |
| 2995 |
} |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 3000 |
EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, |
| 3001 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3002 |
|
| 3003 |
if (data[i].visible) { |
| 3004 |
EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, |
| 3005 |
MF_BYCOMMAND | MF_ENABLED); |
| 3006 |
} |
| 3007 |
} |
| 3008 |
|
| 3009 |
|
| 3010 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 3011 |
EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, |
| 3012 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3013 |
|
| 3014 |
if (data[i].visible) { |
| 3015 |
EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, |
| 3016 |
MF_BYCOMMAND | MF_ENABLED); |
| 3017 |
} |
| 3018 |
} |
| 3019 |
|
| 3020 |
|
| 3021 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 3022 |
EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, |
| 3023 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3024 |
|
| 3025 |
if (data[i].visible) { |
| 3026 |
EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, |
| 3027 |
MF_BYCOMMAND | MF_ENABLED); |
| 3028 |
} |
| 3029 |
} |
| 3030 |
|
| 3031 |
|
| 3032 |
mode = graphics_modes; |
| 3033 |
while (mode) { |
| 3034 |
EnableMenuItem(hm, mode->grafID + IDM_OPTIONS_GRAPHICS_NONE, |
| 3035 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3036 |
mode = mode->pNext; |
| 3037 |
} |
| 3038 |
|
| 3039 |
EnableMenuItem(hm, IDM_OPTIONS_GRAPHICS_NICE, |
| 3040 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3041 |
|
| 3042 |
for (i = IDM_OPTIONS_TILE_1x1; i <= IDM_OPTIONS_TILE_16x16; i++) { |
| 3043 |
EnableMenuItem(hm, i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3044 |
} |
| 3045 |
for (i = IDM_TILE_FONT; i < IDM_TILE_12X13; i++) { |
| 3046 |
EnableMenuItem(hm, i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3047 |
} |
| 3048 |
|
| 3049 |
EnableMenuItem(hm, IDM_TILE_12X20, |
| 3050 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3051 |
EnableMenuItem(hm, IDM_TILE_16X25, |
| 3052 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3053 |
|
| 3054 |
EnableMenuItem(hm, IDM_OPTIONS_SAVER, |
| 3055 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3056 |
EnableMenuItem(hm, IDM_OPTIONS_LOW_PRIORITY, |
| 3057 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3058 |
|
| 3059 |
|
| 3060 |
if (inkey_flag && initialized && (use_graphics != GRAPHICS_NONE)) |
| 3061 |
EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, |
| 3062 |
MF_BYCOMMAND | MF_ENABLED); |
| 3063 |
else |
| 3064 |
EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, |
| 3065 |
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| 3066 |
|
| 3067 |
|
| 3068 |
mode = graphics_modes; |
| 3069 |
while (mode) { |
| 3070 |
CheckMenuItem(hm, mode->grafID + IDM_OPTIONS_GRAPHICS_NONE, |
| 3071 |
(arg_graphics == mode->grafID ? |
| 3072 |
MF_CHECKED : MF_UNCHECKED)); |
| 3073 |
mode = mode->pNext; |
| 3074 |
} |
| 3075 |
|
| 3076 |
CheckMenuItem(hm, IDM_OPTIONS_GRAPHICS_NICE, |
| 3077 |
(arg_graphics_nice ? MF_CHECKED : MF_UNCHECKED)); |
| 3078 |
|
| 3079 |
if ((tile_width == 1) && (tile_height == 1)) |
| 3080 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_1x1, MF_CHECKED); |
| 3081 |
else |
| 3082 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_1x1, MF_UNCHECKED); |
| 3083 |
|
| 3084 |
if ((tile_width == 2) && (tile_height == 1)) |
| 3085 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_2x1, MF_CHECKED); |
| 3086 |
else |
| 3087 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_2x1, MF_UNCHECKED); |
| 3088 |
|
| 3089 |
if ((tile_width == 2) && (tile_height == 2)) |
| 3090 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_2x2, MF_CHECKED); |
| 3091 |
else |
| 3092 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_2x2, MF_UNCHECKED); |
| 3093 |
|
| 3094 |
if ((tile_width == 3) && (tile_height == 1)) |
| 3095 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_3x1, MF_CHECKED); |
| 3096 |
else |
| 3097 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_3x1, MF_UNCHECKED); |
| 3098 |
|
| 3099 |
if ((tile_width == 3) && (tile_height == 3)) |
| 3100 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_3x3, MF_CHECKED); |
| 3101 |
else |
| 3102 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_3x3, MF_UNCHECKED); |
| 3103 |
|
| 3104 |
if ((tile_width == 4) && (tile_height == 2)) |
| 3105 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_4x2, MF_CHECKED); |
| 3106 |
else |
| 3107 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_4x2, MF_UNCHECKED); |
| 3108 |
|
| 3109 |
if ((tile_width == 4) && (tile_height == 4)) |
| 3110 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_4x4, MF_CHECKED); |
| 3111 |
else |
| 3112 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_4x4, MF_UNCHECKED); |
| 3113 |
|
| 3114 |
if ((tile_width == 6) && (tile_height == 3)) |
| 3115 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_6x3, MF_CHECKED); |
| 3116 |
else |
| 3117 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_6x3, MF_UNCHECKED); |
| 3118 |
|
| 3119 |
if ((tile_width == 6) && (tile_height == 6)) |
| 3120 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_6x6, MF_CHECKED); |
| 3121 |
else |
| 3122 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_6x6, MF_UNCHECKED); |
| 3123 |
|
| 3124 |
if ((tile_width == 8) && (tile_height == 4)) |
| 3125 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_8x4, MF_CHECKED); |
| 3126 |
else |
| 3127 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_8x4, MF_UNCHECKED); |
| 3128 |
|
| 3129 |
if ((tile_width == 8) && (tile_height == 8)) |
| 3130 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_8x8, MF_CHECKED); |
| 3131 |
else |
| 3132 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_8x8, MF_UNCHECKED); |
| 3133 |
|
| 3134 |
if ((tile_width == 16) && (tile_height == 8)) |
| 3135 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_16x8, MF_CHECKED); |
| 3136 |
else |
| 3137 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_16x8, MF_UNCHECKED); |
| 3138 |
|
| 3139 |
if ((tile_width == 16) && (tile_height == 16)) |
| 3140 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_16x16, MF_CHECKED); |
| 3141 |
else |
| 3142 |
CheckMenuItem(hm, IDM_OPTIONS_TILE_16x16, MF_UNCHECKED); |
| 3143 |
|
| 3144 |
i = data[0].tile_hgt; |
| 3145 |
if ((data[0].tile_wid == data[0].font_wid) && (i == data[0].font_hgt)) |
| 3146 |
CheckMenuItem(hm, IDM_TILE_FONT, MF_CHECKED); |
| 3147 |
else |
| 3148 |
CheckMenuItem(hm, IDM_TILE_FONT, MF_UNCHECKED); |
| 3149 |
|
| 3150 |
if ((data[0].tile_wid == 8) && (i == 16)) |
| 3151 |
CheckMenuItem(hm, IDM_TILE_08X16, MF_CHECKED); |
| 3152 |
else |
| 3153 |
CheckMenuItem(hm, IDM_TILE_08X16, MF_UNCHECKED); |
| 3154 |
|
| 3155 |
#ifdef USE_SAVER |
| 3156 |
CheckMenuItem(hm, IDM_OPTIONS_SAVER, |
| 3157 |
(hwndSaver ? MF_CHECKED : MF_UNCHECKED)); |
| 3158 |
#endif |
| 3159 |
|
| 3160 |
CheckMenuItem(hm, IDM_OPTIONS_LOW_PRIORITY, |
| 3161 |
(low_priority ? MF_CHECKED : MF_UNCHECKED)); |
| 3162 |
|
| 3163 |
if (inkey_flag && initialized) { |
| 3164 |
|
| 3165 |
mode = graphics_modes; |
| 3166 |
while (mode) { |
| 3167 |
if ((mode->grafID == 0) || (mode->file[0])) { |
| 3168 |
EnableMenuItem(hm, mode->grafID + IDM_OPTIONS_GRAPHICS_NONE, MF_ENABLED); |
| 3169 |
} |
| 3170 |
mode = mode->pNext; |
| 3171 |
} |
| 3172 |
|
| 3173 |
EnableMenuItem(hm, IDM_OPTIONS_GRAPHICS_NICE, MF_ENABLED); |
| 3174 |
|
| 3175 |
|
| 3176 |
if (current_graphics_mode && current_graphics_mode->grafID) { |
| 3177 |
for (i = IDM_OPTIONS_TILE_1x1; |
| 3178 |
i <= IDM_OPTIONS_TILE_16x16; i++) { |
| 3179 |
EnableMenuItem(hm, i, MF_ENABLED); |
| 3180 |
} |
| 3181 |
} |
| 3182 |
for (i = IDM_TILE_FONT; i < IDM_TILE_12X13; i++) { |
| 3183 |
EnableMenuItem(hm, i, MF_ENABLED); |
| 3184 |
} |
| 3185 |
|
| 3186 |
EnableMenuItem(hm, IDM_TILE_12X20, MF_ENABLED); |
| 3187 |
EnableMenuItem(hm, IDM_TILE_16X25, MF_ENABLED); |
| 3188 |
} |
| 3189 |
|
| 3190 |
#ifdef USE_SAVER |
| 3191 |
|
| 3192 |
EnableMenuItem(hm, IDM_OPTIONS_SAVER, |
| 3193 |
MF_BYCOMMAND | MF_ENABLED); |
| 3194 |
#endif |
| 3195 |
|
| 3196 |
EnableMenuItem(hm, IDM_OPTIONS_LOW_PRIORITY, |
| 3197 |
MF_BYCOMMAND | MF_ENABLED); |
| 3198 |
} |
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
static void check_for_save_file(LPSTR cmd_line) |
| 3209 |
{ |
| 3210 |
char *s, *p; |
| 3211 |
|
| 3212 |
|
| 3213 |
s = cmd_line; |
| 3214 |
|
| 3215 |
|
| 3216 |
if (!s || !*s) return; |
| 3217 |
|
| 3218 |
|
| 3219 |
p = strchr(s, ' '); |
| 3220 |
|
| 3221 |
|
| 3222 |
if (p) *p = '\0'; |
| 3223 |
|
| 3224 |
|
| 3225 |
my_strcpy(savefile, s, sizeof(savefile)); |
| 3226 |
|
| 3227 |
|
| 3228 |
validate_file(savefile); |
| 3229 |
|
| 3230 |
|
| 3231 |
game_in_progress = true; |
| 3232 |
Term_fresh(); |
| 3233 |
play_game(GAME_LOAD); |
| 3234 |
quit(NULL); |
| 3235 |
} |
| 3236 |
|
| 3237 |
|
| 3238 |
#ifdef USE_SAVER |
| 3239 |
|
| 3240 |
#ifdef ALLOW_BORG |
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
extern struct keypress(*inkey_hack)(int flush_first); |
| 3254 |
|
| 3255 |
static struct keypress screensaver_inkey_hack_buffer[1024]; |
| 3256 |
|
| 3257 |
static struct keypress screensaver_inkey_hack(int flush_first) |
| 3258 |
{ |
| 3259 |
static size_t screensaver_inkey_hack_index = 0; |
| 3260 |
|
| 3261 |
if (screensaver_inkey_hack_index < sizeof(screensaver_inkey_hack_buffer)) |
| 3262 |
return (screensaver_inkey_hack_buffer[screensaver_inkey_hack_index++]); |
| 3263 |
else |
| 3264 |
{ |
| 3265 |
struct keypress key = { EVT_KBRD, ESCAPE, 0 }; |
| 3266 |
return key; |
| 3267 |
} |
| 3268 |
} |
| 3269 |
|
| 3270 |
#endif |
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
static void start_screensaver(void) |
| 3276 |
{ |
| 3277 |
bool file_exist; |
| 3278 |
#ifdef ALLOW_BORG |
| 3279 |
int i, j; |
| 3280 |
struct keypress key = { EVT_KBRD, 0, 0 }; |
| 3281 |
#endif |
| 3282 |
|
| 3283 |
|
| 3284 |
init_display(); |
| 3285 |
init_angband(); |
| 3286 |
|
| 3287 |
textui_init(); |
| 3288 |
|
| 3289 |
|
| 3290 |
savefile_set_name(saverfilename, true, false); |
| 3291 |
|
| 3292 |
|
| 3293 |
file_exist = file_exists(savefile); |
| 3294 |
|
| 3295 |
|
| 3296 |
if (!file_exist) savefile[0] = '\0'; |
| 3297 |
|
| 3298 |
|
| 3299 |
game_in_progress = true; |
| 3300 |
|
| 3301 |
Term_fresh(); |
| 3302 |
|
| 3303 |
|
| 3304 |
SendMessage(data[0].w, WM_COMMAND, IDM_OPTIONS_SAVER, 0); |
| 3305 |
|
| 3306 |
|
| 3307 |
SendMessage(data[0].w, WM_COMMAND, IDM_OPTIONS_LOW_PRIORITY, 0); |
| 3308 |
|
| 3309 |
#ifdef ALLOW_BORG |
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
inkey_hack = screensaver_inkey_hack; |
| 3318 |
j = 0; |
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
key.code = ESCAPE; |
| 3331 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3332 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3333 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3334 |
key.code = 'n'; |
| 3335 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3336 |
key.code = KC_ENTER; |
| 3337 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3338 |
|
| 3339 |
if (!file_exist) |
| 3340 |
{ |
| 3341 |
|
| 3342 |
int n = strlen(saverfilename); |
| 3343 |
for (i = 0; i < n; i++) |
| 3344 |
{ |
| 3345 |
key.code = saverfilename[i]; |
| 3346 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3347 |
} |
| 3348 |
} |
| 3349 |
|
| 3350 |
key.code = KC_ENTER; |
| 3351 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3352 |
key.code = ESCAPE; |
| 3353 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
player->noscore |= (NOSCORE_BORG); |
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
key.code = '5'; |
| 3368 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3369 |
|
| 3370 |
|
| 3371 |
key.code = '2'; |
| 3372 |
for (i = 0; i < OPT_cheat_live - OPT_cheat_hear - 1; i++) |
| 3373 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3374 |
|
| 3375 |
key.code = 'y'; |
| 3376 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3377 |
key.code = ESCAPE; |
| 3378 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3379 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
key.code = KTRL('Z'); |
| 3386 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3387 |
key.code = 'z'; |
| 3388 |
screensaver_inkey_hack_buffer[j++] = key; |
| 3389 |
#endif |
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
play_game(GAME_LOAD); |
| 3394 |
} |
| 3395 |
|
| 3396 |
#endif |
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
static void display_help(void) |
| 3403 |
{ |
| 3404 |
Term_keypress('?',0); |
| 3405 |
} |
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
static void process_menus(WORD wCmd) |
| 3412 |
{ |
| 3413 |
int i; |
| 3414 |
|
| 3415 |
term_data *td; |
| 3416 |
|
| 3417 |
OPENFILENAME ofn; |
| 3418 |
|
| 3419 |
|
| 3420 |
switch (wCmd) |
| 3421 |
{ |
| 3422 |
|
| 3423 |
case IDM_FILE_NEW: |
| 3424 |
{ |
| 3425 |
if (!initialized) { |
| 3426 |
plog("You cannot do that yet..."); |
| 3427 |
} else if (game_in_progress) { |
| 3428 |
plog("You can't start a new game while you're still playing!"); |
| 3429 |
} else { |
| 3430 |
|
| 3431 |
game_in_progress = true; |
| 3432 |
Term_fresh(); |
| 3433 |
play_game(GAME_NEW); |
| 3434 |
quit(NULL); |
| 3435 |
} |
| 3436 |
break; |
| 3437 |
} |
| 3438 |
|
| 3439 |
|
| 3440 |
case IDM_FILE_OPEN: |
| 3441 |
{ |
| 3442 |
if (!initialized) { |
| 3443 |
plog("You cannot do that yet..."); |
| 3444 |
} else if (game_in_progress) { |
| 3445 |
plog("You can't open a new game while you're still playing!"); |
| 3446 |
} else { |
| 3447 |
memset(&ofn, 0, sizeof(ofn)); |
| 3448 |
ofn.lStructSize = sizeof(ofn); |
| 3449 |
ofn.hwndOwner = data[0].w; |
| 3450 |
ofn.lpstrFilter = "Save Files (*.)\0*\0"; |
| 3451 |
ofn.nFilterIndex = 1; |
| 3452 |
ofn.lpstrFile = savefile; |
| 3453 |
ofn.nMaxFile = 1024; |
| 3454 |
ofn.lpstrInitialDir = ANGBAND_DIR_SAVE; |
| 3455 |
ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; |
| 3456 |
|
| 3457 |
if (GetOpenFileName(&ofn)) { |
| 3458 |
|
| 3459 |
validate_file(savefile); |
| 3460 |
|
| 3461 |
if (monitor_existing_savefile()) { |
| 3462 |
|
| 3463 |
game_in_progress = true; |
| 3464 |
Term_fresh(); |
| 3465 |
play_game(GAME_LOAD); |
| 3466 |
quit(NULL); |
| 3467 |
} |
| 3468 |
} |
| 3469 |
} |
| 3470 |
break; |
| 3471 |
} |
| 3472 |
|
| 3473 |
|
| 3474 |
case IDM_FILE_SAVE: |
| 3475 |
{ |
| 3476 |
if (game_in_progress && character_generated && inkey_flag) { |
| 3477 |
|
| 3478 |
msg_flag = false; |
| 3479 |
|
| 3480 |
|
| 3481 |
save_game(); |
| 3482 |
} else { |
| 3483 |
|
| 3484 |
plog("You may not do that right now."); |
| 3485 |
} |
| 3486 |
break; |
| 3487 |
} |
| 3488 |
|
| 3489 |
|
| 3490 |
case IDM_FILE_EXIT: |
| 3491 |
{ |
| 3492 |
if (game_in_progress && character_generated) { |
| 3493 |
|
| 3494 |
if (!inkey_flag) { |
| 3495 |
plog("You may not do that right now."); |
| 3496 |
break; |
| 3497 |
} |
| 3498 |
|
| 3499 |
|
| 3500 |
msg_flag = false; |
| 3501 |
|
| 3502 |
|
| 3503 |
save_game(); |
| 3504 |
close_game(true); |
| 3505 |
} |
| 3506 |
quit(NULL); |
| 3507 |
break; |
| 3508 |
} |
| 3509 |
|
| 3510 |
case IDM_WINDOW_VIS_0: |
| 3511 |
{ |
| 3512 |
plog("You are not allowed to do that!"); |
| 3513 |
|
| 3514 |
break; |
| 3515 |
} |
| 3516 |
|
| 3517 |
|
| 3518 |
case IDM_WINDOW_VIS_1: |
| 3519 |
case IDM_WINDOW_VIS_2: |
| 3520 |
case IDM_WINDOW_VIS_3: |
| 3521 |
case IDM_WINDOW_VIS_4: |
| 3522 |
case IDM_WINDOW_VIS_5: |
| 3523 |
case IDM_WINDOW_VIS_6: |
| 3524 |
case IDM_WINDOW_VIS_7: |
| 3525 |
{ |
| 3526 |
i = wCmd - IDM_WINDOW_VIS_0; |
| 3527 |
|
| 3528 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3529 |
|
| 3530 |
td = &data[i]; |
| 3531 |
|
| 3532 |
if (!td->visible) { |
| 3533 |
td->visible = true; |
| 3534 |
ShowWindow(td->w, SW_SHOW); |
| 3535 |
term_data_redraw(td); |
| 3536 |
} else { |
| 3537 |
td->visible = false; |
| 3538 |
ShowWindow(td->w, SW_HIDE); |
| 3539 |
} |
| 3540 |
|
| 3541 |
break; |
| 3542 |
} |
| 3543 |
|
| 3544 |
|
| 3545 |
case IDM_WINDOW_FONT_0: |
| 3546 |
case IDM_WINDOW_FONT_1: |
| 3547 |
case IDM_WINDOW_FONT_2: |
| 3548 |
case IDM_WINDOW_FONT_3: |
| 3549 |
case IDM_WINDOW_FONT_4: |
| 3550 |
case IDM_WINDOW_FONT_5: |
| 3551 |
case IDM_WINDOW_FONT_6: |
| 3552 |
case IDM_WINDOW_FONT_7: |
| 3553 |
{ |
| 3554 |
if ((use_graphics_nice) && (!inkey_flag || !initialized)) { |
| 3555 |
plog("You may not do that right now."); |
| 3556 |
break; |
| 3557 |
} |
| 3558 |
|
| 3559 |
i = wCmd - IDM_WINDOW_FONT_0; |
| 3560 |
|
| 3561 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3562 |
|
| 3563 |
td = &data[i]; |
| 3564 |
|
| 3565 |
term_change_font(td); |
| 3566 |
|
| 3567 |
if (use_graphics_nice) { |
| 3568 |
|
| 3569 |
Term_key_push(KTRL('R')); |
| 3570 |
} |
| 3571 |
|
| 3572 |
break; |
| 3573 |
} |
| 3574 |
|
| 3575 |
|
| 3576 |
case IDM_WINDOW_BIZ_0: |
| 3577 |
case IDM_WINDOW_BIZ_1: |
| 3578 |
case IDM_WINDOW_BIZ_2: |
| 3579 |
case IDM_WINDOW_BIZ_3: |
| 3580 |
case IDM_WINDOW_BIZ_4: |
| 3581 |
case IDM_WINDOW_BIZ_5: |
| 3582 |
case IDM_WINDOW_BIZ_6: |
| 3583 |
case IDM_WINDOW_BIZ_7: |
| 3584 |
{ |
| 3585 |
i = wCmd - IDM_WINDOW_BIZ_0; |
| 3586 |
|
| 3587 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3588 |
|
| 3589 |
td = &data[i]; |
| 3590 |
|
| 3591 |
td->bizarre = !td->bizarre; |
| 3592 |
|
| 3593 |
term_getsize(td); |
| 3594 |
|
| 3595 |
term_window_resize(td); |
| 3596 |
|
| 3597 |
break; |
| 3598 |
} |
| 3599 |
|
| 3600 |
|
| 3601 |
case IDM_WINDOW_I_WID_0: |
| 3602 |
case IDM_WINDOW_I_WID_1: |
| 3603 |
case IDM_WINDOW_I_WID_2: |
| 3604 |
case IDM_WINDOW_I_WID_3: |
| 3605 |
case IDM_WINDOW_I_WID_4: |
| 3606 |
case IDM_WINDOW_I_WID_5: |
| 3607 |
case IDM_WINDOW_I_WID_6: |
| 3608 |
case IDM_WINDOW_I_WID_7: |
| 3609 |
{ |
| 3610 |
i = wCmd - IDM_WINDOW_I_WID_0; |
| 3611 |
|
| 3612 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3613 |
|
| 3614 |
td = &data[i]; |
| 3615 |
|
| 3616 |
td->tile_wid += 1; |
| 3617 |
|
| 3618 |
term_getsize(td); |
| 3619 |
|
| 3620 |
term_window_resize(td); |
| 3621 |
|
| 3622 |
break; |
| 3623 |
} |
| 3624 |
|
| 3625 |
|
| 3626 |
case IDM_WINDOW_D_WID_0: |
| 3627 |
case IDM_WINDOW_D_WID_1: |
| 3628 |
case IDM_WINDOW_D_WID_2: |
| 3629 |
case IDM_WINDOW_D_WID_3: |
| 3630 |
case IDM_WINDOW_D_WID_4: |
| 3631 |
case IDM_WINDOW_D_WID_5: |
| 3632 |
case IDM_WINDOW_D_WID_6: |
| 3633 |
case IDM_WINDOW_D_WID_7: |
| 3634 |
{ |
| 3635 |
i = wCmd - IDM_WINDOW_D_WID_0; |
| 3636 |
|
| 3637 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3638 |
|
| 3639 |
td = &data[i]; |
| 3640 |
|
| 3641 |
td->tile_wid -= 1; |
| 3642 |
|
| 3643 |
term_getsize(td); |
| 3644 |
|
| 3645 |
term_window_resize(td); |
| 3646 |
|
| 3647 |
break; |
| 3648 |
} |
| 3649 |
|
| 3650 |
|
| 3651 |
case IDM_WINDOW_I_HGT_0: |
| 3652 |
case IDM_WINDOW_I_HGT_1: |
| 3653 |
case IDM_WINDOW_I_HGT_2: |
| 3654 |
case IDM_WINDOW_I_HGT_3: |
| 3655 |
case IDM_WINDOW_I_HGT_4: |
| 3656 |
case IDM_WINDOW_I_HGT_5: |
| 3657 |
case IDM_WINDOW_I_HGT_6: |
| 3658 |
case IDM_WINDOW_I_HGT_7: |
| 3659 |
{ |
| 3660 |
i = wCmd - IDM_WINDOW_I_HGT_0; |
| 3661 |
|
| 3662 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3663 |
|
| 3664 |
td = &data[i]; |
| 3665 |
|
| 3666 |
td->tile_hgt += 1; |
| 3667 |
|
| 3668 |
term_getsize(td); |
| 3669 |
|
| 3670 |
term_window_resize(td); |
| 3671 |
|
| 3672 |
break; |
| 3673 |
} |
| 3674 |
|
| 3675 |
|
| 3676 |
case IDM_WINDOW_D_HGT_0: |
| 3677 |
case IDM_WINDOW_D_HGT_1: |
| 3678 |
case IDM_WINDOW_D_HGT_2: |
| 3679 |
case IDM_WINDOW_D_HGT_3: |
| 3680 |
case IDM_WINDOW_D_HGT_4: |
| 3681 |
case IDM_WINDOW_D_HGT_5: |
| 3682 |
case IDM_WINDOW_D_HGT_6: |
| 3683 |
case IDM_WINDOW_D_HGT_7: { |
| 3684 |
i = wCmd - IDM_WINDOW_D_HGT_0; |
| 3685 |
|
| 3686 |
if ((i < 0) || (i >= MAX_TERM_DATA)) break; |
| 3687 |
|
| 3688 |
td = &data[i]; |
| 3689 |
td->tile_hgt -= 1; |
| 3690 |
|
| 3691 |
term_getsize(td); |
| 3692 |
term_window_resize(td); |
| 3693 |
|
| 3694 |
break; |
| 3695 |
} |
| 3696 |
|
| 3697 |
case IDM_WINDOW_OPT: { |
| 3698 |
Term_keypress('=',0); |
| 3699 |
Term_keypress('w',0); |
| 3700 |
|
| 3701 |
break; |
| 3702 |
} |
| 3703 |
case IDM_WINDOW_RESET: { |
| 3704 |
|
| 3705 |
if (!inkey_flag || !initialized) { |
| 3706 |
plog("You may not do that right now."); |
| 3707 |
break; |
| 3708 |
} |
| 3709 |
|
| 3710 |
|
| 3711 |
if (MessageBox(NULL, |
| 3712 |
"This will reset the size and layout of the angband windows\n based on your screen size. Do you want to continue?", |
| 3713 |
VERSION_NAME, MB_YESNO|MB_ICONWARNING) == IDYES) { |
| 3714 |
term *old = Term; |
| 3715 |
RECT rc; |
| 3716 |
|
| 3717 |
(void)default_layout_win(data,MAX_TERM_DATA); |
| 3718 |
|
| 3719 |
for (i = 0; i < MAX_TERM_DATA; i++) { |
| 3720 |
|
| 3721 |
Term_activate(&(data[i].t)); |
| 3722 |
|
| 3723 |
|
| 3724 |
Term_resize(data[i].cols, data[i].rows); |
| 3725 |
} |
| 3726 |
|
| 3727 |
Term_activate(old); |
| 3728 |
|
| 3729 |
|
| 3730 |
for (i = MAX_TERM_DATA - 1; i >= 0; i--) { |
| 3731 |
if (!(data[i].w)) continue; |
| 3732 |
|
| 3733 |
|
| 3734 |
rc.left = 0; |
| 3735 |
rc.top = 0; |
| 3736 |
rc.right = rc.left + data[i].cols * data[i].tile_wid + |
| 3737 |
data[i].size_ow1 + data[i].size_ow2; |
| 3738 |
rc.bottom = rc.top + data[i].rows * data[i].tile_hgt + |
| 3739 |
data[i].size_oh1 + data[i].size_oh2; |
| 3740 |
|
| 3741 |
|
| 3742 |
AdjustWindowRectEx(&rc, data[i].dwStyle, true, |
| 3743 |
data[i].dwExStyle); |
| 3744 |
|
| 3745 |
|
| 3746 |
data[i].size_wid = rc.right - rc.left; |
| 3747 |
data[i].size_hgt = rc.bottom - rc.top; |
| 3748 |
|
| 3749 |
if (i == 0) { |
| 3750 |
SetWindowPos(data[i].w, 0, data[i].pos_x, data[i].pos_y, |
| 3751 |
data[i].size_wid, data[i].size_hgt, 0); |
| 3752 |
} else { |
| 3753 |
SetWindowPos(data[i].w, data[0].w, data[i].pos_x, |
| 3754 |
data[i].pos_y, data[i].size_wid, |
| 3755 |
data[i].size_hgt, 0); |
| 3756 |
} |
| 3757 |
if (data[i].visible) { |
| 3758 |
ShowWindow(data[i].w, SW_SHOW); |
| 3759 |
} else { |
| 3760 |
ShowWindow(data[i].w, SW_HIDE); |
| 3761 |
} |
| 3762 |
|
| 3763 |
|
| 3764 |
InvalidateRect(data[i].w, NULL, true); |
| 3765 |
} |
| 3766 |
|
| 3767 |
|
| 3768 |
SetFocus(data[0].w); |
| 3769 |
|
| 3770 |
|
| 3771 |
Term_xtra_win_react(); |
| 3772 |
|
| 3773 |
|
| 3774 |
Term_key_push(KTRL('R')); |
| 3775 |
} |
| 3776 |
|
| 3777 |
break; |
| 3778 |
} |
| 3779 |
|
| 3780 |
case IDM_OPTIONS_GRAPHICS_NICE: { |
| 3781 |
|
| 3782 |
if (!inkey_flag || !initialized) { |
| 3783 |
plog("You may not do that right now."); |
| 3784 |
break; |
| 3785 |
} |
| 3786 |
|
| 3787 |
|
| 3788 |
arg_graphics_nice = !arg_graphics_nice; |
| 3789 |
|
| 3790 |
|
| 3791 |
Term_xtra_win_react(); |
| 3792 |
|
| 3793 |
|
| 3794 |
Term_key_push(KTRL('R')); |
| 3795 |
|
| 3796 |
break; |
| 3797 |
} |
| 3798 |
|
| 3799 |
case IDM_OPTIONS_TILE_1x1: |
| 3800 |
case IDM_OPTIONS_TILE_2x1: |
| 3801 |
case IDM_OPTIONS_TILE_2x2: |
| 3802 |
case IDM_OPTIONS_TILE_3x1: |
| 3803 |
case IDM_OPTIONS_TILE_3x3: |
| 3804 |
case IDM_OPTIONS_TILE_4x2: |
| 3805 |
case IDM_OPTIONS_TILE_4x4: |
| 3806 |
case IDM_OPTIONS_TILE_6x3: |
| 3807 |
case IDM_OPTIONS_TILE_6x6: |
| 3808 |
case IDM_OPTIONS_TILE_8x4: |
| 3809 |
case IDM_OPTIONS_TILE_8x8: |
| 3810 |
case IDM_OPTIONS_TILE_16x8: |
| 3811 |
case IDM_OPTIONS_TILE_16x16: |
| 3812 |
{ |
| 3813 |
|
| 3814 |
if (!inkey_flag || !initialized) { |
| 3815 |
plog("You may not do that right now."); |
| 3816 |
break; |
| 3817 |
} |
| 3818 |
switch (wCmd) |
| 3819 |
{ |
| 3820 |
case IDM_OPTIONS_TILE_1x1: |
| 3821 |
{ |
| 3822 |
tile_width = 1; |
| 3823 |
tile_height = 1; |
| 3824 |
break; |
| 3825 |
} |
| 3826 |
case IDM_OPTIONS_TILE_2x1: |
| 3827 |
{ |
| 3828 |
tile_width = 2; |
| 3829 |
tile_height = 1; |
| 3830 |
break; |
| 3831 |
} |
| 3832 |
case IDM_OPTIONS_TILE_2x2: |
| 3833 |
{ |
| 3834 |
tile_width = 2; |
| 3835 |
tile_height = 2; |
| 3836 |
break; |
| 3837 |
} |
| 3838 |
case IDM_OPTIONS_TILE_3x1: |
| 3839 |
{ |
| 3840 |
tile_width = 3; |
| 3841 |
tile_height = 1; |
| 3842 |
break; |
| 3843 |
} |
| 3844 |
case IDM_OPTIONS_TILE_3x3: |
| 3845 |
{ |
| 3846 |
tile_width = 3; |
| 3847 |
tile_height = 3; |
| 3848 |
break; |
| 3849 |
} |
| 3850 |
case IDM_OPTIONS_TILE_4x2: |
| 3851 |
{ |
| 3852 |
tile_width = 4; |
| 3853 |
tile_height = 2; |
| 3854 |
break; |
| 3855 |
} |
| 3856 |
case IDM_OPTIONS_TILE_4x4: |
| 3857 |
{ |
| 3858 |
tile_width = 4; |
| 3859 |
tile_height = 4; |
| 3860 |
break; |
| 3861 |
} |
| 3862 |
case IDM_OPTIONS_TILE_6x3: |
| 3863 |
{ |
| 3864 |
tile_width = 6; |
| 3865 |
tile_height = 3; |
| 3866 |
break; |
| 3867 |
} |
| 3868 |
case IDM_OPTIONS_TILE_6x6: |
| 3869 |
{ |
| 3870 |
tile_width = 6; |
| 3871 |
tile_height = 6; |
| 3872 |
break; |
| 3873 |
} |
| 3874 |
case IDM_OPTIONS_TILE_8x4: |
| 3875 |
{ |
| 3876 |
tile_width = 8; |
| 3877 |
tile_height = 4; |
| 3878 |
break; |
| 3879 |
} |
| 3880 |
case IDM_OPTIONS_TILE_8x8: |
| 3881 |
{ |
| 3882 |
tile_width = 8; |
| 3883 |
tile_height = 8; |
| 3884 |
break; |
| 3885 |
} |
| 3886 |
case IDM_OPTIONS_TILE_16x8: |
| 3887 |
{ |
| 3888 |
tile_width = 16; |
| 3889 |
tile_height = 8; |
| 3890 |
break; |
| 3891 |
} |
| 3892 |
case IDM_OPTIONS_TILE_16x16: |
| 3893 |
{ |
| 3894 |
tile_width = 16; |
| 3895 |
tile_height = 16; |
| 3896 |
break; |
| 3897 |
} |
| 3898 |
} |
| 3899 |
|
| 3900 |
|
| 3901 |
change_tilesize = true; |
| 3902 |
|
| 3903 |
|
| 3904 |
Term_xtra_win_react(); |
| 3905 |
|
| 3906 |
|
| 3907 |
Term_key_push(KTRL('R')); |
| 3908 |
|
| 3909 |
break; |
| 3910 |
} |
| 3911 |
|
| 3912 |
case IDM_TILE_FONT: |
| 3913 |
case IDM_TILE_08X08: |
| 3914 |
case IDM_TILE_16X16: |
| 3915 |
case IDM_TILE_32X32: |
| 3916 |
case IDM_TILE_08X16: |
| 3917 |
case IDM_TILE_10X20: |
| 3918 |
case IDM_TILE_16X32: |
| 3919 |
case IDM_TILE_08X13: |
| 3920 |
case IDM_TILE_10X17: |
| 3921 |
case IDM_TILE_16X25: |
| 3922 |
case IDM_TILE_12X20: |
| 3923 |
{ |
| 3924 |
|
| 3925 |
if (!inkey_flag || !initialized) { |
| 3926 |
plog("You may not do that right now."); |
| 3927 |
break; |
| 3928 |
} |
| 3929 |
td = &data[0]; |
| 3930 |
switch (wCmd) |
| 3931 |
{ |
| 3932 |
case IDM_TILE_FONT: |
| 3933 |
{ |
| 3934 |
td->tile_wid = td->font_wid; |
| 3935 |
td->tile_hgt = td->font_hgt; |
| 3936 |
break; |
| 3937 |
} |
| 3938 |
case IDM_TILE_08X16: |
| 3939 |
{ |
| 3940 |
td->tile_wid = 8; |
| 3941 |
td->tile_hgt = 16; |
| 3942 |
break; |
| 3943 |
} |
| 3944 |
case IDM_TILE_08X08: |
| 3945 |
{ |
| 3946 |
td->tile_wid = 8; |
| 3947 |
td->tile_hgt = 8; |
| 3948 |
break; |
| 3949 |
} |
| 3950 |
case IDM_TILE_16X16: |
| 3951 |
{ |
| 3952 |
td->tile_wid = 16; |
| 3953 |
td->tile_hgt = 16; |
| 3954 |
break; |
| 3955 |
} |
| 3956 |
case IDM_TILE_32X32: |
| 3957 |
{ |
| 3958 |
td->tile_wid = 32; |
| 3959 |
td->tile_hgt = 32; |
| 3960 |
break; |
| 3961 |
} |
| 3962 |
case IDM_TILE_10X20: |
| 3963 |
{ |
| 3964 |
td->tile_wid = 10; |
| 3965 |
td->tile_hgt = 20; |
| 3966 |
break; |
| 3967 |
} |
| 3968 |
case IDM_TILE_16X32: |
| 3969 |
{ |
| 3970 |
td->tile_wid = 16; |
| 3971 |
td->tile_hgt = 32; |
| 3972 |
break; |
| 3973 |
} |
| 3974 |
case IDM_TILE_12X20: |
| 3975 |
{ |
| 3976 |
td->tile_wid = 12; |
| 3977 |
td->tile_hgt = 20; |
| 3978 |
break; |
| 3979 |
} |
| 3980 |
case IDM_TILE_16X25: |
| 3981 |
{ |
| 3982 |
td->tile_wid = 16; |
| 3983 |
td->tile_hgt = 25; |
| 3984 |
break; |
| 3985 |
} |
| 3986 |
} |
| 3987 |
|
| 3988 |
|
| 3989 |
term_getsize(td); |
| 3990 |
|
| 3991 |
term_window_resize(td); |
| 3992 |
|
| 3993 |
break; |
| 3994 |
} |
| 3995 |
|
| 3996 |
#ifdef USE_SAVER |
| 3997 |
|
| 3998 |
case IDM_OPTIONS_SAVER: |
| 3999 |
{ |
| 4000 |
if (hwndSaver) { |
| 4001 |
DestroyWindow(hwndSaver); |
| 4002 |
hwndSaver = NULL; |
| 4003 |
screensaver_active = false; |
| 4004 |
|
| 4005 |
|
| 4006 |
SetMenu(data[0].w, main_menu); |
| 4007 |
|
| 4008 |
for (i = MAX_TERM_DATA - 1; i >= 0; --i) { |
| 4009 |
td = &data[i]; |
| 4010 |
|
| 4011 |
if (td->visible) { |
| 4012 |
|
| 4013 |
SetWindowLong(td->w, GWL_STYLE, td->dwStyle); |
| 4014 |
|
| 4015 |
|
| 4016 |
SetWindowPos(td->w, HWND_NOTOPMOST, 0, 0, 0, 0, |
| 4017 |
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); |
| 4018 |
} |
| 4019 |
} |
| 4020 |
|
| 4021 |
ShowCursor(true); |
| 4022 |
} else { |
| 4023 |
|
| 4024 |
hwndSaver = CreateWindowEx(WS_EX_TOPMOST, |
| 4025 |
"WindowsScreenSaverClass", |
| 4026 |
"Angband Screensaver", |
| 4027 |
WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, |
| 4028 |
0, 0, GetSystemMetrics(SM_CXSCREEN), |
| 4029 |
GetSystemMetrics(SM_CYSCREEN), |
| 4030 |
NULL, NULL, hInstance, NULL); |
| 4031 |
if (hwndSaver) { |
| 4032 |
for (i = MAX_TERM_DATA - 1; i >= 0; --i) { |
| 4033 |
td = &data[i]; |
| 4034 |
|
| 4035 |
if (td->visible) { |
| 4036 |
|
| 4037 |
SetWindowLong(td->w, GWL_STYLE, WS_VISIBLE); |
| 4038 |
|
| 4039 |
|
| 4040 |
SetMenu(td->w, NULL); |
| 4041 |
|
| 4042 |
|
| 4043 |
SetWindowPos(td->w, HWND_TOPMOST, 0, 0, 0, 0, |
| 4044 |
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); |
| 4045 |
} |
| 4046 |
} |
| 4047 |
|
| 4048 |
ShowCursor(false); |
| 4049 |
|
| 4050 |
screensaver_active = true; |
| 4051 |
} else { |
| 4052 |
plog("Failed to create saver window"); |
| 4053 |
} |
| 4054 |
} |
| 4055 |
|
| 4056 |
break; |
| 4057 |
} |
| 4058 |
|
| 4059 |
#endif |
| 4060 |
|
| 4061 |
case IDM_OPTIONS_LOW_PRIORITY: |
| 4062 |
{ |
| 4063 |
|
| 4064 |
if (low_priority) |
| 4065 |
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); |
| 4066 |
else |
| 4067 |
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); |
| 4068 |
|
| 4069 |
|
| 4070 |
low_priority = !low_priority; |
| 4071 |
|
| 4072 |
break; |
| 4073 |
} |
| 4074 |
|
| 4075 |
case IDM_OPTIONS_MAP: |
| 4076 |
{ |
| 4077 |
|
| 4078 |
if (!inkey_flag || !initialized) { |
| 4079 |
plog("You may not do that right now."); |
| 4080 |
break; |
| 4081 |
} |
| 4082 |
|
| 4083 |
windows_map(); |
| 4084 |
break; |
| 4085 |
} |
| 4086 |
|
| 4087 |
case IDM_HELP_GENERAL: |
| 4088 |
{ |
| 4089 |
display_help(); |
| 4090 |
break; |
| 4091 |
} |
| 4092 |
|
| 4093 |
case IDM_OPTIONS_SCREENSHOT:{ |
| 4094 |
char filename[1024]; |
| 4095 |
char path[1024]; |
| 4096 |
time_t ltime; |
| 4097 |
struct tm *today; |
| 4098 |
int len; |
| 4099 |
|
| 4100 |
time( <ime ); |
| 4101 |
today = localtime( <ime ); |
| 4102 |
strnfmt(filename, sizeof(filename), "%s", player->full_name); |
| 4103 |
len = strlen(filename); |
| 4104 |
strftime(filename+len, sizeof(filename)-len, "_%Y%b%d_%H%M%S.png", |
| 4105 |
today); |
| 4106 |
|
| 4107 |
|
| 4108 |
path_build(path, sizeof(path), ANGBAND_DIR_USER, filename); |
| 4109 |
td = &data[0]; |
| 4110 |
if (!SaveWindow_PNG(td->w, path)) { |
| 4111 |
plog("Screenshot Save Failed."); |
| 4112 |
} |
| 4113 |
break; |
| 4114 |
} |
| 4115 |
|
| 4116 |
default: { |
| 4117 |
if ((wCmd >= IDM_OPTIONS_GRAPHICS_NONE) && |
| 4118 |
(wCmd <= IDM_OPTIONS_GRAPHICS_NONE + graphics_mode_high_id)) { |
| 4119 |
int selected_mode = 0; |
| 4120 |
int desired_mode = wCmd - IDM_OPTIONS_GRAPHICS_NONE; |
| 4121 |
|
| 4122 |
|
| 4123 |
if (!inkey_flag || !initialized) { |
| 4124 |
plog("You may not do that right now."); |
| 4125 |
break; |
| 4126 |
} |
| 4127 |
|
| 4128 |
i = 0; |
| 4129 |
do { |
| 4130 |
if (graphics_modes[i].grafID == desired_mode) { |
| 4131 |
selected_mode = desired_mode; |
| 4132 |
break; |
| 4133 |
} |
| 4134 |
} while (graphics_modes[i++].grafID != 0); |
| 4135 |
|
| 4136 |
|
| 4137 |
if (arg_graphics != selected_mode) { |
| 4138 |
arg_graphics = selected_mode; |
| 4139 |
|
| 4140 |
|
| 4141 |
if ((selected_mode == GRAPHICS_NONE) |
| 4142 |
&& !use_graphics_nice) { |
| 4143 |
td = &data[0]; |
| 4144 |
td->tile_wid = td->font_wid; |
| 4145 |
td->tile_hgt = td->font_hgt; |
| 4146 |
tile_width = 1; |
| 4147 |
tile_height = 1; |
| 4148 |
|
| 4149 |
|
| 4150 |
term_getsize(td); |
| 4151 |
|
| 4152 |
term_window_resize(td); |
| 4153 |
} |
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
Term_xtra_win_react(); |
| 4158 |
|
| 4159 |
|
| 4160 |
Term_key_push(KTRL('R')); |
| 4161 |
} |
| 4162 |
} |
| 4163 |
break; |
| 4164 |
} |
| 4165 |
} |
| 4166 |
} |
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
static void handle_wm_paint(HWND hWnd) |
| 4173 |
{ |
| 4174 |
int x1, y1, x2, y2; |
| 4175 |
PAINTSTRUCT ps; |
| 4176 |
term_data *td; |
| 4177 |
|
| 4178 |
|
| 4179 |
td = (term_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
| 4180 |
|
| 4181 |
BeginPaint(hWnd, &ps); |
| 4182 |
|
| 4183 |
if (td->map_active) { |
| 4184 |
|
| 4185 |
|
| 4186 |
windows_map_aux(); |
| 4187 |
} else { |
| 4188 |
|
| 4189 |
|
| 4190 |
x1 = (ps.rcPaint.left / td->tile_wid) - 1; |
| 4191 |
x2 = (ps.rcPaint.right / td->tile_wid) + 1; |
| 4192 |
y1 = (ps.rcPaint.top / td->tile_hgt) - 1; |
| 4193 |
y2 = (ps.rcPaint.bottom / td->tile_hgt) + 1; |
| 4194 |
|
| 4195 |
|
| 4196 |
if (td) term_data_redraw_section(td, x1, y1, x2, y2); |
| 4197 |
} |
| 4198 |
|
| 4199 |
EndPaint(hWnd, &ps); |
| 4200 |
} |
| 4201 |
|
| 4202 |
|
| 4203 |
static int extract_modifiers(keycode_t ch, bool kp) { |
| 4204 |
bool mc = false; |
| 4205 |
bool ms = false; |
| 4206 |
bool ma = false; |
| 4207 |
|
| 4208 |
|
| 4209 |
if (GetKeyState(VK_CONTROL) & 0x8000) mc = true; |
| 4210 |
if (GetKeyState(VK_SHIFT) & 0x8000) ms = true; |
| 4211 |
if (GetKeyState(VK_MENU) & 0x8000) ma = true; |
| 4212 |
|
| 4213 |
return |
| 4214 |
(mc && (kp || MODS_INCLUDE_CONTROL(ch)) ? KC_MOD_CONTROL : 0) | |
| 4215 |
(ms && (kp || MODS_INCLUDE_SHIFT(ch)) ? KC_MOD_SHIFT : 0) | |
| 4216 |
(ma ? KC_MOD_ALT : 0) | (kp ? KC_MOD_KEYPAD : 0); |
| 4217 |
} |
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
static bool handle_keydown(WPARAM wParam, LPARAM lParam) |
| 4231 |
{ |
| 4232 |
keycode_t ch = 0; |
| 4233 |
|
| 4234 |
bool kp = false; |
| 4235 |
|
| 4236 |
#ifdef USE_SAVER |
| 4237 |
if (screensaver_active) { |
| 4238 |
stop_screensaver(); |
| 4239 |
return true; |
| 4240 |
} |
| 4241 |
#endif |
| 4242 |
|
| 4243 |
|
| 4244 |
switch (wParam) { |
| 4245 |
case VK_F1: ch = KC_F1; break; |
| 4246 |
case VK_F2: ch = KC_F2; break; |
| 4247 |
case VK_F3: ch = KC_F3; break; |
| 4248 |
case VK_F4: ch = KC_F4; break; |
| 4249 |
case VK_F5: ch = KC_F5; break; |
| 4250 |
case VK_F6: ch = KC_F6; break; |
| 4251 |
case VK_F7: ch = KC_F7; break; |
| 4252 |
case VK_F8: ch = KC_F8; break; |
| 4253 |
case VK_F9: ch = KC_F9; break; |
| 4254 |
case VK_F10: ch = KC_F10; break; |
| 4255 |
case VK_F11: ch = KC_F11; break; |
| 4256 |
case VK_F12: ch = KC_F12; break; |
| 4257 |
case VK_F13: ch = KC_F13; break; |
| 4258 |
case VK_F14: ch = KC_F14; break; |
| 4259 |
case VK_F15: ch = KC_F15; break; |
| 4260 |
|
| 4261 |
case VK_INSERT: ch = KC_INSERT; break; |
| 4262 |
case VK_DELETE: ch = KC_DELETE; break; |
| 4263 |
|
| 4264 |
|
| 4265 |
case VK_BACK: break; |
| 4266 |
|
| 4267 |
case VK_TAB: break; |
| 4268 |
case VK_PRIOR: ch = KC_PGUP; break; |
| 4269 |
case VK_NEXT: ch = KC_PGDOWN; break; |
| 4270 |
case VK_END: ch = KC_END; break; |
| 4271 |
case VK_HOME: ch = KC_HOME; break; |
| 4272 |
case VK_LEFT: ch = ARROW_LEFT; break; |
| 4273 |
case VK_RIGHT: ch = ARROW_RIGHT; break; |
| 4274 |
case VK_UP: ch = ARROW_UP; break; |
| 4275 |
case VK_DOWN: ch = ARROW_DOWN; break; |
| 4276 |
|
| 4277 |
case VK_CLEAR: ch = '5'; kp=true; break; |
| 4278 |
case VK_PAUSE: ch = KC_PAUSE; break; |
| 4279 |
} |
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
if (ch) { |
| 4286 |
int mods = extract_modifiers(ch, kp); |
| 4287 |
|
| 4288 |
|
| 4289 |
Term_keypress(ch, mods); |
| 4290 |
return false; |
| 4291 |
} |
| 4292 |
return true; |
| 4293 |
} |
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
static LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, |
| 4298 |
WPARAM wParam, LPARAM lParam) |
| 4299 |
{ |
| 4300 |
HDC hdc; |
| 4301 |
term_data *td; |
| 4302 |
int i; |
| 4303 |
|
| 4304 |
int xPos, yPos, button, vsc, vk, mods; |
| 4305 |
bool kp = false, extended_key; |
| 4306 |
keycode_t ch; |
| 4307 |
|
| 4308 |
#ifdef USE_SAVER |
| 4309 |
static int iMouse = 0; |
| 4310 |
static WORD xMouse = 0; |
| 4311 |
static WORD yMouse = 0; |
| 4312 |
|
| 4313 |
int dx, dy; |
| 4314 |
#endif |
| 4315 |
|
| 4316 |
|
| 4317 |
td = (term_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
| 4318 |
|
| 4319 |
|
| 4320 |
switch (uMsg) |
| 4321 |
{ |
| 4322 |
|
| 4323 |
case WM_NCCREATE: |
| 4324 |
{ |
| 4325 |
SetWindowLongPtr(hWnd, GWLP_USERDATA, (size_t) my_td); |
| 4326 |
break; |
| 4327 |
} |
| 4328 |
|
| 4329 |
|
| 4330 |
case WM_CREATE: |
| 4331 |
{ |
| 4332 |
return 0; |
| 4333 |
} |
| 4334 |
|
| 4335 |
case WM_GETMINMAXINFO: |
| 4336 |
{ |
| 4337 |
MINMAXINFO FAR *lpmmi; |
| 4338 |
RECT rc; |
| 4339 |
|
| 4340 |
lpmmi = (MINMAXINFO FAR *)lParam; |
| 4341 |
|
| 4342 |
|
| 4343 |
if (!td) return 1; |
| 4344 |
|
| 4345 |
|
| 4346 |
rc.left = rc.top = 0; |
| 4347 |
rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + |
| 4348 |
td->size_ow2; |
| 4349 |
rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + |
| 4350 |
td->size_oh2 + 1; |
| 4351 |
|
| 4352 |
|
| 4353 |
AdjustWindowRectEx(&rc, td->dwStyle, true, td->dwExStyle); |
| 4354 |
|
| 4355 |
|
| 4356 |
lpmmi->ptMinTrackSize.x = rc.right - rc.left; |
| 4357 |
lpmmi->ptMinTrackSize.y = rc.bottom - rc.top; |
| 4358 |
|
| 4359 |
return 0; |
| 4360 |
} |
| 4361 |
|
| 4362 |
case WM_PAINT: |
| 4363 |
{ |
| 4364 |
handle_wm_paint(hWnd); |
| 4365 |
|
| 4366 |
return 0; |
| 4367 |
} |
| 4368 |
|
| 4369 |
case WM_SYSKEYDOWN: |
| 4370 |
case WM_KEYDOWN: |
| 4371 |
{ |
| 4372 |
return handle_keydown(wParam, lParam); |
| 4373 |
} |
| 4374 |
|
| 4375 |
case WM_CHAR: |
| 4376 |
{ |
| 4377 |
vsc = LOBYTE(HIWORD(lParam)); |
| 4378 |
extended_key = HIBYTE(HIWORD(lParam)) & 0x1; |
| 4379 |
vk = MapVirtualKey(vsc, 1); |
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
if (!game_in_progress) { |
| 4385 |
|
| 4386 |
switch (wParam) { |
| 4387 |
case KTRL('N'): process_menus(IDM_FILE_NEW); break; |
| 4388 |
case KTRL('O'): process_menus(IDM_FILE_OPEN); break; |
| 4389 |
case KTRL('X'): process_menus(IDM_FILE_EXIT); break; |
| 4390 |
default: return true; |
| 4391 |
} |
| 4392 |
return false; |
| 4393 |
} |
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
switch (vk) |
| 4398 |
{ |
| 4399 |
case 8: |
| 4400 |
ch = KC_BACKSPACE; |
| 4401 |
break; |
| 4402 |
case 9: |
| 4403 |
ch = KC_TAB; |
| 4404 |
break; |
| 4405 |
case 13: |
| 4406 |
ch = KC_ENTER; |
| 4407 |
if(extended_key) kp = true; |
| 4408 |
break; |
| 4409 |
case 27: |
| 4410 |
ch = ESCAPE; |
| 4411 |
break; |
| 4412 |
default: |
| 4413 |
Term_keypress(wParam, 0); |
| 4414 |
return 0; |
| 4415 |
} |
| 4416 |
|
| 4417 |
mods = extract_modifiers(ch, kp); |
| 4418 |
Term_keypress(ch, mods); |
| 4419 |
|
| 4420 |
return 0; |
| 4421 |
} |
| 4422 |
|
| 4423 |
case WM_MBUTTONDOWN: |
| 4424 |
case WM_RBUTTONDOWN: |
| 4425 |
case WM_LBUTTONDOWN: |
| 4426 |
{ |
| 4427 |
if (screensaver_active) { |
| 4428 |
#ifdef USE_SAVER |
| 4429 |
stop_screensaver(); |
| 4430 |
#else |
| 4431 |
screensaver_active = false; |
| 4432 |
#endif |
| 4433 |
return 0; |
| 4434 |
} else { |
| 4435 |
|
| 4436 |
xPos = GET_X_LPARAM(lParam); |
| 4437 |
yPos = GET_Y_LPARAM(lParam); |
| 4438 |
xPos /= td->tile_wid; |
| 4439 |
yPos /= td->tile_hgt; |
| 4440 |
|
| 4441 |
if (uMsg == WM_LBUTTONDOWN) |
| 4442 |
button = 1; |
| 4443 |
else if (uMsg == WM_RBUTTONDOWN) |
| 4444 |
button = 2; |
| 4445 |
else |
| 4446 |
button = 3; |
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
if (GetKeyState(VK_CONTROL) & 0x8000) button |= 16; |
| 4456 |
if (GetKeyState(VK_SHIFT) & 0x8000) button |= 32; |
| 4457 |
if (GetKeyState(VK_MENU) & 0x8000) button |= 64; |
| 4458 |
|
| 4459 |
Term_mousepress(xPos,yPos,button); |
| 4460 |
} |
| 4461 |
break; |
| 4462 |
} |
| 4463 |
|
| 4464 |
#ifdef USE_SAVER |
| 4465 |
case WM_MOUSEMOVE: |
| 4466 |
{ |
| 4467 |
if (!screensaver_active) break; |
| 4468 |
|
| 4469 |
if (iMouse) { |
| 4470 |
dx = LOWORD(lParam) - xMouse; |
| 4471 |
dy = HIWORD(lParam) - yMouse; |
| 4472 |
|
| 4473 |
if (dx < 0) dx = -dx; |
| 4474 |
if (dy < 0) dy = -dy; |
| 4475 |
|
| 4476 |
if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) |
| 4477 |
stop_screensaver(); |
| 4478 |
} |
| 4479 |
|
| 4480 |
|
| 4481 |
iMouse = 1; |
| 4482 |
xMouse = LOWORD(lParam); |
| 4483 |
yMouse = HIWORD(lParam); |
| 4484 |
|
| 4485 |
return 0; |
| 4486 |
} |
| 4487 |
#endif |
| 4488 |
|
| 4489 |
case WM_INITMENU: |
| 4490 |
{ |
| 4491 |
setup_menus(); |
| 4492 |
return 0; |
| 4493 |
} |
| 4494 |
|
| 4495 |
#ifndef WM_QUERYENDSESSION |
| 4496 |
#define WM_QUERYENDSESSION 0x0011 |
| 4497 |
#endif |
| 4498 |
|
| 4499 |
case WM_QUERYENDSESSION: |
| 4500 |
case WM_QUIT: { |
| 4501 |
if (game_in_progress && character_generated) { |
| 4502 |
if (uMsg == WM_QUERYENDSESSION && !inkey_flag) { |
| 4503 |
plog("Please exit any open menus before closing the game."); |
| 4504 |
return false; |
| 4505 |
} |
| 4506 |
|
| 4507 |
msg_flag = false; |
| 4508 |
save_game(); |
| 4509 |
close_game(true); |
| 4510 |
} |
| 4511 |
|
| 4512 |
quit(NULL); |
| 4513 |
return true; |
| 4514 |
} |
| 4515 |
|
| 4516 |
|
| 4517 |
case WM_CLOSE: |
| 4518 |
{ |
| 4519 |
if (game_in_progress && character_generated) { |
| 4520 |
if (!inkey_flag) { |
| 4521 |
plog("Please exit any open menus before closing the game."); |
| 4522 |
return 0; |
| 4523 |
} |
| 4524 |
|
| 4525 |
|
| 4526 |
msg_flag = false; |
| 4527 |
save_game(); |
| 4528 |
close_game(true); |
| 4529 |
} |
| 4530 |
|
| 4531 |
quit(NULL); |
| 4532 |
return 0; |
| 4533 |
} |
| 4534 |
|
| 4535 |
case WM_COMMAND: |
| 4536 |
{ |
| 4537 |
process_menus(LOWORD(wParam)); |
| 4538 |
return 0; |
| 4539 |
} |
| 4540 |
|
| 4541 |
case WM_SIZE: |
| 4542 |
{ |
| 4543 |
|
| 4544 |
if (!td) return 1; |
| 4545 |
|
| 4546 |
|
| 4547 |
if (!td->w) return 1; |
| 4548 |
|
| 4549 |
|
| 4550 |
if (td->size_hack) return 1; |
| 4551 |
|
| 4552 |
switch (wParam) |
| 4553 |
{ |
| 4554 |
case SIZE_MINIMIZED: |
| 4555 |
{ |
| 4556 |
|
| 4557 |
for (i = 1; i < MAX_TERM_DATA; i++) |
| 4558 |
if (data[i].visible) |
| 4559 |
ShowWindow(data[i].w, SW_HIDE); |
| 4560 |
|
| 4561 |
return 0; |
| 4562 |
} |
| 4563 |
|
| 4564 |
case SIZE_MAXIMIZED: |
| 4565 |
{ |
| 4566 |
|
| 4567 |
} |
| 4568 |
|
| 4569 |
case SIZE_RESTORED: |
| 4570 |
{ |
| 4571 |
int cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid; |
| 4572 |
int rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt; |
| 4573 |
|
| 4574 |
|
| 4575 |
if ((td->cols != cols) || (td->rows != rows)) { |
| 4576 |
|
| 4577 |
td->cols = cols; |
| 4578 |
td->rows = rows; |
| 4579 |
|
| 4580 |
|
| 4581 |
Term_activate(&td->t); |
| 4582 |
|
| 4583 |
|
| 4584 |
Term_resize(td->cols, td->rows); |
| 4585 |
|
| 4586 |
|
| 4587 |
InvalidateRect(td->w, NULL, true); |
| 4588 |
} |
| 4589 |
|
| 4590 |
td->size_hack = true; |
| 4591 |
|
| 4592 |
|
| 4593 |
for (i = 1; i < MAX_TERM_DATA; i++) |
| 4594 |
if (data[i].visible) |
| 4595 |
ShowWindow(data[i].w, SW_SHOW); |
| 4596 |
|
| 4597 |
td->size_hack = false; |
| 4598 |
|
| 4599 |
return 0; |
| 4600 |
} |
| 4601 |
} |
| 4602 |
break; |
| 4603 |
} |
| 4604 |
|
| 4605 |
case WM_PALETTECHANGED: |
| 4606 |
{ |
| 4607 |
|
| 4608 |
if ((HWND)wParam == hWnd) return 0; |
| 4609 |
|
| 4610 |
|
| 4611 |
} |
| 4612 |
|
| 4613 |
case WM_QUERYNEWPALETTE: |
| 4614 |
{ |
| 4615 |
if (!paletted) return 0; |
| 4616 |
|
| 4617 |
hdc = GetDC(hWnd); |
| 4618 |
|
| 4619 |
SelectPalette(hdc, hPal, false); |
| 4620 |
|
| 4621 |
i = RealizePalette(hdc); |
| 4622 |
|
| 4623 |
|
| 4624 |
if (i) InvalidateRect(hWnd, NULL, true); |
| 4625 |
|
| 4626 |
ReleaseDC(hWnd, hdc); |
| 4627 |
|
| 4628 |
return 0; |
| 4629 |
} |
| 4630 |
|
| 4631 |
case WM_ACTIVATE: |
| 4632 |
{ |
| 4633 |
if (wParam && !HIWORD(lParam)) { |
| 4634 |
|
| 4635 |
for (i = MAX_TERM_DATA - 1; i >= 0; i--) |
| 4636 |
SetWindowPos(data[i].w, hWnd, 0, 0, 0, 0, |
| 4637 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 4638 |
|
| 4639 |
|
| 4640 |
SetFocus(hWnd); |
| 4641 |
|
| 4642 |
return 0; |
| 4643 |
} |
| 4644 |
|
| 4645 |
break; |
| 4646 |
} |
| 4647 |
} |
| 4648 |
|
| 4649 |
return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 4650 |
} |
| 4651 |
|
| 4652 |
|
| 4653 |
static LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg, |
| 4654 |
WPARAM wParam, LPARAM lParam) |
| 4655 |
{ |
| 4656 |
term_data *td; |
| 4657 |
HDC hdc; |
| 4658 |
int i; |
| 4659 |
|
| 4660 |
#ifdef USE_SAVER |
| 4661 |
static int iMouse = 0; |
| 4662 |
static WORD xMouse = 0; |
| 4663 |
static WORD yMouse = 0; |
| 4664 |
|
| 4665 |
int dx, dy; |
| 4666 |
#endif |
| 4667 |
|
| 4668 |
|
| 4669 |
|
| 4670 |
td = (term_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
| 4671 |
|
| 4672 |
|
| 4673 |
switch (uMsg) |
| 4674 |
{ |
| 4675 |
|
| 4676 |
case WM_NCCREATE: |
| 4677 |
{ |
| 4678 |
SetWindowLongPtr(hWnd, GWLP_USERDATA, (size_t)(my_td)); |
| 4679 |
break; |
| 4680 |
} |
| 4681 |
|
| 4682 |
|
| 4683 |
case WM_CREATE: |
| 4684 |
{ |
| 4685 |
return 0; |
| 4686 |
} |
| 4687 |
|
| 4688 |
case WM_GETMINMAXINFO: |
| 4689 |
{ |
| 4690 |
#if 0 |
| 4691 |
MINMAXINFO FAR *lpmmi; |
| 4692 |
RECT rc; |
| 4693 |
|
| 4694 |
|
| 4695 |
if (!td) return 1; |
| 4696 |
|
| 4697 |
lpmmi = (MINMAXINFO FAR *)lParam; |
| 4698 |
|
| 4699 |
|
| 4700 |
rc.left = rc.top = 0; |
| 4701 |
rc.right = rc.left + 8 * td->tile_wid + td->size_ow1 + td->size_ow2; |
| 4702 |
rc.bottom = rc.top + 2 * td->tile_hgt + td->size_oh1 + td->size_oh2; |
| 4703 |
|
| 4704 |
|
| 4705 |
AdjustWindowRectEx(&rc, td->dwStyle, true, td->dwExStyle); |
| 4706 |
|
| 4707 |
|
| 4708 |
lpmmi->ptMinTrackSize.x = rc.right - rc.left; |
| 4709 |
lpmmi->ptMinTrackSize.y = rc.bottom - rc.top; |
| 4710 |
|
| 4711 |
|
| 4712 |
rc.left = rc.top = 0; |
| 4713 |
rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + |
| 4714 |
td->size_ow2; |
| 4715 |
rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + |
| 4716 |
td->size_oh2; |
| 4717 |
|
| 4718 |
|
| 4719 |
rc.right += (td->tile_wid - 1); |
| 4720 |
rc.bottom += (td->tile_hgt - 1); |
| 4721 |
|
| 4722 |
|
| 4723 |
AdjustWindowRectEx(&rc, td->dwStyle, true, td->dwExStyle); |
| 4724 |
|
| 4725 |
|
| 4726 |
lpmmi->ptMaxSize.x = rc.right - rc.left; |
| 4727 |
lpmmi->ptMaxSize.y = rc.bottom - rc.top; |
| 4728 |
|
| 4729 |
|
| 4730 |
lpmmi->ptMaxTrackSize.x = rc.right - rc.left; |
| 4731 |
lpmmi->ptMaxTrackSize.y = rc.bottom - rc.top; |
| 4732 |
#endif |
| 4733 |
return 0; |
| 4734 |
} |
| 4735 |
|
| 4736 |
case WM_SIZE: |
| 4737 |
{ |
| 4738 |
int cols; |
| 4739 |
int rows; |
| 4740 |
|
| 4741 |
|
| 4742 |
if (!td) return 1; |
| 4743 |
|
| 4744 |
|
| 4745 |
if (!td->w) return 1; |
| 4746 |
|
| 4747 |
|
| 4748 |
if (td->size_hack) return 1; |
| 4749 |
|
| 4750 |
td->size_hack = true; |
| 4751 |
|
| 4752 |
cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid; |
| 4753 |
rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt; |
| 4754 |
|
| 4755 |
|
| 4756 |
if ((td->cols != cols) || (td->rows != rows)) { |
| 4757 |
|
| 4758 |
term *old_term = Term; |
| 4759 |
|
| 4760 |
|
| 4761 |
td->cols = cols; |
| 4762 |
td->rows = rows; |
| 4763 |
|
| 4764 |
|
| 4765 |
Term_activate(&td->t); |
| 4766 |
|
| 4767 |
|
| 4768 |
Term_resize(td->cols, td->rows); |
| 4769 |
|
| 4770 |
|
| 4771 |
Term_activate(old_term); |
| 4772 |
|
| 4773 |
|
| 4774 |
InvalidateRect(td->w, NULL, true); |
| 4775 |
|
| 4776 |
|
| 4777 |
if (character_dungeon) do_cmd_redraw(); |
| 4778 |
} |
| 4779 |
|
| 4780 |
td->size_hack = false; |
| 4781 |
|
| 4782 |
return 0; |
| 4783 |
} |
| 4784 |
|
| 4785 |
case WM_PAINT: |
| 4786 |
{ |
| 4787 |
handle_wm_paint(hWnd); |
| 4788 |
|
| 4789 |
return 0; |
| 4790 |
} |
| 4791 |
|
| 4792 |
case WM_SYSKEYDOWN: |
| 4793 |
case WM_KEYDOWN: |
| 4794 |
{ |
| 4795 |
return handle_keydown(wParam, lParam); |
| 4796 |
break; |
| 4797 |
} |
| 4798 |
|
| 4799 |
case WM_CHAR: |
| 4800 |
{ |
| 4801 |
Term_keypress(wParam, 0); |
| 4802 |
return 0; |
| 4803 |
} |
| 4804 |
|
| 4805 |
|
| 4806 |
#ifdef USE_SAVER |
| 4807 |
case WM_MBUTTONDOWN: |
| 4808 |
case WM_RBUTTONDOWN: |
| 4809 |
case WM_LBUTTONDOWN: |
| 4810 |
{ |
| 4811 |
if (screensaver_active) { |
| 4812 |
stop_screensaver(); |
| 4813 |
return 0; |
| 4814 |
} |
| 4815 |
break; |
| 4816 |
} |
| 4817 |
|
| 4818 |
case WM_MOUSEMOVE: |
| 4819 |
{ |
| 4820 |
if (!screensaver_active) break; |
| 4821 |
|
| 4822 |
if (iMouse) { |
| 4823 |
dx = LOWORD(lParam) - xMouse; |
| 4824 |
dy = HIWORD(lParam) - yMouse; |
| 4825 |
|
| 4826 |
if (dx < 0) dx = -dx; |
| 4827 |
if (dy < 0) dy = -dy; |
| 4828 |
|
| 4829 |
if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) |
| 4830 |
stop_screensaver(); |
| 4831 |
} |
| 4832 |
|
| 4833 |
|
| 4834 |
iMouse = 1; |
| 4835 |
xMouse = LOWORD(lParam); |
| 4836 |
yMouse = HIWORD(lParam); |
| 4837 |
|
| 4838 |
return 0; |
| 4839 |
} |
| 4840 |
#endif |
| 4841 |
|
| 4842 |
case WM_PALETTECHANGED: |
| 4843 |
{ |
| 4844 |
|
| 4845 |
if ((HWND)wParam == hWnd) return false; |
| 4846 |
|
| 4847 |
} |
| 4848 |
|
| 4849 |
case WM_QUERYNEWPALETTE: |
| 4850 |
{ |
| 4851 |
if (!paletted) return 0; |
| 4852 |
hdc = GetDC(hWnd); |
| 4853 |
SelectPalette(hdc, hPal, false); |
| 4854 |
i = RealizePalette(hdc); |
| 4855 |
|
| 4856 |
if (i) InvalidateRect(hWnd, NULL, true); |
| 4857 |
ReleaseDC(hWnd, hdc); |
| 4858 |
return 0; |
| 4859 |
} |
| 4860 |
|
| 4861 |
case WM_NCLBUTTONDOWN: |
| 4862 |
{ |
| 4863 |
|
| 4864 |
#ifdef HTCLOSE |
| 4865 |
if (wParam == HTCLOSE) wParam = HTSYSMENU; |
| 4866 |
#endif |
| 4867 |
|
| 4868 |
if (wParam == HTSYSMENU) { |
| 4869 |
if (td->visible) { |
| 4870 |
td->visible = false; |
| 4871 |
ShowWindow(td->w, SW_HIDE); |
| 4872 |
} |
| 4873 |
|
| 4874 |
return 0; |
| 4875 |
} |
| 4876 |
|
| 4877 |
break; |
| 4878 |
} |
| 4879 |
} |
| 4880 |
|
| 4881 |
return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 4882 |
} |
| 4883 |
|
| 4884 |
|
| 4885 |
#ifdef USE_SAVER |
| 4886 |
|
| 4887 |
LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, |
| 4888 |
WPARAM wParam, LPARAM lParam) |
| 4889 |
{ |
| 4890 |
static int iMouse = 0; |
| 4891 |
static WORD xMouse = 0; |
| 4892 |
static WORD yMouse = 0; |
| 4893 |
|
| 4894 |
int dx, dy; |
| 4895 |
|
| 4896 |
|
| 4897 |
|
| 4898 |
switch (uMsg) |
| 4899 |
{ |
| 4900 |
|
| 4901 |
case WM_NCCREATE: |
| 4902 |
{ |
| 4903 |
break; |
| 4904 |
} |
| 4905 |
|
| 4906 |
case WM_SETCURSOR: |
| 4907 |
{ |
| 4908 |
SetCursor(NULL); |
| 4909 |
return 0; |
| 4910 |
} |
| 4911 |
|
| 4912 |
#if 0 |
| 4913 |
case WM_ACTIVATE: |
| 4914 |
{ |
| 4915 |
if (LOWORD(wParam) == WA_INACTIVE) break; |
| 4916 |
|
| 4917 |
|
| 4918 |
} |
| 4919 |
#endif |
| 4920 |
|
| 4921 |
case WM_LBUTTONDOWN: |
| 4922 |
case WM_MBUTTONDOWN: |
| 4923 |
case WM_RBUTTONDOWN: |
| 4924 |
case WM_KEYDOWN: |
| 4925 |
{ |
| 4926 |
stop_screensaver(); |
| 4927 |
return 0; |
| 4928 |
} |
| 4929 |
|
| 4930 |
case WM_MOUSEMOVE: |
| 4931 |
{ |
| 4932 |
if (iMouse) { |
| 4933 |
dx = LOWORD(lParam) - xMouse; |
| 4934 |
dy = HIWORD(lParam) - yMouse; |
| 4935 |
|
| 4936 |
if (dx < 0) dx = -dx; |
| 4937 |
if (dy < 0) dy = -dy; |
| 4938 |
|
| 4939 |
if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) |
| 4940 |
stop_screensaver(); |
| 4941 |
} |
| 4942 |
|
| 4943 |
|
| 4944 |
iMouse = 1; |
| 4945 |
xMouse = LOWORD(lParam); |
| 4946 |
yMouse = HIWORD(lParam); |
| 4947 |
|
| 4948 |
return 0; |
| 4949 |
} |
| 4950 |
|
| 4951 |
case WM_CLOSE: |
| 4952 |
{ |
| 4953 |
DestroyWindow(hwndSaver); |
| 4954 |
if (screensaver) |
| 4955 |
SendMessage(data[0].w, WM_CLOSE, 0, 0); |
| 4956 |
hwndSaver = NULL; |
| 4957 |
return 0; |
| 4958 |
} |
| 4959 |
} |
| 4960 |
|
| 4961 |
|
| 4962 |
return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 4963 |
} |
| 4964 |
|
| 4965 |
#endif |
| 4966 |
|
| 4967 |
|
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
|
| 4975 |
|
| 4976 |
|
| 4977 |
|
| 4978 |
|
| 4979 |
|
| 4980 |
|
| 4981 |
static void hack_plog(const char *str) |
| 4982 |
{ |
| 4983 |
|
| 4984 |
if (str) |
| 4985 |
MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK); |
| 4986 |
} |
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
|
| 4992 |
static void hack_quit(const char *str) |
| 4993 |
{ |
| 4994 |
|
| 4995 |
if (str) |
| 4996 |
MessageBox(NULL, str, "Error", |
| 4997 |
MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP); |
| 4998 |
|
| 4999 |
|
| 5000 |
UnregisterClass(AppName, hInstance); |
| 5001 |
|
| 5002 |
|
| 5003 |
if (hIcon) DestroyIcon(hIcon); |
| 5004 |
|
| 5005 |
|
| 5006 |
finish_monitoring_savefile(EVENT_LEAVE_GAME, NULL, NULL); |
| 5007 |
|
| 5008 |
#ifdef USE_SAVER |
| 5009 |
if (screensaverSemaphore) |
| 5010 |
CloseHandle(screensaverSemaphore); |
| 5011 |
#endif |
| 5012 |
|
| 5013 |
|
| 5014 |
exit(0); |
| 5015 |
} |
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
|
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
static void hook_plog(const char *str) |
| 5030 |
{ |
| 5031 |
#ifdef USE_SAVER |
| 5032 |
if (screensaver_active) return; |
| 5033 |
#endif |
| 5034 |
|
| 5035 |
|
| 5036 |
if (str) |
| 5037 |
MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK); |
| 5038 |
} |
| 5039 |
|
| 5040 |
|
| 5041 |
|
| 5042 |
|
| 5043 |
|
| 5044 |
static void hook_quit(const char *str) |
| 5045 |
{ |
| 5046 |
int i; |
| 5047 |
|
| 5048 |
|
| 5049 |
#ifdef USE_SAVER |
| 5050 |
if (!screensaver_active) |
| 5051 |
#endif |
| 5052 |
{ |
| 5053 |
|
| 5054 |
if (str) |
| 5055 |
MessageBox(data[0].w, str, "Error", |
| 5056 |
MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP); |
| 5057 |
|
| 5058 |
|
| 5059 |
save_prefs(); |
| 5060 |
} |
| 5061 |
|
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
for (i = MAX_TERM_DATA - 1; i >= 0; --i) { |
| 5066 |
|
| 5067 |
if (data[i].font_file) term_remove_font(data[i].font_file); |
| 5068 |
if (data[i].font_id) DeleteObject(data[i].font_id); |
| 5069 |
if (data[i].font_want) string_free(data[i].font_want); |
| 5070 |
|
| 5071 |
|
| 5072 |
if (data[i].w) DestroyWindow(data[i].w); |
| 5073 |
data[i].w = 0; |
| 5074 |
term_nuke(&data[i].t); |
| 5075 |
} |
| 5076 |
|
| 5077 |
|
| 5078 |
FreeDIB(&infGraph); |
| 5079 |
FreeDIB(&infMask); |
| 5080 |
|
| 5081 |
close_graphics_modes(); |
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
DeleteObject(hbrYellow); |
| 5086 |
|
| 5087 |
if (hPal) DeleteObject(hPal); |
| 5088 |
|
| 5089 |
UnregisterClass(AppName, hInstance); |
| 5090 |
|
| 5091 |
if (hIcon) DestroyIcon(hIcon); |
| 5092 |
|
| 5093 |
|
| 5094 |
string_free(ini_file); |
| 5095 |
string_free(argv0); |
| 5096 |
|
| 5097 |
#ifdef HAS_CLEANUP |
| 5098 |
textui_cleanup(); |
| 5099 |
cleanup_angband(); |
| 5100 |
close_sound(); |
| 5101 |
#endif |
| 5102 |
|
| 5103 |
exit(0); |
| 5104 |
} |
| 5105 |
|
| 5106 |
|
| 5107 |
|
| 5108 |
|
| 5109 |
|
| 5110 |
|
| 5111 |
|
| 5112 |
|
| 5113 |
|
| 5114 |
|
| 5115 |
static void init_stuff(void) |
| 5116 |
{ |
| 5117 |
int i; |
| 5118 |
|
| 5119 |
char path[1024]; |
| 5120 |
#ifdef USE_SAVER |
| 5121 |
char tmp[1024]; |
| 5122 |
#endif |
| 5123 |
|
| 5124 |
|
| 5125 |
if (GetModuleFileName(hInstance, path, sizeof(path)) == 0) |
| 5126 |
show_win_error(); |
| 5127 |
|
| 5128 |
|
| 5129 |
path[sizeof(path) - 1] = '\0'; |
| 5130 |
|
| 5131 |
|
| 5132 |
argv0 = string_make(path); |
| 5133 |
|
| 5134 |
|
| 5135 |
my_strcpy(path + strlen(path) - 4, ".INI", 5); |
| 5136 |
|
| 5137 |
#ifdef USE_SAVER |
| 5138 |
|
| 5139 |
if (screensaver) { |
| 5140 |
|
| 5141 |
GetPrivateProfileStringA("Angband", "SaverFile", "", |
| 5142 |
saverfilename, sizeof(saverfilename), path); |
| 5143 |
|
| 5144 |
GetPrivateProfileStringA("Angband", "AngbandPath", "", tmp, |
| 5145 |
sizeof(tmp), path); |
| 5146 |
strnfmt(path, sizeof(path), "%sangband.ini", tmp); |
| 5147 |
} |
| 5148 |
|
| 5149 |
#endif |
| 5150 |
|
| 5151 |
|
| 5152 |
ini_file = string_make(path); |
| 5153 |
|
| 5154 |
|
| 5155 |
i = strlen(path); |
| 5156 |
|
| 5157 |
|
| 5158 |
for (; i > 0; i--) { |
| 5159 |
if (path[i] == '\\') { |
| 5160 |
|
| 5161 |
break; |
| 5162 |
} |
| 5163 |
} |
| 5164 |
|
| 5165 |
|
| 5166 |
my_strcpy(path + i + 1, "lib\\", sizeof(path) - i - 1); |
| 5167 |
|
| 5168 |
|
| 5169 |
validate_dir(path); |
| 5170 |
|
| 5171 |
|
| 5172 |
init_file_paths(path, path, path); |
| 5173 |
|
| 5174 |
|
| 5175 |
validate_dir(ANGBAND_DIR_GAMEDATA); |
| 5176 |
validate_dir(ANGBAND_DIR_CUSTOMIZE); |
| 5177 |
validate_dir(ANGBAND_DIR_HELP); |
| 5178 |
validate_dir(ANGBAND_DIR_SCREENS); |
| 5179 |
validate_dir(ANGBAND_DIR_FONTS); |
| 5180 |
validate_dir(ANGBAND_DIR_TILES); |
| 5181 |
validate_dir(ANGBAND_DIR_SOUNDS); |
| 5182 |
validate_dir(ANGBAND_DIR_ICONS); |
| 5183 |
validate_dir(ANGBAND_DIR_USER); |
| 5184 |
validate_dir(ANGBAND_DIR_SAVE); |
| 5185 |
validate_dir(ANGBAND_DIR_PANIC); |
| 5186 |
validate_dir(ANGBAND_DIR_SCORES); |
| 5187 |
|
| 5188 |
|
| 5189 |
path_build(path, sizeof(path), ANGBAND_DIR_SCREENS, "news.txt"); |
| 5190 |
|
| 5191 |
|
| 5192 |
validate_file(path); |
| 5193 |
|
| 5194 |
|
| 5195 |
path_build(path, sizeof(path), ANGBAND_DIR_FONTS, DEFAULT_FONT); |
| 5196 |
|
| 5197 |
|
| 5198 |
validate_file(path); |
| 5199 |
|
| 5200 |
|
| 5201 |
validate_dir(ANGBAND_DIR_TILES); |
| 5202 |
|
| 5203 |
|
| 5204 |
validate_dir(ANGBAND_DIR_SOUNDS); |
| 5205 |
} |
| 5206 |
|
| 5207 |
|
| 5208 |
|
| 5209 |
|
| 5210 |
|
| 5211 |
|
| 5212 |
static void win_reinit(void) |
| 5213 |
{ |
| 5214 |
|
| 5215 |
#ifdef SOUND |
| 5216 |
#if defined(SOUND_SDL) || defined(SOUND_SOUND_SDL2) |
| 5217 |
init_sound("sdl", 0, NULL); |
| 5218 |
#else |
| 5219 |
init_sound("win", 0, NULL); |
| 5220 |
#endif |
| 5221 |
#endif |
| 5222 |
|
| 5223 |
|
| 5224 |
|
| 5225 |
|
| 5226 |
|
| 5227 |
event_add_handler(EVENT_LEAVE_INIT, monitor_new_savefile, NULL); |
| 5228 |
event_add_handler(EVENT_LEAVE_GAME, finish_monitoring_savefile, NULL); |
| 5229 |
} |
| 5230 |
|
| 5231 |
|
| 5232 |
int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, |
| 5233 |
LPSTR lpCmdLine, int nCmdShow) |
| 5234 |
{ |
| 5235 |
int i; |
| 5236 |
|
| 5237 |
WNDCLASS wc; |
| 5238 |
HDC hdc; |
| 5239 |
MSG msg; |
| 5240 |
|
| 5241 |
|
| 5242 |
(void)nCmdShow; |
| 5243 |
|
| 5244 |
#ifdef USE_SAVER |
| 5245 |
if (lpCmdLine && ((*lpCmdLine == '-') || (*lpCmdLine == '/'))) { |
| 5246 |
lpCmdLine++; |
| 5247 |
|
| 5248 |
switch (*lpCmdLine) |
| 5249 |
{ |
| 5250 |
case 's': |
| 5251 |
case 'S': |
| 5252 |
{ |
| 5253 |
screensaver = true; |
| 5254 |
|
| 5255 |
|
| 5256 |
screensaverSemaphore = CreateSemaphore(NULL, 0, 1, |
| 5257 |
"AngbandSaverSemaphore"); |
| 5258 |
|
| 5259 |
if (!screensaverSemaphore) exit(0); |
| 5260 |
|
| 5261 |
if (GetLastError() == ERROR_ALREADY_EXISTS) { |
| 5262 |
CloseHandle(screensaverSemaphore); |
| 5263 |
exit(0); |
| 5264 |
} |
| 5265 |
|
| 5266 |
break; |
| 5267 |
} |
| 5268 |
|
| 5269 |
case 'P': |
| 5270 |
case 'p': |
| 5271 |
case 'C': |
| 5272 |
case 'c': |
| 5273 |
case 'A': |
| 5274 |
case 'a': |
| 5275 |
{ |
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
exit(0); |
| 5281 |
} |
| 5282 |
} |
| 5283 |
} |
| 5284 |
|
| 5285 |
#endif |
| 5286 |
|
| 5287 |
|
| 5288 |
if (hPrevInst == NULL) { |
| 5289 |
wc.style = CS_CLASSDC; |
| 5290 |
wc.lpfnWndProc = AngbandWndProc; |
| 5291 |
wc.cbClsExtra = 0; |
| 5292 |
wc.cbWndExtra = 4; |
| 5293 |
wc.hInstance = hInst; |
| 5294 |
wc.hIcon = hIcon = LoadIcon(hInst, "ANGBAND"); |
| 5295 |
wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5296 |
wc.hbrBackground = GetStockObject(BLACK_BRUSH); |
| 5297 |
wc.lpszMenuName = "ANGBAND"; |
| 5298 |
wc.lpszClassName = AppName; |
| 5299 |
|
| 5300 |
if (!RegisterClass(&wc)) exit(1); |
| 5301 |
|
| 5302 |
wc.lpfnWndProc = AngbandListProc; |
| 5303 |
wc.lpszMenuName = NULL; |
| 5304 |
wc.lpszClassName = AngList; |
| 5305 |
|
| 5306 |
if (!RegisterClass(&wc)) exit(2); |
| 5307 |
|
| 5308 |
#ifdef USE_SAVER |
| 5309 |
|
| 5310 |
wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS; |
| 5311 |
wc.lpfnWndProc = AngbandSaverProc; |
| 5312 |
wc.hCursor = NULL; |
| 5313 |
wc.lpszMenuName = NULL; |
| 5314 |
wc.lpszClassName = "WindowsScreenSaverClass"; |
| 5315 |
|
| 5316 |
if (!RegisterClass(&wc)) exit(3); |
| 5317 |
|
| 5318 |
#endif |
| 5319 |
|
| 5320 |
} |
| 5321 |
|
| 5322 |
setlocale(LC_CTYPE, ""); |
| 5323 |
|
| 5324 |
|
| 5325 |
hInstance = hInst; |
| 5326 |
|
| 5327 |
|
| 5328 |
plog_aux = hack_plog; |
| 5329 |
quit_aux = hack_quit; |
| 5330 |
|
| 5331 |
|
| 5332 |
init_stuff(); |
| 5333 |
|
| 5334 |
|
| 5335 |
hdc = GetDC(NULL); |
| 5336 |
colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4); |
| 5337 |
paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? true : false); |
| 5338 |
ReleaseDC(NULL, hdc); |
| 5339 |
|
| 5340 |
|
| 5341 |
for (i = 0; i < MAX_COLORS; i++) { |
| 5342 |
uint8_t rv, gv, bv; |
| 5343 |
|
| 5344 |
|
| 5345 |
rv = angband_color_table[i][1]; |
| 5346 |
gv = angband_color_table[i][2]; |
| 5347 |
bv = angband_color_table[i][3]; |
| 5348 |
|
| 5349 |
|
| 5350 |
win_clr[i] = PALETTERGB(rv, gv, bv); |
| 5351 |
|
| 5352 |
|
| 5353 |
angband_color_table[i][0] = win_pal[i]; |
| 5354 |
} |
| 5355 |
|
| 5356 |
|
| 5357 |
if (!init_graphics_modes()) { |
| 5358 |
plog_fmt("Graphics list load failed"); |
| 5359 |
} |
| 5360 |
|
| 5361 |
|
| 5362 |
init_windows(); |
| 5363 |
|
| 5364 |
|
| 5365 |
plog_aux = hook_plog; |
| 5366 |
quit_aux = hook_quit; |
| 5367 |
|
| 5368 |
|
| 5369 |
ANGBAND_SYS = "win"; |
| 5370 |
|
| 5371 |
|
| 5372 |
cmd_get_hook = textui_get_cmd; |
| 5373 |
|
| 5374 |
#ifdef USE_SAVER |
| 5375 |
if (screensaver) { |
| 5376 |
|
| 5377 |
start_screensaver(); |
| 5378 |
|
| 5379 |
|
| 5380 |
quit(NULL); |
| 5381 |
} |
| 5382 |
#endif |
| 5383 |
|
| 5384 |
|
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
reinit_hook = win_reinit; |
| 5389 |
win_reinit(); |
| 5390 |
|
| 5391 |
|
| 5392 |
init_display(); |
| 5393 |
init_angband(); |
| 5394 |
|
| 5395 |
textui_init(); |
| 5396 |
|
| 5397 |
initialized = true; |
| 5398 |
|
| 5399 |
|
| 5400 |
check_for_save_file(lpCmdLine); |
| 5401 |
|
| 5402 |
|
| 5403 |
prt("[Choose 'New' or 'Open' from the 'File' menu]", |
| 5404 |
(Term->hgt - 23) / 5 + 23, (Term->wid - 45) / 2); |
| 5405 |
Term_fresh(); |
| 5406 |
|
| 5407 |
|
| 5408 |
while (GetMessage(&msg, NULL, 0, 0)) { |
| 5409 |
TranslateMessage(&msg); |
| 5410 |
DispatchMessage(&msg); |
| 5411 |
} |
| 5412 |
|
| 5413 |
|
| 5414 |
quit(NULL); |
| 5415 |
|
| 5416 |
|
| 5417 |
return (0); |
| 5418 |
} |
| 5419 |
|
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
|
| 5424 |
|
| 5425 |
|
| 5426 |
|
| 5427 |
static bool create_savefile_tracking_file(bool message_on_failure) |
| 5428 |
{ |
| 5429 |
const char *tracking_extension = ".lok"; |
| 5430 |
char *name = mem_alloc(MAX_PATH); |
| 5431 |
size_t offset = path_filename_index(savefile); |
| 5432 |
bool result = true; |
| 5433 |
|
| 5434 |
path_build(name, MAX_PATH, ANGBAND_DIR_USER, savefile + offset); |
| 5435 |
my_strcat(name, tracking_extension, MAX_PATH); |
| 5436 |
|
| 5437 |
if (!suffix(name, tracking_extension)) { |
| 5438 |
|
| 5439 |
mem_free(name); |
| 5440 |
return result; |
| 5441 |
} |
| 5442 |
|
| 5443 |
multapp_file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, |
| 5444 |
0, NULL, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, NULL); |
| 5445 |
if (multapp_file == INVALID_HANDLE_VALUE) { |
| 5446 |
result = false; |
| 5447 |
if (message_on_failure) { |
| 5448 |
plog_fmt("Another instance of the game appears to using that savefile. If that's incorrect, delete %s and retry.", name); |
| 5449 |
} |
| 5450 |
} |
| 5451 |
|
| 5452 |
mem_free(name); |
| 5453 |
return result; |
| 5454 |
} |
| 5455 |
|
| 5456 |
|
| 5457 |
|
| 5458 |
|
| 5459 |
|
| 5460 |
static bool monitor_existing_savefile(void) |
| 5461 |
{ |
| 5462 |
assert(multapp_file == INVALID_HANDLE_VALUE); |
| 5463 |
return create_savefile_tracking_file(true); |
| 5464 |
} |
| 5465 |
|
| 5466 |
|
| 5467 |
|
| 5468 |
|
| 5469 |
|
| 5470 |
|
| 5471 |
static void monitor_new_savefile(game_event_type ev_type, |
| 5472 |
game_event_data *ev_data, void *user) |
| 5473 |
{ |
| 5474 |
assert(ev_type == EVENT_LEAVE_INIT && ev_data == NULL && user == NULL); |
| 5475 |
if (multapp_file == INVALID_HANDLE_VALUE) { |
| 5476 |
(void) create_savefile_tracking_file(false); |
| 5477 |
} |
| 5478 |
} |
| 5479 |
|
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
static void finish_monitoring_savefile(game_event_type ev_type, |
| 5484 |
game_event_data *ev_data, void *user) |
| 5485 |
{ |
| 5486 |
assert(ev_type == EVENT_LEAVE_GAME && ev_data == NULL && user == NULL); |
| 5487 |
if (multapp_file != INVALID_HANDLE_VALUE) { |
| 5488 |
(void) CloseHandle(multapp_file); |
| 5489 |
multapp_file = INVALID_HANDLE_VALUE; |
| 5490 |
} |
| 5491 |
} |
| 5492 |
|
| 5493 |
#endif |