• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Révision827f9301429ad31255ae5bf6d8ac9264a1cd48bb (tree)
l'heure2016-09-09 00:26:04
AuteurDeskull <desull@user...>
CommiterDeskull

Message de Log

VM プリプロセッサを除去。 / Remove VM preprocessor.

Change Summary

Modification

--- a/src/files.c
+++ b/src/files.c
@@ -5918,11 +5918,6 @@ void process_player_name(bool sf)
59185918 (void)sprintf(temp, "%s", player_base);
59195919 #endif
59205920
5921-#ifdef VM
5922- /* Hack -- support "flat directory" usage on VM/ESA */
5923- (void)sprintf(temp, "%s.sv", player_base);
5924-#endif /* VM */
5925-
59265921 /* Build the filename */
59275922 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
59285923 }
--- a/src/h-config.h
+++ b/src/h-config.h
@@ -202,10 +202,6 @@
202202 # undef PATH_SEP
203203 # define PATH_SEP "/"
204204 #endif
205-#ifdef VM
206-# undef PATH_SEP
207-# define PATH_SEP ""
208-#endif
209205
210206
211207 /*
--- a/src/h-define.h
+++ b/src/h-define.h
@@ -123,21 +123,12 @@
123123 * all "digits" must be "digits". Control characters can be made
124124 * from any legal characters. XXX XXX XXX
125125 */
126-#ifdef VM
127-# define A2I(X) alphatoindex(X)
128-# define I2A(X) indextoalpha(X)
129-# define D2I(X) ((X) - '0')
130-# define I2D(X) ((X) + '0')
131-# define KTRL(X) ((X) & 0x1F)
132-# define ESCAPE '\033'
133-#else
134-# define A2I(X) ((X) - 'a')
135-# define I2A(X) ((X) + 'a')
136-# define D2I(X) ((X) - '0')
137-# define I2D(X) ((X) + '0')
138-# define KTRL(X) ((X) & 0x1F)
139-# define ESCAPE '\033'
140-#endif
126+#define A2I(X) ((X) - 'a')
127+#define I2A(X) ((X) + 'a')
128+#define D2I(X) ((X) - '0')
129+#define I2D(X) ((X) + '0')
130+#define KTRL(X) ((X) & 0x1F)
131+#define ESCAPE '\033'
141132
142133 /*
143134 * Refer to the member at offset of structure
--- a/src/init2.c
+++ b/src/init2.c
@@ -113,28 +113,6 @@ void init_file_paths(char *path)
113113 /* Prepare to append to the Base Path */
114114 tail = path + strlen(path);
115115
116-
117-#ifdef VM
118-
119- /*** Use "flat" paths with VM/ESA ***/
120-
121- /* Use "blank" path names */
122- ANGBAND_DIR_APEX = string_make("");
123- ANGBAND_DIR_BONE = string_make("");
124- ANGBAND_DIR_DATA = string_make("");
125- ANGBAND_DIR_EDIT = string_make("");
126- ANGBAND_DIR_SCRIPT = string_make("");
127- ANGBAND_DIR_FILE = string_make("");
128- ANGBAND_DIR_HELP = string_make("");
129- ANGBAND_DIR_INFO = string_make("");
130- ANGBAND_DIR_SAVE = string_make("");
131- ANGBAND_DIR_USER = string_make("");
132- ANGBAND_DIR_XTRA = string_make("");
133-
134-
135-#else /* VM */
136-
137-
138116 /*** Build the sub-directory names ***/
139117
140118 /* Build a path name */
@@ -197,8 +175,6 @@ void init_file_paths(char *path)
197175 strcpy(tail, "xtra");
198176 ANGBAND_DIR_XTRA = string_make(path);
199177
200-#endif /* VM */
201-
202178
203179 #ifdef NeXT
204180
--- a/src/main-win.c
+++ b/src/main-win.c
@@ -1,5855 +1,5855 @@
1-/* File: main-win.c */
2-
3-/*
4- * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
5- *
6- * This software may be copied and distributed for educational, research,
7- * and not for profit purposes provided that this copyright and statement
8- * are included in all such copies.
9- */
10-
11-
12-/*
13- * This file helps Angband work with Windows computers.
14- *
15- * To use this file, use an appropriate "Makefile" or "Project File",
16- * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17- * make sure to obtain various extra files as described below.
18- *
19- * The official compilation uses the CodeWarrior Pro compiler, which
20- * includes a special project file and precompilable header file.
21- *
22- *
23- * See also "main-dos.c" and "main-ibm.c".
24- *
25- *
26- * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27- * and/or color redefinitions.
28- *
29- * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30- * normal "lib/xtra/font/*.fon" font files.
31- *
32- * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33- * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
34- * item.
35- *
36- *
37- * Compiling this file, and using the resulting executable, requires
38- * several extra files not distributed with the standard Angband code.
39- * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40- * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41- * into "lib/xtra/graf". In any case, some "*.fon" files (including
42- * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43- * If "USE_SOUND" is defined, then some special library (for example,
44- * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45- * files must be placed into "lib/xtra/sound/". All of these extra
46- * files can be found in the "ext-win" archive.
47- *
48- *
49- * The "Term_xtra_win_clear()" function should probably do a low-level
50- * clear of the current window, and redraw the borders and other things,
51- * if only for efficiency. XXX XXX XXX
52- *
53- * A simpler method is needed for selecting the "tile size" for windows.
54- * XXX XXX XXX
55- *
56- * The various "warning" messages assume the existance of the "screen.w"
57- * window, I think, and only a few calls actually check for its existance,
58- * this may be okay since "NULL" means "on top of all windows". (?) The
59- * user must never be allowed to "hide" the main window, or the "menubar"
60- * will disappear. XXX XXX XXX
61- *
62- * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63- * use with the "winhelp.exe" program. These files *may* be available
64- * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
65- *
66- *
67- * Initial framework (and most code) by Ben Harrison (benh@phial.com).
68- *
69- * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
70- *
71- * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72- * and Chris R. Martin (crm7479@tam2000.tamu.edu).
73- */
74-
75-#include "angband.h"
76-
77-#ifdef WINDOWS
78-#include <windows.h>
79-#include <direct.h>
80-#include <locale.h>
81-#include "z-term.h"
82-
83-/*
84- * Extract the "WIN32" flag from the compiler
85- */
86-#if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
87-# ifndef WIN32
88-# define WIN32
89-# endif
90-#endif
91-
92-
93-/*
94- * Hack -- allow use of "screen saver" mode
95- */
96-#define USE_SAVER
97-
98-
99-/*
100- * Menu constants -- see "ANGBAND.RC"
101- */
102-
103-#define IDM_FILE_NEW 100
104-#define IDM_FILE_OPEN 101
105-#define IDM_FILE_SAVE 110
106-#define IDM_FILE_SCORE 120
107-#define IDM_FILE_MOVIE 121
108-#define IDM_FILE_EXIT 130
109-
110-#define IDM_WINDOW_VIS_0 200
111-#define IDM_WINDOW_VIS_1 201
112-#define IDM_WINDOW_VIS_2 202
113-#define IDM_WINDOW_VIS_3 203
114-#define IDM_WINDOW_VIS_4 204
115-#define IDM_WINDOW_VIS_5 205
116-#define IDM_WINDOW_VIS_6 206
117-#define IDM_WINDOW_VIS_7 207
118-
119-#define IDM_WINDOW_FONT_0 210
120-#define IDM_WINDOW_FONT_1 211
121-#define IDM_WINDOW_FONT_2 212
122-#define IDM_WINDOW_FONT_3 213
123-#define IDM_WINDOW_FONT_4 214
124-#define IDM_WINDOW_FONT_5 215
125-#define IDM_WINDOW_FONT_6 216
126-#define IDM_WINDOW_FONT_7 217
127-
128-#define IDM_WINDOW_POS_0 220
129-#define IDM_WINDOW_POS_1 221
130-#define IDM_WINDOW_POS_2 222
131-#define IDM_WINDOW_POS_3 223
132-#define IDM_WINDOW_POS_4 224
133-#define IDM_WINDOW_POS_5 225
134-#define IDM_WINDOW_POS_6 226
135-#define IDM_WINDOW_POS_7 227
136-
137-#define IDM_WINDOW_BIZ_0 230
138-#define IDM_WINDOW_BIZ_1 231
139-#define IDM_WINDOW_BIZ_2 232
140-#define IDM_WINDOW_BIZ_3 233
141-#define IDM_WINDOW_BIZ_4 234
142-#define IDM_WINDOW_BIZ_5 235
143-#define IDM_WINDOW_BIZ_6 236
144-#define IDM_WINDOW_BIZ_7 237
145-
146-#define IDM_WINDOW_I_WID_0 240
147-#define IDM_WINDOW_I_WID_1 241
148-#define IDM_WINDOW_I_WID_2 242
149-#define IDM_WINDOW_I_WID_3 243
150-#define IDM_WINDOW_I_WID_4 244
151-#define IDM_WINDOW_I_WID_5 245
152-#define IDM_WINDOW_I_WID_6 246
153-#define IDM_WINDOW_I_WID_7 247
154-
155-#define IDM_WINDOW_D_WID_0 250
156-#define IDM_WINDOW_D_WID_1 251
157-#define IDM_WINDOW_D_WID_2 252
158-#define IDM_WINDOW_D_WID_3 253
159-#define IDM_WINDOW_D_WID_4 254
160-#define IDM_WINDOW_D_WID_5 255
161-#define IDM_WINDOW_D_WID_6 256
162-#define IDM_WINDOW_D_WID_7 257
163-
164-#define IDM_WINDOW_I_HGT_0 260
165-#define IDM_WINDOW_I_HGT_1 261
166-#define IDM_WINDOW_I_HGT_2 262
167-#define IDM_WINDOW_I_HGT_3 263
168-#define IDM_WINDOW_I_HGT_4 264
169-#define IDM_WINDOW_I_HGT_5 265
170-#define IDM_WINDOW_I_HGT_6 266
171-#define IDM_WINDOW_I_HGT_7 267
172-
173-#define IDM_WINDOW_D_HGT_0 270
174-#define IDM_WINDOW_D_HGT_1 271
175-#define IDM_WINDOW_D_HGT_2 272
176-#define IDM_WINDOW_D_HGT_3 273
177-#define IDM_WINDOW_D_HGT_4 274
178-#define IDM_WINDOW_D_HGT_5 275
179-#define IDM_WINDOW_D_HGT_6 276
180-#define IDM_WINDOW_D_HGT_7 277
181-
182-#define IDM_OPTIONS_NO_GRAPHICS 400
183-#define IDM_OPTIONS_OLD_GRAPHICS 401
184-#define IDM_OPTIONS_NEW_GRAPHICS 402
185-#define IDM_OPTIONS_NEW2_GRAPHICS 403
186-#define IDM_OPTIONS_BIGTILE 409
187-#define IDM_OPTIONS_SOUND 410
188-#define IDM_OPTIONS_MUSIC 411
189-#define IDM_OPTIONS_SAVER 420
190-#define IDM_OPTIONS_MAP 430
191-#define IDM_OPTIONS_BG 440
192-#define IDM_OPTIONS_OPEN_BG 441
193-
194-#define IDM_DUMP_SCREEN_HTML 450
195-
196-#define IDM_HELP_CONTENTS 901
197-
198-
199-
200-/*
201- * This may need to be removed for some compilers XXX XXX XXX
202- */
203-#if 0
204-#define STRICT
205-#endif
206-
207-/*
208- * Exclude parts of WINDOWS.H that are not needed
209- */
210-#define NOCOMM /* Comm driver APIs and definitions */
211-#define NOLOGERROR /* LogError() and related definitions */
212-#define NOPROFILER /* Profiler APIs */
213-#define NOLFILEIO /* _l* file I/O routines */
214-#define NOOPENFILE /* OpenFile and related definitions */
215-#define NORESOURCE /* Resource management */
216-#define NOATOM /* Atom management */
217-#define NOLANGUAGE /* Character test routines */
218-#define NOLSTRING /* lstr* string management routines */
219-#define NODBCS /* Double-byte character set routines */
220-#define NOKEYBOARDINFO /* Keyboard driver routines */
221-#define NOCOLOR /* COLOR_* color values */
222-#define NODRAWTEXT /* DrawText() and related definitions */
223-#define NOSCALABLEFONT /* Truetype scalable font support */
224-#define NOMETAFILE /* Metafile support */
225-#define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226-#define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227-#define NOKEYSTATES /* MK_* message key state flags */
228-#define NOWH /* SetWindowsHook and related WH_* definitions */
229-#define NOCLIPBOARD /* Clipboard APIs and definitions */
230-#define NOICONS /* IDI_* icon IDs */
231-#define NOMDI /* MDI support */
232-#define NOHELP /* Help support */
233-
234-/* Not defined since it breaks Borland C++ 5.5 */
235-/* #define NOCTLMGR */ /* Control management and controls */
236-
237-/*
238- * Exclude parts of WINDOWS.H that are not needed (Win32)
239- */
240-#define WIN32_LEAN_AND_MEAN
241-#define NONLS /* All NLS defines and routines */
242-#define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243-#define NOKANJI /* Kanji support stuff. */
244-#define NOMCX /* Modem Configuration Extensions */
245-
246-/*
247- * Include the "windows" support file
248- */
249-#include <windows.h>
250-
251-/*
252- * Exclude parts of MMSYSTEM.H that are not needed
253- */
254-#define MMNODRV /* Installable driver support */
255-#define MMNOWAVE /* Waveform support */
256-#define MMNOMIDI /* MIDI support */
257-#define MMNOAUX /* Auxiliary audio support */
258-#define MMNOTIMER /* Timer support */
259-#define MMNOJOY /* Joystick support */
260-#define MMNOMCI /* MCI support */
261-#define MMNOMMIO /* Multimedia file I/O support */
262-#define MMNOMMSYSTEM /* General MMSYSTEM functions */
263-
264-/*
265- * Include some more files. Note: the Cygnus Cygwin compiler
266- * doesn't use mmsystem.h instead it includes the winmm library
267- * which performs a similar function.
268- */
269-#include <mmsystem.h>
270-#include <commdlg.h>
271-
272-/*
273- * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274- * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
275- */
276-/* #define HTML_HELP */
277-
278-#ifdef HTML_HELP
279-#include <htmlhelp.h>
280-#endif /* HTML_HELP */
281-
282-/*
283- * Include the support for loading bitmaps
284- */
285-#ifdef USE_GRAPHICS
286-# include "readdib.h"
287-#endif
288-
289-/*
290- * Hack -- Fake declarations from "dos.h" XXX XXX XXX
291- */
292-#ifdef WIN32
293-#define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
294-#else /* WIN32 */
295-#define FA_LABEL 0x08 /* Volume label */
296-#define FA_DIREC 0x10 /* Directory */
297-unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
298-#endif /* WIN32 */
299-
300-/*
301- * Silliness in WIN32 drawing routine
302- */
303-#ifdef WIN32
304-# define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
305-#endif /* WIN32 */
306-
307-/*
308- * Silliness for Windows 95
309- */
310-#ifndef WS_EX_TOOLWINDOW
311-# define WS_EX_TOOLWINDOW 0
312-#endif
313-
314-/*
315- * Foreground color bits (hard-coded by DOS)
316- */
317-#define VID_BLACK 0x00
318-#define VID_BLUE 0x01
319-#define VID_GREEN 0x02
320-#define VID_CYAN 0x03
321-#define VID_RED 0x04
322-#define VID_MAGENTA 0x05
323-#define VID_YELLOW 0x06
324-#define VID_WHITE 0x07
325-
326-/*
327- * Bright text (hard-coded by DOS)
328- */
329-#define VID_BRIGHT 0x08
330-
331-/*
332- * Background color bits (hard-coded by DOS)
333- */
334-#define VUD_BLACK 0x00
335-#define VUD_BLUE 0x10
336-#define VUD_GREEN 0x20
337-#define VUD_CYAN 0x30
338-#define VUD_RED 0x40
339-#define VUD_MAGENTA 0x50
340-#define VUD_YELLOW 0x60
341-#define VUD_WHITE 0x70
342-
343-/*
344- * Blinking text (hard-coded by DOS)
345- */
346-#define VUD_BRIGHT 0x80
347-
348-
349-/*
350- * Forward declare
351- */
352-typedef struct _term_data term_data;
353-
354-/*
355- * Extra "term" data
356- *
357- * Note the use of "font_want" for the names of the font file requested by
358- * the user, and the use of "font_file" for the currently active font file.
359- *
360- * The "font_file" is uppercased, and takes the form "8X13.FON", while
361- * "font_want" can be in almost any form as long as it could be construed
362- * as attempting to represent the name of a font.
363- */
364-struct _term_data
365-{
366- term t;
367-
368- cptr s;
369-
370- HWND w;
371-
372- DWORD dwStyle;
373- DWORD dwExStyle;
374-
375- uint keys;
376-
377- uint rows; /* int -> uint */
378- uint cols;
379-
380- uint pos_x;
381- uint pos_y;
382- uint size_wid;
383- uint size_hgt;
384- uint size_ow1;
385- uint size_oh1;
386- uint size_ow2;
387- uint size_oh2;
388-
389- bool size_hack;
390-
391- bool xtra_hack;
392-
393- bool visible;
394-
395- bool bizarre;
396-
397- cptr font_want;
398-
399- cptr font_file;
400-
401- HFONT font_id;
402-
403- uint font_wid;
404- uint font_hgt;
405-
406- uint tile_wid;
407- uint tile_hgt;
408-
409- uint map_tile_wid;
410- uint map_tile_hgt;
411-
412- bool map_active;
413-#if 1 /* #ifdef JP */
414- LOGFONT lf;
415-#endif
416-
417- bool posfix;
418-
419-/* bg */
420-#if 0
421- char *bgfile;
422- int use_bg;
423-#endif
424-};
425-
426-
427-/*
428- * Maximum number of windows XXX XXX XXX
429- */
430-#define MAX_TERM_DATA 8
431-
432-/*
433- * An array of term_data's
434- */
435-static term_data data[MAX_TERM_DATA];
436-
437-/*
438- * Hack -- global "window creation" pointer
439- */
440-static term_data *my_td;
441-
442-/*
443- * Remember normal size of main window when maxmized
444- */
445-POINT normsize;
446-
447-/*
448- * was main window maximized on previous playing
449- */
450-bool win_maximized = FALSE;
451-
452-/*
453- * game in progress
454- */
455-bool game_in_progress = FALSE;
456-
457-/*
458- * note when "open"/"new" become valid
459- */
460-bool initialized = FALSE;
461-
462-/*
463- * screen paletted, i.e. 256 colors
464- */
465-bool paletted = FALSE;
466-
467-/*
468- * 16 colors screen, don't use RGB()
469- */
470-bool colors16 = FALSE;
471-
472-/*
473- * Saved instance handle
474- */
475-static HINSTANCE hInstance;
476-
477-/*
478- * Yellow brush for the cursor
479- */
480-static HBRUSH hbrYellow;
481-
482-/*
483- * An icon
484- */
485-static HICON hIcon;
486-
487-/*
488- * A palette
489- */
490-static HPALETTE hPal;
491-
492-/* bg */
493-static HBITMAP hBG = NULL;
494-static int use_bg = 0;
495-static char bg_bitmap_file[1024] = "bg.bmp";
496-
497-#ifdef USE_SAVER
498-
499-/*
500- * The screen saver window
501- */
502-static HWND hwndSaver;
503-
504-#endif /* USE_SAVER */
505-
506-
507-#ifdef USE_GRAPHICS
508-
509-/*
510- * Flag set once "graphics" has been initialized
511- */
512-static bool can_use_graphics = FALSE;
513-
514-/*
515- * The global bitmap
516- */
517-static DIBINIT infGraph;
518-
519-/*
520- * The global bitmap mask
521- */
522-static DIBINIT infMask;
523-
524-#endif /* USE_GRAPHICS */
525-
526-
527-#ifdef USE_SOUND
528-
529-/*
530- * Flag set once "sound" has been initialized
531- */
532-static bool can_use_sound = FALSE;
533-
534-#define SAMPLE_MAX 8
535-/*
536- * An array of sound file names
537- */
538-static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
539-
540-#endif /* USE_SOUND */
541-
542-
543-
544-#ifdef USE_MUSIC
545-
546-#define SAMPLE_MUSIC_MAX 16
547-static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548-static cptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549-static cptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550-static cptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551-static bool can_use_music = FALSE;
552-
553-static MCI_OPEN_PARMS mop;
554-static char mci_device_type[256];
555-
556-int current_music_type = 0;
557-int current_music_id = 0;
558-
559-#endif /* USE_MUSIC */
560-
561-
562-/*
563- * Full path to ANGBAND.INI
564- */
565-static cptr ini_file = NULL;
566-
567-/*
568- * Name of application
569- */
570-static cptr AppName = "ANGBAND";
571-
572-/*
573- * Name of sub-window type
574- */
575-static cptr AngList = "AngList";
576-
577-/*
578- * Directory names
579- */
580-static cptr ANGBAND_DIR_XTRA_GRAF;
581-static cptr ANGBAND_DIR_XTRA_SOUND;
582-static cptr ANGBAND_DIR_XTRA_MUSIC;
583-static cptr ANGBAND_DIR_XTRA_HELP;
584-#if 0 /* #ifndef JP */
585-static cptr ANGBAND_DIR_XTRA_FONT;
586-#endif
587-#ifdef USE_MUSIC
588-static cptr ANGBAND_DIR_XTRA_MUSIC;
589-#endif
590-
591-
592-/*
593- * The "complex" color values
594- */
595-static COLORREF win_clr[256];
596-
597-
598-/*
599- * Flag for macro trigger with dump ASCII
600- */
601-static bool Term_no_press = FALSE;
602-
603-/*
604- * Copy and paste
605- */
606-static bool mouse_down = FALSE;
607-static bool paint_rect = FALSE;
608-static int mousex = 0, mousey = 0;
609-static int oldx, oldy;
610-
611-
612-/*
613- * The "simple" color values
614- *
615- * See "main-ibm.c" for original table information
616- *
617- * The entries below are taken from the "color bits" defined above.
618- *
619- * Note that many of the choices below suck, but so do crappy monitors.
620- */
621-static BYTE win_pal[256] =
622-{
623- VID_BLACK, /* Dark */
624- VID_WHITE, /* White */
625- VID_CYAN, /* Slate XXX */
626- VID_RED | VID_BRIGHT, /* Orange XXX */
627- VID_RED, /* Red */
628- VID_GREEN, /* Green */
629- VID_BLUE, /* Blue */
630- VID_YELLOW, /* Umber XXX */
631- VID_BLACK | VID_BRIGHT, /* Light Dark */
632- VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
633- VID_MAGENTA, /* Violet XXX */
634- VID_YELLOW | VID_BRIGHT, /* Yellow */
635- VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
636- VID_GREEN | VID_BRIGHT, /* Light Green */
637- VID_BLUE | VID_BRIGHT, /* Light Blue */
638- VID_YELLOW /* Light Umber XXX */
639-};
640-
641-
642-/*
643- * Hack -- define which keys are "special"
644- */
645-static bool special_key[256];
646-static bool ignore_key[256];
647-
648-#if 1
649-/*
650- * Hack -- initialization list for "special_key"
651- */
652-static byte special_key_list[] = {
653- VK_CLEAR, VK_PAUSE, VK_CAPITAL,
654- VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
655- VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
656- VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
657- VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
658- VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
659- VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
660- VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
661- VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
662- VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
663- VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
664- VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
665- VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
666- VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
667- VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
668- VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
669- VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
670- VK_NONAME, VK_PA1,
671- 0 /* End of List */
672-};
673-
674-static byte ignore_key_list[] = {
675- VK_ESCAPE, VK_TAB, VK_SPACE,
676- 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
677- VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
678- VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
679- VK_LMENU, VK_RMENU,
680- 0 /* End of List */
681-};
682-#else
683-/*
684- * Hack -- initialization list for "special_key"
685- *
686- * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
687- * and the normal keys (escape, tab, return, letters, numbers, etc), but we
688- * catch the keypad keys (with and without numlock set, including keypad 5),
689- * the function keys (including the "menu" key which maps to F10), and the
690- * "pause" key (between scroll lock and numlock). We also catch a few odd
691- * keys which I do not recognize, but which are listed among keys which we
692- * do catch, so they should be harmless to catch.
693- */
694-static byte special_key_list[] =
695-{
696- VK_CLEAR, /* 0x0C (KP<5>) */
697-
698- VK_PAUSE, /* 0x13 (pause) */
699-
700- VK_PRIOR, /* 0x21 (KP<9>) */
701- VK_NEXT, /* 0x22 (KP<3>) */
702- VK_END, /* 0x23 (KP<1>) */
703- VK_HOME, /* 0x24 (KP<7>) */
704- VK_LEFT, /* 0x25 (KP<4>) */
705- VK_UP, /* 0x26 (KP<8>) */
706- VK_RIGHT, /* 0x27 (KP<6>) */
707- VK_DOWN, /* 0x28 (KP<2>) */
708- VK_SELECT, /* 0x29 (?????) */
709- VK_PRINT, /* 0x2A (?????) */
710- VK_EXECUTE, /* 0x2B (?????) */
711- VK_SNAPSHOT, /* 0x2C (?????) */
712- VK_INSERT, /* 0x2D (KP<0>) */
713- VK_DELETE, /* 0x2E (KP<.>) */
714- VK_HELP, /* 0x2F (?????) */
715-#if 0
716- VK_NUMPAD0, /* 0x60 (KP<0>) */
717- VK_NUMPAD1, /* 0x61 (KP<1>) */
718- VK_NUMPAD2, /* 0x62 (KP<2>) */
719- VK_NUMPAD3, /* 0x63 (KP<3>) */
720- VK_NUMPAD4, /* 0x64 (KP<4>) */
721- VK_NUMPAD5, /* 0x65 (KP<5>) */
722- VK_NUMPAD6, /* 0x66 (KP<6>) */
723- VK_NUMPAD7, /* 0x67 (KP<7>) */
724- VK_NUMPAD8, /* 0x68 (KP<8>) */
725- VK_NUMPAD9, /* 0x69 (KP<9>) */
726- VK_MULTIPLY, /* 0x6A (KP<*>) */
727- VK_ADD, /* 0x6B (KP<+>) */
728- VK_SEPARATOR, /* 0x6C (?????) */
729- VK_SUBTRACT, /* 0x6D (KP<->) */
730- VK_DECIMAL, /* 0x6E (KP<.>) */
731- VK_DIVIDE, /* 0x6F (KP</>) */
732-#endif
733- VK_F1, /* 0x70 */
734- VK_F2, /* 0x71 */
735- VK_F3, /* 0x72 */
736- VK_F4, /* 0x73 */
737- VK_F5, /* 0x74 */
738- VK_F6, /* 0x75 */
739- VK_F7, /* 0x76 */
740- VK_F8, /* 0x77 */
741- VK_F9, /* 0x78 */
742- VK_F10, /* 0x79 */
743- VK_F11, /* 0x7A */
744- VK_F12, /* 0x7B */
745- VK_F13, /* 0x7C */
746- VK_F14, /* 0x7D */
747- VK_F15, /* 0x7E */
748- VK_F16, /* 0x7F */
749- VK_F17, /* 0x80 */
750- VK_F18, /* 0x81 */
751- VK_F19, /* 0x82 */
752- VK_F20, /* 0x83 */
753- VK_F21, /* 0x84 */
754- VK_F22, /* 0x85 */
755- VK_F23, /* 0x86 */
756- VK_F24, /* 0x87 */
757- 0
758-};
759-#endif
760-
761-/* bg */
762-static void delete_bg(void)
763-{
764- if (hBG != NULL)
765- {
766- DeleteObject(hBG);
767- hBG = NULL;
768- }
769-}
770-
771-static int init_bg(void)
772-{
773- char * bmfile = bg_bitmap_file;
774-
775- delete_bg();
776- if (use_bg == 0) return 0;
777-
778- hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
779- if (!hBG) {
780- plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
781- use_bg = 0;
782- return 0;
783- }
784-#if 0 /* gomi */
785- HDC wnddc, dcimage, dcbg;
786- HBITMAP bmimage, bmimage_old, bmbg_old;
787- int i, j;
788-
789- delete_bg();
790-
791- wnddc = GetDC(hwnd);
792- dcimage = CreateCompatibleDC(wnddc);
793- dcbg = CreateCompatibleDC(wnddc);
794-
795- bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
796- if (!bmimage) quit("bg.bmpが読みこめない!");
797- bmimage_old = SelectObject(dcimage, bmimage);
798-
799- CreateCompatibleBitmap();
800-
801- ReleaseDC(hwnd, wnddc);
802-#endif
803- use_bg = 1;
804- return 1;
805-}
806-
807-static void DrawBG(HDC hdc, RECT *r)
808-{
809- HDC hdcSrc;
810- HBITMAP hOld;
811- BITMAP bm;
812- int x = r->left, y = r->top;
813- int nx, ny, sx, sy, swid, shgt, cwid, chgt;
814-
815- if (!use_bg || !hBG)
816- return;
817-
818- nx = x; ny = y;
819- GetObject(hBG, sizeof(bm), &bm);
820- swid = bm.bmWidth; shgt = bm.bmHeight;
821-
822- hdcSrc = CreateCompatibleDC(hdc);
823- hOld = SelectObject(hdcSrc, hBG);
824-
825- do {
826- sx = nx % swid;
827- cwid = MIN(swid - sx, r->right - nx);
828- do {
829- sy = ny % shgt;
830- chgt = MIN(shgt - sy, r->bottom - ny);
831- BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
832- ny += chgt;
833- } while (ny < r->bottom);
834- ny = y;
835- nx += cwid;
836- } while (nx < r->right);
837-
838- SelectObject(hdcSrc, hOld);
839- DeleteDC(hdcSrc);
840-}
841-
842-#if 0
843-/*
844- * Hack -- given a pathname, point at the filename
845- */
846-static cptr extract_file_name(cptr s)
847-{
848- cptr p;
849-
850- /* Start at the end */
851- p = s + strlen(s) - 1;
852-
853- /* Back up to divider */
854- while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
855-
856- /* Return file name */
857- return (p+1);
858-}
859-#endif
860-
861-
862-/*
863- * Hack -- given a simple filename, extract the "font size" info
864- *
865- * Return a pointer to a static buffer holding the capitalized base name.
866- */
867-#if 0 /* #ifndef JP */
868-static char *analyze_font(char *path, int *wp, int *hp)
869-{
870- int wid, hgt;
871-
872- char *s, *p;
873-
874- /* Start at the end */
875- p = path + strlen(path) - 1;
876-
877- /* Back up to divider */
878- while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
879-
880- /* Advance to file name */
881- ++p;
882-
883- /* Capitalize */
884- for (s = p; *s; ++s)
885- {
886- /* Capitalize (be paranoid) */
887- if (islower(*s)) *s = toupper(*s);
888- }
889-
890- /* Find first 'X' */
891- s = my_strchr(p, 'X');
892-
893- /* Extract font width */
894- wid = atoi(p);
895-
896- /* Extract height */
897- hgt = s ? atoi(s+1) : 0;
898-
899- /* Save results */
900- (*wp) = wid;
901- (*hp) = hgt;
902-
903- /* Result */
904- return (p);
905-}
906-#endif
907-
908-
909-/*
910- * Check for existance of a file
911- */
912-static bool check_file(cptr s)
913-{
914- char path[1024];
915-
916-#ifdef WIN32
917-
918- DWORD attrib;
919-
920-#else /* WIN32 */
921-
922- unsigned int attrib;
923-
924-#endif /* WIN32 */
925-
926- /* Copy it */
927- strcpy(path, s);
928-
929-#ifdef WIN32
930-
931- /* Examine */
932- attrib = GetFileAttributes(path);
933-
934- /* Require valid filename */
935- if (attrib == INVALID_FILE_NAME) return (FALSE);
936-
937- /* Prohibit directory */
938- if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
939-
940-#else /* WIN32 */
941-
942- /* Examine and verify */
943- if (_dos_getfileattr(path, &attrib)) return (FALSE);
944-
945- /* Prohibit something */
946- if (attrib & FA_LABEL) return (FALSE);
947-
948- /* Prohibit directory */
949- if (attrib & FA_DIREC) return (FALSE);
950-
951-#endif /* WIN32 */
952-
953- /* Success */
954- return (TRUE);
955-}
956-
957-
958-/*
959- * Check for existance of a directory
960- */
961-static bool check_dir(cptr s)
962-{
963- int i;
964-
965- char path[1024];
966-
967-#ifdef WIN32
968-
969- DWORD attrib;
970-
971-#else /* WIN32 */
972-
973- unsigned int attrib;
974-
975-#endif /* WIN32 */
976-
977- /* Copy it */
978- strcpy(path, s);
979-
980- /* Check length */
981- i = strlen(path);
982-
983- /* Remove trailing backslash */
984- if (i && (path[i-1] == '\\')) path[--i] = '\0';
985-
986-#ifdef WIN32
987-
988- /* Examine */
989- attrib = GetFileAttributes(path);
990-
991- /* Require valid filename */
992- if (attrib == INVALID_FILE_NAME) return (FALSE);
993-
994- /* Require directory */
995- if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
996-
997-#else /* WIN32 */
998-
999- /* Examine and verify */
1000- if (_dos_getfileattr(path, &attrib)) return (FALSE);
1001-
1002- /* Prohibit something */
1003- if (attrib & FA_LABEL) return (FALSE);
1004-
1005- /* Require directory */
1006- if (!(attrib & FA_DIREC)) return (FALSE);
1007-
1008-#endif /* WIN32 */
1009-
1010- /* Success */
1011- return (TRUE);
1012-}
1013-
1014-
1015-/*
1016- * Validate a file
1017- */
1018-static void validate_file(cptr s)
1019-{
1020- /* Verify or fail */
1021- if (!check_file(s))
1022- {
1023- quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1024- }
1025-}
1026-
1027-
1028-/*
1029- * Validate a directory
1030- */
1031-static void validate_dir(cptr s, bool vital)
1032-{
1033- /* Verify or fail */
1034- if (!check_dir(s))
1035- {
1036- /* This directory contains needed data */
1037- if (vital)
1038- {
1039- quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1040- }
1041- /* Attempt to create this directory */
1042- else if (mkdir(s))
1043- {
1044- quit_fmt("Unable to create directory:\n%s", s);
1045- }
1046- }
1047-}
1048-
1049-
1050-/*
1051- * Get the "size" for a window
1052- */
1053-static void term_getsize(term_data *td)
1054-{
1055- RECT rc;
1056-
1057- int wid, hgt;
1058-
1059- /* Paranoia */
1060- if (td->cols < 1) td->cols = 1;
1061- if (td->rows < 1) td->rows = 1;
1062-
1063- /* Window sizes */
1064- wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1065- hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1066-
1067- /* Fake window size */
1068- rc.left = 0;
1069- rc.right = rc.left + wid;
1070- rc.top = 0;
1071- rc.bottom = rc.top + hgt;
1072-
1073- /* XXX XXX XXX */
1074- /* rc.right += 1; */
1075- /* rc.bottom += 1; */
1076-
1077- /* Adjust */
1078- AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1079-
1080- /* Total size */
1081- td->size_wid = rc.right - rc.left;
1082- td->size_hgt = rc.bottom - rc.top;
1083-
1084- /* See CreateWindowEx */
1085- if (!td->w) return;
1086-
1087- /* Extract actual location */
1088- GetWindowRect(td->w, &rc);
1089-
1090- /* Save the location */
1091- td->pos_x = rc.left;
1092- td->pos_y = rc.top;
1093-}
1094-
1095-
1096-/*
1097- * Write the "prefs" for a single term
1098- */
1099-static void save_prefs_aux(int i)
1100-{
1101- term_data *td = &data[i];
1102- char sec_name[128];
1103- char buf[1024];
1104-
1105- RECT rc;
1106- WINDOWPLACEMENT lpwndpl;
1107-
1108- /* Paranoia */
1109- if (!td->w) return;
1110-
1111- /* Make section name */
1112- sprintf(sec_name, "Term-%d", i);
1113-
1114- /* Visible */
1115- if (i > 0)
1116- {
1117- strcpy(buf, td->visible ? "1" : "0");
1118- WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1119- }
1120-
1121- /* Font */
1122-#ifdef JP
1123- strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1124-#else
1125-#if 0
1126- strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1127-#else
1128- strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1129-#endif
1130-#endif
1131-
1132- WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1133-
1134-#if 1 /* #ifdef JP */
1135- wsprintf(buf, "%d", td->lf.lfWidth);
1136- WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1137- wsprintf(buf, "%d", td->lf.lfHeight);
1138- WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1139- wsprintf(buf, "%d", td->lf.lfWeight);
1140- WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1141-#endif
1142- /* Bizarre */
1143- strcpy(buf, td->bizarre ? "1" : "0");
1144- WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1145-
1146- /* Tile size (x) */
1147- wsprintf(buf, "%d", td->tile_wid);
1148- WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1149-
1150- /* Tile size (y) */
1151- wsprintf(buf, "%d", td->tile_hgt);
1152- WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1153-
1154- /* Get window placement and dimensions */
1155- lpwndpl.length = sizeof(WINDOWPLACEMENT);
1156- GetWindowPlacement(td->w, &lpwndpl);
1157-
1158- /* Acquire position in *normal* mode (not minimized) */
1159- rc = lpwndpl.rcNormalPosition;
1160-
1161- /* Window size (x) */
1162- if (i == 0) wsprintf(buf, "%d", normsize.x);
1163- else wsprintf(buf, "%d", td->cols);
1164- WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1165-
1166- /* Window size (y) */
1167- if (i == 0) wsprintf(buf, "%d", normsize.y);
1168- else wsprintf(buf, "%d", td->rows);
1169- WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1170-
1171- /* Maxmized (only main window) */
1172- if (i == 0)
1173- {
1174- strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1175- WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1176- }
1177-
1178- /* Acquire position */
1179- GetWindowRect(td->w, &rc);
1180-
1181- /* Window position (x) */
1182- wsprintf(buf, "%d", rc.left);
1183- WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1184-
1185- /* Window position (y) */
1186- wsprintf(buf, "%d", rc.top);
1187- WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1188-
1189- /* Window Z position */
1190- if (i > 0)
1191- {
1192- strcpy(buf, td->posfix ? "1" : "0");
1193- WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1194- }
1195-}
1196-
1197-
1198-/*
1199- * Write the "prefs"
1200- *
1201- * We assume that the windows have all been initialized
1202- */
1203-static void save_prefs(void)
1204-{
1205- int i;
1206-
1207- char buf[128];
1208-
1209- /* Save the "arg_graphics" flag */
1210- sprintf(buf, "%d", arg_graphics);
1211- WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1212-
1213- /* Save the "arg_bigtile" flag */
1214- strcpy(buf, arg_bigtile ? "1" : "0");
1215- WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1216-
1217- /* Save the "arg_sound" flag */
1218- strcpy(buf, arg_sound ? "1" : "0");
1219- WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1220-
1221- /* Save the "arg_sound" flag */
1222- strcpy(buf, arg_music ? "1" : "0");
1223- WritePrivateProfileString("Angband", "Music", buf, ini_file);
1224-
1225- /* bg */
1226- strcpy(buf, use_bg ? "1" : "0");
1227- WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1228- WritePrivateProfileString("Angband", "BackGroundBitmap",
1229- bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1230-
1231- /* Save window prefs */
1232- for (i = 0; i < MAX_TERM_DATA; ++i)
1233- {
1234- save_prefs_aux(i);
1235- }
1236-}
1237-
1238-
1239-/*
1240- * Load the "prefs" for a single term
1241- */
1242-static void load_prefs_aux(int i)
1243-{
1244- term_data *td = &data[i];
1245- char sec_name[128];
1246- char tmp[1024];
1247-
1248- int wid, hgt, posx, posy;
1249- int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1250- int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1251- posx=0;
1252- posy=0;
1253-
1254- /* Make section name */
1255- sprintf(sec_name, "Term-%d", i);
1256-
1257- /* Make section name */
1258- sprintf(sec_name, "Term-%d", i);
1259-
1260- /* Visible */
1261- if (i > 0)
1262- {
1263- td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1264- }
1265-
1266- /* Desired font, with default */
1267-#ifdef JP
1268- GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1269-#else
1270-#if 0
1271- GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1272-#else
1273- GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1274-#endif
1275-#endif
1276-
1277-
1278- /* Bizarre */
1279- td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1280-
1281- /* Analyze font, save desired font name */
1282-#if 1 /* #ifdef JP */
1283- td->font_want = string_make(tmp);
1284- hgt = 15; wid = 0;
1285- td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1286- td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1287- td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1288-#else
1289- td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1290-#endif
1291-
1292-
1293- /* Tile size */
1294-#if 1 /* #ifdef JP */
1295- td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1296- td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1297-#else
1298- td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1299- td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1300-#endif
1301-
1302-
1303- /* Window size */
1304- td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1305- td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1306- normsize.x = td->cols; normsize.y = td->rows;
1307-
1308- /* Window size */
1309- if (i == 0)
1310- {
1311- win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1312- }
1313-
1314- /* Window position */
1315- posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1316- posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1317- td->pos_x = MIN(MAX(0, posx), dispx-128);
1318- td->pos_y = MIN(MAX(0, posy), dispy-128);
1319-
1320- /* Window Z position */
1321- if (i > 0)
1322- {
1323- td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1324- }
1325-}
1326-
1327-
1328-/*
1329- * Load the "prefs"
1330- */
1331-static void load_prefs(void)
1332-{
1333- int i;
1334-
1335- /* Extract the "arg_graphics" flag */
1336- arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1337-
1338- /* Extract the "arg_bigtile" flag */
1339- arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1340- use_bigtile = arg_bigtile;
1341-
1342- /* Extract the "arg_sound" flag */
1343- arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1344-
1345- /* Extract the "arg_sound" flag */
1346- arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1347-
1348- /* bg */
1349- use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1350- GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1351-
1352- /* Load window prefs */
1353- for (i = 0; i < MAX_TERM_DATA; ++i)
1354- {
1355- load_prefs_aux(i);
1356- }
1357-}
1358-
1359-#if defined(USE_SOUND) || defined(USE_MUSIC)
1360-
1361-/*
1362- * XXX XXX XXX - Taken from files.c.
1363- *
1364- * Extract "tokens" from a buffer
1365- *
1366- * This function uses "whitespace" as delimiters, and treats any amount of
1367- * whitespace as a single delimiter. We will never return any empty tokens.
1368- * When given an empty buffer, or a buffer containing only "whitespace", we
1369- * will return no tokens. We will never extract more than "num" tokens.
1370- *
1371- * By running a token through the "text_to_ascii()" function, you can allow
1372- * that token to include (encoded) whitespace, using "\s" to encode spaces.
1373- *
1374- * We save pointers to the tokens in "tokens", and return the number found.
1375- */
1376-static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1377-{
1378- int k = 0;
1379-
1380- char *s = buf;
1381-
1382-
1383- /* Process */
1384- while (k < num)
1385- {
1386- char *t;
1387-
1388- /* Skip leading whitespace */
1389- for ( ; *s && iswspace(*s); ++s) /* loop */;
1390-
1391- /* All done */
1392- if (!*s) break;
1393-
1394- /* Find next whitespace, if any */
1395- for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1396-
1397- /* Nuke and advance (if necessary) */
1398- if (*t) *t++ = '\0';
1399-
1400- /* Save the token */
1401- tokens[k++] = s;
1402-
1403- /* Advance */
1404- s = t;
1405- }
1406-
1407- /* Count */
1408- return (k);
1409-}
1410-
1411-#endif /* USE_SOUND || USE_MUSIC */
1412-
1413-#ifdef USE_SOUND
1414-
1415-static void load_sound_prefs(void)
1416-{
1417- int i, j, num;
1418- char tmp[1024];
1419- char ini_path[1024];
1420- char wav_path[1024];
1421- char *zz[SAMPLE_MAX];
1422-
1423- /* Access the sound.cfg */
1424-
1425- path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1426-
1427- for (i = 0; i < SOUND_MAX; i++)
1428- {
1429- GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1430-
1431- num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1432-
1433- for (j = 0; j < num; j++)
1434- {
1435- /* Access the sound */
1436- path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1437-
1438- /* Save the sound filename, if it exists */
1439- if (check_file(wav_path))
1440- sound_file[i][j] = string_make(zz[j]);
1441- }
1442- }
1443-}
1444-
1445-#endif /* USE_SOUND */
1446-
1447-#ifdef USE_MUSIC
1448-
1449-static void load_music_prefs(void)
1450-{
1451- int i, j, num;
1452- char tmp[1024];
1453- char ini_path[1024];
1454- char wav_path[1024];
1455- char *zz[SAMPLE_MAX];
1456- char key[80];
1457-
1458- /* Access the music.cfg */
1459-
1460- path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1461-
1462- GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1463-
1464- for (i = 0; i < MUSIC_BASIC_MAX; i++)
1465- {
1466- GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1467-
1468- num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1469-
1470- for (j = 0; j < num; j++)
1471- {
1472- /* Access the sound */
1473- path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1474-
1475- /* Save the sound filename, if it exists */
1476- if (check_file(wav_path))
1477- music_file[i][j] = string_make(zz[j]);
1478- }
1479- }
1480-
1481- for (i = 0; i < max_d_idx; i++)
1482- {
1483- sprintf(key, "dungeon%03d", i);
1484- GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1485-
1486- num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1487-
1488- for (j = 0; j < num; j++)
1489- {
1490- /* Access the sound */
1491- path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1492-
1493- /* Save the sound filename, if it exists */
1494- if (check_file(wav_path))
1495- dungeon_music_file[i][j] = string_make(zz[j]);
1496- }
1497- }
1498-
1499- for (i = 0; i < 1000; i++) /*!< @todo クエスト最大数指定 */
1500- {
1501- sprintf(key, "quest%03d", i);
1502- GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1503-
1504- num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1505-
1506- for (j = 0; j < num; j++)
1507- {
1508- /* Access the sound */
1509- path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1510-
1511- /* Save the sound filename, if it exists */
1512- if (check_file(wav_path))
1513- quest_music_file[i][j] = string_make(zz[j]);
1514- }
1515- }
1516-
1517- for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1518- {
1519- sprintf(key, "town%03d", i);
1520- GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1521-
1522- num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1523-
1524- for (j = 0; j < num; j++)
1525- {
1526- /* Access the sound */
1527- path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1528-
1529- /* Save the sound filename, if it exists */
1530- if (check_file(wav_path))
1531- town_music_file[i][j] = string_make(zz[j]);
1532- }
1533- }
1534-
1535-
1536-}
1537-
1538-#endif /* USE_MUSIC */
1539-
1540-/*
1541- * Create the new global palette based on the bitmap palette
1542- * (if any), and the standard 16 entry palette derived from
1543- * "win_clr[]" which is used for the basic 16 Angband colors.
1544- *
1545- * This function is never called before all windows are ready.
1546- *
1547- * This function returns FALSE if the new palette could not be
1548- * prepared, which should normally be a fatal error. XXX XXX
1549- *
1550- * Note that only some machines actually use a "palette".
1551- */
1552-static int new_palette(void)
1553-{
1554- HPALETTE hBmPal;
1555- HPALETTE hNewPal;
1556- HDC hdc;
1557- int i, nEntries;
1558- int pLogPalSize;
1559- int lppeSize;
1560- LPLOGPALETTE pLogPal;
1561- LPPALETTEENTRY lppe;
1562-
1563- term_data *td;
1564-
1565-
1566- /* This makes no sense */
1567- if (!paletted) return (TRUE);
1568-
1569-
1570- /* No bitmap */
1571- lppeSize = 0;
1572- lppe = NULL;
1573- nEntries = 0;
1574-
1575-#ifdef USE_GRAPHICS
1576-
1577- /* Check the bitmap palette */
1578- hBmPal = infGraph.hPalette;
1579-
1580- /* Use the bitmap */
1581- if (hBmPal)
1582- {
1583- lppeSize = 256 * sizeof(PALETTEENTRY);
1584- lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1585- nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1586- if ((nEntries == 0) || (nEntries > 220))
1587- {
1588- /* Warn the user */
1589- plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1590-
1591- /* Cleanup */
1592- rnfree(lppe, lppeSize);
1593-
1594- /* Fail */
1595- return (FALSE);
1596- }
1597- }
1598-
1599-#endif /* USE_GRAPHICS */
1600-
1601- /* Size of palette */
1602- pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1603-
1604- /* Allocate palette */
1605- pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1606-
1607- /* Version */
1608- pLogPal->palVersion = 0x300;
1609-
1610- /* Make room for bitmap and normal data */
1611- pLogPal->palNumEntries = nEntries + 16;
1612-
1613- /* Save the bitmap data */
1614- for (i = 0; i < nEntries; i++)
1615- {
1616- pLogPal->palPalEntry[i] = lppe[i];
1617- }
1618-
1619- /* Save the normal data */
1620- for (i = 0; i < 16; i++)
1621- {
1622- LPPALETTEENTRY p;
1623-
1624- /* Access the entry */
1625- p = &(pLogPal->palPalEntry[i+nEntries]);
1626-
1627- /* Save the colors */
1628- p->peRed = GetRValue(win_clr[i]);
1629- p->peGreen = GetGValue(win_clr[i]);
1630- p->peBlue = GetBValue(win_clr[i]);
1631-
1632- /* Save the flags */
1633- p->peFlags = PC_NOCOLLAPSE;
1634- }
1635-
1636- /* Free something */
1637- if (lppe) rnfree(lppe, lppeSize);
1638-
1639- /* Create a new palette, or fail */
1640- hNewPal = CreatePalette(pLogPal);
1641- if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1642-
1643- /* Free the palette */
1644- rnfree(pLogPal, pLogPalSize);
1645-
1646- /* Main window */
1647- td = &data[0];
1648-
1649- /* Realize the palette */
1650- hdc = GetDC(td->w);
1651- SelectPalette(hdc, hNewPal, 0);
1652- i = RealizePalette(hdc);
1653- ReleaseDC(td->w, hdc);
1654- if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1655-
1656-
1657- /* Sub-windows */
1658- for (i = 1; i < MAX_TERM_DATA; i++)
1659- {
1660- td = &data[i];
1661-
1662- hdc = GetDC(td->w);
1663- SelectPalette(hdc, hNewPal, 0);
1664- ReleaseDC(td->w, hdc);
1665- }
1666-
1667- /* Delete old palette */
1668- if (hPal) DeleteObject(hPal);
1669-
1670- /* Save new palette */
1671- hPal = hNewPal;
1672-
1673- /* Success */
1674- return (TRUE);
1675-}
1676-
1677-
1678-#ifdef USE_GRAPHICS
1679-/*
1680- * Initialize graphics
1681- */
1682-static bool init_graphics(void)
1683-{
1684- /* Initialize once */
1685- /* if (can_use_graphics != arg_graphics) */
1686- {
1687- char buf[1024];
1688- int wid, hgt, twid, thgt, ox, oy;
1689- cptr name;
1690-
1691- if (arg_graphics == GRAPHICS_ADAM_BOLT)
1692- {
1693- wid = 16;
1694- hgt = 16;
1695- twid = 16;
1696- thgt = 16;
1697- ox = 0;
1698- oy = 0;
1699- name = "16X16.BMP";
1700-
1701- ANGBAND_GRAF = "new";
1702- }
1703- else if (arg_graphics == GRAPHICS_HENGBAND)
1704- {
1705- /*! @todo redraw
1706- wid = 64;
1707- hgt = 64;
1708- twid = 32;
1709- thgt = 32;
1710- ox = -16;
1711- oy = -24;
1712- name = "64X64.BMP";
1713- */
1714-
1715- wid = 32;
1716- hgt = 32;
1717- twid = 32;
1718- thgt = 32;
1719- ox = 0;
1720- oy = 0;
1721- name = "32X32.BMP";
1722-
1723- ANGBAND_GRAF = "ne2";
1724- }
1725- else
1726- {
1727- wid = 8;
1728- hgt = 8;
1729- twid = 8;
1730- thgt = 8;
1731- ox = 0;
1732- oy = 0;
1733- name = "8X8.BMP";
1734- ANGBAND_GRAF = "old";
1735- }
1736-
1737- /* Access the bitmap file */
1738- path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1739-
1740- /* Load the bitmap or quit */
1741- if (!ReadDIB(data[0].w, buf, &infGraph))
1742- {
1743- plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1744- return (FALSE);
1745- }
1746-
1747- /* Save the new sizes */
1748- infGraph.CellWidth = wid;
1749- infGraph.CellHeight = hgt;
1750- infGraph.TileWidth = twid;
1751- infGraph.TileHeight = thgt;
1752- infGraph.OffsetX = ox;
1753- infGraph.OffsetY = oy;
1754-
1755- if (arg_graphics == GRAPHICS_ADAM_BOLT)
1756- {
1757- /* Access the mask file */
1758- path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1759-
1760- /* Load the bitmap or quit */
1761- if (!ReadDIB(data[0].w, buf, &infMask))
1762- {
1763- plog_fmt("Cannot read bitmap file '%s'", buf);
1764- return (FALSE);
1765- }
1766- }
1767- if (arg_graphics == GRAPHICS_HENGBAND)
1768- {
1769- /* Access the mask file */
1770- path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1771-
1772- /* Load the bitmap or quit */
1773- if (!ReadDIB(data[0].w, buf, &infMask))
1774- {
1775- plog_fmt("Cannot read bitmap file '%s'", buf);
1776- return (FALSE);
1777- }
1778- }
1779-
1780- /* Activate a palette */
1781- if (!new_palette())
1782- {
1783- /* Free bitmap XXX XXX XXX */
1784-
1785- /* Oops */
1786- plog(_("パレットを実現できません!", "Cannot activate palette!"));
1787- return (FALSE);
1788- }
1789-
1790- /* Graphics available */
1791- can_use_graphics = arg_graphics;
1792- }
1793-
1794- /* Result */
1795- return (can_use_graphics);
1796-}
1797-#endif /* USE_GRAPHICS */
1798-
1799-
1800-#ifdef USE_MUSIC
1801-/*
1802- * Initialize music
1803- */
1804-static bool init_music(void)
1805-{
1806- /* Initialize once */
1807- if (!can_use_music)
1808- {
1809- /* Load the prefs */
1810- load_music_prefs();
1811-
1812- /* Sound available */
1813- can_use_music = TRUE;
1814- }
1815-
1816- /* Result */
1817- return (can_use_music);
1818-}
1819-
1820-/*
1821- * Hack -- Stop a music
1822- */
1823-static void stop_music(void)
1824-{
1825- mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1826- mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1827-}
1828-
1829-#endif /* USE_MUSIC */
1830-
1831-#ifdef USE_SOUND
1832-/*
1833- * Initialize sound
1834- */
1835-static bool init_sound(void)
1836-{
1837- /* Initialize once */
1838- if (!can_use_sound)
1839- {
1840- /* Load the prefs */
1841- load_sound_prefs();
1842-
1843- /* Sound available */
1844- can_use_sound = TRUE;
1845- }
1846-
1847- /* Result */
1848- return (can_use_sound);
1849-}
1850-#endif /* USE_SOUND */
1851-
1852-
1853-/*
1854- * Resize a window
1855- */
1856-static void term_window_resize(term_data *td)
1857-{
1858- /* Require window */
1859- if (!td->w) return;
1860-
1861- /* Resize the window */
1862- SetWindowPos(td->w, 0, 0, 0,
1863- td->size_wid, td->size_hgt,
1864- SWP_NOMOVE | SWP_NOZORDER);
1865-
1866- /* Redraw later */
1867- InvalidateRect(td->w, NULL, TRUE);
1868-}
1869-
1870-
1871-/*
1872- * Force the use of a new "font file" for a term_data
1873- *
1874- * This function may be called before the "window" is ready
1875- *
1876- * This function returns zero only if everything succeeds.
1877- *
1878- * Note that the "font name" must be capitalized!!!
1879- */
1880-static errr term_force_font(term_data *td, cptr path)
1881-{
1882- int wid, hgt;
1883-
1884-#if 0 /* #ifndef JP */
1885- int i;
1886- char *base;
1887- char buf[1024];
1888-#endif
1889-
1890- /* Forget the old font (if needed) */
1891- if (td->font_id) DeleteObject(td->font_id);
1892-
1893-#if 1 /* #ifdef JP */
1894- /* Unused */
1895- (void)path;
1896-
1897- /* Create the font (using the 'base' of the font file name!) */
1898- td->font_id = CreateFontIndirect(&(td->lf));
1899- wid = td->lf.lfWidth;
1900- hgt = td->lf.lfHeight;
1901- if (!td->font_id) return (1);
1902-#else
1903- /* Forget old font */
1904- if (td->font_file)
1905- {
1906- bool used = FALSE;
1907-
1908- /* Scan windows */
1909- for (i = 0; i < MAX_TERM_DATA; i++)
1910- {
1911- /* Don't check when closing the application */
1912- if (!path) break;
1913-
1914- /* Check "screen" */
1915- if ((td != &data[i]) &&
1916- (data[i].font_file) &&
1917- (streq(data[i].font_file, td->font_file)))
1918- {
1919- used = TRUE;
1920- }
1921- }
1922-
1923- /* Remove unused font resources */
1924- if (!used) RemoveFontResource(td->font_file);
1925-
1926- /* Free the old name */
1927- string_free(td->font_file);
1928-
1929- /* Forget it */
1930- td->font_file = NULL;
1931- }
1932-
1933- /* No path given */
1934- if (!path) return (1);
1935-
1936- /* Local copy */
1937- strcpy(buf, path);
1938-
1939- /* Analyze font path */
1940- base = analyze_font(buf, &wid, &hgt);
1941-
1942- /* Verify suffix */
1943- if (!suffix(base, ".FON")) return (1);
1944-
1945- /* Verify file */
1946- if (!check_file(buf)) return (1);
1947-
1948- /* Load the new font */
1949- if (!AddFontResource(buf)) return (1);
1950-
1951- /* Save new font name */
1952- td->font_file = string_make(base);
1953-
1954- /* Remove the "suffix" */
1955- base[strlen(base)-4] = '\0';
1956-
1957- /* Create the font (using the 'base' of the font file name!) */
1958- td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1959- ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1960- CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1961- FIXED_PITCH | FF_DONTCARE, base);
1962-#endif
1963-
1964- /* Hack -- Unknown size */
1965- if (!wid || !hgt)
1966- {
1967- HDC hdcDesktop;
1968- HFONT hfOld;
1969- TEXTMETRIC tm;
1970-
1971- /* all this trouble to get the cell size */
1972- hdcDesktop = GetDC(HWND_DESKTOP);
1973- hfOld = SelectObject(hdcDesktop, td->font_id);
1974- GetTextMetrics(hdcDesktop, &tm);
1975- SelectObject(hdcDesktop, hfOld);
1976- ReleaseDC(HWND_DESKTOP, hdcDesktop);
1977-
1978- /* Font size info */
1979- wid = tm.tmAveCharWidth;
1980- hgt = tm.tmHeight;
1981- }
1982-
1983- /* Save the size info */
1984- td->font_wid = wid;
1985- td->font_hgt = hgt;
1986-
1987- /* Success */
1988- return (0);
1989-}
1990-
1991-
1992-
1993-/*
1994- * Allow the user to change the font for this window.
1995- */
1996-static void term_change_font(term_data *td)
1997-{
1998-#if 1 /* #ifdef JP */
1999- CHOOSEFONT cf;
2000-
2001- memset(&cf, 0, sizeof(cf));
2002- cf.lStructSize = sizeof(cf);
2003- cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2004- cf.lpLogFont = &(td->lf);
2005-
2006- if (ChooseFont(&cf))
2007- {
2008- /* Force the font */
2009- term_force_font(td, NULL);
2010-
2011- /* Assume not bizarre */
2012- td->bizarre = TRUE;
2013-
2014- /* Reset the tile info */
2015- td->tile_wid = td->font_wid;
2016- td->tile_hgt = td->font_hgt;
2017-
2018- /* Analyze the font */
2019- term_getsize(td);
2020-
2021- /* Resize the window */
2022- term_window_resize(td);
2023- }
2024-
2025-#else
2026- OPENFILENAME ofn;
2027-
2028- char tmp[1024] = "";
2029-
2030- /* Extract a default if possible */
2031- if (td->font_file) strcpy(tmp, td->font_file);
2032-
2033- /* Ask for a choice */
2034- memset(&ofn, 0, sizeof(ofn));
2035- ofn.lStructSize = sizeof(ofn);
2036- ofn.hwndOwner = data[0].w;
2037- ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2038- ofn.nFilterIndex = 1;
2039- ofn.lpstrFile = tmp;
2040- ofn.nMaxFile = 128;
2041- ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2042- ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2043- ofn.lpstrDefExt = "fon";
2044-
2045- /* Force choice if legal */
2046- if (GetOpenFileName(&ofn))
2047- {
2048- /* Force the font */
2049- if (term_force_font(td, tmp))
2050- {
2051- /* Access the standard font file */
2052- path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2053-
2054- /* Force the use of that font */
2055- (void)term_force_font(td, tmp);
2056- }
2057-
2058- /* Assume not bizarre */
2059- td->bizarre = FALSE;
2060-
2061- /* Reset the tile info */
2062- td->tile_wid = td->font_wid;
2063- td->tile_hgt = td->font_hgt;
2064-
2065- /* Analyze the font */
2066- term_getsize(td);
2067-
2068- /* Resize the window */
2069- term_window_resize(td);
2070- }
2071-#endif
2072-
2073-}
2074-
2075-/*
2076- * Allow the user to lock this window.
2077- */
2078-static void term_window_pos(term_data *td, HWND hWnd)
2079-{
2080- SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2081- SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2082-}
2083-
2084-static void windows_map(void);
2085-
2086-/*
2087- * Hack -- redraw a term_data
2088- */
2089-static void term_data_redraw(term_data *td)
2090-{
2091- if (td->map_active)
2092- {
2093- /* Redraw the map */
2094- windows_map();
2095- }
2096- else
2097- {
2098- /* Activate the term */
2099- Term_activate(&td->t);
2100-
2101- /* Redraw the contents */
2102- Term_redraw();
2103-
2104- /* Restore the term */
2105- Term_activate(term_screen);
2106- }
2107-}
2108-
2109-
2110-void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2111-{
2112- HDC hdc;
2113- HPEN oldPen;
2114- HBRUSH myBrush, oldBrush;
2115-
2116- term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2117- int tx = td->size_ow1 + x * td->tile_wid;
2118- int ty = td->size_oh1 + y * td->tile_hgt;
2119- int tw = w * td->tile_wid - 1;
2120- int th = h * td->tile_hgt - 1;
2121-
2122- hdc = GetDC(hWnd);
2123- myBrush = CreateSolidBrush(RGB(255, 255, 255));
2124- oldBrush = SelectObject(hdc, myBrush);
2125- oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2126-
2127- PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2128-
2129- SelectObject(hdc, oldBrush);
2130- SelectObject(hdc, oldPen);
2131-}
2132-
2133-
2134-
2135-/*** Function hooks needed by "Term" ***/
2136-
2137-
2138-#if 0
2139-
2140-/*
2141- * Initialize a new Term
2142- */
2143-static void Term_init_win(term *t)
2144-{
2145- /* XXX Unused */
2146-}
2147-
2148-
2149-/*
2150- * Nuke an old Term
2151- */
2152-static void Term_nuke_win(term *t)
2153-{
2154- /* XXX Unused */
2155-}
2156-
2157-#endif
2158-
2159-
2160-/*
2161- * Interact with the User
2162- */
2163-static errr Term_user_win(int n)
2164-{
2165- /* Unused */
2166- (void)n;
2167-
2168- /* Success */
2169- return (0);
2170-}
2171-
2172-
2173-/*
2174- * React to global changes
2175- */
2176-static errr Term_xtra_win_react(void)
2177-{
2178- int i;
2179-
2180-
2181- /* Simple color */
2182- if (colors16)
2183- {
2184- /* Save the default colors */
2185- for (i = 0; i < 256; i++)
2186- {
2187- /* Simply accept the desired colors */
2188- win_pal[i] = angband_color_table[i][0];
2189- }
2190- }
2191-
2192- /* Complex color */
2193- else
2194- {
2195- COLORREF code;
2196-
2197- byte rv, gv, bv;
2198-
2199- bool change = FALSE;
2200-
2201- /* Save the default colors */
2202- for (i = 0; i < 256; i++)
2203- {
2204- /* Extract desired values */
2205- rv = angband_color_table[i][1];
2206- gv = angband_color_table[i][2];
2207- bv = angband_color_table[i][3];
2208-
2209- /* Extract a full color code */
2210- code = PALETTERGB(rv, gv, bv);
2211-
2212- /* Activate changes */
2213- if (win_clr[i] != code)
2214- {
2215- /* Note the change */
2216- change = TRUE;
2217-
2218- /* Apply the desired color */
2219- win_clr[i] = code;
2220- }
2221- }
2222-
2223- /* Activate the palette if needed */
2224- if (change) (void)new_palette();
2225- }
2226-
2227-
2228-#ifdef USE_SOUND
2229-
2230- /* Handle "arg_sound" */
2231- if (use_sound != arg_sound)
2232- {
2233- /* Initialize (if needed) */
2234- if (arg_sound && !init_sound())
2235- {
2236- /* Warning */
2237- plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2238-
2239- /* Cannot enable */
2240- arg_sound = FALSE;
2241- }
2242-
2243- /* Change setting */
2244- use_sound = arg_sound;
2245- }
2246-
2247-#endif
2248-
2249-#ifdef USE_MUSIC
2250-
2251- /* Handle "arg_sound" */
2252- if (use_music != arg_music)
2253- {
2254- /* Initialize (if needed) */
2255- if (arg_music && !init_music())
2256- {
2257- /* Warning */
2258- plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2259- /* Cannot enable */
2260- arg_music = FALSE;
2261- }
2262-
2263- /* Change setting */
2264- use_music = arg_music;
2265-
2266- if(!arg_music) stop_music();
2267- else select_floor_music();
2268-
2269- }
2270-
2271-#endif
2272-
2273-
2274-#ifdef USE_GRAPHICS
2275-
2276- /* Handle "arg_graphics" */
2277- if (use_graphics != arg_graphics)
2278- {
2279- /* Initialize (if needed) */
2280- if (arg_graphics && !init_graphics())
2281- {
2282- /* Warning */
2283- plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2284-
2285- /* Cannot enable */
2286- arg_graphics = GRAPHICS_NONE;
2287- }
2288-
2289- /* Change setting */
2290- use_graphics = arg_graphics;
2291-
2292- /* Reset visuals */
2293-#ifdef ANGBAND_2_8_1
2294- reset_visuals();
2295-#else /* ANGBAND_2_8_1 */
2296- reset_visuals(TRUE);
2297-#endif /* ANGBAND_2_8_1 */
2298- }
2299-
2300-#endif /* USE_GRAPHICS */
2301-
2302-
2303- /* Clean up windows */
2304- for (i = 0; i < MAX_TERM_DATA; i++)
2305- {
2306- term *old = Term;
2307-
2308- term_data *td = &data[i];
2309-
2310- /* Update resized windows */
2311- if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2312- {
2313- /* Activate */
2314- Term_activate(&td->t);
2315-
2316- /* Hack -- Resize the term */
2317- Term_resize(td->cols, td->rows);
2318-
2319- /* Redraw the contents */
2320- Term_redraw();
2321-
2322- /* Restore */
2323- Term_activate(old);
2324- }
2325- }
2326-
2327-
2328- /* Success */
2329- return (0);
2330-}
2331-
2332-
2333-/*
2334- * Process at least one event
2335- */
2336-static errr Term_xtra_win_event(int v)
2337-{
2338- MSG msg;
2339-
2340- /* Wait for an event */
2341- if (v)
2342- {
2343- /* Block */
2344- if (GetMessage(&msg, NULL, 0, 0))
2345- {
2346- TranslateMessage(&msg);
2347- DispatchMessage(&msg);
2348- }
2349- }
2350-
2351- /* Check for an event */
2352- else
2353- {
2354- /* Check */
2355- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2356- {
2357- TranslateMessage(&msg);
2358- DispatchMessage(&msg);
2359- }
2360- }
2361-
2362- /* Success */
2363- return 0;
2364-}
2365-
2366-
2367-/*
2368- * Process all pending events
2369- */
2370-static errr Term_xtra_win_flush(void)
2371-{
2372- MSG msg;
2373-
2374- /* Process all pending events */
2375- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2376- {
2377- TranslateMessage(&msg);
2378- DispatchMessage(&msg);
2379- }
2380-
2381- /* Success */
2382- return (0);
2383-}
2384-
2385-
2386-/*
2387- * Hack -- clear the screen
2388- *
2389- * Make this more efficient XXX XXX XXX
2390- */
2391-static errr Term_xtra_win_clear(void)
2392-{
2393- term_data *td = (term_data*)(Term->data);
2394-
2395- HDC hdc;
2396- RECT rc;
2397-
2398- /* Rectangle to erase */
2399- rc.left = td->size_ow1;
2400- rc.right = rc.left + td->cols * td->tile_wid;
2401- rc.top = td->size_oh1;
2402- rc.bottom = rc.top + td->rows * td->tile_hgt;
2403-
2404- /* Erase it */
2405- hdc = GetDC(td->w);
2406- SetBkColor(hdc, RGB(0, 0, 0));
2407- SelectObject(hdc, td->font_id);
2408- ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2409-
2410- /* bg */
2411- if (use_bg)
2412- {
2413- rc.left = 0; rc.top = 0;
2414- DrawBG(hdc, &rc);
2415- }
2416- ReleaseDC(td->w, hdc);
2417-
2418- /* Success */
2419- return 0;
2420-}
2421-
2422-
2423-/*
2424- * Hack -- make a noise
2425- */
2426-static errr Term_xtra_win_noise(void)
2427-{
2428- MessageBeep(MB_ICONASTERISK);
2429- return (0);
2430-}
2431-
2432-
2433-/*
2434- * Hack -- make a sound
2435- */
2436-static errr Term_xtra_win_sound(int v)
2437-{
2438-#ifdef USE_SOUND
2439- int i;
2440- char buf[1024];
2441-#endif /* USE_SOUND */
2442-
2443- /* Sound disabled */
2444- if (!use_sound) return (1);
2445-
2446- /* Illegal sound */
2447- if ((v < 0) || (v >= SOUND_MAX)) return (1);
2448-
2449-#ifdef USE_SOUND
2450-
2451- /* Count the samples */
2452- for (i = 0; i < SAMPLE_MAX; i++)
2453- {
2454- if (!sound_file[v][i])
2455- break;
2456- }
2457-
2458- /* No sample */
2459- if (i == 0) return (1);
2460-
2461- /* Build the path */
2462- path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2463-
2464-#ifdef WIN32
2465-
2466- /* Play the sound, catch errors */
2467- return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2468-
2469-#else /* WIN32 */
2470-
2471- /* Play the sound, catch errors */
2472- return (sndPlaySound(buf, SND_ASYNC));
2473-
2474-#endif /* WIN32 */
2475-
2476-#else /* USE_SOUND */
2477-
2478- /* Oops */
2479- return (1);
2480-
2481-#endif /* USE_SOUND */
2482-}
2483-
2484-/*
2485- * Hack -- play a music
2486- */
2487-static errr Term_xtra_win_music(int n, int v)
2488-{
2489-#ifdef USE_MUSIC
2490- int i = 0;
2491- char buf[1024];
2492-#endif /* USE_MUSIC */
2493-
2494- /* Sound disabled */
2495-
2496- if(!use_music) return (1);
2497-
2498- /* Illegal sound */
2499- if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2500- else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2501-
2502-#ifdef USE_MUSIC
2503-
2504- switch(n)
2505- {
2506- case TERM_XTRA_MUSIC_BASIC:
2507- for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2508- break;
2509- case TERM_XTRA_MUSIC_DUNGEON:
2510- for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2511- break;
2512- case TERM_XTRA_MUSIC_QUEST:
2513- for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2514- break;
2515- case TERM_XTRA_MUSIC_TOWN:
2516- for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2517- break;
2518- }
2519-
2520- /* No sample */
2521- if (i == 0)
2522- {
2523- //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2524- //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2525- return (1);
2526- }
2527-
2528- switch(n)
2529- {
2530- case TERM_XTRA_MUSIC_BASIC:
2531- for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2532- break;
2533- case TERM_XTRA_MUSIC_DUNGEON:
2534- for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2535- break;
2536- case TERM_XTRA_MUSIC_QUEST:
2537- for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2538- break;
2539- case TERM_XTRA_MUSIC_TOWN:
2540- for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2541- break;
2542- }
2543-
2544- /* No sample */
2545- if (i == 0)
2546- {
2547- mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2548- mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2549- return (1);
2550- }
2551-
2552- switch(n)
2553- {
2554- case TERM_XTRA_MUSIC_BASIC:
2555- path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2556- break;
2557- case TERM_XTRA_MUSIC_DUNGEON:
2558- path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2559- break;
2560- case TERM_XTRA_MUSIC_QUEST:
2561- path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2562- break;
2563- case TERM_XTRA_MUSIC_TOWN:
2564- path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2565- break;
2566- }
2567-
2568- if(current_music_type == n && current_music_id == v)
2569- {
2570- return (0);
2571- }
2572- current_music_type = n;
2573- current_music_id = v;
2574-
2575-#ifdef WIN32
2576-
2577- mop.lpstrDeviceType = mci_device_type;
2578- mop.lpstrElementName = buf;
2579- mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2580- mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2581- mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2582- mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2583- mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2584- return (0);
2585-
2586-#endif /* WIN32 */
2587-
2588-#else /* USE_MUSIC */
2589-
2590- return (1);
2591-
2592-#endif /* USE_MUSIC */
2593-
2594-}
2595-
2596-
2597-/*
2598- * Delay for "x" milliseconds
2599- */
2600-static int Term_xtra_win_delay(int v)
2601-{
2602-
2603-#ifdef WIN32
2604-
2605- /* Sleep */
2606- Sleep(v);
2607-
2608-#else /* WIN32 */
2609-
2610- DWORD t;
2611- MSG msg;
2612-
2613- /* Final count */
2614- t = GetTickCount() + v;
2615-
2616- /* Wait for it */
2617- while (GetTickCount() < t)
2618- {
2619- /* Handle messages */
2620- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2621- {
2622- TranslateMessage(&msg);
2623- DispatchMessage(&msg);
2624- }
2625- }
2626-
2627-#endif /* WIN32 */
2628-
2629- /* Success */
2630- return (0);
2631-}
2632-
2633-
2634-/*
2635- * Do a "special thing"
2636- */
2637-static errr Term_xtra_win(int n, int v)
2638-{
2639- /* Handle a subset of the legal requests */
2640- switch (n)
2641- {
2642- /* Make a bell sound */
2643- case TERM_XTRA_NOISE:
2644- {
2645- return (Term_xtra_win_noise());
2646- }
2647-
2648- /* Play a music */
2649- case TERM_XTRA_MUSIC_BASIC:
2650- case TERM_XTRA_MUSIC_DUNGEON:
2651- case TERM_XTRA_MUSIC_QUEST:
2652- case TERM_XTRA_MUSIC_TOWN:
2653- {
2654- return (Term_xtra_win_music(n, v));
2655- }
2656-
2657- /* Make a special sound */
2658- case TERM_XTRA_SOUND:
2659- {
2660- return (Term_xtra_win_sound(v));
2661- }
2662-
2663- /* Process random events */
2664- case TERM_XTRA_BORED:
2665- {
2666- return (Term_xtra_win_event(0));
2667- }
2668-
2669- /* Process an event */
2670- case TERM_XTRA_EVENT:
2671- {
2672- return (Term_xtra_win_event(v));
2673- }
2674-
2675- /* Flush all events */
2676- case TERM_XTRA_FLUSH:
2677- {
2678- return (Term_xtra_win_flush());
2679- }
2680-
2681- /* Clear the screen */
2682- case TERM_XTRA_CLEAR:
2683- {
2684- return (Term_xtra_win_clear());
2685- }
2686-
2687- /* React to global changes */
2688- case TERM_XTRA_REACT:
2689- {
2690- return (Term_xtra_win_react());
2691- }
2692-
2693- /* Delay for some milliseconds */
2694- case TERM_XTRA_DELAY:
2695- {
2696- return (Term_xtra_win_delay(v));
2697- }
2698- }
2699-
2700- /* Oops */
2701- return 1;
2702-}
2703-
2704-
2705-
2706-/*
2707- * Low level graphics (Assumes valid input).
2708- *
2709- * Draw a "cursor" at (x,y), using a "yellow box".
2710- */
2711-static errr Term_curs_win(int x, int y)
2712-{
2713- term_data *td = (term_data*)(Term->data);
2714-
2715- RECT rc;
2716- HDC hdc;
2717-
2718- int tile_wid, tile_hgt;
2719-
2720- if (td->map_active)
2721- {
2722- tile_wid = td->map_tile_wid;
2723- tile_hgt = td->map_tile_hgt;
2724- }
2725- else
2726- {
2727- tile_wid = td->tile_wid;
2728- tile_hgt = td->tile_hgt;
2729- }
2730-
2731- /* Frame the grid */
2732- rc.left = x * tile_wid + td->size_ow1;
2733- rc.right = rc.left + tile_wid;
2734- rc.top = y * tile_hgt + td->size_oh1;
2735- rc.bottom = rc.top + tile_hgt;
2736-
2737- /* Cursor is done as a yellow "box" */
2738- hdc = GetDC(td->w);
2739- FrameRect(hdc, &rc, hbrYellow);
2740- ReleaseDC(td->w, hdc);
2741-
2742- /* Success */
2743- return 0;
2744-}
2745-
2746-
2747-/*
2748- * Low level graphics (Assumes valid input).
2749- *
2750- * Draw a "big cursor" at (x,y), using a "yellow box".
2751- */
2752-static errr Term_bigcurs_win(int x, int y)
2753-{
2754- term_data *td = (term_data*)(Term->data);
2755-
2756- RECT rc;
2757- HDC hdc;
2758-
2759- int tile_wid, tile_hgt;
2760-
2761- if (td->map_active)
2762- {
2763- /* Normal cursor in map window */
2764- Term_curs_win(x, y);
2765- return 0;
2766- }
2767- else
2768- {
2769- tile_wid = td->tile_wid;
2770- tile_hgt = td->tile_hgt;
2771- }
2772-
2773- /* Frame the grid */
2774- rc.left = x * tile_wid + td->size_ow1;
2775- rc.right = rc.left + 2 * tile_wid;
2776- rc.top = y * tile_hgt + td->size_oh1;
2777- rc.bottom = rc.top + tile_hgt;
2778-
2779- /* Cursor is done as a yellow "box" */
2780- hdc = GetDC(td->w);
2781- FrameRect(hdc, &rc, hbrYellow);
2782- ReleaseDC(td->w, hdc);
2783-
2784- /* Success */
2785- return 0;
2786-}
2787-
2788-
2789-/*
2790- * Low level graphics (Assumes valid input).
2791- *
2792- * Erase a "block" of "n" characters starting at (x,y).
2793- */
2794-static errr Term_wipe_win(int x, int y, int n)
2795-{
2796- term_data *td = (term_data*)(Term->data);
2797-
2798- HDC hdc;
2799- RECT rc;
2800-
2801- /* Rectangle to erase in client coords */
2802- rc.left = x * td->tile_wid + td->size_ow1;
2803- rc.right = rc.left + n * td->tile_wid;
2804- rc.top = y * td->tile_hgt + td->size_oh1;
2805- rc.bottom = rc.top + td->tile_hgt;
2806-
2807- hdc = GetDC(td->w);
2808- SetBkColor(hdc, RGB(0, 0, 0));
2809- SelectObject(hdc, td->font_id);
2810- /* bg */
2811- if (use_bg)
2812- DrawBG(hdc, &rc);
2813- else
2814- ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2815- ReleaseDC(td->w, hdc);
2816-
2817- /* Success */
2818- return 0;
2819-}
2820-
2821-
2822-/*
2823- * Low level graphics. Assumes valid input.
2824- *
2825- * Draw several ("n") chars, with an attr, at a given location.
2826- *
2827- * All "graphic" data is handled by "Term_pict_win()", below.
2828- *
2829- * One would think there is a more efficient method for telling a window
2830- * what color it should be using to draw with, but perhaps simply changing
2831- * it every time is not too inefficient. XXX XXX XXX
2832- */
2833-static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2834-{
2835- term_data *td = (term_data*)(Term->data);
2836- RECT rc;
2837- HDC hdc;
2838-
2839-#if 1 /* #ifdef JP */
2840- static HBITMAP WALL;
2841- static HBRUSH myBrush, oldBrush;
2842- static HPEN oldPen;
2843- static bool init_done = FALSE;
2844-
2845- if (!init_done){
2846- WALL = LoadBitmap(hInstance, AppName);
2847- myBrush = CreatePatternBrush(WALL);
2848- init_done = TRUE;
2849- }
2850-#endif
2851-
2852- /* Total rectangle */
2853- rc.left = x * td->tile_wid + td->size_ow1;
2854- rc.right = rc.left + n * td->tile_wid;
2855- rc.top = y * td->tile_hgt + td->size_oh1;
2856- rc.bottom = rc.top + td->tile_hgt;
2857-
2858- /* Acquire DC */
2859- hdc = GetDC(td->w);
2860-
2861- /* Background color */
2862- SetBkColor(hdc, RGB(0, 0, 0));
2863-
2864- /* Foreground color */
2865- if (colors16)
2866- {
2867- SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2868- }
2869- else if (paletted)
2870- {
2871- SetTextColor(hdc, win_clr[a&0x0F]);
2872- }
2873- else
2874- {
2875- SetTextColor(hdc, win_clr[a]);
2876- }
2877-
2878- /* Use the font */
2879- SelectObject(hdc, td->font_id);
2880-
2881- /* bg */
2882- if (use_bg) SetBkMode(hdc, TRANSPARENT);
2883-
2884- /* Bizarre size */
2885- if (td->bizarre ||
2886- (td->tile_hgt != td->font_hgt) ||
2887- (td->tile_wid != td->font_wid))
2888- {
2889- int i;
2890-
2891- /* Erase complete rectangle */
2892- ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2893-
2894- /* bg */
2895- if (use_bg) DrawBG(hdc, &rc);
2896-
2897- /* New rectangle */
2898- rc.left += ((td->tile_wid - td->font_wid) / 2);
2899- rc.right = rc.left + td->font_wid;
2900- rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2901- rc.bottom = rc.top + td->font_hgt;
2902-
2903- /* Dump each character */
2904- for (i = 0; i < n; i++)
2905- {
2906-#ifdef JP
2907- if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2908- {
2909- rc.right += td->font_wid;
2910-
2911- oldBrush = SelectObject(hdc, myBrush);
2912- oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2913-
2914- /* Dump the wall */
2915- Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2916-
2917- SelectObject(hdc, oldBrush);
2918- SelectObject(hdc, oldPen);
2919- rc.right -= td->font_wid;
2920-
2921- /* Advance */
2922- i++;
2923- rc.left += 2 * td->tile_wid;
2924- rc.right += 2 * td->tile_wid;
2925- }
2926- else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2927- {
2928- rc.right += td->font_wid;
2929- /* Dump the text */
2930- ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2931- s+i, 2, NULL);
2932- rc.right -= td->font_wid;
2933-
2934- /* Advance */
2935- i++;
2936- rc.left += 2 * td->tile_wid;
2937- rc.right += 2 * td->tile_wid;
2938- } else if (*(s+i)==127){
2939- oldBrush = SelectObject(hdc, myBrush);
2940- oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2941-
2942- /* Dump the wall */
2943- Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2944-
2945- SelectObject(hdc, oldBrush);
2946- SelectObject(hdc, oldPen);
2947-
2948- /* Advance */
2949- rc.left += td->tile_wid;
2950- rc.right += td->tile_wid;
2951- } else {
2952- /* Dump the text */
2953- ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2954-
2955- /* Advance */
2956- rc.left += td->tile_wid;
2957- rc.right += td->tile_wid;
2958- }
2959-#else
2960-#if 1
2961- if (*(s+i)==127){
2962- oldBrush = SelectObject(hdc, myBrush);
2963- oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2964-
2965- /* Dump the wall */
2966- Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2967-
2968- SelectObject(hdc, oldBrush);
2969- SelectObject(hdc, oldPen);
2970-
2971- /* Advance */
2972- rc.left += td->tile_wid;
2973- rc.right += td->tile_wid;
2974- } else {
2975- /* Dump the text */
2976- ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2977- s+i, 1, NULL);
2978-
2979- /* Advance */
2980- rc.left += td->tile_wid;
2981- rc.right += td->tile_wid;
2982- }
2983-#else
2984- /* Dump the text */
2985- ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2986- s+i, 1, NULL);
2987-
2988- /* Advance */
2989- rc.left += td->tile_wid;
2990- rc.right += td->tile_wid;
2991-#endif
2992-#endif
2993-
2994- }
2995- }
2996-
2997- /* Normal size */
2998- else
2999- {
3000- /* Dump the text */
3001- ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3002- s, n, NULL);
3003- }
3004-
3005- /* Release DC */
3006- ReleaseDC(td->w, hdc);
3007-
3008- /* Success */
3009- return 0;
3010-}
3011-
3012-
3013-/*
3014- * Low level graphics. Assumes valid input.
3015- *
3016- * Draw an array of "special" attr/char pairs at the given location.
3017- *
3018- * We use the "Term_pict_win()" function for "graphic" data, which are
3019- * encoded by setting the "high-bits" of both the "attr" and the "char"
3020- * data. We use the "attr" to represent the "row" of the main bitmap,
3021- * and the "char" to represent the "col" of the main bitmap. The use
3022- * of this function is induced by the "higher_pict" flag.
3023- *
3024- * If "graphics" is not available, we simply "wipe" the given grids.
3025- */
3026-static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
3027-{
3028- term_data *td = (term_data*)(Term->data);
3029-
3030-#ifdef USE_GRAPHICS
3031-
3032- int i;
3033- int x1, y1, w1, h1, tw1, th1;
3034- int x2, y2, w2, h2, tw2 = 0;
3035- int x3, y3;
3036-
3037- HDC hdcMask = NULL;
3038-
3039- HDC hdc;
3040- HDC hdcSrc;
3041- HBITMAP hbmSrcOld;
3042-
3043- /* Paranoia */
3044- if (!use_graphics)
3045- {
3046- /* Erase the grids */
3047- return (Term_wipe_win(x, y, n));
3048- }
3049-
3050- /* Size of bitmap cell */
3051- w1 = infGraph.CellWidth;
3052- h1 = infGraph.CellHeight;
3053- tw1 = infGraph.TileWidth;
3054- th1 = infGraph.TileHeight;
3055-
3056- /* Size of window cell */
3057- if (td->map_active)
3058- {
3059- w2 = td->map_tile_wid;
3060- h2 = td->map_tile_hgt;
3061- }
3062- else
3063- {
3064- w2 = td->tile_wid;
3065- h2 = td->tile_hgt;
3066- tw2 = w2;
3067-
3068- /* big tile mode */
3069- if (use_bigtile) tw2 *= 2;
3070- }
3071-
3072- /* Location of window cell */
3073- x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3074- y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3075-
3076- /* Info */
3077- hdc = GetDC(td->w);
3078-
3079- /* More info */
3080- hdcSrc = CreateCompatibleDC(hdc);
3081- hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3082-
3083- if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3084- {
3085- hdcMask = CreateCompatibleDC(hdc);
3086- SelectObject(hdcMask, infMask.hBitmap);
3087- }
3088-
3089- /* Draw attr/char pairs */
3090- for (i = 0; i < n; i++, x2 += w2)
3091- {
3092- byte a = ap[i];
3093- char c = cp[i];
3094-
3095-
3096- /* Extract picture */
3097- int row = (a & 0x7F);
3098- int col = (c & 0x7F);
3099-
3100- /* Location of bitmap cell */
3101- x1 = col * w1;
3102- y1 = row * h1;
3103-
3104- if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3105- {
3106- x3 = (tcp[i] & 0x7F) * w1;
3107- y3 = (tap[i] & 0x7F) * h1;
3108- tw2 = tw2 * w1 / tw1;
3109- h2 = h2 * h1 / th1;
3110-
3111- /* Perfect size */
3112- if ((tw1 == tw2) && (th1 == h2))
3113- {
3114- /* Copy the terrain picture from the bitmap to the window */
3115- BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3116-
3117- /* Mask out the tile */
3118- BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3119-
3120- /* Draw the tile */
3121- BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3122- }
3123-
3124- /* Need to stretch */
3125- else
3126- {
3127- /* Set the correct mode for stretching the tiles */
3128- SetStretchBltMode(hdc, COLORONCOLOR);
3129-
3130- /* Copy the terrain picture from the bitmap to the window */
3131- StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3132-
3133- StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3134-
3135- /* Only draw if terrain and overlay are different */
3136- if ((x1 != x3) || (y1 != y3))
3137- {
3138- /* Mask out the tile */
3139- StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3140-
3141- /* Draw the tile */
3142- StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3143- }
3144- }
3145- }
3146- else
3147- {
3148- /* Perfect size */
3149- if ((w1 == tw2) && (h1 == h2))
3150- {
3151- /* Copy the picture from the bitmap to the window */
3152- BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3153- }
3154-
3155- /* Need to stretch */
3156- else
3157- {
3158- /* Set the correct mode for stretching the tiles */
3159- SetStretchBltMode(hdc, COLORONCOLOR);
3160-
3161- /* Copy the picture from the bitmap to the window */
3162- StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3163- }
3164- }
3165- }
3166-
3167- /* Release */
3168- SelectObject(hdcSrc, hbmSrcOld);
3169- DeleteDC(hdcSrc);
3170-
3171- if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3172- {
3173- /* Release */
3174- SelectObject(hdcMask, hbmSrcOld);
3175- DeleteDC(hdcMask);
3176- }
3177-
3178- /* Release */
3179- ReleaseDC(td->w, hdc);
3180-
3181-#else /* USE_GRAPHICS */
3182-
3183- /* Just erase this grid */
3184- return (Term_wipe_win(x, y, n));
3185-
3186-#endif /* USE_GRAPHICS */
3187-
3188- /* Success */
3189- return 0;
3190-}
3191-
3192-
3193-static void windows_map(void)
3194-{
3195- term_data *td = &data[0];
3196- byte a, c;
3197- int x, min_x, max_x;
3198- int y, min_y, max_y;
3199-
3200- byte ta, tc;
3201-
3202- /* Only in graphics mode */
3203- if (!use_graphics) return;
3204-
3205- /* Clear screen */
3206- Term_xtra_win_clear();
3207-
3208- td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3209- td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3210- td->map_active = TRUE;
3211-
3212- {
3213- min_x = 0;
3214- min_y = 0;
3215- max_x = cur_wid;
3216- max_y = cur_hgt;
3217- }
3218-
3219- /* Draw the map */
3220- for (x = min_x; x < max_x; x++)
3221- {
3222- for (y = min_y; y < max_y; y++)
3223- {
3224- map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3225-
3226- /* Ignore non-graphics */
3227- if ((a & 0x80) && (c & 0x80))
3228- {
3229- Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3230- }
3231- }
3232- }
3233-
3234- /* Hilite the player */
3235- Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3236-
3237- /* Wait for a keypress, flush key buffer */
3238- Term_inkey(&c, TRUE, TRUE);
3239- Term_flush();
3240-
3241- /* Switch off the map display */
3242- td->map_active = FALSE;
3243-
3244- /* Restore screen */
3245- Term_xtra_win_clear();
3246- Term_redraw();
3247-}
3248-
3249-
3250-/*** Other routines ***/
3251-
3252-
3253-/*
3254- * Create and initialize a "term_data" given a title
3255- */
3256-static void term_data_link(term_data *td)
3257-{
3258- term *t = &td->t;
3259-
3260- /* Initialize the term */
3261- term_init(t, td->cols, td->rows, td->keys);
3262-
3263- /* Use a "software" cursor */
3264- t->soft_cursor = TRUE;
3265-
3266- /* Use "Term_pict" for "graphic" data */
3267- t->higher_pict = TRUE;
3268-
3269- /* Erase with "white space" */
3270- t->attr_blank = TERM_WHITE;
3271- t->char_blank = ' ';
3272-
3273-#if 0
3274- /* Prepare the init/nuke hooks */
3275- t->init_hook = Term_init_win;
3276- t->nuke_hook = Term_nuke_win;
3277-#endif
3278-
3279- /* Prepare the template hooks */
3280- t->user_hook = Term_user_win;
3281- t->xtra_hook = Term_xtra_win;
3282- t->curs_hook = Term_curs_win;
3283- t->bigcurs_hook = Term_bigcurs_win;
3284- t->wipe_hook = Term_wipe_win;
3285- t->text_hook = Term_text_win;
3286- t->pict_hook = Term_pict_win;
3287-
3288- /* Remember where we came from */
3289- t->data = (vptr)(td);
3290-}
3291-
3292-
3293-/*
3294- * Create the windows
3295- *
3296- * First, instantiate the "default" values, then read the "ini_file"
3297- * to over-ride selected values, then create the windows, and fonts.
3298- *
3299- * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3300- * must make active to realize the palette. XXX XXX XXX
3301- */
3302-static void init_windows(void)
3303-{
3304- int i;
3305-
3306- term_data *td;
3307-
3308-#if 0 /* #ifndef JP */
3309- char buf[1024];
3310-#endif
3311-
3312- /* Main window */
3313- td = &data[0];
3314- WIPE(td, term_data);
3315-#ifdef JP
3316- td->s = "変愚蛮怒";
3317-#else
3318- td->s = angband_term_name[0];
3319-#endif
3320-
3321- td->keys = 1024;
3322- td->rows = 24;
3323- td->cols = 80;
3324- td->visible = TRUE;
3325- td->size_ow1 = 2;
3326- td->size_ow2 = 2;
3327- td->size_oh1 = 2;
3328- td->size_oh2 = 2;
3329- td->pos_x = 7 * 30;
3330- td->pos_y = 7 * 20;
3331- td->posfix = FALSE;
3332-#if 1 /* #ifdef JP */
3333- td->bizarre = TRUE;
3334-#endif
3335- /* Sub windows */
3336- for (i = 1; i < MAX_TERM_DATA; i++)
3337- {
3338- td = &data[i];
3339- WIPE(td, term_data);
3340- td->s = angband_term_name[i];
3341- td->keys = 16;
3342- td->rows = 24;
3343- td->cols = 80;
3344- td->visible = FALSE;
3345- td->size_ow1 = 1;
3346- td->size_ow2 = 1;
3347- td->size_oh1 = 1;
3348- td->size_oh2 = 1;
3349- td->pos_x = (7 - i) * 30;
3350- td->pos_y = (7 - i) * 20;
3351- td->posfix = FALSE;
3352-#if 1 /* #ifdef JP */
3353- td->bizarre = TRUE;
3354-#endif
3355- }
3356-
3357-
3358- /* Load prefs */
3359- load_prefs();
3360-
3361-
3362- /* Main window (need these before term_getsize gets called) */
3363- td = &data[0];
3364- td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3365- WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3366- WS_VISIBLE);
3367- td->dwExStyle = 0;
3368- td->visible = TRUE;
3369-
3370- /* Sub windows (need these before term_getsize gets called) */
3371- for (i = 1; i < MAX_TERM_DATA; i++)
3372- {
3373- td = &data[i];
3374- td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3375- td->dwExStyle = (WS_EX_TOOLWINDOW);
3376- }
3377-
3378-
3379- /* All windows */
3380- for (i = 0; i < MAX_TERM_DATA; i++)
3381- {
3382- td = &data[i];
3383-
3384-#if 1 /* #ifdef JP */
3385- strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3386- td->lf.lfCharSet = DEFAULT_CHARSET;
3387- td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3388- /* Activate the chosen font */
3389- term_force_font(td, NULL);
3390- if(!td->tile_wid) td->tile_wid = td->font_wid;
3391- if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3392-#else
3393- /* Access the standard font file */
3394- path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3395-
3396- /* Activate the chosen font */
3397- if (term_force_font(td, buf))
3398- {
3399- /* Access the standard font file */
3400- path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3401-
3402- /* Force the use of that font */
3403- (void)term_force_font(td, buf);
3404-
3405- /* Oops */
3406- td->tile_wid = 8;
3407- td->tile_hgt = 13;
3408-
3409- /* Assume not bizarre */
3410- td->bizarre = FALSE;
3411- }
3412-#endif
3413-
3414-
3415- /* Analyze the font */
3416- term_getsize(td);
3417-
3418- /* Resize the window */
3419- term_window_resize(td);
3420- }
3421-
3422-
3423- /* Sub windows (reverse order) */
3424- for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3425- {
3426- td = &data[i];
3427-
3428- my_td = td;
3429- td->w = CreateWindowEx(td->dwExStyle, AngList,
3430- td->s, td->dwStyle,
3431- td->pos_x, td->pos_y,
3432- td->size_wid, td->size_hgt,
3433- HWND_DESKTOP, NULL, hInstance, NULL);
3434- my_td = NULL;
3435- if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3436-
3437- if (td->visible)
3438- {
3439- td->size_hack = TRUE;
3440- ShowWindow(td->w, SW_SHOW);
3441- td->size_hack = FALSE;
3442- }
3443-
3444- term_data_link(td);
3445- angband_term[i] = &td->t;
3446-
3447- if (td->visible)
3448- {
3449- /* Activate the window */
3450- SetActiveWindow(td->w);
3451- }
3452-
3453- if (data[i].posfix)
3454- {
3455- term_window_pos(&data[i], HWND_TOPMOST);
3456- }
3457- else
3458- {
3459- term_window_pos(&data[i], td->w);
3460- }
3461- }
3462-
3463-
3464- /* Main window */
3465- td = &data[0];
3466-
3467- /* Main window */
3468- my_td = td;
3469- td->w = CreateWindowEx(td->dwExStyle, AppName,
3470- td->s, td->dwStyle,
3471- td->pos_x, td->pos_y,
3472- td->size_wid, td->size_hgt,
3473- HWND_DESKTOP, NULL, hInstance, NULL);
3474- my_td = NULL;
3475- if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3476-
3477- term_data_link(td);
3478- angband_term[0] = &td->t;
3479- normsize.x = td->cols;
3480- normsize.y = td->rows;
3481-
3482- /* Activate the main window */
3483- if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3484- else ShowWindow(td->w, SW_SHOW);
3485-
3486- /* Bring main window back to top */
3487- SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3488-
3489-
3490- /* New palette XXX XXX XXX */
3491- (void)new_palette();
3492-
3493-
3494- /* Create a "brush" for drawing the "cursor" */
3495- hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3496-
3497-
3498- /* Process pending messages */
3499- (void)Term_xtra_win_flush();
3500-}
3501-
3502-
3503-
3504-/*
3505- * Prepare the menus
3506- */
3507-static void setup_menus(void)
3508-{
3509- int i;
3510-
3511- HMENU hm = GetMenu(data[0].w);
3512-
3513-
3514- /* Menu "File", Disable all */
3515- EnableMenuItem(hm, IDM_FILE_NEW,
3516- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3517- EnableMenuItem(hm, IDM_FILE_OPEN,
3518- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3519- EnableMenuItem(hm, IDM_FILE_SAVE,
3520- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3521- EnableMenuItem(hm, IDM_FILE_EXIT,
3522- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3523- EnableMenuItem(hm, IDM_FILE_SCORE,
3524- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3525-
3526-
3527- /* No character available */
3528- if (!character_generated)
3529- {
3530- /* Menu "File", Item "New" */
3531- EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3532-
3533- /* Menu "File", Item "Open" */
3534- EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3535- }
3536-
3537- /* A character available */
3538- if (character_generated)
3539- {
3540- /* Menu "File", Item "Save" */
3541- EnableMenuItem(hm, IDM_FILE_SAVE,
3542- MF_BYCOMMAND | MF_ENABLED);
3543- }
3544-
3545- /* Menu "File", Item "Exit" */
3546- EnableMenuItem(hm, IDM_FILE_EXIT,
3547- MF_BYCOMMAND | MF_ENABLED);
3548-
3549- EnableMenuItem(hm, IDM_FILE_SCORE,
3550- MF_BYCOMMAND | MF_ENABLED);
3551-
3552-
3553- /* Menu "Window::Visibility" */
3554- for (i = 0; i < MAX_TERM_DATA; i++)
3555- {
3556- EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3557- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558-
3559- CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3560- (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3561-
3562- EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3563- MF_BYCOMMAND | MF_ENABLED);
3564- }
3565-
3566- /* Menu "Window::Font" */
3567- for (i = 0; i < MAX_TERM_DATA; i++)
3568- {
3569- EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3570- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3571-
3572- if (data[i].visible)
3573- {
3574- EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3575- MF_BYCOMMAND | MF_ENABLED);
3576- }
3577- }
3578-
3579- /* Menu "Window::Window Position Fix" */
3580- for (i = 0; i < MAX_TERM_DATA; i++)
3581- {
3582- EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3583- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3584-
3585- CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3586- (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3587-
3588- if (data[i].visible)
3589- {
3590- EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3591- MF_BYCOMMAND | MF_ENABLED);
3592- }
3593- }
3594-
3595- /* Menu "Window::Bizarre Display" */
3596- for (i = 0; i < MAX_TERM_DATA; i++)
3597- {
3598- EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3599- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3600-
3601- CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3602- (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3603-
3604- if (data[i].visible)
3605- {
3606- EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3607- MF_BYCOMMAND | MF_ENABLED);
3608-
3609- }
3610- }
3611-
3612- /* Menu "Window::Increase Tile Width" */
3613- for (i = 0; i < MAX_TERM_DATA; i++)
3614- {
3615- EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3616- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3617-
3618- if (data[i].visible)
3619- {
3620- EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3621- MF_BYCOMMAND | MF_ENABLED);
3622-
3623- }
3624- }
3625-
3626- /* Menu "Window::Decrease Tile Width" */
3627- for (i = 0; i < MAX_TERM_DATA; i++)
3628- {
3629- EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3630- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3631-
3632- if (data[i].visible)
3633- {
3634- EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3635- MF_BYCOMMAND | MF_ENABLED);
3636-
3637- }
3638- }
3639-
3640- /* Menu "Window::Increase Tile Height" */
3641- for (i = 0; i < MAX_TERM_DATA; i++)
3642- {
3643- EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3644- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3645-
3646- if (data[i].visible)
3647- {
3648- EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3649- MF_BYCOMMAND | MF_ENABLED);
3650-
3651- }
3652- }
3653-
3654- /* Menu "Window::Decrease Tile Height" */
3655- for (i = 0; i < MAX_TERM_DATA; i++)
3656- {
3657- EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3658- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3659-
3660- if (data[i].visible)
3661- {
3662- EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3663- MF_BYCOMMAND | MF_ENABLED);
3664-
3665- }
3666- }
3667-
3668- /* Menu "Options", disable all */
3669- EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3670- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3671- EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3672- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3673- EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3674- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3675- EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3676- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3677- EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3678- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3679-#ifndef JP
3680- EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3681- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3682-#endif
3683-
3684- /* Menu "Options", Item "Map" */
3685- if (use_graphics != GRAPHICS_NONE)
3686- EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3687- else
3688- EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3689- MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3690-
3691- /* Menu "Options", update all */
3692- CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3693- (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3694- CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3695- (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3696- CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3697- (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3698- CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3699- (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3700- CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3701- (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3702- CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3703- (arg_music ? MF_CHECKED : MF_UNCHECKED));
3704- CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3705- (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3706- CheckMenuItem(hm, IDM_OPTIONS_BG,
3707- (use_bg ? MF_CHECKED : MF_UNCHECKED));
3708-#ifndef JP
3709- CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3710- (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3711-#endif
3712-
3713-#ifdef USE_GRAPHICS
3714- /* Menu "Options", Item "Graphics" */
3715- EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3716- /* Menu "Options", Item "Graphics" */
3717- EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3718- /* Menu "Options", Item "Graphics" */
3719- EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3720- /* Menu "Options", Item "Graphics" */
3721- EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3722-#endif /* USE_GRAPHICS */
3723-
3724-#ifdef USE_SOUND
3725- /* Menu "Options", Item "Sound" */
3726- EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3727-#endif /* USE_SOUND */
3728-
3729-#ifdef USE_SAVER
3730- /* Menu "Options", Item "ScreenSaver" */
3731- EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3732- MF_BYCOMMAND | MF_ENABLED);
3733-#endif /* USE_SAVER */
3734-}
3735-
3736-
3737-/*
3738- * Check for double clicked (or dragged) savefile
3739- *
3740- * Apparently, Windows copies the entire filename into the first
3741- * piece of the "command line string". Perhaps we should extract
3742- * the "basename" of that filename and append it to the "save" dir.
3743- */
3744-static void check_for_save_file(LPSTR cmd_line)
3745-{
3746- char *s;
3747-
3748- /* First arg */
3749- s = cmd_line;
3750-
3751- /* No args */
3752- if (!*s) return;
3753-
3754- /* Extract filename */
3755- strcat(savefile, s);
3756-
3757- /* Validate the file */
3758- validate_file(savefile);
3759-
3760- /* Game in progress */
3761- game_in_progress = TRUE;
3762-
3763- /* Play game */
3764- play_game(FALSE);
3765-}
3766-
3767-
3768-/*
3769- * Process a menu command
3770- */
3771-static void process_menus(WORD wCmd)
3772-{
3773- int i;
3774-
3775- term_data *td;
3776-
3777- OPENFILENAME ofn;
3778-
3779- /* Analyze */
3780- switch (wCmd)
3781- {
3782- /* New game */
3783- case IDM_FILE_NEW:
3784- {
3785- if (!initialized)
3786- {
3787- plog(_("まだ初期化中です...", "You cannot do that yet..."));
3788- }
3789- else if (game_in_progress)
3790- {
3791- plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3792- }
3793- else
3794- {
3795- game_in_progress = TRUE;
3796- Term_flush();
3797- play_game(TRUE);
3798- quit(NULL);
3799- }
3800- break;
3801- }
3802-
3803- /* Open game */
3804- case IDM_FILE_OPEN:
3805- {
3806- if (!initialized)
3807- {
3808- plog(_("まだ初期化中です...", "You cannot do that yet..."));
3809- }
3810- else if (game_in_progress)
3811- {
3812- plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3813- }
3814- else
3815- {
3816- memset(&ofn, 0, sizeof(ofn));
3817- ofn.lStructSize = sizeof(ofn);
3818- ofn.hwndOwner = data[0].w;
3819- ofn.lpstrFilter = "Save Files (*.)\0*\0";
3820- ofn.nFilterIndex = 1;
3821- ofn.lpstrFile = savefile;
3822- ofn.nMaxFile = 1024;
3823- ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3824- ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3825-
3826- if (GetOpenFileName(&ofn))
3827- {
3828- /* Load 'savefile' */
3829- validate_file(savefile);
3830- game_in_progress = TRUE;
3831- Term_flush();
3832- play_game(FALSE);
3833- quit(NULL);
3834- }
3835- }
3836- break;
3837- }
3838-
3839- /* Save game */
3840- case IDM_FILE_SAVE:
3841- {
3842- if (game_in_progress && character_generated)
3843- {
3844- /* Paranoia */
3845- if (!can_save)
3846- {
3847- plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3848- break;
3849- }
3850-
3851- /* Hack -- Forget messages */
3852- msg_flag = FALSE;
3853-
3854- /* Save the game */
3855-#ifdef ZANGBAND
3856- do_cmd_save_game(FALSE);
3857-#else /* ZANGBAND */
3858- do_cmd_save_game();
3859-#endif /* ZANGBAND */
3860- }
3861- else
3862- {
3863- plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3864- }
3865- break;
3866- }
3867-
3868- /* Exit */
3869- case IDM_FILE_EXIT:
3870- {
3871- if (game_in_progress && character_generated)
3872- {
3873- /* Paranoia */
3874- if (!can_save)
3875- {
3876- plog(_("今は終了できません。", "You may not do that right now."));
3877- break;
3878- }
3879-
3880- /* Hack -- Forget messages */
3881- msg_flag = FALSE;
3882-
3883- forget_lite();
3884- forget_view();
3885- clear_mon_lite();
3886-
3887- /* Save the game */
3888-#ifdef ZANGBAND
3889- /* do_cmd_save_game(FALSE); */
3890-#else /* ZANGBAND */
3891- /* do_cmd_save_game(); */
3892-#endif /* ZANGBAND */
3893- Term_key_push(SPECIAL_KEY_QUIT);
3894- break;
3895- }
3896- quit(NULL);
3897- break;
3898- }
3899-
3900- /* Show scores */
3901- case IDM_FILE_SCORE:
3902- {
3903- char buf[1024];
3904-
3905- /* Build the filename */
3906- path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3907-
3908- /* Open the binary high score file, for reading */
3909- highscore_fd = fd_open(buf, O_RDONLY);
3910-
3911- /* Paranoia -- No score file */
3912- if (highscore_fd < 0)
3913- {
3914- msg_print("Score file unavailable.");
3915- }
3916- else
3917- {
3918- /* Save Screen */
3919- screen_save();
3920-
3921- /* Clear screen */
3922- Term_clear();
3923-
3924- /* Display the scores */
3925- display_scores_aux(0, MAX_HISCORES, -1, NULL);
3926-
3927- /* Shut the high score file */
3928- (void)fd_close(highscore_fd);
3929-
3930- /* Forget the high score fd */
3931- highscore_fd = -1;
3932-
3933- /* Load screen */
3934- screen_load();
3935-
3936- /* Hack - Flush it */
3937- Term_fresh();
3938- }
3939-
3940- break;
3941- }
3942-
3943- /* Open game */
3944- case IDM_FILE_MOVIE:
3945- {
3946- if (!initialized)
3947- {
3948- plog(_("まだ初期化中です...", "You cannot do that yet..."));
3949- }
3950- else if (game_in_progress)
3951- {
3952- plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3953- }
3954- else
3955- {
3956- memset(&ofn, 0, sizeof(ofn));
3957- ofn.lStructSize = sizeof(ofn);
3958- ofn.hwndOwner = data[0].w;
3959- ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3960- ofn.nFilterIndex = 1;
3961- ofn.lpstrFile = savefile;
3962- ofn.nMaxFile = 1024;
3963- ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3964- ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3965-
3966- if (GetOpenFileName(&ofn))
3967- {
3968- /* Load 'savefile' */
3969- prepare_browse_movie_aux(savefile);
3970- play_game(FALSE);
3971- quit(NULL);
3972- return;
3973- }
3974- }
3975- break;
3976- }
3977-
3978-
3979- case IDM_WINDOW_VIS_0:
3980- {
3981- plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3982- break;
3983- }
3984-
3985- /* Window visibility */
3986- case IDM_WINDOW_VIS_1:
3987- case IDM_WINDOW_VIS_2:
3988- case IDM_WINDOW_VIS_3:
3989- case IDM_WINDOW_VIS_4:
3990- case IDM_WINDOW_VIS_5:
3991- case IDM_WINDOW_VIS_6:
3992- case IDM_WINDOW_VIS_7:
3993- {
3994- i = wCmd - IDM_WINDOW_VIS_0;
3995-
3996- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3997-
3998- td = &data[i];
3999-
4000- if (!td->visible)
4001- {
4002- td->visible = TRUE;
4003- ShowWindow(td->w, SW_SHOW);
4004- term_data_redraw(td);
4005- }
4006- else
4007- {
4008- td->visible = FALSE;
4009- td->posfix = FALSE;
4010- ShowWindow(td->w, SW_HIDE);
4011- }
4012-
4013- break;
4014- }
4015-
4016- /* Window fonts */
4017- case IDM_WINDOW_FONT_0:
4018- case IDM_WINDOW_FONT_1:
4019- case IDM_WINDOW_FONT_2:
4020- case IDM_WINDOW_FONT_3:
4021- case IDM_WINDOW_FONT_4:
4022- case IDM_WINDOW_FONT_5:
4023- case IDM_WINDOW_FONT_6:
4024- case IDM_WINDOW_FONT_7:
4025- {
4026- i = wCmd - IDM_WINDOW_FONT_0;
4027-
4028- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4029-
4030- td = &data[i];
4031-
4032- term_change_font(td);
4033-
4034- break;
4035- }
4036-
4037- /* Window Z Position */
4038- case IDM_WINDOW_POS_1:
4039- case IDM_WINDOW_POS_2:
4040- case IDM_WINDOW_POS_3:
4041- case IDM_WINDOW_POS_4:
4042- case IDM_WINDOW_POS_5:
4043- case IDM_WINDOW_POS_6:
4044- case IDM_WINDOW_POS_7:
4045- {
4046- i = wCmd - IDM_WINDOW_POS_0;
4047-
4048- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4049-
4050- td = &data[i];
4051-
4052- if (!td->posfix && td->visible)
4053- {
4054- td->posfix = TRUE;
4055- term_window_pos(td, HWND_TOPMOST);
4056- }
4057- else
4058- {
4059- td->posfix = FALSE;
4060- term_window_pos(td, data[0].w);
4061- }
4062-
4063- break;
4064- }
4065-
4066- /* Bizarre Display */
4067- case IDM_WINDOW_BIZ_0:
4068- case IDM_WINDOW_BIZ_1:
4069- case IDM_WINDOW_BIZ_2:
4070- case IDM_WINDOW_BIZ_3:
4071- case IDM_WINDOW_BIZ_4:
4072- case IDM_WINDOW_BIZ_5:
4073- case IDM_WINDOW_BIZ_6:
4074- case IDM_WINDOW_BIZ_7:
4075- {
4076- i = wCmd - IDM_WINDOW_BIZ_0;
4077-
4078- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4079-
4080- td = &data[i];
4081-
4082- td->bizarre = !td->bizarre;
4083-
4084- term_getsize(td);
4085-
4086- term_window_resize(td);
4087-
4088- break;
4089- }
4090-
4091- /* Increase Tile Width */
4092- case IDM_WINDOW_I_WID_0:
4093- case IDM_WINDOW_I_WID_1:
4094- case IDM_WINDOW_I_WID_2:
4095- case IDM_WINDOW_I_WID_3:
4096- case IDM_WINDOW_I_WID_4:
4097- case IDM_WINDOW_I_WID_5:
4098- case IDM_WINDOW_I_WID_6:
4099- case IDM_WINDOW_I_WID_7:
4100- {
4101- i = wCmd - IDM_WINDOW_I_WID_0;
4102-
4103- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4104-
4105- td = &data[i];
4106-
4107- td->tile_wid += 1;
4108-
4109- term_getsize(td);
4110-
4111- term_window_resize(td);
4112-
4113- break;
4114- }
4115-
4116- /* Decrease Tile Height */
4117- case IDM_WINDOW_D_WID_0:
4118- case IDM_WINDOW_D_WID_1:
4119- case IDM_WINDOW_D_WID_2:
4120- case IDM_WINDOW_D_WID_3:
4121- case IDM_WINDOW_D_WID_4:
4122- case IDM_WINDOW_D_WID_5:
4123- case IDM_WINDOW_D_WID_6:
4124- case IDM_WINDOW_D_WID_7:
4125- {
4126- i = wCmd - IDM_WINDOW_D_WID_0;
4127-
4128- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4129-
4130- td = &data[i];
4131-
4132- td->tile_wid -= 1;
4133-
4134- term_getsize(td);
4135-
4136- term_window_resize(td);
4137-
4138- break;
4139- }
4140-
4141- /* Increase Tile Height */
4142- case IDM_WINDOW_I_HGT_0:
4143- case IDM_WINDOW_I_HGT_1:
4144- case IDM_WINDOW_I_HGT_2:
4145- case IDM_WINDOW_I_HGT_3:
4146- case IDM_WINDOW_I_HGT_4:
4147- case IDM_WINDOW_I_HGT_5:
4148- case IDM_WINDOW_I_HGT_6:
4149- case IDM_WINDOW_I_HGT_7:
4150- {
4151- i = wCmd - IDM_WINDOW_I_HGT_0;
4152-
4153- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4154-
4155- td = &data[i];
4156-
4157- td->tile_hgt += 1;
4158-
4159- term_getsize(td);
4160-
4161- term_window_resize(td);
4162-
4163- break;
4164- }
4165-
4166- /* Decrease Tile Height */
4167- case IDM_WINDOW_D_HGT_0:
4168- case IDM_WINDOW_D_HGT_1:
4169- case IDM_WINDOW_D_HGT_2:
4170- case IDM_WINDOW_D_HGT_3:
4171- case IDM_WINDOW_D_HGT_4:
4172- case IDM_WINDOW_D_HGT_5:
4173- case IDM_WINDOW_D_HGT_6:
4174- case IDM_WINDOW_D_HGT_7:
4175- {
4176- i = wCmd - IDM_WINDOW_D_HGT_0;
4177-
4178- if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4179-
4180- td = &data[i];
4181-
4182- td->tile_hgt -= 1;
4183-
4184- term_getsize(td);
4185-
4186- term_window_resize(td);
4187-
4188- break;
4189- }
4190-
4191- case IDM_OPTIONS_NO_GRAPHICS:
4192- {
4193- /* Paranoia */
4194- if (!inkey_flag)
4195- {
4196- plog("You may not do that right now.");
4197- break;
4198- }
4199-
4200- /* Toggle "arg_graphics" */
4201- if (arg_graphics != GRAPHICS_NONE)
4202- {
4203- arg_graphics = GRAPHICS_NONE;
4204-
4205- /* React to changes */
4206- Term_xtra_win_react();
4207-
4208- /* Hack -- Force redraw */
4209- Term_key_push(KTRL('R'));
4210- }
4211-
4212- break;
4213- }
4214-
4215- case IDM_OPTIONS_OLD_GRAPHICS:
4216- {
4217- /* Paranoia */
4218- if (!inkey_flag)
4219- {
4220- plog("You may not do that right now.");
4221- break;
4222- }
4223-
4224- /* Toggle "arg_graphics" */
4225- if (arg_graphics != GRAPHICS_ORIGINAL)
4226- {
4227- arg_graphics = GRAPHICS_ORIGINAL;
4228-
4229- /* React to changes */
4230- Term_xtra_win_react();
4231-
4232- /* Hack -- Force redraw */
4233- Term_key_push(KTRL('R'));
4234- }
4235-
4236- break;
4237- }
4238-
4239- case IDM_OPTIONS_NEW_GRAPHICS:
4240- {
4241- /* Paranoia */
4242- if (!inkey_flag)
4243- {
4244- plog("You may not do that right now.");
4245- break;
4246- }
4247-
4248- /* Toggle "arg_graphics" */
4249- if (arg_graphics != GRAPHICS_ADAM_BOLT)
4250- {
4251- arg_graphics = GRAPHICS_ADAM_BOLT;
4252-
4253- /* React to changes */
4254- Term_xtra_win_react();
4255-
4256- /* Hack -- Force redraw */
4257- Term_key_push(KTRL('R'));
4258- }
4259-
4260- break;
4261- }
4262-
4263- case IDM_OPTIONS_NEW2_GRAPHICS:
4264- {
4265- /* Paranoia */
4266- if (!inkey_flag)
4267- {
4268- plog("You may not do that right now.");
4269- break;
4270- }
4271-
4272- /* Toggle "arg_graphics" */
4273- if (arg_graphics != GRAPHICS_HENGBAND)
4274- {
4275- arg_graphics = GRAPHICS_HENGBAND;
4276-
4277- /* React to changes */
4278- Term_xtra_win_react();
4279-
4280- /* Hack -- Force redraw */
4281- Term_key_push(KTRL('R'));
4282- }
4283-
4284- break;
4285- }
4286-
4287- case IDM_OPTIONS_BIGTILE:
4288- {
4289- term_data *td = &data[0];
4290-
4291- /* Paranoia */
4292- if (!inkey_flag)
4293- {
4294- plog("You may not do that right now.");
4295- break;
4296- }
4297-
4298- /* Toggle "arg_sound" */
4299- arg_bigtile = !arg_bigtile;
4300-
4301- /* Activate */
4302- Term_activate(&td->t);
4303-
4304- /* Resize the term */
4305- Term_resize(td->cols, td->rows);
4306-
4307- /* Redraw later */
4308- InvalidateRect(td->w, NULL, TRUE);
4309-
4310- break;
4311- }
4312-
4313- case IDM_OPTIONS_MUSIC:
4314- {
4315- /* Paranoia */
4316- if (!inkey_flag)
4317- {
4318- plog("You may not do that right now.");
4319- break;
4320- }
4321-
4322- /* Toggle "arg_sound" */
4323- arg_music = !arg_music;
4324-
4325- /* React to changes */
4326- Term_xtra_win_react();
4327-
4328- /* Hack -- Force redraw */
4329- Term_key_push(KTRL('R'));
4330-
4331- break;
4332- }
4333-
4334- case IDM_OPTIONS_SOUND:
4335- {
4336- /* Paranoia */
4337- if (!inkey_flag)
4338- {
4339- plog("You may not do that right now.");
4340- break;
4341- }
4342-
4343- /* Toggle "arg_sound" */
4344- arg_sound = !arg_sound;
4345-
4346- /* React to changes */
4347- Term_xtra_win_react();
4348-
4349- /* Hack -- Force redraw */
4350- Term_key_push(KTRL('R'));
4351-
4352- break;
4353- }
4354-
4355- /* bg */
4356- case IDM_OPTIONS_BG:
4357- {
4358- /* Paranoia */
4359- if (!inkey_flag)
4360- {
4361- plog("You may not do that right now.");
4362- break;
4363- }
4364-
4365- /* Toggle "use_bg" */
4366- use_bg = !use_bg;
4367-
4368- init_bg();
4369-
4370- /* React to changes */
4371- Term_xtra_win_react();
4372-
4373- /* Hack -- Force redraw */
4374- Term_key_push(KTRL('R'));
4375-
4376- break;
4377- }
4378-
4379- /* bg */
4380- case IDM_OPTIONS_OPEN_BG:
4381- {
4382- /* Paranoia */
4383- if (!inkey_flag)
4384- {
4385- plog("You may not do that right now.");
4386- break;
4387- }
4388- else
4389- {
4390- memset(&ofn, 0, sizeof(ofn));
4391- ofn.lStructSize = sizeof(ofn);
4392- ofn.hwndOwner = data[0].w;
4393- ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4394- ofn.nFilterIndex = 1;
4395- ofn.lpstrFile = bg_bitmap_file;
4396- ofn.nMaxFile = 1023;
4397- ofn.lpstrInitialDir = NULL;
4398- ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4399- ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4400-
4401- if (GetOpenFileName(&ofn))
4402- {
4403- /* Load 'savefile' */
4404- use_bg = 1;
4405- init_bg();
4406- }
4407-
4408- /* React to changes */
4409- Term_xtra_win_react();
4410-
4411- /* Hack -- Force redraw */
4412- Term_key_push(KTRL('R'));
4413- }
4414- break;
4415- }
4416-
4417- case IDM_DUMP_SCREEN_HTML:
4418- {
4419- static char buf[1024] = "";
4420- memset(&ofn, 0, sizeof(ofn));
4421- ofn.lStructSize = sizeof(ofn);
4422- ofn.hwndOwner = data[0].w;
4423- ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4424- ofn.nFilterIndex = 1;
4425- ofn.lpstrFile = buf;
4426- ofn.nMaxFile = 1023;
4427- ofn.lpstrDefExt = "html";
4428- ofn.lpstrInitialDir = NULL;
4429- ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4430- ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4431-
4432- if (GetSaveFileName(&ofn))
4433- {
4434- do_cmd_save_screen_html_aux(buf, 0);
4435- }
4436- break;
4437- }
4438-
4439-#ifdef USE_SAVER
4440-
4441- case IDM_OPTIONS_SAVER:
4442- {
4443- if (hwndSaver)
4444- {
4445- DestroyWindow(hwndSaver);
4446- hwndSaver = NULL;
4447- }
4448- else
4449- {
4450- /* Create a screen scaver window */
4451- hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4452- "Angband Screensaver",
4453- WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4454- 0, 0, GetSystemMetrics(SM_CXSCREEN),
4455- GetSystemMetrics(SM_CYSCREEN),
4456- NULL, NULL, hInstance, NULL);
4457-
4458- if (hwndSaver)
4459- {
4460- /* Push the window to the bottom XXX XXX XXX */
4461- SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4462- }
4463- else
4464- {
4465- plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4466- }
4467- }
4468- break;
4469- }
4470-
4471-#endif
4472-
4473- case IDM_OPTIONS_MAP:
4474- {
4475- windows_map();
4476- break;
4477- }
4478-
4479- case IDM_HELP_CONTENTS:
4480- {
4481-#ifdef HTML_HELP
4482- char tmp[1024];
4483- path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4484- if (check_file(tmp))
4485- {
4486- HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4487- }
4488- else
4489- {
4490-#ifdef JP
4491- plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4492- plog("代わりにオンラインヘルプを使用してください。");
4493-#else
4494- plog_fmt("Cannot find help file: %s", tmp);
4495- plog("Use the online help files instead.");
4496-#endif
4497-
4498- }
4499- break;
4500-#else /* HTML_HELP */
4501- char buf[1024];
4502- char tmp[1024];
4503- path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4504- if (check_file(tmp))
4505- {
4506- sprintf(buf, "winhelp.exe %s", tmp);
4507- WinExec(buf, SW_NORMAL);
4508- }
4509- else
4510- {
4511-#ifdef JP
4512- plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4513- plog("代わりにオンラインヘルプを使用してください。");
4514-#else
4515- plog_fmt("Cannot find help file: %s", tmp);
4516- plog("Use the online help files instead.");
4517-#endif
4518-
4519- }
4520- break;
4521-#endif /* HTML_HELP */
4522- }
4523- }
4524-}
4525-
4526-
4527-static bool process_keydown(WPARAM wParam, LPARAM lParam)
4528-{
4529- int i;
4530- bool mc = FALSE;
4531- bool ms = FALSE;
4532- bool ma = FALSE;
4533-
4534- /* Extract the modifiers */
4535- if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4536- if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4537- if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4538-
4539- Term_no_press = (ma) ? TRUE : FALSE;
4540-
4541- /* Handle "special" keys */
4542- if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4543- {
4544- bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4545- bool numpad = FALSE;
4546-
4547- /* Begin the macro trigger */
4548- Term_keypress(31);
4549-
4550- /* Send the modifiers */
4551- if (mc) Term_keypress('C');
4552- if (ms) Term_keypress('S');
4553- if (ma) Term_keypress('A');
4554-
4555- /* Extract "scan code" */
4556- i = LOBYTE(HIWORD(lParam));
4557-
4558- /* Introduce the scan code */
4559- Term_keypress('x');
4560-
4561- /* Extended key bit */
4562- switch (wParam)
4563- {
4564- /* Numpad Enter and '/' are extended key */
4565- case VK_DIVIDE:
4566- Term_no_press = TRUE;
4567- case VK_RETURN: /* Enter */
4568- numpad = ext_key;
4569- break;
4570- /* Other extended keys are on full keyboard */
4571- case VK_NUMPAD0:
4572- case VK_NUMPAD1:
4573- case VK_NUMPAD2:
4574- case VK_NUMPAD3:
4575- case VK_NUMPAD4:
4576- case VK_NUMPAD5:
4577- case VK_NUMPAD6:
4578- case VK_NUMPAD7:
4579- case VK_NUMPAD8:
4580- case VK_NUMPAD9:
4581- case VK_ADD:
4582- case VK_MULTIPLY:
4583- case VK_SUBTRACT:
4584- case VK_SEPARATOR:
4585- case VK_DECIMAL:
4586- Term_no_press = TRUE;
4587- case VK_CLEAR:
4588- case VK_HOME:
4589- case VK_END:
4590- case VK_PRIOR: /* Page Up */
4591- case VK_NEXT: /* Page Down */
4592- case VK_INSERT:
4593- case VK_DELETE:
4594- case VK_UP:
4595- case VK_DOWN:
4596- case VK_LEFT:
4597- case VK_RIGHT:
4598- numpad = !ext_key;
4599- }
4600-
4601- /* Special modifiers for keypad keys */
4602- if (numpad) Term_keypress('K');
4603-
4604- /* Encode the hexidecimal scan code */
4605- Term_keypress(hexsym[i/16]);
4606- Term_keypress(hexsym[i%16]);
4607-
4608- /* End the macro trigger */
4609- Term_keypress(13);
4610-
4611- return 1;
4612- }
4613-
4614- return 0;
4615-}
4616-
4617-
4618-#ifdef __MWERKS__
4619-LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4620- WPARAM wParam, LPARAM lParam);
4621-LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4622- WPARAM wParam, LPARAM lParam)
4623-#else /* __MWERKS__ */
4624-LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4625- WPARAM wParam, LPARAM lParam)
4626-#endif /* __MWERKS__ */
4627-{
4628- PAINTSTRUCT ps;
4629- HDC hdc;
4630- term_data *td;
4631-#if 0
4632- MINMAXINFO FAR *lpmmi;
4633- RECT rc;
4634-#endif
4635- int i;
4636-
4637-
4638- /* Acquire proper "term_data" info */
4639- td = (term_data *)GetWindowLong(hWnd, 0);
4640-
4641- /* Handle message */
4642- switch (uMsg)
4643- {
4644- /* XXX XXX XXX */
4645- case WM_NCCREATE:
4646- {
4647- SetWindowLong(hWnd, 0, (LONG)(my_td));
4648- break;
4649- }
4650-
4651- /* XXX XXX XXX */
4652- case WM_CREATE:
4653- {
4654-#ifdef USE_MUSIC
4655- mop.dwCallback=(DWORD)hWnd;
4656-#endif
4657- return 0;
4658- }
4659-
4660- case WM_GETMINMAXINFO:
4661- {
4662- MINMAXINFO FAR *lpmmi;
4663- RECT rc;
4664-
4665- lpmmi = (MINMAXINFO FAR *)lParam;
4666-
4667- /* this message was sent before WM_NCCREATE */
4668- if (!td) return 1;
4669-
4670- /* Minimum window size is 80x24 */
4671- rc.left = rc.top = 0;
4672- rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4673- rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4674-
4675- /* Adjust */
4676- AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4677-
4678- /* Save minimum size */
4679- lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4680- lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4681-
4682- return 0;
4683- }
4684-
4685- case WM_PAINT:
4686- {
4687- BeginPaint(hWnd, &ps);
4688- if (td) term_data_redraw(td);
4689- EndPaint(hWnd, &ps);
4690- ValidateRect(hWnd, NULL);
4691- return 0;
4692- }
4693-
4694-#ifdef USE_MUSIC
4695- case MM_MCINOTIFY:
4696- {
4697- if(wParam == MCI_NOTIFY_SUCCESSFUL)
4698- {
4699- mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4700- mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4701- }
4702- return 0;
4703- }
4704-#endif
4705-
4706- case WM_SYSKEYDOWN:
4707- case WM_KEYDOWN:
4708- {
4709- if (process_keydown(wParam, lParam))
4710- return 0;
4711- break;
4712- }
4713-
4714- case WM_CHAR:
4715- {
4716- if (Term_no_press) Term_no_press = FALSE;
4717- else Term_keypress(wParam);
4718- return 0;
4719- }
4720-
4721- case WM_LBUTTONDOWN:
4722- {
4723- mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4724- mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4725- mouse_down = TRUE;
4726- oldx = mousex;
4727- oldy = mousey;
4728- return 0;
4729- }
4730-
4731- case WM_LBUTTONUP:
4732- {
4733- HGLOBAL hGlobal;
4734- LPSTR lpStr;
4735- int i, j, sz;
4736- int dx = abs(oldx - mousex) + 1;
4737- int dy = abs(oldy - mousey) + 1;
4738- int ox = (oldx > mousex) ? mousex : oldx;
4739- int oy = (oldy > mousey) ? mousey : oldy;
4740-
4741- mouse_down = FALSE;
4742- paint_rect = FALSE;
4743-
4744-#ifdef JP
4745- sz = (dx + 3) * dy;
4746-#else
4747- sz = (dx + 2) * dy;
4748-#endif
4749- hGlobal = GlobalAlloc(GHND, sz + 1);
4750- if (hGlobal == NULL) return 0;
4751- lpStr = (LPSTR)GlobalLock(hGlobal);
4752-
4753- for (i = 0; i < dy; i++)
4754- {
4755-#ifdef JP
4756- char *s;
4757- char **scr = data[0].t.scr->c;
4758-
4759- C_MAKE(s, (dx + 1), char);
4760- strncpy(s, &scr[oy + i][ox], dx);
4761-
4762- if (ox > 0)
4763- {
4764- if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4765- }
4766-
4767- if (ox + dx < data[0].cols)
4768- {
4769- if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4770- }
4771-
4772- for (j = 0; j < dx; j++)
4773- {
4774- if (s[j] == 127) s[j] = '#';
4775- *lpStr++ = s[j];
4776- }
4777-#else
4778- for (j = 0; j < dx; j++)
4779- {
4780- *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4781- }
4782-#endif
4783- if (dy > 1)
4784- {
4785- *lpStr++ = '\r';
4786- *lpStr++ = '\n';
4787- }
4788- }
4789-
4790- GlobalUnlock(hGlobal);
4791- if (OpenClipboard(hWnd) == 0)
4792- {
4793- GlobalFree(hGlobal);
4794- return 0;
4795- }
4796- EmptyClipboard();
4797- SetClipboardData(CF_TEXT, hGlobal);
4798- CloseClipboard();
4799-
4800- Term_redraw();
4801-
4802- return 0;
4803- }
4804-
4805- case WM_MOUSEMOVE:
4806- {
4807- if (mouse_down)
4808- {
4809- int dx, dy;
4810- int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4811- int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4812- int ox, oy;
4813-
4814- if (paint_rect)
4815- {
4816- dx = abs(oldx - mousex) + 1;
4817- dy = abs(oldy - mousey) + 1;
4818- ox = (oldx > mousex) ? mousex : oldx;
4819- oy = (oldy > mousey) ? mousey : oldy;
4820- Term_inversed_area(hWnd, ox, oy, dx, dy);
4821- }
4822- else
4823- {
4824- paint_rect = TRUE;
4825- }
4826-
4827- dx = abs(cx - mousex) + 1;
4828- dy = abs(cy - mousey) + 1;
4829- ox = (cx > mousex) ? mousex : cx;
4830- oy = (cy > mousey) ? mousey : cy;
4831- Term_inversed_area(hWnd, ox, oy, dx, dy);
4832-
4833- oldx = cx;
4834- oldy = cy;
4835- }
4836- return 0;
4837- }
4838-
4839- case WM_INITMENU:
4840- {
4841- setup_menus();
4842- return 0;
4843- }
4844-
4845- case WM_CLOSE:
4846- {
4847- if (game_in_progress && character_generated)
4848- {
4849- if (!can_save)
4850- {
4851- plog(_("今は終了できません。", "You may not do that right now."));
4852- return 0;
4853- }
4854-
4855- /* Hack -- Forget messages */
4856- msg_flag = FALSE;
4857-
4858- forget_lite();
4859- forget_view();
4860- clear_mon_lite();
4861-
4862- /* Save the game */
4863-#ifdef ZANGBAND
4864- /* do_cmd_save_game(FALSE); */
4865-#else /* ZANGBAND */
4866- /* do_cmd_save_game(); */
4867-#endif /* ZANGBAND */
4868- Term_key_push(SPECIAL_KEY_QUIT);
4869- return 0;
4870- }
4871- quit(NULL);
4872- return 0;
4873- }
4874-
4875- case WM_QUERYENDSESSION:
4876- {
4877- if (game_in_progress && character_generated)
4878- {
4879- /* Hack -- Forget messages */
4880- msg_flag = FALSE;
4881-
4882- /* Mega-Hack -- Delay death */
4883- if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4884- do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4885-
4886- /* Hardcode panic save */
4887- p_ptr->panic_save = 1;
4888-
4889- /* Forbid suspend */
4890- signals_ignore_tstp();
4891-
4892- /* Indicate panic save */
4893- (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4894-
4895- /* Panic save */
4896- (void)save_player();
4897- }
4898- quit(NULL);
4899- return 0;
4900- }
4901-
4902- case WM_QUIT:
4903- {
4904- quit(NULL);
4905- return 0;
4906- }
4907-
4908- case WM_COMMAND:
4909- {
4910- process_menus(LOWORD(wParam));
4911- return 0;
4912- }
4913-
4914- case WM_SIZE:
4915- {
4916- /* this message was sent before WM_NCCREATE */
4917- if (!td) return 1;
4918-
4919- /* it was sent from inside CreateWindowEx */
4920- if (!td->w) return 1;
4921-
4922- /* was sent from WM_SIZE */
4923- if (td->size_hack) return 1;
4924-
4925- switch (wParam)
4926- {
4927- case SIZE_MINIMIZED:
4928- {
4929- /* Hide sub-windows */
4930- for (i = 1; i < MAX_TERM_DATA; i++)
4931- {
4932- if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4933- }
4934- return 0;
4935- }
4936-
4937- case SIZE_MAXIMIZED:
4938- {
4939- /* fall through XXX XXX XXX */
4940- }
4941-
4942- case SIZE_RESTORED:
4943- {
4944- uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4945- uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4946-
4947- /* New size */
4948- if ((td->cols != cols) || (td->rows != rows))
4949- {
4950- /* Save the new size */
4951- td->cols = cols;
4952- td->rows = rows;
4953-
4954- if (!IsZoomed(td->w) && !IsIconic(td->w))
4955- {
4956- normsize.x = td->cols;
4957- normsize.y = td->rows;
4958- }
4959-
4960- /* Activate */
4961- Term_activate(&td->t);
4962-
4963- /* Resize the term */
4964- Term_resize(td->cols, td->rows);
4965-
4966- /* Redraw later */
4967- InvalidateRect(td->w, NULL, TRUE);
4968- }
4969-
4970- td->size_hack = TRUE;
4971-
4972- /* Show sub-windows */
4973- for (i = 1; i < MAX_TERM_DATA; i++)
4974- {
4975- if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4976- }
4977-
4978- td->size_hack = FALSE;
4979-
4980- return 0;
4981- }
4982- }
4983- break;
4984- }
4985-
4986- case WM_PALETTECHANGED:
4987- {
4988- /* Ignore if palette change caused by itself */
4989- if ((HWND)wParam == hWnd) return 0;
4990-
4991- /* Fall through... */
4992- }
4993-
4994- case WM_QUERYNEWPALETTE:
4995- {
4996- if (!paletted) return 0;
4997-
4998- hdc = GetDC(hWnd);
4999-
5000- SelectPalette(hdc, hPal, FALSE);
5001-
5002- i = RealizePalette(hdc);
5003-
5004- /* if any palette entries changed, repaint the window. */
5005- if (i) InvalidateRect(hWnd, NULL, TRUE);
5006-
5007- ReleaseDC(hWnd, hdc);
5008-
5009- return 0;
5010- }
5011-
5012- case WM_ACTIVATE:
5013- {
5014- if (wParam && !HIWORD(lParam))
5015- {
5016- /* Do something to sub-windows */
5017- for (i = 1; i < MAX_TERM_DATA; i++)
5018- {
5019- if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5020- }
5021-
5022- /* Focus on main window */
5023- SetFocus(hWnd);
5024-
5025- return 0;
5026- }
5027-
5028- break;
5029- }
5030-
5031- case WM_ACTIVATEAPP:
5032- {
5033- if (IsIconic(td->w)) break;
5034-
5035- for (i = 1; i < MAX_TERM_DATA; i++)
5036- {
5037- if(data[i].visible)
5038- {
5039- if (wParam == TRUE)
5040- {
5041- ShowWindow(data[i].w, SW_SHOW);
5042- }
5043- else
5044- {
5045- ShowWindow(data[i].w, SW_HIDE);
5046- }
5047- }
5048- }
5049- }
5050- }
5051-
5052- return DefWindowProc(hWnd, uMsg, wParam, lParam);
5053-}
5054-
5055-
5056-#ifdef __MWERKS__
5057-LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5058- WPARAM wParam, LPARAM lParam);
5059-LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5060- WPARAM wParam, LPARAM lParam)
5061-#else /* __MWERKS__ */
5062-LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5063- WPARAM wParam, LPARAM lParam)
5064-#endif /* __MWERKS__ */
5065-{
5066- term_data *td;
5067-#if 0
5068- MINMAXINFO FAR *lpmmi;
5069- RECT rc;
5070-#endif
5071- PAINTSTRUCT ps;
5072- HDC hdc;
5073- int i;
5074-
5075-
5076- /* Acquire proper "term_data" info */
5077- td = (term_data *)GetWindowLong(hWnd, 0);
5078-
5079- /* Process message */
5080- switch (uMsg)
5081- {
5082- /* XXX XXX XXX */
5083- case WM_NCCREATE:
5084- {
5085- SetWindowLong(hWnd, 0, (LONG)(my_td));
5086- break;
5087- }
5088-
5089- /* XXX XXX XXX */
5090- case WM_CREATE:
5091- {
5092- return 0;
5093- }
5094-
5095- case WM_GETMINMAXINFO:
5096- {
5097- MINMAXINFO FAR *lpmmi;
5098- RECT rc;
5099-
5100- lpmmi = (MINMAXINFO FAR *)lParam;
5101-
5102- /* this message was sent before WM_NCCREATE */
5103- if (!td) return 1;
5104-
5105- /* Minimum window size is 80x24 */
5106- rc.left = rc.top = 0;
5107- rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5108- rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5109-
5110- /* Adjust */
5111- AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5112-
5113- /* Save minimum size */
5114- lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5115- lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5116-
5117- return 0;
5118- }
5119-
5120- case WM_SIZE:
5121- {
5122- uint cols;
5123- uint rows;
5124-
5125- /* this message was sent before WM_NCCREATE */
5126- if (!td) return 1;
5127-
5128- /* it was sent from inside CreateWindowEx */
5129- if (!td->w) return 1;
5130-
5131- /* was sent from inside WM_SIZE */
5132- if (td->size_hack) return 1;
5133-
5134- td->size_hack = TRUE;
5135-
5136- cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5137- rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5138-
5139- /* New size */
5140- if ((td->cols != cols) || (td->rows != rows))
5141- {
5142- /* Save old term */
5143- term *old_term = Term;
5144-
5145- /* Save the new size */
5146- td->cols = cols;
5147- td->rows = rows;
5148-
5149- /* Activate */
5150- Term_activate(&td->t);
5151-
5152- /* Resize the term */
5153- Term_resize(td->cols, td->rows);
5154-
5155- /* Activate */
5156- Term_activate(old_term);
5157-
5158- /* Redraw later */
5159- InvalidateRect(td->w, NULL, TRUE);
5160-
5161- /* HACK - Redraw all windows */
5162- p_ptr->window = 0xFFFFFFFF;
5163- window_stuff();
5164- }
5165-
5166- td->size_hack = FALSE;
5167-
5168- return 0;
5169- }
5170-
5171- case WM_PAINT:
5172- {
5173- BeginPaint(hWnd, &ps);
5174- if (td) term_data_redraw(td);
5175- EndPaint(hWnd, &ps);
5176- return 0;
5177- }
5178-
5179- case WM_SYSKEYDOWN:
5180- case WM_KEYDOWN:
5181- {
5182- if (process_keydown(wParam, lParam))
5183- return 0;
5184- break;
5185- }
5186-
5187- case WM_CHAR:
5188- {
5189- if (Term_no_press) Term_no_press = FALSE;
5190- else Term_keypress(wParam);
5191- return 0;
5192- }
5193-
5194- case WM_PALETTECHANGED:
5195- {
5196- /* ignore if palette change caused by itself */
5197- if ((HWND)wParam == hWnd) return FALSE;
5198- /* otherwise, fall through!!! */
5199- }
5200-
5201- case WM_QUERYNEWPALETTE:
5202- {
5203- if (!paletted) return 0;
5204- hdc = GetDC(hWnd);
5205- SelectPalette(hdc, hPal, FALSE);
5206- i = RealizePalette(hdc);
5207- /* if any palette entries changed, repaint the window. */
5208- if (i) InvalidateRect(hWnd, NULL, TRUE);
5209- ReleaseDC(hWnd, hdc);
5210- return 0;
5211- }
5212-
5213- case WM_NCLBUTTONDOWN:
5214- {
5215-
5216-#ifdef HTCLOSE
5217- if (wParam == HTCLOSE) wParam = HTSYSMENU;
5218-#endif /* HTCLOSE */
5219-
5220- if (wParam == HTSYSMENU)
5221- {
5222- if (td->visible)
5223- {
5224- td->visible = FALSE;
5225- ShowWindow(td->w, SW_HIDE);
5226- }
5227-
5228- return 0;
5229- }
5230-
5231- break;
5232- }
5233- }
5234-
5235- return DefWindowProc(hWnd, uMsg, wParam, lParam);
5236-}
5237-
5238-
5239-#ifdef USE_SAVER
5240-
5241-#define MOUSE_SENS 40
5242-
5243-#ifdef __MWERKS__
5244-LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5245- WPARAM wParam, LPARAM lParam);
5246-LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5247- WPARAM wParam, LPARAM lParam)
5248-#else /* __MWERKS__ */
5249-LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5250- WPARAM wParam, LPARAM lParam)
5251-#endif /* __MWERKS__ */
5252-{
5253- static int iMouse = 0;
5254- static WORD xMouse = 0;
5255- static WORD yMouse = 0;
5256-
5257- int dx, dy;
5258-
5259-
5260- /* Process */
5261- switch (uMsg)
5262- {
5263- /* XXX XXX XXX */
5264- case WM_NCCREATE:
5265- {
5266- break;
5267- }
5268-
5269- case WM_SETCURSOR:
5270- {
5271- SetCursor(NULL);
5272- return 0;
5273- }
5274-
5275-#if 0
5276- case WM_ACTIVATE:
5277- {
5278- if (LOWORD(wParam) == WA_INACTIVE) break;
5279-
5280- /* else fall through */
5281- }
5282-#endif
5283-
5284- case WM_LBUTTONDOWN:
5285- case WM_MBUTTONDOWN:
5286- case WM_RBUTTONDOWN:
5287- case WM_KEYDOWN:
5288- {
5289- SendMessage(hWnd, WM_CLOSE, 0, 0);
5290- return 0;
5291- }
5292-
5293- case WM_MOUSEMOVE:
5294- {
5295- if (iMouse)
5296- {
5297- dx = LOWORD(lParam) - xMouse;
5298- dy = HIWORD(lParam) - yMouse;
5299-
5300- if (dx < 0) dx = -dx;
5301- if (dy < 0) dy = -dy;
5302-
5303- if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5304- {
5305- SendMessage(hWnd, WM_CLOSE, 0, 0);
5306- }
5307- }
5308-
5309- /* Save last location */
5310- iMouse = 1;
5311- xMouse = LOWORD(lParam);
5312- yMouse = HIWORD(lParam);
5313-
5314- return 0;
5315- }
5316-
5317- case WM_CLOSE:
5318- {
5319- DestroyWindow(hwndSaver);
5320- hwndSaver = NULL;
5321- return 0;
5322- }
5323- }
5324-
5325- /* Oops */
5326- return DefWindowProc(hWnd, uMsg, wParam, lParam);
5327-}
5328-
5329-#endif /* USE_SAVER */
5330-
5331-
5332-
5333-
5334-
5335-/*** Temporary Hooks ***/
5336-
5337-
5338-/*
5339- * Display warning message (see "z-util.c")
5340- */
5341-static void hack_plog(cptr str)
5342-{
5343- /* Give a warning */
5344- if (str)
5345- {
5346-#ifdef JP
5347- MessageBox(NULL, str, "警告!",
5348- MB_ICONEXCLAMATION | MB_OK);
5349-#else
5350- MessageBox(NULL, str, "Warning",
5351- MB_ICONEXCLAMATION | MB_OK);
5352-#endif
5353-
5354- }
5355-}
5356-
5357-
5358-/*
5359- * Display error message and quit (see "z-util.c")
5360- */
5361-static void hack_quit(cptr str)
5362-{
5363- /* Give a warning */
5364- if (str)
5365- {
5366-#ifdef JP
5367- MessageBox(NULL, str, "エラー!",
5368- MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5369-#else
5370- MessageBox(NULL, str, "Error",
5371- MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5372-#endif
5373-
5374- }
5375-
5376- /* Unregister the classes */
5377- UnregisterClass(AppName, hInstance);
5378-
5379- /* Destroy the icon */
5380- if (hIcon) DestroyIcon(hIcon);
5381-
5382- /* Exit */
5383- exit(0);
5384-}
5385-
5386-
5387-
5388-/*** Various hooks ***/
5389-
5390-
5391-/*
5392- * Display warning message (see "z-util.c")
5393- */
5394-static void hook_plog(cptr str)
5395-{
5396- /* Warning */
5397- if (str)
5398- {
5399-#ifdef JP
5400- MessageBox(data[0].w, str, "警告!",
5401- MB_ICONEXCLAMATION | MB_OK);
5402-#else
5403- MessageBox(data[0].w, str, "Warning",
5404- MB_ICONEXCLAMATION | MB_OK);
5405-#endif
5406-
5407- }
5408-}
5409-
5410-
5411-/*
5412- * Display error message and quit (see "z-util.c")
5413- */
5414-static void hook_quit(cptr str)
5415-{
5416- int i;
5417-
5418-
5419- /* Give a warning */
5420- if (str)
5421- {
5422-#ifdef JP
5423- MessageBox(data[0].w, str, "エラー!",
5424- MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5425-#else
5426- MessageBox(data[0].w, str, "Error",
5427- MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5428-#endif
5429-
5430- }
5431-
5432-
5433- /* Save the preferences */
5434- save_prefs();
5435-
5436-
5437- /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5438-
5439- /* Destroy all windows */
5440- for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5441- {
5442- term_force_font(&data[i], NULL);
5443- if (data[i].font_want) string_free(data[i].font_want);
5444- if (data[i].w) DestroyWindow(data[i].w);
5445- data[i].w = 0;
5446- }
5447-
5448- /* Free the bitmap stuff */
5449-#ifdef USE_GRAPHICS
5450- if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5451- if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5452-
5453- if (infMask.hPalette) DeleteObject(infMask.hPalette);
5454- if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5455-
5456-#endif /* USE_GRAPHICS */
5457-
5458- /*** Free some other stuff ***/
5459-
5460- DeleteObject(hbrYellow);
5461-
5462- /* bg */
5463- delete_bg();
5464-
5465- if (hPal) DeleteObject(hPal);
5466-
5467- UnregisterClass(AppName, hInstance);
5468-
5469- if (hIcon) DestroyIcon(hIcon);
5470-
5471- exit(0);
5472-}
5473-
5474-
5475-
5476-/*** Initialize ***/
5477-
5478-
5479-/*
5480- * Init some stuff
5481- */
5482-static void init_stuff(void)
5483-{
5484- int i;
5485-
5486- char path[1024];
5487-
5488-
5489- /* Get program name with full path */
5490- GetModuleFileName(hInstance, path, 512);
5491-
5492- /* Save the "program name" XXX XXX XXX */
5493- argv0 = path;
5494-
5495- /* Get the name of the "*.ini" file */
5496- strcpy(path + strlen(path) - 4, ".INI");
5497-
5498- /* Save the the name of the ini-file */
5499- ini_file = string_make(path);
5500-
5501- /* Analyze the path */
5502- i = strlen(path);
5503-
5504- /* Get the path */
5505- for (; i > 0; i--)
5506- {
5507- if (path[i] == '\\')
5508- {
5509- /* End of path */
5510- break;
5511- }
5512- }
5513-
5514- /* Add "lib" to the path */
5515- strcpy(path + i + 1, "lib\\");
5516-
5517- /* Validate the path */
5518- validate_dir(path, TRUE);
5519-
5520- /* Init the file paths */
5521- init_file_paths(path);
5522-
5523- /* Hack -- Validate the paths */
5524- validate_dir(ANGBAND_DIR_APEX, FALSE);
5525- validate_dir(ANGBAND_DIR_BONE, FALSE);
5526-
5527- /* Allow missing 'edit' directory */
5528- if (!check_dir(ANGBAND_DIR_EDIT))
5529- {
5530- /* Must have 'data'! */
5531- validate_dir(ANGBAND_DIR_DATA, TRUE);
5532- }
5533- else
5534- {
5535- /* Don't need 'data' */
5536- validate_dir(ANGBAND_DIR_DATA, FALSE);
5537- }
5538-
5539- validate_dir(ANGBAND_DIR_FILE, TRUE);
5540- validate_dir(ANGBAND_DIR_HELP, FALSE);
5541- validate_dir(ANGBAND_DIR_INFO, FALSE);
5542- validate_dir(ANGBAND_DIR_PREF, TRUE);
5543- validate_dir(ANGBAND_DIR_SAVE, FALSE);
5544- validate_dir(ANGBAND_DIR_USER, TRUE);
5545- validate_dir(ANGBAND_DIR_XTRA, TRUE);
5546-
5547- /* Build the filename */
5548- path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5549-
5550- /* Hack -- Validate the "news.txt" file */
5551- validate_file(path);
5552-
5553-
5554-#if 0 /* #ifndef JP */
5555- /* Build the "font" path */
5556- path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5557-
5558- /* Allocate the path */
5559- ANGBAND_DIR_XTRA_FONT = string_make(path);
5560-
5561- /* Validate the "font" directory */
5562- validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5563-
5564- /* Build the filename */
5565- path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5566-
5567- /* Hack -- Validate the basic font */
5568- validate_file(path);
5569-#endif
5570-
5571-
5572-#ifdef USE_GRAPHICS
5573-
5574- /* Build the "graf" path */
5575- path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5576-
5577- /* Allocate the path */
5578- ANGBAND_DIR_XTRA_GRAF = string_make(path);
5579-
5580- /* Validate the "graf" directory */
5581- validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5582-
5583-#endif /* USE_GRAPHICS */
5584-
5585-
5586-#ifdef USE_SOUND
5587-
5588- /* Build the "sound" path */
5589- path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5590-
5591- /* Allocate the path */
5592- ANGBAND_DIR_XTRA_SOUND = string_make(path);
5593-
5594- /* Validate the "sound" directory */
5595- validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5596-
5597-#endif /* USE_SOUND */
5598-
5599-#ifdef USE_MUSIC
5600-
5601- /* Build the "music" path */
5602- path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5603-
5604- /* Allocate the path */
5605- ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5606-
5607- /* Validate the "music" directory */
5608- validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5609-
5610-#endif /* USE_MUSIC */
5611-
5612- /* Build the "help" path */
5613- path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5614-
5615- /* Allocate the path */
5616- ANGBAND_DIR_XTRA_HELP = string_make(path);
5617-
5618- /* Validate the "help" directory */
5619- /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5620-}
5621-
5622-bool is_already_running()
5623-{
5624- bool result = FALSE;
5625- HANDLE hMutex;
5626-
5627- hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5628- if (GetLastError() == ERROR_ALREADY_EXISTS)
5629- {
5630- result = TRUE;
5631- }
5632- return result;
5633-}
5634-
5635-
5636-int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5637- LPSTR lpCmdLine, int nCmdShow)
5638-{
5639- int i;
5640-
5641- WNDCLASS wc;
5642- HDC hdc;
5643- MSG msg;
5644-
5645- setlocale( LC_ALL, "ja_JP" );
5646-
5647- /* Unused */
5648- (void)nCmdShow;
5649-
5650- /* Save globally */
5651- hInstance = hInst;
5652-
5653-
5654- /* Prevent multiple run */
5655- if (is_already_running())
5656- {
5657- MessageBox(NULL,
5658- _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5659- _("エラー!", "Error") ,
5660- MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5661- return FALSE;
5662- }
5663-
5664- /* Initialize */
5665- if (hPrevInst == NULL)
5666- {
5667- wc.style = CS_CLASSDC;
5668- wc.lpfnWndProc = AngbandWndProc;
5669- wc.cbClsExtra = 0;
5670- wc.cbWndExtra = 4; /* one long pointer to term_data */
5671- wc.hInstance = hInst;
5672- wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5673- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5674- wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5675- wc.lpszMenuName = AppName;
5676- wc.lpszClassName = AppName;
5677-
5678- if (!RegisterClass(&wc)) exit(1);
5679-
5680- wc.lpfnWndProc = AngbandListProc;
5681- wc.lpszMenuName = NULL;
5682- wc.lpszClassName = AngList;
5683-
5684- if (!RegisterClass(&wc)) exit(2);
5685-
5686-#ifdef USE_SAVER
5687-
5688- wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5689- wc.lpfnWndProc = AngbandSaverProc;
5690- wc.hCursor = NULL;
5691- wc.lpszMenuName = NULL;
5692- wc.lpszClassName = "WindowsScreenSaverClass";
5693-
5694- if (!RegisterClass(&wc)) exit(3);
5695-
5696-#endif
5697-
5698- }
5699-
5700- /* Temporary hooks */
5701- plog_aux = hack_plog;
5702- quit_aux = hack_quit;
5703- core_aux = hack_quit;
5704-
5705- /* Prepare the filepaths */
5706- init_stuff();
5707-
5708- /* Initialize the keypress analyzer */
5709- for (i = 0; special_key_list[i]; ++i)
5710- {
5711- special_key[special_key_list[i]] = TRUE;
5712- }
5713- /* Initialize the keypress analyzer */
5714- for (i = 0; ignore_key_list[i]; ++i)
5715- {
5716- ignore_key[ignore_key_list[i]] = TRUE;
5717- }
5718-
5719- /* Determine if display is 16/256/true color */
5720- hdc = GetDC(NULL);
5721- colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5722- paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5723- ReleaseDC(NULL, hdc);
5724-
5725- /* Initialize the colors */
5726- for (i = 0; i < 256; i++)
5727- {
5728- byte rv, gv, bv;
5729-
5730- /* Extract desired values */
5731- rv = angband_color_table[i][1];
5732- gv = angband_color_table[i][2];
5733- bv = angband_color_table[i][3];
5734-
5735- /* Extract the "complex" code */
5736- win_clr[i] = PALETTERGB(rv, gv, bv);
5737-
5738- /* Save the "simple" code */
5739- angband_color_table[i][0] = win_pal[i];
5740- }
5741-
5742- /* Prepare the windows */
5743- init_windows();
5744-
5745- /* bg */
5746- init_bg();
5747-
5748- /* Activate hooks */
5749- plog_aux = hook_plog;
5750- quit_aux = hook_quit;
5751- core_aux = hook_quit;
5752-
5753- /* Set the system suffix */
5754- ANGBAND_SYS = "win";
5755-
5756- /* Set the keyboard suffix */
5757- if (7 != GetKeyboardType(0))
5758- ANGBAND_KEYBOARD = "0";
5759- else
5760- {
5761- /* Japanese keyboard */
5762- switch (GetKeyboardType(1))
5763- {
5764- case 0x0D01: case 0x0D02:
5765- case 0x0D03: case 0x0D04:
5766- case 0x0D05: case 0x0D06:
5767- /* NEC PC-98x1 */
5768- ANGBAND_KEYBOARD = "NEC98";
5769- break;
5770- default:
5771- /* PC/AT */
5772- ANGBAND_KEYBOARD = "JAPAN";
5773- }
5774- }
5775-
5776- /* Catch nasty signals */
5777- signals_init();
5778-
5779- /* Initialize */
1+/* File: main-win.c */
2+
3+/*
4+ * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
5+ *
6+ * This software may be copied and distributed for educational, research,
7+ * and not for profit purposes provided that this copyright and statement
8+ * are included in all such copies.
9+ */
10+
11+
12+/*
13+ * This file helps Angband work with Windows computers.
14+ *
15+ * To use this file, use an appropriate "Makefile" or "Project File",
16+ * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17+ * make sure to obtain various extra files as described below.
18+ *
19+ * The official compilation uses the CodeWarrior Pro compiler, which
20+ * includes a special project file and precompilable header file.
21+ *
22+ *
23+ * See also "main-dos.c" and "main-ibm.c".
24+ *
25+ *
26+ * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27+ * and/or color redefinitions.
28+ *
29+ * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30+ * normal "lib/xtra/font/*.fon" font files.
31+ *
32+ * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33+ * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
34+ * item.
35+ *
36+ *
37+ * Compiling this file, and using the resulting executable, requires
38+ * several extra files not distributed with the standard Angband code.
39+ * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40+ * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41+ * into "lib/xtra/graf". In any case, some "*.fon" files (including
42+ * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43+ * If "USE_SOUND" is defined, then some special library (for example,
44+ * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45+ * files must be placed into "lib/xtra/sound/". All of these extra
46+ * files can be found in the "ext-win" archive.
47+ *
48+ *
49+ * The "Term_xtra_win_clear()" function should probably do a low-level
50+ * clear of the current window, and redraw the borders and other things,
51+ * if only for efficiency. XXX XXX XXX
52+ *
53+ * A simpler method is needed for selecting the "tile size" for windows.
54+ * XXX XXX XXX
55+ *
56+ * The various "warning" messages assume the existance of the "screen.w"
57+ * window, I think, and only a few calls actually check for its existance,
58+ * this may be okay since "NULL" means "on top of all windows". (?) The
59+ * user must never be allowed to "hide" the main window, or the "menubar"
60+ * will disappear. XXX XXX XXX
61+ *
62+ * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63+ * use with the "winhelp.exe" program. These files *may* be available
64+ * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
65+ *
66+ *
67+ * Initial framework (and most code) by Ben Harrison (benh@phial.com).
68+ *
69+ * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
70+ *
71+ * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72+ * and Chris R. Martin (crm7479@tam2000.tamu.edu).
73+ */
74+
75+#include "angband.h"
76+
77+#ifdef WINDOWS
78+#include <windows.h>
79+#include <direct.h>
80+#include <locale.h>
81+#include "z-term.h"
82+
83+/*
84+ * Extract the "WIN32" flag from the compiler
85+ */
86+#if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
87+# ifndef WIN32
88+# define WIN32
89+# endif
90+#endif
91+
92+
93+/*
94+ * Hack -- allow use of "screen saver" mode
95+ */
96+#define USE_SAVER
97+
98+
99+/*
100+ * Menu constants -- see "ANGBAND.RC"
101+ */
102+
103+#define IDM_FILE_NEW 100
104+#define IDM_FILE_OPEN 101
105+#define IDM_FILE_SAVE 110
106+#define IDM_FILE_SCORE 120
107+#define IDM_FILE_MOVIE 121
108+#define IDM_FILE_EXIT 130
109+
110+#define IDM_WINDOW_VIS_0 200
111+#define IDM_WINDOW_VIS_1 201
112+#define IDM_WINDOW_VIS_2 202
113+#define IDM_WINDOW_VIS_3 203
114+#define IDM_WINDOW_VIS_4 204
115+#define IDM_WINDOW_VIS_5 205
116+#define IDM_WINDOW_VIS_6 206
117+#define IDM_WINDOW_VIS_7 207
118+
119+#define IDM_WINDOW_FONT_0 210
120+#define IDM_WINDOW_FONT_1 211
121+#define IDM_WINDOW_FONT_2 212
122+#define IDM_WINDOW_FONT_3 213
123+#define IDM_WINDOW_FONT_4 214
124+#define IDM_WINDOW_FONT_5 215
125+#define IDM_WINDOW_FONT_6 216
126+#define IDM_WINDOW_FONT_7 217
127+
128+#define IDM_WINDOW_POS_0 220
129+#define IDM_WINDOW_POS_1 221
130+#define IDM_WINDOW_POS_2 222
131+#define IDM_WINDOW_POS_3 223
132+#define IDM_WINDOW_POS_4 224
133+#define IDM_WINDOW_POS_5 225
134+#define IDM_WINDOW_POS_6 226
135+#define IDM_WINDOW_POS_7 227
136+
137+#define IDM_WINDOW_BIZ_0 230
138+#define IDM_WINDOW_BIZ_1 231
139+#define IDM_WINDOW_BIZ_2 232
140+#define IDM_WINDOW_BIZ_3 233
141+#define IDM_WINDOW_BIZ_4 234
142+#define IDM_WINDOW_BIZ_5 235
143+#define IDM_WINDOW_BIZ_6 236
144+#define IDM_WINDOW_BIZ_7 237
145+
146+#define IDM_WINDOW_I_WID_0 240
147+#define IDM_WINDOW_I_WID_1 241
148+#define IDM_WINDOW_I_WID_2 242
149+#define IDM_WINDOW_I_WID_3 243
150+#define IDM_WINDOW_I_WID_4 244
151+#define IDM_WINDOW_I_WID_5 245
152+#define IDM_WINDOW_I_WID_6 246
153+#define IDM_WINDOW_I_WID_7 247
154+
155+#define IDM_WINDOW_D_WID_0 250
156+#define IDM_WINDOW_D_WID_1 251
157+#define IDM_WINDOW_D_WID_2 252
158+#define IDM_WINDOW_D_WID_3 253
159+#define IDM_WINDOW_D_WID_4 254
160+#define IDM_WINDOW_D_WID_5 255
161+#define IDM_WINDOW_D_WID_6 256
162+#define IDM_WINDOW_D_WID_7 257
163+
164+#define IDM_WINDOW_I_HGT_0 260
165+#define IDM_WINDOW_I_HGT_1 261
166+#define IDM_WINDOW_I_HGT_2 262
167+#define IDM_WINDOW_I_HGT_3 263
168+#define IDM_WINDOW_I_HGT_4 264
169+#define IDM_WINDOW_I_HGT_5 265
170+#define IDM_WINDOW_I_HGT_6 266
171+#define IDM_WINDOW_I_HGT_7 267
172+
173+#define IDM_WINDOW_D_HGT_0 270
174+#define IDM_WINDOW_D_HGT_1 271
175+#define IDM_WINDOW_D_HGT_2 272
176+#define IDM_WINDOW_D_HGT_3 273
177+#define IDM_WINDOW_D_HGT_4 274
178+#define IDM_WINDOW_D_HGT_5 275
179+#define IDM_WINDOW_D_HGT_6 276
180+#define IDM_WINDOW_D_HGT_7 277
181+
182+#define IDM_OPTIONS_NO_GRAPHICS 400
183+#define IDM_OPTIONS_OLD_GRAPHICS 401
184+#define IDM_OPTIONS_NEW_GRAPHICS 402
185+#define IDM_OPTIONS_NEW2_GRAPHICS 403
186+#define IDM_OPTIONS_BIGTILE 409
187+#define IDM_OPTIONS_SOUND 410
188+#define IDM_OPTIONS_MUSIC 411
189+#define IDM_OPTIONS_SAVER 420
190+#define IDM_OPTIONS_MAP 430
191+#define IDM_OPTIONS_BG 440
192+#define IDM_OPTIONS_OPEN_BG 441
193+
194+#define IDM_DUMP_SCREEN_HTML 450
195+
196+#define IDM_HELP_CONTENTS 901
197+
198+
199+
200+/*
201+ * This may need to be removed for some compilers XXX XXX XXX
202+ */
203+#if 0
204+#define STRICT
205+#endif
206+
207+/*
208+ * Exclude parts of WINDOWS.H that are not needed
209+ */
210+#define NOCOMM /* Comm driver APIs and definitions */
211+#define NOLOGERROR /* LogError() and related definitions */
212+#define NOPROFILER /* Profiler APIs */
213+#define NOLFILEIO /* _l* file I/O routines */
214+#define NOOPENFILE /* OpenFile and related definitions */
215+#define NORESOURCE /* Resource management */
216+#define NOATOM /* Atom management */
217+#define NOLANGUAGE /* Character test routines */
218+#define NOLSTRING /* lstr* string management routines */
219+#define NODBCS /* Double-byte character set routines */
220+#define NOKEYBOARDINFO /* Keyboard driver routines */
221+#define NOCOLOR /* COLOR_* color values */
222+#define NODRAWTEXT /* DrawText() and related definitions */
223+#define NOSCALABLEFONT /* Truetype scalable font support */
224+#define NOMETAFILE /* Metafile support */
225+#define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226+#define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227+#define NOKEYSTATES /* MK_* message key state flags */
228+#define NOWH /* SetWindowsHook and related WH_* definitions */
229+#define NOCLIPBOARD /* Clipboard APIs and definitions */
230+#define NOICONS /* IDI_* icon IDs */
231+#define NOMDI /* MDI support */
232+#define NOHELP /* Help support */
233+
234+/* Not defined since it breaks Borland C++ 5.5 */
235+/* #define NOCTLMGR */ /* Control management and controls */
236+
237+/*
238+ * Exclude parts of WINDOWS.H that are not needed (Win32)
239+ */
240+#define WIN32_LEAN_AND_MEAN
241+#define NONLS /* All NLS defines and routines */
242+#define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243+#define NOKANJI /* Kanji support stuff. */
244+#define NOMCX /* Modem Configuration Extensions */
245+
246+/*
247+ * Include the "windows" support file
248+ */
249+#include <windows.h>
250+
251+/*
252+ * Exclude parts of MMSYSTEM.H that are not needed
253+ */
254+#define MMNODRV /* Installable driver support */
255+#define MMNOWAVE /* Waveform support */
256+#define MMNOMIDI /* MIDI support */
257+#define MMNOAUX /* Auxiliary audio support */
258+#define MMNOTIMER /* Timer support */
259+#define MMNOJOY /* Joystick support */
260+#define MMNOMCI /* MCI support */
261+#define MMNOMMIO /* Multimedia file I/O support */
262+#define MMNOMMSYSTEM /* General MMSYSTEM functions */
263+
264+/*
265+ * Include some more files. Note: the Cygnus Cygwin compiler
266+ * doesn't use mmsystem.h instead it includes the winmm library
267+ * which performs a similar function.
268+ */
269+#include <mmsystem.h>
270+#include <commdlg.h>
271+
272+/*
273+ * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274+ * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
275+ */
276+/* #define HTML_HELP */
277+
278+#ifdef HTML_HELP
279+#include <htmlhelp.h>
280+#endif /* HTML_HELP */
281+
282+/*
283+ * Include the support for loading bitmaps
284+ */
285+#ifdef USE_GRAPHICS
286+# include "readdib.h"
287+#endif
288+
289+/*
290+ * Hack -- Fake declarations from "dos.h" XXX XXX XXX
291+ */
292+#ifdef WIN32
293+#define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
294+#else /* WIN32 */
295+#define FA_LABEL 0x08 /* Volume label */
296+#define FA_DIREC 0x10 /* Directory */
297+unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
298+#endif /* WIN32 */
299+
300+/*
301+ * Silliness in WIN32 drawing routine
302+ */
303+#ifdef WIN32
304+# define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
305+#endif /* WIN32 */
306+
307+/*
308+ * Silliness for Windows 95
309+ */
310+#ifndef WS_EX_TOOLWINDOW
311+# define WS_EX_TOOLWINDOW 0
312+#endif
313+
314+/*
315+ * Foreground color bits (hard-coded by DOS)
316+ */
317+#define VID_BLACK 0x00
318+#define VID_BLUE 0x01
319+#define VID_GREEN 0x02
320+#define VID_CYAN 0x03
321+#define VID_RED 0x04
322+#define VID_MAGENTA 0x05
323+#define VID_YELLOW 0x06
324+#define VID_WHITE 0x07
325+
326+/*
327+ * Bright text (hard-coded by DOS)
328+ */
329+#define VID_BRIGHT 0x08
330+
331+/*
332+ * Background color bits (hard-coded by DOS)
333+ */
334+#define VUD_BLACK 0x00
335+#define VUD_BLUE 0x10
336+#define VUD_GREEN 0x20
337+#define VUD_CYAN 0x30
338+#define VUD_RED 0x40
339+#define VUD_MAGENTA 0x50
340+#define VUD_YELLOW 0x60
341+#define VUD_WHITE 0x70
342+
343+/*
344+ * Blinking text (hard-coded by DOS)
345+ */
346+#define VUD_BRIGHT 0x80
347+
348+
349+/*
350+ * Forward declare
351+ */
352+typedef struct _term_data term_data;
353+
354+/*
355+ * Extra "term" data
356+ *
357+ * Note the use of "font_want" for the names of the font file requested by
358+ * the user, and the use of "font_file" for the currently active font file.
359+ *
360+ * The "font_file" is uppercased, and takes the form "8X13.FON", while
361+ * "font_want" can be in almost any form as long as it could be construed
362+ * as attempting to represent the name of a font.
363+ */
364+struct _term_data
365+{
366+ term t;
367+
368+ cptr s;
369+
370+ HWND w;
371+
372+ DWORD dwStyle;
373+ DWORD dwExStyle;
374+
375+ uint keys;
376+
377+ uint rows; /* int -> uint */
378+ uint cols;
379+
380+ uint pos_x;
381+ uint pos_y;
382+ uint size_wid;
383+ uint size_hgt;
384+ uint size_ow1;
385+ uint size_oh1;
386+ uint size_ow2;
387+ uint size_oh2;
388+
389+ bool size_hack;
390+
391+ bool xtra_hack;
392+
393+ bool visible;
394+
395+ bool bizarre;
396+
397+ cptr font_want;
398+
399+ cptr font_file;
400+
401+ HFONT font_id;
402+
403+ uint font_wid;
404+ uint font_hgt;
405+
406+ uint tile_wid;
407+ uint tile_hgt;
408+
409+ uint map_tile_wid;
410+ uint map_tile_hgt;
411+
412+ bool map_active;
413+#if 1 /* #ifdef JP */
414+ LOGFONT lf;
415+#endif
416+
417+ bool posfix;
418+
419+/* bg */
420+#if 0
421+ char *bgfile;
422+ int use_bg;
423+#endif
424+};
425+
426+
427+/*
428+ * Maximum number of windows XXX XXX XXX
429+ */
430+#define MAX_TERM_DATA 8
431+
432+/*
433+ * An array of term_data's
434+ */
435+static term_data data[MAX_TERM_DATA];
436+
437+/*
438+ * Hack -- global "window creation" pointer
439+ */
440+static term_data *my_td;
441+
442+/*
443+ * Remember normal size of main window when maxmized
444+ */
445+POINT normsize;
446+
447+/*
448+ * was main window maximized on previous playing
449+ */
450+bool win_maximized = FALSE;
451+
452+/*
453+ * game in progress
454+ */
455+bool game_in_progress = FALSE;
456+
457+/*
458+ * note when "open"/"new" become valid
459+ */
460+bool initialized = FALSE;
461+
462+/*
463+ * screen paletted, i.e. 256 colors
464+ */
465+bool paletted = FALSE;
466+
467+/*
468+ * 16 colors screen, don't use RGB()
469+ */
470+bool colors16 = FALSE;
471+
472+/*
473+ * Saved instance handle
474+ */
475+static HINSTANCE hInstance;
476+
477+/*
478+ * Yellow brush for the cursor
479+ */
480+static HBRUSH hbrYellow;
481+
482+/*
483+ * An icon
484+ */
485+static HICON hIcon;
486+
487+/*
488+ * A palette
489+ */
490+static HPALETTE hPal;
491+
492+/* bg */
493+static HBITMAP hBG = NULL;
494+static int use_bg = 0;
495+static char bg_bitmap_file[1024] = "bg.bmp";
496+
497+#ifdef USE_SAVER
498+
499+/*
500+ * The screen saver window
501+ */
502+static HWND hwndSaver;
503+
504+#endif /* USE_SAVER */
505+
506+
507+#ifdef USE_GRAPHICS
508+
509+/*
510+ * Flag set once "graphics" has been initialized
511+ */
512+static bool can_use_graphics = FALSE;
513+
514+/*
515+ * The global bitmap
516+ */
517+static DIBINIT infGraph;
518+
519+/*
520+ * The global bitmap mask
521+ */
522+static DIBINIT infMask;
523+
524+#endif /* USE_GRAPHICS */
525+
526+
527+#ifdef USE_SOUND
528+
529+/*
530+ * Flag set once "sound" has been initialized
531+ */
532+static bool can_use_sound = FALSE;
533+
534+#define SAMPLE_MAX 8
535+/*
536+ * An array of sound file names
537+ */
538+static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
539+
540+#endif /* USE_SOUND */
541+
542+
543+
544+#ifdef USE_MUSIC
545+
546+#define SAMPLE_MUSIC_MAX 16
547+static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548+static cptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549+static cptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550+static cptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551+static bool can_use_music = FALSE;
552+
553+static MCI_OPEN_PARMS mop;
554+static char mci_device_type[256];
555+
556+int current_music_type = 0;
557+int current_music_id = 0;
558+
559+#endif /* USE_MUSIC */
560+
561+
562+/*
563+ * Full path to ANGBAND.INI
564+ */
565+static cptr ini_file = NULL;
566+
567+/*
568+ * Name of application
569+ */
570+static cptr AppName = "ANGBAND";
571+
572+/*
573+ * Name of sub-window type
574+ */
575+static cptr AngList = "AngList";
576+
577+/*
578+ * Directory names
579+ */
580+static cptr ANGBAND_DIR_XTRA_GRAF;
581+static cptr ANGBAND_DIR_XTRA_SOUND;
582+static cptr ANGBAND_DIR_XTRA_MUSIC;
583+static cptr ANGBAND_DIR_XTRA_HELP;
584+#if 0 /* #ifndef JP */
585+static cptr ANGBAND_DIR_XTRA_FONT;
586+#endif
587+#ifdef USE_MUSIC
588+static cptr ANGBAND_DIR_XTRA_MUSIC;
589+#endif
590+
591+
592+/*
593+ * The "complex" color values
594+ */
595+static COLORREF win_clr[256];
596+
597+
598+/*
599+ * Flag for macro trigger with dump ASCII
600+ */
601+static bool Term_no_press = FALSE;
602+
603+/*
604+ * Copy and paste
605+ */
606+static bool mouse_down = FALSE;
607+static bool paint_rect = FALSE;
608+static int mousex = 0, mousey = 0;
609+static int oldx, oldy;
610+
611+
612+/*
613+ * The "simple" color values
614+ *
615+ * See "main-ibm.c" for original table information
616+ *
617+ * The entries below are taken from the "color bits" defined above.
618+ *
619+ * Note that many of the choices below suck, but so do crappy monitors.
620+ */
621+static BYTE win_pal[256] =
622+{
623+ VID_BLACK, /* Dark */
624+ VID_WHITE, /* White */
625+ VID_CYAN, /* Slate XXX */
626+ VID_RED | VID_BRIGHT, /* Orange XXX */
627+ VID_RED, /* Red */
628+ VID_GREEN, /* Green */
629+ VID_BLUE, /* Blue */
630+ VID_YELLOW, /* Umber XXX */
631+ VID_BLACK | VID_BRIGHT, /* Light Dark */
632+ VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
633+ VID_MAGENTA, /* Violet XXX */
634+ VID_YELLOW | VID_BRIGHT, /* Yellow */
635+ VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
636+ VID_GREEN | VID_BRIGHT, /* Light Green */
637+ VID_BLUE | VID_BRIGHT, /* Light Blue */
638+ VID_YELLOW /* Light Umber XXX */
639+};
640+
641+
642+/*
643+ * Hack -- define which keys are "special"
644+ */
645+static bool special_key[256];
646+static bool ignore_key[256];
647+
648+#if 1
649+/*
650+ * Hack -- initialization list for "special_key"
651+ */
652+static byte special_key_list[] = {
653+ VK_CLEAR, VK_PAUSE, VK_CAPITAL,
654+ VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
655+ VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
656+ VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
657+ VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
658+ VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
659+ VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
660+ VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
661+ VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
662+ VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
663+ VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
664+ VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
665+ VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
666+ VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
667+ VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
668+ VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
669+ VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
670+ VK_NONAME, VK_PA1,
671+ 0 /* End of List */
672+};
673+
674+static byte ignore_key_list[] = {
675+ VK_ESCAPE, VK_TAB, VK_SPACE,
676+ 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
677+ VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
678+ VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
679+ VK_LMENU, VK_RMENU,
680+ 0 /* End of List */
681+};
682+#else
683+/*
684+ * Hack -- initialization list for "special_key"
685+ *
686+ * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
687+ * and the normal keys (escape, tab, return, letters, numbers, etc), but we
688+ * catch the keypad keys (with and without numlock set, including keypad 5),
689+ * the function keys (including the "menu" key which maps to F10), and the
690+ * "pause" key (between scroll lock and numlock). We also catch a few odd
691+ * keys which I do not recognize, but which are listed among keys which we
692+ * do catch, so they should be harmless to catch.
693+ */
694+static byte special_key_list[] =
695+{
696+ VK_CLEAR, /* 0x0C (KP<5>) */
697+
698+ VK_PAUSE, /* 0x13 (pause) */
699+
700+ VK_PRIOR, /* 0x21 (KP<9>) */
701+ VK_NEXT, /* 0x22 (KP<3>) */
702+ VK_END, /* 0x23 (KP<1>) */
703+ VK_HOME, /* 0x24 (KP<7>) */
704+ VK_LEFT, /* 0x25 (KP<4>) */
705+ VK_UP, /* 0x26 (KP<8>) */
706+ VK_RIGHT, /* 0x27 (KP<6>) */
707+ VK_DOWN, /* 0x28 (KP<2>) */
708+ VK_SELECT, /* 0x29 (?????) */
709+ VK_PRINT, /* 0x2A (?????) */
710+ VK_EXECUTE, /* 0x2B (?????) */
711+ VK_SNAPSHOT, /* 0x2C (?????) */
712+ VK_INSERT, /* 0x2D (KP<0>) */
713+ VK_DELETE, /* 0x2E (KP<.>) */
714+ VK_HELP, /* 0x2F (?????) */
715+#if 0
716+ VK_NUMPAD0, /* 0x60 (KP<0>) */
717+ VK_NUMPAD1, /* 0x61 (KP<1>) */
718+ VK_NUMPAD2, /* 0x62 (KP<2>) */
719+ VK_NUMPAD3, /* 0x63 (KP<3>) */
720+ VK_NUMPAD4, /* 0x64 (KP<4>) */
721+ VK_NUMPAD5, /* 0x65 (KP<5>) */
722+ VK_NUMPAD6, /* 0x66 (KP<6>) */
723+ VK_NUMPAD7, /* 0x67 (KP<7>) */
724+ VK_NUMPAD8, /* 0x68 (KP<8>) */
725+ VK_NUMPAD9, /* 0x69 (KP<9>) */
726+ VK_MULTIPLY, /* 0x6A (KP<*>) */
727+ VK_ADD, /* 0x6B (KP<+>) */
728+ VK_SEPARATOR, /* 0x6C (?????) */
729+ VK_SUBTRACT, /* 0x6D (KP<->) */
730+ VK_DECIMAL, /* 0x6E (KP<.>) */
731+ VK_DIVIDE, /* 0x6F (KP</>) */
732+#endif
733+ VK_F1, /* 0x70 */
734+ VK_F2, /* 0x71 */
735+ VK_F3, /* 0x72 */
736+ VK_F4, /* 0x73 */
737+ VK_F5, /* 0x74 */
738+ VK_F6, /* 0x75 */
739+ VK_F7, /* 0x76 */
740+ VK_F8, /* 0x77 */
741+ VK_F9, /* 0x78 */
742+ VK_F10, /* 0x79 */
743+ VK_F11, /* 0x7A */
744+ VK_F12, /* 0x7B */
745+ VK_F13, /* 0x7C */
746+ VK_F14, /* 0x7D */
747+ VK_F15, /* 0x7E */
748+ VK_F16, /* 0x7F */
749+ VK_F17, /* 0x80 */
750+ VK_F18, /* 0x81 */
751+ VK_F19, /* 0x82 */
752+ VK_F20, /* 0x83 */
753+ VK_F21, /* 0x84 */
754+ VK_F22, /* 0x85 */
755+ VK_F23, /* 0x86 */
756+ VK_F24, /* 0x87 */
757+ 0
758+};
759+#endif
760+
761+/* bg */
762+static void delete_bg(void)
763+{
764+ if (hBG != NULL)
765+ {
766+ DeleteObject(hBG);
767+ hBG = NULL;
768+ }
769+}
770+
771+static int init_bg(void)
772+{
773+ char * bmfile = bg_bitmap_file;
774+
775+ delete_bg();
776+ if (use_bg == 0) return 0;
777+
778+ hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
779+ if (!hBG) {
780+ plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
781+ use_bg = 0;
782+ return 0;
783+ }
784+#if 0 /* gomi */
785+ HDC wnddc, dcimage, dcbg;
786+ HBITMAP bmimage, bmimage_old, bmbg_old;
787+ int i, j;
788+
789+ delete_bg();
790+
791+ wnddc = GetDC(hwnd);
792+ dcimage = CreateCompatibleDC(wnddc);
793+ dcbg = CreateCompatibleDC(wnddc);
794+
795+ bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
796+ if (!bmimage) quit("bg.bmpが読みこめない!");
797+ bmimage_old = SelectObject(dcimage, bmimage);
798+
799+ CreateCompatibleBitmap();
800+
801+ ReleaseDC(hwnd, wnddc);
802+#endif
803+ use_bg = 1;
804+ return 1;
805+}
806+
807+static void DrawBG(HDC hdc, RECT *r)
808+{
809+ HDC hdcSrc;
810+ HBITMAP hOld;
811+ BITMAP bm;
812+ int x = r->left, y = r->top;
813+ int nx, ny, sx, sy, swid, shgt, cwid, chgt;
814+
815+ if (!use_bg || !hBG)
816+ return;
817+
818+ nx = x; ny = y;
819+ GetObject(hBG, sizeof(bm), &bm);
820+ swid = bm.bmWidth; shgt = bm.bmHeight;
821+
822+ hdcSrc = CreateCompatibleDC(hdc);
823+ hOld = SelectObject(hdcSrc, hBG);
824+
825+ do {
826+ sx = nx % swid;
827+ cwid = MIN(swid - sx, r->right - nx);
828+ do {
829+ sy = ny % shgt;
830+ chgt = MIN(shgt - sy, r->bottom - ny);
831+ BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
832+ ny += chgt;
833+ } while (ny < r->bottom);
834+ ny = y;
835+ nx += cwid;
836+ } while (nx < r->right);
837+
838+ SelectObject(hdcSrc, hOld);
839+ DeleteDC(hdcSrc);
840+}
841+
842+#if 0
843+/*
844+ * Hack -- given a pathname, point at the filename
845+ */
846+static cptr extract_file_name(cptr s)
847+{
848+ cptr p;
849+
850+ /* Start at the end */
851+ p = s + strlen(s) - 1;
852+
853+ /* Back up to divider */
854+ while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
855+
856+ /* Return file name */
857+ return (p+1);
858+}
859+#endif
860+
861+
862+/*
863+ * Hack -- given a simple filename, extract the "font size" info
864+ *
865+ * Return a pointer to a static buffer holding the capitalized base name.
866+ */
867+#if 0 /* #ifndef JP */
868+static char *analyze_font(char *path, int *wp, int *hp)
869+{
870+ int wid, hgt;
871+
872+ char *s, *p;
873+
874+ /* Start at the end */
875+ p = path + strlen(path) - 1;
876+
877+ /* Back up to divider */
878+ while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
879+
880+ /* Advance to file name */
881+ ++p;
882+
883+ /* Capitalize */
884+ for (s = p; *s; ++s)
885+ {
886+ /* Capitalize (be paranoid) */
887+ if (islower(*s)) *s = toupper(*s);
888+ }
889+
890+ /* Find first 'X' */
891+ s = my_strchr(p, 'X');
892+
893+ /* Extract font width */
894+ wid = atoi(p);
895+
896+ /* Extract height */
897+ hgt = s ? atoi(s+1) : 0;
898+
899+ /* Save results */
900+ (*wp) = wid;
901+ (*hp) = hgt;
902+
903+ /* Result */
904+ return (p);
905+}
906+#endif
907+
908+
909+/*
910+ * Check for existance of a file
911+ */
912+static bool check_file(cptr s)
913+{
914+ char path[1024];
915+
916+#ifdef WIN32
917+
918+ DWORD attrib;
919+
920+#else /* WIN32 */
921+
922+ unsigned int attrib;
923+
924+#endif /* WIN32 */
925+
926+ /* Copy it */
927+ strcpy(path, s);
928+
929+#ifdef WIN32
930+
931+ /* Examine */
932+ attrib = GetFileAttributes(path);
933+
934+ /* Require valid filename */
935+ if (attrib == INVALID_FILE_NAME) return (FALSE);
936+
937+ /* Prohibit directory */
938+ if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
939+
940+#else /* WIN32 */
941+
942+ /* Examine and verify */
943+ if (_dos_getfileattr(path, &attrib)) return (FALSE);
944+
945+ /* Prohibit something */
946+ if (attrib & FA_LABEL) return (FALSE);
947+
948+ /* Prohibit directory */
949+ if (attrib & FA_DIREC) return (FALSE);
950+
951+#endif /* WIN32 */
952+
953+ /* Success */
954+ return (TRUE);
955+}
956+
957+
958+/*
959+ * Check for existance of a directory
960+ */
961+static bool check_dir(cptr s)
962+{
963+ int i;
964+
965+ char path[1024];
966+
967+#ifdef WIN32
968+
969+ DWORD attrib;
970+
971+#else /* WIN32 */
972+
973+ unsigned int attrib;
974+
975+#endif /* WIN32 */
976+
977+ /* Copy it */
978+ strcpy(path, s);
979+
980+ /* Check length */
981+ i = strlen(path);
982+
983+ /* Remove trailing backslash */
984+ if (i && (path[i-1] == '\\')) path[--i] = '\0';
985+
986+#ifdef WIN32
987+
988+ /* Examine */
989+ attrib = GetFileAttributes(path);
990+
991+ /* Require valid filename */
992+ if (attrib == INVALID_FILE_NAME) return (FALSE);
993+
994+ /* Require directory */
995+ if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
996+
997+#else /* WIN32 */
998+
999+ /* Examine and verify */
1000+ if (_dos_getfileattr(path, &attrib)) return (FALSE);
1001+
1002+ /* Prohibit something */
1003+ if (attrib & FA_LABEL) return (FALSE);
1004+
1005+ /* Require directory */
1006+ if (!(attrib & FA_DIREC)) return (FALSE);
1007+
1008+#endif /* WIN32 */
1009+
1010+ /* Success */
1011+ return (TRUE);
1012+}
1013+
1014+
1015+/*
1016+ * Validate a file
1017+ */
1018+static void validate_file(cptr s)
1019+{
1020+ /* Verify or fail */
1021+ if (!check_file(s))
1022+ {
1023+ quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1024+ }
1025+}
1026+
1027+
1028+/*
1029+ * Validate a directory
1030+ */
1031+static void validate_dir(cptr s, bool vital)
1032+{
1033+ /* Verify or fail */
1034+ if (!check_dir(s))
1035+ {
1036+ /* This directory contains needed data */
1037+ if (vital)
1038+ {
1039+ quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1040+ }
1041+ /* Attempt to create this directory */
1042+ else if (mkdir(s))
1043+ {
1044+ quit_fmt("Unable to create directory:\n%s", s);
1045+ }
1046+ }
1047+}
1048+
1049+
1050+/*
1051+ * Get the "size" for a window
1052+ */
1053+static void term_getsize(term_data *td)
1054+{
1055+ RECT rc;
1056+
1057+ int wid, hgt;
1058+
1059+ /* Paranoia */
1060+ if (td->cols < 1) td->cols = 1;
1061+ if (td->rows < 1) td->rows = 1;
1062+
1063+ /* Window sizes */
1064+ wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1065+ hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1066+
1067+ /* Fake window size */
1068+ rc.left = 0;
1069+ rc.right = rc.left + wid;
1070+ rc.top = 0;
1071+ rc.bottom = rc.top + hgt;
1072+
1073+ /* XXX XXX XXX */
1074+ /* rc.right += 1; */
1075+ /* rc.bottom += 1; */
1076+
1077+ /* Adjust */
1078+ AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1079+
1080+ /* Total size */
1081+ td->size_wid = rc.right - rc.left;
1082+ td->size_hgt = rc.bottom - rc.top;
1083+
1084+ /* See CreateWindowEx */
1085+ if (!td->w) return;
1086+
1087+ /* Extract actual location */
1088+ GetWindowRect(td->w, &rc);
1089+
1090+ /* Save the location */
1091+ td->pos_x = rc.left;
1092+ td->pos_y = rc.top;
1093+}
1094+
1095+
1096+/*
1097+ * Write the "prefs" for a single term
1098+ */
1099+static void save_prefs_aux(int i)
1100+{
1101+ term_data *td = &data[i];
1102+ char sec_name[128];
1103+ char buf[1024];
1104+
1105+ RECT rc;
1106+ WINDOWPLACEMENT lpwndpl;
1107+
1108+ /* Paranoia */
1109+ if (!td->w) return;
1110+
1111+ /* Make section name */
1112+ sprintf(sec_name, "Term-%d", i);
1113+
1114+ /* Visible */
1115+ if (i > 0)
1116+ {
1117+ strcpy(buf, td->visible ? "1" : "0");
1118+ WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1119+ }
1120+
1121+ /* Font */
1122+#ifdef JP
1123+ strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1124+#else
1125+#if 0
1126+ strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1127+#else
1128+ strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1129+#endif
1130+#endif
1131+
1132+ WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1133+
1134+#if 1 /* #ifdef JP */
1135+ wsprintf(buf, "%d", td->lf.lfWidth);
1136+ WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1137+ wsprintf(buf, "%d", td->lf.lfHeight);
1138+ WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1139+ wsprintf(buf, "%d", td->lf.lfWeight);
1140+ WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1141+#endif
1142+ /* Bizarre */
1143+ strcpy(buf, td->bizarre ? "1" : "0");
1144+ WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1145+
1146+ /* Tile size (x) */
1147+ wsprintf(buf, "%d", td->tile_wid);
1148+ WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1149+
1150+ /* Tile size (y) */
1151+ wsprintf(buf, "%d", td->tile_hgt);
1152+ WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1153+
1154+ /* Get window placement and dimensions */
1155+ lpwndpl.length = sizeof(WINDOWPLACEMENT);
1156+ GetWindowPlacement(td->w, &lpwndpl);
1157+
1158+ /* Acquire position in *normal* mode (not minimized) */
1159+ rc = lpwndpl.rcNormalPosition;
1160+
1161+ /* Window size (x) */
1162+ if (i == 0) wsprintf(buf, "%d", normsize.x);
1163+ else wsprintf(buf, "%d", td->cols);
1164+ WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1165+
1166+ /* Window size (y) */
1167+ if (i == 0) wsprintf(buf, "%d", normsize.y);
1168+ else wsprintf(buf, "%d", td->rows);
1169+ WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1170+
1171+ /* Maxmized (only main window) */
1172+ if (i == 0)
1173+ {
1174+ strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1175+ WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1176+ }
1177+
1178+ /* Acquire position */
1179+ GetWindowRect(td->w, &rc);
1180+
1181+ /* Window position (x) */
1182+ wsprintf(buf, "%d", rc.left);
1183+ WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1184+
1185+ /* Window position (y) */
1186+ wsprintf(buf, "%d", rc.top);
1187+ WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1188+
1189+ /* Window Z position */
1190+ if (i > 0)
1191+ {
1192+ strcpy(buf, td->posfix ? "1" : "0");
1193+ WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1194+ }
1195+}
1196+
1197+
1198+/*
1199+ * Write the "prefs"
1200+ *
1201+ * We assume that the windows have all been initialized
1202+ */
1203+static void save_prefs(void)
1204+{
1205+ int i;
1206+
1207+ char buf[128];
1208+
1209+ /* Save the "arg_graphics" flag */
1210+ sprintf(buf, "%d", arg_graphics);
1211+ WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1212+
1213+ /* Save the "arg_bigtile" flag */
1214+ strcpy(buf, arg_bigtile ? "1" : "0");
1215+ WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1216+
1217+ /* Save the "arg_sound" flag */
1218+ strcpy(buf, arg_sound ? "1" : "0");
1219+ WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1220+
1221+ /* Save the "arg_sound" flag */
1222+ strcpy(buf, arg_music ? "1" : "0");
1223+ WritePrivateProfileString("Angband", "Music", buf, ini_file);
1224+
1225+ /* bg */
1226+ strcpy(buf, use_bg ? "1" : "0");
1227+ WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1228+ WritePrivateProfileString("Angband", "BackGroundBitmap",
1229+ bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1230+
1231+ /* Save window prefs */
1232+ for (i = 0; i < MAX_TERM_DATA; ++i)
1233+ {
1234+ save_prefs_aux(i);
1235+ }
1236+}
1237+
1238+
1239+/*
1240+ * Load the "prefs" for a single term
1241+ */
1242+static void load_prefs_aux(int i)
1243+{
1244+ term_data *td = &data[i];
1245+ char sec_name[128];
1246+ char tmp[1024];
1247+
1248+ int wid, hgt, posx, posy;
1249+ int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1250+ int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1251+ posx=0;
1252+ posy=0;
1253+
1254+ /* Make section name */
1255+ sprintf(sec_name, "Term-%d", i);
1256+
1257+ /* Make section name */
1258+ sprintf(sec_name, "Term-%d", i);
1259+
1260+ /* Visible */
1261+ if (i > 0)
1262+ {
1263+ td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1264+ }
1265+
1266+ /* Desired font, with default */
1267+#ifdef JP
1268+ GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1269+#else
1270+#if 0
1271+ GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1272+#else
1273+ GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1274+#endif
1275+#endif
1276+
1277+
1278+ /* Bizarre */
1279+ td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1280+
1281+ /* Analyze font, save desired font name */
1282+#if 1 /* #ifdef JP */
1283+ td->font_want = string_make(tmp);
1284+ hgt = 15; wid = 0;
1285+ td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1286+ td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1287+ td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1288+#else
1289+ td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1290+#endif
1291+
1292+
1293+ /* Tile size */
1294+#if 1 /* #ifdef JP */
1295+ td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1296+ td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1297+#else
1298+ td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1299+ td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1300+#endif
1301+
1302+
1303+ /* Window size */
1304+ td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1305+ td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1306+ normsize.x = td->cols; normsize.y = td->rows;
1307+
1308+ /* Window size */
1309+ if (i == 0)
1310+ {
1311+ win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1312+ }
1313+
1314+ /* Window position */
1315+ posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1316+ posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1317+ td->pos_x = MIN(MAX(0, posx), dispx-128);
1318+ td->pos_y = MIN(MAX(0, posy), dispy-128);
1319+
1320+ /* Window Z position */
1321+ if (i > 0)
1322+ {
1323+ td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1324+ }
1325+}
1326+
1327+
1328+/*
1329+ * Load the "prefs"
1330+ */
1331+static void load_prefs(void)
1332+{
1333+ int i;
1334+
1335+ /* Extract the "arg_graphics" flag */
1336+ arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1337+
1338+ /* Extract the "arg_bigtile" flag */
1339+ arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1340+ use_bigtile = arg_bigtile;
1341+
1342+ /* Extract the "arg_sound" flag */
1343+ arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1344+
1345+ /* Extract the "arg_sound" flag */
1346+ arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1347+
1348+ /* bg */
1349+ use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1350+ GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1351+
1352+ /* Load window prefs */
1353+ for (i = 0; i < MAX_TERM_DATA; ++i)
1354+ {
1355+ load_prefs_aux(i);
1356+ }
1357+}
1358+
1359+#if defined(USE_SOUND) || defined(USE_MUSIC)
1360+
1361+/*
1362+ * XXX XXX XXX - Taken from files.c.
1363+ *
1364+ * Extract "tokens" from a buffer
1365+ *
1366+ * This function uses "whitespace" as delimiters, and treats any amount of
1367+ * whitespace as a single delimiter. We will never return any empty tokens.
1368+ * When given an empty buffer, or a buffer containing only "whitespace", we
1369+ * will return no tokens. We will never extract more than "num" tokens.
1370+ *
1371+ * By running a token through the "text_to_ascii()" function, you can allow
1372+ * that token to include (encoded) whitespace, using "\s" to encode spaces.
1373+ *
1374+ * We save pointers to the tokens in "tokens", and return the number found.
1375+ */
1376+static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1377+{
1378+ int k = 0;
1379+
1380+ char *s = buf;
1381+
1382+
1383+ /* Process */
1384+ while (k < num)
1385+ {
1386+ char *t;
1387+
1388+ /* Skip leading whitespace */
1389+ for ( ; *s && iswspace(*s); ++s) /* loop */;
1390+
1391+ /* All done */
1392+ if (!*s) break;
1393+
1394+ /* Find next whitespace, if any */
1395+ for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1396+
1397+ /* Nuke and advance (if necessary) */
1398+ if (*t) *t++ = '\0';
1399+
1400+ /* Save the token */
1401+ tokens[k++] = s;
1402+
1403+ /* Advance */
1404+ s = t;
1405+ }
1406+
1407+ /* Count */
1408+ return (k);
1409+}
1410+
1411+#endif /* USE_SOUND || USE_MUSIC */
1412+
1413+#ifdef USE_SOUND
1414+
1415+static void load_sound_prefs(void)
1416+{
1417+ int i, j, num;
1418+ char tmp[1024];
1419+ char ini_path[1024];
1420+ char wav_path[1024];
1421+ char *zz[SAMPLE_MAX];
1422+
1423+ /* Access the sound.cfg */
1424+
1425+ path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1426+
1427+ for (i = 0; i < SOUND_MAX; i++)
1428+ {
1429+ GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1430+
1431+ num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1432+
1433+ for (j = 0; j < num; j++)
1434+ {
1435+ /* Access the sound */
1436+ path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1437+
1438+ /* Save the sound filename, if it exists */
1439+ if (check_file(wav_path))
1440+ sound_file[i][j] = string_make(zz[j]);
1441+ }
1442+ }
1443+}
1444+
1445+#endif /* USE_SOUND */
1446+
1447+#ifdef USE_MUSIC
1448+
1449+static void load_music_prefs(void)
1450+{
1451+ int i, j, num;
1452+ char tmp[1024];
1453+ char ini_path[1024];
1454+ char wav_path[1024];
1455+ char *zz[SAMPLE_MAX];
1456+ char key[80];
1457+
1458+ /* Access the music.cfg */
1459+
1460+ path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1461+
1462+ GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1463+
1464+ for (i = 0; i < MUSIC_BASIC_MAX; i++)
1465+ {
1466+ GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1467+
1468+ num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1469+
1470+ for (j = 0; j < num; j++)
1471+ {
1472+ /* Access the sound */
1473+ path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1474+
1475+ /* Save the sound filename, if it exists */
1476+ if (check_file(wav_path))
1477+ music_file[i][j] = string_make(zz[j]);
1478+ }
1479+ }
1480+
1481+ for (i = 0; i < max_d_idx; i++)
1482+ {
1483+ sprintf(key, "dungeon%03d", i);
1484+ GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1485+
1486+ num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1487+
1488+ for (j = 0; j < num; j++)
1489+ {
1490+ /* Access the sound */
1491+ path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1492+
1493+ /* Save the sound filename, if it exists */
1494+ if (check_file(wav_path))
1495+ dungeon_music_file[i][j] = string_make(zz[j]);
1496+ }
1497+ }
1498+
1499+ for (i = 0; i < 1000; i++) /*!< @todo クエスト最大数指定 */
1500+ {
1501+ sprintf(key, "quest%03d", i);
1502+ GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1503+
1504+ num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1505+
1506+ for (j = 0; j < num; j++)
1507+ {
1508+ /* Access the sound */
1509+ path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1510+
1511+ /* Save the sound filename, if it exists */
1512+ if (check_file(wav_path))
1513+ quest_music_file[i][j] = string_make(zz[j]);
1514+ }
1515+ }
1516+
1517+ for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1518+ {
1519+ sprintf(key, "town%03d", i);
1520+ GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1521+
1522+ num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1523+
1524+ for (j = 0; j < num; j++)
1525+ {
1526+ /* Access the sound */
1527+ path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1528+
1529+ /* Save the sound filename, if it exists */
1530+ if (check_file(wav_path))
1531+ town_music_file[i][j] = string_make(zz[j]);
1532+ }
1533+ }
1534+
1535+
1536+}
1537+
1538+#endif /* USE_MUSIC */
1539+
1540+/*
1541+ * Create the new global palette based on the bitmap palette
1542+ * (if any), and the standard 16 entry palette derived from
1543+ * "win_clr[]" which is used for the basic 16 Angband colors.
1544+ *
1545+ * This function is never called before all windows are ready.
1546+ *
1547+ * This function returns FALSE if the new palette could not be
1548+ * prepared, which should normally be a fatal error. XXX XXX
1549+ *
1550+ * Note that only some machines actually use a "palette".
1551+ */
1552+static int new_palette(void)
1553+{
1554+ HPALETTE hBmPal;
1555+ HPALETTE hNewPal;
1556+ HDC hdc;
1557+ int i, nEntries;
1558+ int pLogPalSize;
1559+ int lppeSize;
1560+ LPLOGPALETTE pLogPal;
1561+ LPPALETTEENTRY lppe;
1562+
1563+ term_data *td;
1564+
1565+
1566+ /* This makes no sense */
1567+ if (!paletted) return (TRUE);
1568+
1569+
1570+ /* No bitmap */
1571+ lppeSize = 0;
1572+ lppe = NULL;
1573+ nEntries = 0;
1574+
1575+#ifdef USE_GRAPHICS
1576+
1577+ /* Check the bitmap palette */
1578+ hBmPal = infGraph.hPalette;
1579+
1580+ /* Use the bitmap */
1581+ if (hBmPal)
1582+ {
1583+ lppeSize = 256 * sizeof(PALETTEENTRY);
1584+ lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1585+ nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1586+ if ((nEntries == 0) || (nEntries > 220))
1587+ {
1588+ /* Warn the user */
1589+ plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1590+
1591+ /* Cleanup */
1592+ rnfree(lppe, lppeSize);
1593+
1594+ /* Fail */
1595+ return (FALSE);
1596+ }
1597+ }
1598+
1599+#endif /* USE_GRAPHICS */
1600+
1601+ /* Size of palette */
1602+ pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1603+
1604+ /* Allocate palette */
1605+ pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1606+
1607+ /* Version */
1608+ pLogPal->palVersion = 0x300;
1609+
1610+ /* Make room for bitmap and normal data */
1611+ pLogPal->palNumEntries = nEntries + 16;
1612+
1613+ /* Save the bitmap data */
1614+ for (i = 0; i < nEntries; i++)
1615+ {
1616+ pLogPal->palPalEntry[i] = lppe[i];
1617+ }
1618+
1619+ /* Save the normal data */
1620+ for (i = 0; i < 16; i++)
1621+ {
1622+ LPPALETTEENTRY p;
1623+
1624+ /* Access the entry */
1625+ p = &(pLogPal->palPalEntry[i+nEntries]);
1626+
1627+ /* Save the colors */
1628+ p->peRed = GetRValue(win_clr[i]);
1629+ p->peGreen = GetGValue(win_clr[i]);
1630+ p->peBlue = GetBValue(win_clr[i]);
1631+
1632+ /* Save the flags */
1633+ p->peFlags = PC_NOCOLLAPSE;
1634+ }
1635+
1636+ /* Free something */
1637+ if (lppe) rnfree(lppe, lppeSize);
1638+
1639+ /* Create a new palette, or fail */
1640+ hNewPal = CreatePalette(pLogPal);
1641+ if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1642+
1643+ /* Free the palette */
1644+ rnfree(pLogPal, pLogPalSize);
1645+
1646+ /* Main window */
1647+ td = &data[0];
1648+
1649+ /* Realize the palette */
1650+ hdc = GetDC(td->w);
1651+ SelectPalette(hdc, hNewPal, 0);
1652+ i = RealizePalette(hdc);
1653+ ReleaseDC(td->w, hdc);
1654+ if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1655+
1656+
1657+ /* Sub-windows */
1658+ for (i = 1; i < MAX_TERM_DATA; i++)
1659+ {
1660+ td = &data[i];
1661+
1662+ hdc = GetDC(td->w);
1663+ SelectPalette(hdc, hNewPal, 0);
1664+ ReleaseDC(td->w, hdc);
1665+ }
1666+
1667+ /* Delete old palette */
1668+ if (hPal) DeleteObject(hPal);
1669+
1670+ /* Save new palette */
1671+ hPal = hNewPal;
1672+
1673+ /* Success */
1674+ return (TRUE);
1675+}
1676+
1677+
1678+#ifdef USE_GRAPHICS
1679+/*
1680+ * Initialize graphics
1681+ */
1682+static bool init_graphics(void)
1683+{
1684+ /* Initialize once */
1685+ /* if (can_use_graphics != arg_graphics) */
1686+ {
1687+ char buf[1024];
1688+ int wid, hgt, twid, thgt, ox, oy;
1689+ cptr name;
1690+
1691+ if (arg_graphics == GRAPHICS_ADAM_BOLT)
1692+ {
1693+ wid = 16;
1694+ hgt = 16;
1695+ twid = 16;
1696+ thgt = 16;
1697+ ox = 0;
1698+ oy = 0;
1699+ name = "16X16.BMP";
1700+
1701+ ANGBAND_GRAF = "new";
1702+ }
1703+ else if (arg_graphics == GRAPHICS_HENGBAND)
1704+ {
1705+ /*! @todo redraw
1706+ wid = 64;
1707+ hgt = 64;
1708+ twid = 32;
1709+ thgt = 32;
1710+ ox = -16;
1711+ oy = -24;
1712+ name = "64X64.BMP";
1713+ */
1714+
1715+ wid = 32;
1716+ hgt = 32;
1717+ twid = 32;
1718+ thgt = 32;
1719+ ox = 0;
1720+ oy = 0;
1721+ name = "32X32.BMP";
1722+
1723+ ANGBAND_GRAF = "ne2";
1724+ }
1725+ else
1726+ {
1727+ wid = 8;
1728+ hgt = 8;
1729+ twid = 8;
1730+ thgt = 8;
1731+ ox = 0;
1732+ oy = 0;
1733+ name = "8X8.BMP";
1734+ ANGBAND_GRAF = "old";
1735+ }
1736+
1737+ /* Access the bitmap file */
1738+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1739+
1740+ /* Load the bitmap or quit */
1741+ if (!ReadDIB(data[0].w, buf, &infGraph))
1742+ {
1743+ plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1744+ return (FALSE);
1745+ }
1746+
1747+ /* Save the new sizes */
1748+ infGraph.CellWidth = wid;
1749+ infGraph.CellHeight = hgt;
1750+ infGraph.TileWidth = twid;
1751+ infGraph.TileHeight = thgt;
1752+ infGraph.OffsetX = ox;
1753+ infGraph.OffsetY = oy;
1754+
1755+ if (arg_graphics == GRAPHICS_ADAM_BOLT)
1756+ {
1757+ /* Access the mask file */
1758+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1759+
1760+ /* Load the bitmap or quit */
1761+ if (!ReadDIB(data[0].w, buf, &infMask))
1762+ {
1763+ plog_fmt("Cannot read bitmap file '%s'", buf);
1764+ return (FALSE);
1765+ }
1766+ }
1767+ if (arg_graphics == GRAPHICS_HENGBAND)
1768+ {
1769+ /* Access the mask file */
1770+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1771+
1772+ /* Load the bitmap or quit */
1773+ if (!ReadDIB(data[0].w, buf, &infMask))
1774+ {
1775+ plog_fmt("Cannot read bitmap file '%s'", buf);
1776+ return (FALSE);
1777+ }
1778+ }
1779+
1780+ /* Activate a palette */
1781+ if (!new_palette())
1782+ {
1783+ /* Free bitmap XXX XXX XXX */
1784+
1785+ /* Oops */
1786+ plog(_("パレットを実現できません!", "Cannot activate palette!"));
1787+ return (FALSE);
1788+ }
1789+
1790+ /* Graphics available */
1791+ can_use_graphics = arg_graphics;
1792+ }
1793+
1794+ /* Result */
1795+ return (can_use_graphics);
1796+}
1797+#endif /* USE_GRAPHICS */
1798+
1799+
1800+#ifdef USE_MUSIC
1801+/*
1802+ * Initialize music
1803+ */
1804+static bool init_music(void)
1805+{
1806+ /* Initialize once */
1807+ if (!can_use_music)
1808+ {
1809+ /* Load the prefs */
1810+ load_music_prefs();
1811+
1812+ /* Sound available */
1813+ can_use_music = TRUE;
1814+ }
1815+
1816+ /* Result */
1817+ return (can_use_music);
1818+}
1819+
1820+/*
1821+ * Hack -- Stop a music
1822+ */
1823+static void stop_music(void)
1824+{
1825+ mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1826+ mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1827+}
1828+
1829+#endif /* USE_MUSIC */
1830+
1831+#ifdef USE_SOUND
1832+/*
1833+ * Initialize sound
1834+ */
1835+static bool init_sound(void)
1836+{
1837+ /* Initialize once */
1838+ if (!can_use_sound)
1839+ {
1840+ /* Load the prefs */
1841+ load_sound_prefs();
1842+
1843+ /* Sound available */
1844+ can_use_sound = TRUE;
1845+ }
1846+
1847+ /* Result */
1848+ return (can_use_sound);
1849+}
1850+#endif /* USE_SOUND */
1851+
1852+
1853+/*
1854+ * Resize a window
1855+ */
1856+static void term_window_resize(term_data *td)
1857+{
1858+ /* Require window */
1859+ if (!td->w) return;
1860+
1861+ /* Resize the window */
1862+ SetWindowPos(td->w, 0, 0, 0,
1863+ td->size_wid, td->size_hgt,
1864+ SWP_NOMOVE | SWP_NOZORDER);
1865+
1866+ /* Redraw later */
1867+ InvalidateRect(td->w, NULL, TRUE);
1868+}
1869+
1870+
1871+/*
1872+ * Force the use of a new "font file" for a term_data
1873+ *
1874+ * This function may be called before the "window" is ready
1875+ *
1876+ * This function returns zero only if everything succeeds.
1877+ *
1878+ * Note that the "font name" must be capitalized!!!
1879+ */
1880+static errr term_force_font(term_data *td, cptr path)
1881+{
1882+ int wid, hgt;
1883+
1884+#if 0 /* #ifndef JP */
1885+ int i;
1886+ char *base;
1887+ char buf[1024];
1888+#endif
1889+
1890+ /* Forget the old font (if needed) */
1891+ if (td->font_id) DeleteObject(td->font_id);
1892+
1893+#if 1 /* #ifdef JP */
1894+ /* Unused */
1895+ (void)path;
1896+
1897+ /* Create the font (using the 'base' of the font file name!) */
1898+ td->font_id = CreateFontIndirect(&(td->lf));
1899+ wid = td->lf.lfWidth;
1900+ hgt = td->lf.lfHeight;
1901+ if (!td->font_id) return (1);
1902+#else
1903+ /* Forget old font */
1904+ if (td->font_file)
1905+ {
1906+ bool used = FALSE;
1907+
1908+ /* Scan windows */
1909+ for (i = 0; i < MAX_TERM_DATA; i++)
1910+ {
1911+ /* Don't check when closing the application */
1912+ if (!path) break;
1913+
1914+ /* Check "screen" */
1915+ if ((td != &data[i]) &&
1916+ (data[i].font_file) &&
1917+ (streq(data[i].font_file, td->font_file)))
1918+ {
1919+ used = TRUE;
1920+ }
1921+ }
1922+
1923+ /* Remove unused font resources */
1924+ if (!used) RemoveFontResource(td->font_file);
1925+
1926+ /* Free the old name */
1927+ string_free(td->font_file);
1928+
1929+ /* Forget it */
1930+ td->font_file = NULL;
1931+ }
1932+
1933+ /* No path given */
1934+ if (!path) return (1);
1935+
1936+ /* Local copy */
1937+ strcpy(buf, path);
1938+
1939+ /* Analyze font path */
1940+ base = analyze_font(buf, &wid, &hgt);
1941+
1942+ /* Verify suffix */
1943+ if (!suffix(base, ".FON")) return (1);
1944+
1945+ /* Verify file */
1946+ if (!check_file(buf)) return (1);
1947+
1948+ /* Load the new font */
1949+ if (!AddFontResource(buf)) return (1);
1950+
1951+ /* Save new font name */
1952+ td->font_file = string_make(base);
1953+
1954+ /* Remove the "suffix" */
1955+ base[strlen(base)-4] = '\0';
1956+
1957+ /* Create the font (using the 'base' of the font file name!) */
1958+ td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1959+ ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1960+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1961+ FIXED_PITCH | FF_DONTCARE, base);
1962+#endif
1963+
1964+ /* Hack -- Unknown size */
1965+ if (!wid || !hgt)
1966+ {
1967+ HDC hdcDesktop;
1968+ HFONT hfOld;
1969+ TEXTMETRIC tm;
1970+
1971+ /* all this trouble to get the cell size */
1972+ hdcDesktop = GetDC(HWND_DESKTOP);
1973+ hfOld = SelectObject(hdcDesktop, td->font_id);
1974+ GetTextMetrics(hdcDesktop, &tm);
1975+ SelectObject(hdcDesktop, hfOld);
1976+ ReleaseDC(HWND_DESKTOP, hdcDesktop);
1977+
1978+ /* Font size info */
1979+ wid = tm.tmAveCharWidth;
1980+ hgt = tm.tmHeight;
1981+ }
1982+
1983+ /* Save the size info */
1984+ td->font_wid = wid;
1985+ td->font_hgt = hgt;
1986+
1987+ /* Success */
1988+ return (0);
1989+}
1990+
1991+
1992+
1993+/*
1994+ * Allow the user to change the font for this window.
1995+ */
1996+static void term_change_font(term_data *td)
1997+{
1998+#if 1 /* #ifdef JP */
1999+ CHOOSEFONT cf;
2000+
2001+ memset(&cf, 0, sizeof(cf));
2002+ cf.lStructSize = sizeof(cf);
2003+ cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2004+ cf.lpLogFont = &(td->lf);
2005+
2006+ if (ChooseFont(&cf))
2007+ {
2008+ /* Force the font */
2009+ term_force_font(td, NULL);
2010+
2011+ /* Assume not bizarre */
2012+ td->bizarre = TRUE;
2013+
2014+ /* Reset the tile info */
2015+ td->tile_wid = td->font_wid;
2016+ td->tile_hgt = td->font_hgt;
2017+
2018+ /* Analyze the font */
2019+ term_getsize(td);
2020+
2021+ /* Resize the window */
2022+ term_window_resize(td);
2023+ }
2024+
2025+#else
2026+ OPENFILENAME ofn;
2027+
2028+ char tmp[1024] = "";
2029+
2030+ /* Extract a default if possible */
2031+ if (td->font_file) strcpy(tmp, td->font_file);
2032+
2033+ /* Ask for a choice */
2034+ memset(&ofn, 0, sizeof(ofn));
2035+ ofn.lStructSize = sizeof(ofn);
2036+ ofn.hwndOwner = data[0].w;
2037+ ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2038+ ofn.nFilterIndex = 1;
2039+ ofn.lpstrFile = tmp;
2040+ ofn.nMaxFile = 128;
2041+ ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2042+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2043+ ofn.lpstrDefExt = "fon";
2044+
2045+ /* Force choice if legal */
2046+ if (GetOpenFileName(&ofn))
2047+ {
2048+ /* Force the font */
2049+ if (term_force_font(td, tmp))
2050+ {
2051+ /* Access the standard font file */
2052+ path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2053+
2054+ /* Force the use of that font */
2055+ (void)term_force_font(td, tmp);
2056+ }
2057+
2058+ /* Assume not bizarre */
2059+ td->bizarre = FALSE;
2060+
2061+ /* Reset the tile info */
2062+ td->tile_wid = td->font_wid;
2063+ td->tile_hgt = td->font_hgt;
2064+
2065+ /* Analyze the font */
2066+ term_getsize(td);
2067+
2068+ /* Resize the window */
2069+ term_window_resize(td);
2070+ }
2071+#endif
2072+
2073+}
2074+
2075+/*
2076+ * Allow the user to lock this window.
2077+ */
2078+static void term_window_pos(term_data *td, HWND hWnd)
2079+{
2080+ SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2081+ SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2082+}
2083+
2084+static void windows_map(void);
2085+
2086+/*
2087+ * Hack -- redraw a term_data
2088+ */
2089+static void term_data_redraw(term_data *td)
2090+{
2091+ if (td->map_active)
2092+ {
2093+ /* Redraw the map */
2094+ windows_map();
2095+ }
2096+ else
2097+ {
2098+ /* Activate the term */
2099+ Term_activate(&td->t);
2100+
2101+ /* Redraw the contents */
2102+ Term_redraw();
2103+
2104+ /* Restore the term */
2105+ Term_activate(term_screen);
2106+ }
2107+}
2108+
2109+
2110+void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2111+{
2112+ HDC hdc;
2113+ HPEN oldPen;
2114+ HBRUSH myBrush, oldBrush;
2115+
2116+ term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2117+ int tx = td->size_ow1 + x * td->tile_wid;
2118+ int ty = td->size_oh1 + y * td->tile_hgt;
2119+ int tw = w * td->tile_wid - 1;
2120+ int th = h * td->tile_hgt - 1;
2121+
2122+ hdc = GetDC(hWnd);
2123+ myBrush = CreateSolidBrush(RGB(255, 255, 255));
2124+ oldBrush = SelectObject(hdc, myBrush);
2125+ oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2126+
2127+ PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2128+
2129+ SelectObject(hdc, oldBrush);
2130+ SelectObject(hdc, oldPen);
2131+}
2132+
2133+
2134+
2135+/*** Function hooks needed by "Term" ***/
2136+
2137+
2138+#if 0
2139+
2140+/*
2141+ * Initialize a new Term
2142+ */
2143+static void Term_init_win(term *t)
2144+{
2145+ /* XXX Unused */
2146+}
2147+
2148+
2149+/*
2150+ * Nuke an old Term
2151+ */
2152+static void Term_nuke_win(term *t)
2153+{
2154+ /* XXX Unused */
2155+}
2156+
2157+#endif
2158+
2159+
2160+/*
2161+ * Interact with the User
2162+ */
2163+static errr Term_user_win(int n)
2164+{
2165+ /* Unused */
2166+ (void)n;
2167+
2168+ /* Success */
2169+ return (0);
2170+}
2171+
2172+
2173+/*
2174+ * React to global changes
2175+ */
2176+static errr Term_xtra_win_react(void)
2177+{
2178+ int i;
2179+
2180+
2181+ /* Simple color */
2182+ if (colors16)
2183+ {
2184+ /* Save the default colors */
2185+ for (i = 0; i < 256; i++)
2186+ {
2187+ /* Simply accept the desired colors */
2188+ win_pal[i] = angband_color_table[i][0];
2189+ }
2190+ }
2191+
2192+ /* Complex color */
2193+ else
2194+ {
2195+ COLORREF code;
2196+
2197+ byte rv, gv, bv;
2198+
2199+ bool change = FALSE;
2200+
2201+ /* Save the default colors */
2202+ for (i = 0; i < 256; i++)
2203+ {
2204+ /* Extract desired values */
2205+ rv = angband_color_table[i][1];
2206+ gv = angband_color_table[i][2];
2207+ bv = angband_color_table[i][3];
2208+
2209+ /* Extract a full color code */
2210+ code = PALETTERGB(rv, gv, bv);
2211+
2212+ /* Activate changes */
2213+ if (win_clr[i] != code)
2214+ {
2215+ /* Note the change */
2216+ change = TRUE;
2217+
2218+ /* Apply the desired color */
2219+ win_clr[i] = code;
2220+ }
2221+ }
2222+
2223+ /* Activate the palette if needed */
2224+ if (change) (void)new_palette();
2225+ }
2226+
2227+
2228+#ifdef USE_SOUND
2229+
2230+ /* Handle "arg_sound" */
2231+ if (use_sound != arg_sound)
2232+ {
2233+ /* Initialize (if needed) */
2234+ if (arg_sound && !init_sound())
2235+ {
2236+ /* Warning */
2237+ plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2238+
2239+ /* Cannot enable */
2240+ arg_sound = FALSE;
2241+ }
2242+
2243+ /* Change setting */
2244+ use_sound = arg_sound;
2245+ }
2246+
2247+#endif
2248+
2249+#ifdef USE_MUSIC
2250+
2251+ /* Handle "arg_sound" */
2252+ if (use_music != arg_music)
2253+ {
2254+ /* Initialize (if needed) */
2255+ if (arg_music && !init_music())
2256+ {
2257+ /* Warning */
2258+ plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2259+ /* Cannot enable */
2260+ arg_music = FALSE;
2261+ }
2262+
2263+ /* Change setting */
2264+ use_music = arg_music;
2265+
2266+ if(!arg_music) stop_music();
2267+ else select_floor_music();
2268+
2269+ }
2270+
2271+#endif
2272+
2273+
2274+#ifdef USE_GRAPHICS
2275+
2276+ /* Handle "arg_graphics" */
2277+ if (use_graphics != arg_graphics)
2278+ {
2279+ /* Initialize (if needed) */
2280+ if (arg_graphics && !init_graphics())
2281+ {
2282+ /* Warning */
2283+ plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2284+
2285+ /* Cannot enable */
2286+ arg_graphics = GRAPHICS_NONE;
2287+ }
2288+
2289+ /* Change setting */
2290+ use_graphics = arg_graphics;
2291+
2292+ /* Reset visuals */
2293+#ifdef ANGBAND_2_8_1
2294+ reset_visuals();
2295+#else /* ANGBAND_2_8_1 */
2296+ reset_visuals(TRUE);
2297+#endif /* ANGBAND_2_8_1 */
2298+ }
2299+
2300+#endif /* USE_GRAPHICS */
2301+
2302+
2303+ /* Clean up windows */
2304+ for (i = 0; i < MAX_TERM_DATA; i++)
2305+ {
2306+ term *old = Term;
2307+
2308+ term_data *td = &data[i];
2309+
2310+ /* Update resized windows */
2311+ if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2312+ {
2313+ /* Activate */
2314+ Term_activate(&td->t);
2315+
2316+ /* Hack -- Resize the term */
2317+ Term_resize(td->cols, td->rows);
2318+
2319+ /* Redraw the contents */
2320+ Term_redraw();
2321+
2322+ /* Restore */
2323+ Term_activate(old);
2324+ }
2325+ }
2326+
2327+
2328+ /* Success */
2329+ return (0);
2330+}
2331+
2332+
2333+/*
2334+ * Process at least one event
2335+ */
2336+static errr Term_xtra_win_event(int v)
2337+{
2338+ MSG msg;
2339+
2340+ /* Wait for an event */
2341+ if (v)
2342+ {
2343+ /* Block */
2344+ if (GetMessage(&msg, NULL, 0, 0))
2345+ {
2346+ TranslateMessage(&msg);
2347+ DispatchMessage(&msg);
2348+ }
2349+ }
2350+
2351+ /* Check for an event */
2352+ else
2353+ {
2354+ /* Check */
2355+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2356+ {
2357+ TranslateMessage(&msg);
2358+ DispatchMessage(&msg);
2359+ }
2360+ }
2361+
2362+ /* Success */
2363+ return 0;
2364+}
2365+
2366+
2367+/*
2368+ * Process all pending events
2369+ */
2370+static errr Term_xtra_win_flush(void)
2371+{
2372+ MSG msg;
2373+
2374+ /* Process all pending events */
2375+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2376+ {
2377+ TranslateMessage(&msg);
2378+ DispatchMessage(&msg);
2379+ }
2380+
2381+ /* Success */
2382+ return (0);
2383+}
2384+
2385+
2386+/*
2387+ * Hack -- clear the screen
2388+ *
2389+ * Make this more efficient XXX XXX XXX
2390+ */
2391+static errr Term_xtra_win_clear(void)
2392+{
2393+ term_data *td = (term_data*)(Term->data);
2394+
2395+ HDC hdc;
2396+ RECT rc;
2397+
2398+ /* Rectangle to erase */
2399+ rc.left = td->size_ow1;
2400+ rc.right = rc.left + td->cols * td->tile_wid;
2401+ rc.top = td->size_oh1;
2402+ rc.bottom = rc.top + td->rows * td->tile_hgt;
2403+
2404+ /* Erase it */
2405+ hdc = GetDC(td->w);
2406+ SetBkColor(hdc, RGB(0, 0, 0));
2407+ SelectObject(hdc, td->font_id);
2408+ ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2409+
2410+ /* bg */
2411+ if (use_bg)
2412+ {
2413+ rc.left = 0; rc.top = 0;
2414+ DrawBG(hdc, &rc);
2415+ }
2416+ ReleaseDC(td->w, hdc);
2417+
2418+ /* Success */
2419+ return 0;
2420+}
2421+
2422+
2423+/*
2424+ * Hack -- make a noise
2425+ */
2426+static errr Term_xtra_win_noise(void)
2427+{
2428+ MessageBeep(MB_ICONASTERISK);
2429+ return (0);
2430+}
2431+
2432+
2433+/*
2434+ * Hack -- make a sound
2435+ */
2436+static errr Term_xtra_win_sound(int v)
2437+{
2438+#ifdef USE_SOUND
2439+ int i;
2440+ char buf[1024];
2441+#endif /* USE_SOUND */
2442+
2443+ /* Sound disabled */
2444+ if (!use_sound) return (1);
2445+
2446+ /* Illegal sound */
2447+ if ((v < 0) || (v >= SOUND_MAX)) return (1);
2448+
2449+#ifdef USE_SOUND
2450+
2451+ /* Count the samples */
2452+ for (i = 0; i < SAMPLE_MAX; i++)
2453+ {
2454+ if (!sound_file[v][i])
2455+ break;
2456+ }
2457+
2458+ /* No sample */
2459+ if (i == 0) return (1);
2460+
2461+ /* Build the path */
2462+ path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2463+
2464+#ifdef WIN32
2465+
2466+ /* Play the sound, catch errors */
2467+ return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2468+
2469+#else /* WIN32 */
2470+
2471+ /* Play the sound, catch errors */
2472+ return (sndPlaySound(buf, SND_ASYNC));
2473+
2474+#endif /* WIN32 */
2475+
2476+#else /* USE_SOUND */
2477+
2478+ /* Oops */
2479+ return (1);
2480+
2481+#endif /* USE_SOUND */
2482+}
2483+
2484+/*
2485+ * Hack -- play a music
2486+ */
2487+static errr Term_xtra_win_music(int n, int v)
2488+{
2489+#ifdef USE_MUSIC
2490+ int i = 0;
2491+ char buf[1024];
2492+#endif /* USE_MUSIC */
2493+
2494+ /* Sound disabled */
2495+
2496+ if(!use_music) return (1);
2497+
2498+ /* Illegal sound */
2499+ if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2500+ else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2501+
2502+#ifdef USE_MUSIC
2503+
2504+ switch(n)
2505+ {
2506+ case TERM_XTRA_MUSIC_BASIC:
2507+ for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2508+ break;
2509+ case TERM_XTRA_MUSIC_DUNGEON:
2510+ for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2511+ break;
2512+ case TERM_XTRA_MUSIC_QUEST:
2513+ for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2514+ break;
2515+ case TERM_XTRA_MUSIC_TOWN:
2516+ for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2517+ break;
2518+ }
2519+
2520+ /* No sample */
2521+ if (i == 0)
2522+ {
2523+ //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2524+ //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2525+ return (1);
2526+ }
2527+
2528+ switch(n)
2529+ {
2530+ case TERM_XTRA_MUSIC_BASIC:
2531+ for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2532+ break;
2533+ case TERM_XTRA_MUSIC_DUNGEON:
2534+ for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2535+ break;
2536+ case TERM_XTRA_MUSIC_QUEST:
2537+ for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2538+ break;
2539+ case TERM_XTRA_MUSIC_TOWN:
2540+ for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2541+ break;
2542+ }
2543+
2544+ /* No sample */
2545+ if (i == 0)
2546+ {
2547+ mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2548+ mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2549+ return (1);
2550+ }
2551+
2552+ switch(n)
2553+ {
2554+ case TERM_XTRA_MUSIC_BASIC:
2555+ path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2556+ break;
2557+ case TERM_XTRA_MUSIC_DUNGEON:
2558+ path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2559+ break;
2560+ case TERM_XTRA_MUSIC_QUEST:
2561+ path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2562+ break;
2563+ case TERM_XTRA_MUSIC_TOWN:
2564+ path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2565+ break;
2566+ }
2567+
2568+ if(current_music_type == n && current_music_id == v)
2569+ {
2570+ return (0);
2571+ }
2572+ current_music_type = n;
2573+ current_music_id = v;
2574+
2575+#ifdef WIN32
2576+
2577+ mop.lpstrDeviceType = mci_device_type;
2578+ mop.lpstrElementName = buf;
2579+ mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2580+ mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2581+ mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2582+ mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2583+ mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2584+ return (0);
2585+
2586+#endif /* WIN32 */
2587+
2588+#else /* USE_MUSIC */
2589+
2590+ return (1);
2591+
2592+#endif /* USE_MUSIC */
2593+
2594+}
2595+
2596+
2597+/*
2598+ * Delay for "x" milliseconds
2599+ */
2600+static int Term_xtra_win_delay(int v)
2601+{
2602+
2603+#ifdef WIN32
2604+
2605+ /* Sleep */
2606+ Sleep(v);
2607+
2608+#else /* WIN32 */
2609+
2610+ DWORD t;
2611+ MSG msg;
2612+
2613+ /* Final count */
2614+ t = GetTickCount() + v;
2615+
2616+ /* Wait for it */
2617+ while (GetTickCount() < t)
2618+ {
2619+ /* Handle messages */
2620+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2621+ {
2622+ TranslateMessage(&msg);
2623+ DispatchMessage(&msg);
2624+ }
2625+ }
2626+
2627+#endif /* WIN32 */
2628+
2629+ /* Success */
2630+ return (0);
2631+}
2632+
2633+
2634+/*
2635+ * Do a "special thing"
2636+ */
2637+static errr Term_xtra_win(int n, int v)
2638+{
2639+ /* Handle a subset of the legal requests */
2640+ switch (n)
2641+ {
2642+ /* Make a bell sound */
2643+ case TERM_XTRA_NOISE:
2644+ {
2645+ return (Term_xtra_win_noise());
2646+ }
2647+
2648+ /* Play a music */
2649+ case TERM_XTRA_MUSIC_BASIC:
2650+ case TERM_XTRA_MUSIC_DUNGEON:
2651+ case TERM_XTRA_MUSIC_QUEST:
2652+ case TERM_XTRA_MUSIC_TOWN:
2653+ {
2654+ return (Term_xtra_win_music(n, v));
2655+ }
2656+
2657+ /* Make a special sound */
2658+ case TERM_XTRA_SOUND:
2659+ {
2660+ return (Term_xtra_win_sound(v));
2661+ }
2662+
2663+ /* Process random events */
2664+ case TERM_XTRA_BORED:
2665+ {
2666+ return (Term_xtra_win_event(0));
2667+ }
2668+
2669+ /* Process an event */
2670+ case TERM_XTRA_EVENT:
2671+ {
2672+ return (Term_xtra_win_event(v));
2673+ }
2674+
2675+ /* Flush all events */
2676+ case TERM_XTRA_FLUSH:
2677+ {
2678+ return (Term_xtra_win_flush());
2679+ }
2680+
2681+ /* Clear the screen */
2682+ case TERM_XTRA_CLEAR:
2683+ {
2684+ return (Term_xtra_win_clear());
2685+ }
2686+
2687+ /* React to global changes */
2688+ case TERM_XTRA_REACT:
2689+ {
2690+ return (Term_xtra_win_react());
2691+ }
2692+
2693+ /* Delay for some milliseconds */
2694+ case TERM_XTRA_DELAY:
2695+ {
2696+ return (Term_xtra_win_delay(v));
2697+ }
2698+ }
2699+
2700+ /* Oops */
2701+ return 1;
2702+}
2703+
2704+
2705+
2706+/*
2707+ * Low level graphics (Assumes valid input).
2708+ *
2709+ * Draw a "cursor" at (x,y), using a "yellow box".
2710+ */
2711+static errr Term_curs_win(int x, int y)
2712+{
2713+ term_data *td = (term_data*)(Term->data);
2714+
2715+ RECT rc;
2716+ HDC hdc;
2717+
2718+ int tile_wid, tile_hgt;
2719+
2720+ if (td->map_active)
2721+ {
2722+ tile_wid = td->map_tile_wid;
2723+ tile_hgt = td->map_tile_hgt;
2724+ }
2725+ else
2726+ {
2727+ tile_wid = td->tile_wid;
2728+ tile_hgt = td->tile_hgt;
2729+ }
2730+
2731+ /* Frame the grid */
2732+ rc.left = x * tile_wid + td->size_ow1;
2733+ rc.right = rc.left + tile_wid;
2734+ rc.top = y * tile_hgt + td->size_oh1;
2735+ rc.bottom = rc.top + tile_hgt;
2736+
2737+ /* Cursor is done as a yellow "box" */
2738+ hdc = GetDC(td->w);
2739+ FrameRect(hdc, &rc, hbrYellow);
2740+ ReleaseDC(td->w, hdc);
2741+
2742+ /* Success */
2743+ return 0;
2744+}
2745+
2746+
2747+/*
2748+ * Low level graphics (Assumes valid input).
2749+ *
2750+ * Draw a "big cursor" at (x,y), using a "yellow box".
2751+ */
2752+static errr Term_bigcurs_win(int x, int y)
2753+{
2754+ term_data *td = (term_data*)(Term->data);
2755+
2756+ RECT rc;
2757+ HDC hdc;
2758+
2759+ int tile_wid, tile_hgt;
2760+
2761+ if (td->map_active)
2762+ {
2763+ /* Normal cursor in map window */
2764+ Term_curs_win(x, y);
2765+ return 0;
2766+ }
2767+ else
2768+ {
2769+ tile_wid = td->tile_wid;
2770+ tile_hgt = td->tile_hgt;
2771+ }
2772+
2773+ /* Frame the grid */
2774+ rc.left = x * tile_wid + td->size_ow1;
2775+ rc.right = rc.left + 2 * tile_wid;
2776+ rc.top = y * tile_hgt + td->size_oh1;
2777+ rc.bottom = rc.top + tile_hgt;
2778+
2779+ /* Cursor is done as a yellow "box" */
2780+ hdc = GetDC(td->w);
2781+ FrameRect(hdc, &rc, hbrYellow);
2782+ ReleaseDC(td->w, hdc);
2783+
2784+ /* Success */
2785+ return 0;
2786+}
2787+
2788+
2789+/*
2790+ * Low level graphics (Assumes valid input).
2791+ *
2792+ * Erase a "block" of "n" characters starting at (x,y).
2793+ */
2794+static errr Term_wipe_win(int x, int y, int n)
2795+{
2796+ term_data *td = (term_data*)(Term->data);
2797+
2798+ HDC hdc;
2799+ RECT rc;
2800+
2801+ /* Rectangle to erase in client coords */
2802+ rc.left = x * td->tile_wid + td->size_ow1;
2803+ rc.right = rc.left + n * td->tile_wid;
2804+ rc.top = y * td->tile_hgt + td->size_oh1;
2805+ rc.bottom = rc.top + td->tile_hgt;
2806+
2807+ hdc = GetDC(td->w);
2808+ SetBkColor(hdc, RGB(0, 0, 0));
2809+ SelectObject(hdc, td->font_id);
2810+ /* bg */
2811+ if (use_bg)
2812+ DrawBG(hdc, &rc);
2813+ else
2814+ ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2815+ ReleaseDC(td->w, hdc);
2816+
2817+ /* Success */
2818+ return 0;
2819+}
2820+
2821+
2822+/*
2823+ * Low level graphics. Assumes valid input.
2824+ *
2825+ * Draw several ("n") chars, with an attr, at a given location.
2826+ *
2827+ * All "graphic" data is handled by "Term_pict_win()", below.
2828+ *
2829+ * One would think there is a more efficient method for telling a window
2830+ * what color it should be using to draw with, but perhaps simply changing
2831+ * it every time is not too inefficient. XXX XXX XXX
2832+ */
2833+static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2834+{
2835+ term_data *td = (term_data*)(Term->data);
2836+ RECT rc;
2837+ HDC hdc;
2838+
2839+#if 1 /* #ifdef JP */
2840+ static HBITMAP WALL;
2841+ static HBRUSH myBrush, oldBrush;
2842+ static HPEN oldPen;
2843+ static bool init_done = FALSE;
2844+
2845+ if (!init_done){
2846+ WALL = LoadBitmap(hInstance, AppName);
2847+ myBrush = CreatePatternBrush(WALL);
2848+ init_done = TRUE;
2849+ }
2850+#endif
2851+
2852+ /* Total rectangle */
2853+ rc.left = x * td->tile_wid + td->size_ow1;
2854+ rc.right = rc.left + n * td->tile_wid;
2855+ rc.top = y * td->tile_hgt + td->size_oh1;
2856+ rc.bottom = rc.top + td->tile_hgt;
2857+
2858+ /* Acquire DC */
2859+ hdc = GetDC(td->w);
2860+
2861+ /* Background color */
2862+ SetBkColor(hdc, RGB(0, 0, 0));
2863+
2864+ /* Foreground color */
2865+ if (colors16)
2866+ {
2867+ SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2868+ }
2869+ else if (paletted)
2870+ {
2871+ SetTextColor(hdc, win_clr[a&0x0F]);
2872+ }
2873+ else
2874+ {
2875+ SetTextColor(hdc, win_clr[a]);
2876+ }
2877+
2878+ /* Use the font */
2879+ SelectObject(hdc, td->font_id);
2880+
2881+ /* bg */
2882+ if (use_bg) SetBkMode(hdc, TRANSPARENT);
2883+
2884+ /* Bizarre size */
2885+ if (td->bizarre ||
2886+ (td->tile_hgt != td->font_hgt) ||
2887+ (td->tile_wid != td->font_wid))
2888+ {
2889+ int i;
2890+
2891+ /* Erase complete rectangle */
2892+ ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2893+
2894+ /* bg */
2895+ if (use_bg) DrawBG(hdc, &rc);
2896+
2897+ /* New rectangle */
2898+ rc.left += ((td->tile_wid - td->font_wid) / 2);
2899+ rc.right = rc.left + td->font_wid;
2900+ rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2901+ rc.bottom = rc.top + td->font_hgt;
2902+
2903+ /* Dump each character */
2904+ for (i = 0; i < n; i++)
2905+ {
2906+#ifdef JP
2907+ if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2908+ {
2909+ rc.right += td->font_wid;
2910+
2911+ oldBrush = SelectObject(hdc, myBrush);
2912+ oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2913+
2914+ /* Dump the wall */
2915+ Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2916+
2917+ SelectObject(hdc, oldBrush);
2918+ SelectObject(hdc, oldPen);
2919+ rc.right -= td->font_wid;
2920+
2921+ /* Advance */
2922+ i++;
2923+ rc.left += 2 * td->tile_wid;
2924+ rc.right += 2 * td->tile_wid;
2925+ }
2926+ else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2927+ {
2928+ rc.right += td->font_wid;
2929+ /* Dump the text */
2930+ ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2931+ s+i, 2, NULL);
2932+ rc.right -= td->font_wid;
2933+
2934+ /* Advance */
2935+ i++;
2936+ rc.left += 2 * td->tile_wid;
2937+ rc.right += 2 * td->tile_wid;
2938+ } else if (*(s+i)==127){
2939+ oldBrush = SelectObject(hdc, myBrush);
2940+ oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2941+
2942+ /* Dump the wall */
2943+ Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2944+
2945+ SelectObject(hdc, oldBrush);
2946+ SelectObject(hdc, oldPen);
2947+
2948+ /* Advance */
2949+ rc.left += td->tile_wid;
2950+ rc.right += td->tile_wid;
2951+ } else {
2952+ /* Dump the text */
2953+ ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2954+
2955+ /* Advance */
2956+ rc.left += td->tile_wid;
2957+ rc.right += td->tile_wid;
2958+ }
2959+#else
2960+#if 1
2961+ if (*(s+i)==127){
2962+ oldBrush = SelectObject(hdc, myBrush);
2963+ oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2964+
2965+ /* Dump the wall */
2966+ Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2967+
2968+ SelectObject(hdc, oldBrush);
2969+ SelectObject(hdc, oldPen);
2970+
2971+ /* Advance */
2972+ rc.left += td->tile_wid;
2973+ rc.right += td->tile_wid;
2974+ } else {
2975+ /* Dump the text */
2976+ ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2977+ s+i, 1, NULL);
2978+
2979+ /* Advance */
2980+ rc.left += td->tile_wid;
2981+ rc.right += td->tile_wid;
2982+ }
2983+#else
2984+ /* Dump the text */
2985+ ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2986+ s+i, 1, NULL);
2987+
2988+ /* Advance */
2989+ rc.left += td->tile_wid;
2990+ rc.right += td->tile_wid;
2991+#endif
2992+#endif
2993+
2994+ }
2995+ }
2996+
2997+ /* Normal size */
2998+ else
2999+ {
3000+ /* Dump the text */
3001+ ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3002+ s, n, NULL);
3003+ }
3004+
3005+ /* Release DC */
3006+ ReleaseDC(td->w, hdc);
3007+
3008+ /* Success */
3009+ return 0;
3010+}
3011+
3012+
3013+/*
3014+ * Low level graphics. Assumes valid input.
3015+ *
3016+ * Draw an array of "special" attr/char pairs at the given location.
3017+ *
3018+ * We use the "Term_pict_win()" function for "graphic" data, which are
3019+ * encoded by setting the "high-bits" of both the "attr" and the "char"
3020+ * data. We use the "attr" to represent the "row" of the main bitmap,
3021+ * and the "char" to represent the "col" of the main bitmap. The use
3022+ * of this function is induced by the "higher_pict" flag.
3023+ *
3024+ * If "graphics" is not available, we simply "wipe" the given grids.
3025+ */
3026+static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
3027+{
3028+ term_data *td = (term_data*)(Term->data);
3029+
3030+#ifdef USE_GRAPHICS
3031+
3032+ int i;
3033+ int x1, y1, w1, h1, tw1, th1;
3034+ int x2, y2, w2, h2, tw2 = 0;
3035+ int x3, y3;
3036+
3037+ HDC hdcMask = NULL;
3038+
3039+ HDC hdc;
3040+ HDC hdcSrc;
3041+ HBITMAP hbmSrcOld;
3042+
3043+ /* Paranoia */
3044+ if (!use_graphics)
3045+ {
3046+ /* Erase the grids */
3047+ return (Term_wipe_win(x, y, n));
3048+ }
3049+
3050+ /* Size of bitmap cell */
3051+ w1 = infGraph.CellWidth;
3052+ h1 = infGraph.CellHeight;
3053+ tw1 = infGraph.TileWidth;
3054+ th1 = infGraph.TileHeight;
3055+
3056+ /* Size of window cell */
3057+ if (td->map_active)
3058+ {
3059+ w2 = td->map_tile_wid;
3060+ h2 = td->map_tile_hgt;
3061+ }
3062+ else
3063+ {
3064+ w2 = td->tile_wid;
3065+ h2 = td->tile_hgt;
3066+ tw2 = w2;
3067+
3068+ /* big tile mode */
3069+ if (use_bigtile) tw2 *= 2;
3070+ }
3071+
3072+ /* Location of window cell */
3073+ x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3074+ y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3075+
3076+ /* Info */
3077+ hdc = GetDC(td->w);
3078+
3079+ /* More info */
3080+ hdcSrc = CreateCompatibleDC(hdc);
3081+ hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3082+
3083+ if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3084+ {
3085+ hdcMask = CreateCompatibleDC(hdc);
3086+ SelectObject(hdcMask, infMask.hBitmap);
3087+ }
3088+
3089+ /* Draw attr/char pairs */
3090+ for (i = 0; i < n; i++, x2 += w2)
3091+ {
3092+ byte a = ap[i];
3093+ char c = cp[i];
3094+
3095+
3096+ /* Extract picture */
3097+ int row = (a & 0x7F);
3098+ int col = (c & 0x7F);
3099+
3100+ /* Location of bitmap cell */
3101+ x1 = col * w1;
3102+ y1 = row * h1;
3103+
3104+ if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3105+ {
3106+ x3 = (tcp[i] & 0x7F) * w1;
3107+ y3 = (tap[i] & 0x7F) * h1;
3108+ tw2 = tw2 * w1 / tw1;
3109+ h2 = h2 * h1 / th1;
3110+
3111+ /* Perfect size */
3112+ if ((tw1 == tw2) && (th1 == h2))
3113+ {
3114+ /* Copy the terrain picture from the bitmap to the window */
3115+ BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3116+
3117+ /* Mask out the tile */
3118+ BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3119+
3120+ /* Draw the tile */
3121+ BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3122+ }
3123+
3124+ /* Need to stretch */
3125+ else
3126+ {
3127+ /* Set the correct mode for stretching the tiles */
3128+ SetStretchBltMode(hdc, COLORONCOLOR);
3129+
3130+ /* Copy the terrain picture from the bitmap to the window */
3131+ StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3132+
3133+ StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3134+
3135+ /* Only draw if terrain and overlay are different */
3136+ if ((x1 != x3) || (y1 != y3))
3137+ {
3138+ /* Mask out the tile */
3139+ StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3140+
3141+ /* Draw the tile */
3142+ StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3143+ }
3144+ }
3145+ }
3146+ else
3147+ {
3148+ /* Perfect size */
3149+ if ((w1 == tw2) && (h1 == h2))
3150+ {
3151+ /* Copy the picture from the bitmap to the window */
3152+ BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3153+ }
3154+
3155+ /* Need to stretch */
3156+ else
3157+ {
3158+ /* Set the correct mode for stretching the tiles */
3159+ SetStretchBltMode(hdc, COLORONCOLOR);
3160+
3161+ /* Copy the picture from the bitmap to the window */
3162+ StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3163+ }
3164+ }
3165+ }
3166+
3167+ /* Release */
3168+ SelectObject(hdcSrc, hbmSrcOld);
3169+ DeleteDC(hdcSrc);
3170+
3171+ if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3172+ {
3173+ /* Release */
3174+ SelectObject(hdcMask, hbmSrcOld);
3175+ DeleteDC(hdcMask);
3176+ }
3177+
3178+ /* Release */
3179+ ReleaseDC(td->w, hdc);
3180+
3181+#else /* USE_GRAPHICS */
3182+
3183+ /* Just erase this grid */
3184+ return (Term_wipe_win(x, y, n));
3185+
3186+#endif /* USE_GRAPHICS */
3187+
3188+ /* Success */
3189+ return 0;
3190+}
3191+
3192+
3193+static void windows_map(void)
3194+{
3195+ term_data *td = &data[0];
3196+ byte a, c;
3197+ int x, min_x, max_x;
3198+ int y, min_y, max_y;
3199+
3200+ byte ta, tc;
3201+
3202+ /* Only in graphics mode */
3203+ if (!use_graphics) return;
3204+
3205+ /* Clear screen */
3206+ Term_xtra_win_clear();
3207+
3208+ td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3209+ td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3210+ td->map_active = TRUE;
3211+
3212+ {
3213+ min_x = 0;
3214+ min_y = 0;
3215+ max_x = cur_wid;
3216+ max_y = cur_hgt;
3217+ }
3218+
3219+ /* Draw the map */
3220+ for (x = min_x; x < max_x; x++)
3221+ {
3222+ for (y = min_y; y < max_y; y++)
3223+ {
3224+ map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3225+
3226+ /* Ignore non-graphics */
3227+ if ((a & 0x80) && (c & 0x80))
3228+ {
3229+ Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3230+ }
3231+ }
3232+ }
3233+
3234+ /* Hilite the player */
3235+ Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3236+
3237+ /* Wait for a keypress, flush key buffer */
3238+ Term_inkey(&c, TRUE, TRUE);
3239+ Term_flush();
3240+
3241+ /* Switch off the map display */
3242+ td->map_active = FALSE;
3243+
3244+ /* Restore screen */
3245+ Term_xtra_win_clear();
3246+ Term_redraw();
3247+}
3248+
3249+
3250+/*** Other routines ***/
3251+
3252+
3253+/*
3254+ * Create and initialize a "term_data" given a title
3255+ */
3256+static void term_data_link(term_data *td)
3257+{
3258+ term *t = &td->t;
3259+
3260+ /* Initialize the term */
3261+ term_init(t, td->cols, td->rows, td->keys);
3262+
3263+ /* Use a "software" cursor */
3264+ t->soft_cursor = TRUE;
3265+
3266+ /* Use "Term_pict" for "graphic" data */
3267+ t->higher_pict = TRUE;
3268+
3269+ /* Erase with "white space" */
3270+ t->attr_blank = TERM_WHITE;
3271+ t->char_blank = ' ';
3272+
3273+#if 0
3274+ /* Prepare the init/nuke hooks */
3275+ t->init_hook = Term_init_win;
3276+ t->nuke_hook = Term_nuke_win;
3277+#endif
3278+
3279+ /* Prepare the template hooks */
3280+ t->user_hook = Term_user_win;
3281+ t->xtra_hook = Term_xtra_win;
3282+ t->curs_hook = Term_curs_win;
3283+ t->bigcurs_hook = Term_bigcurs_win;
3284+ t->wipe_hook = Term_wipe_win;
3285+ t->text_hook = Term_text_win;
3286+ t->pict_hook = Term_pict_win;
3287+
3288+ /* Remember where we came from */
3289+ t->data = (vptr)(td);
3290+}
3291+
3292+
3293+/*
3294+ * Create the windows
3295+ *
3296+ * First, instantiate the "default" values, then read the "ini_file"
3297+ * to over-ride selected values, then create the windows, and fonts.
3298+ *
3299+ * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3300+ * must make active to realize the palette. XXX XXX XXX
3301+ */
3302+static void init_windows(void)
3303+{
3304+ int i;
3305+
3306+ term_data *td;
3307+
3308+#if 0 /* #ifndef JP */
3309+ char buf[1024];
3310+#endif
3311+
3312+ /* Main window */
3313+ td = &data[0];
3314+ WIPE(td, term_data);
3315+#ifdef JP
3316+ td->s = "変愚蛮怒";
3317+#else
3318+ td->s = angband_term_name[0];
3319+#endif
3320+
3321+ td->keys = 1024;
3322+ td->rows = 24;
3323+ td->cols = 80;
3324+ td->visible = TRUE;
3325+ td->size_ow1 = 2;
3326+ td->size_ow2 = 2;
3327+ td->size_oh1 = 2;
3328+ td->size_oh2 = 2;
3329+ td->pos_x = 7 * 30;
3330+ td->pos_y = 7 * 20;
3331+ td->posfix = FALSE;
3332+#if 1 /* #ifdef JP */
3333+ td->bizarre = TRUE;
3334+#endif
3335+ /* Sub windows */
3336+ for (i = 1; i < MAX_TERM_DATA; i++)
3337+ {
3338+ td = &data[i];
3339+ WIPE(td, term_data);
3340+ td->s = angband_term_name[i];
3341+ td->keys = 16;
3342+ td->rows = 24;
3343+ td->cols = 80;
3344+ td->visible = FALSE;
3345+ td->size_ow1 = 1;
3346+ td->size_ow2 = 1;
3347+ td->size_oh1 = 1;
3348+ td->size_oh2 = 1;
3349+ td->pos_x = (7 - i) * 30;
3350+ td->pos_y = (7 - i) * 20;
3351+ td->posfix = FALSE;
3352+#if 1 /* #ifdef JP */
3353+ td->bizarre = TRUE;
3354+#endif
3355+ }
3356+
3357+
3358+ /* Load prefs */
3359+ load_prefs();
3360+
3361+
3362+ /* Main window (need these before term_getsize gets called) */
3363+ td = &data[0];
3364+ td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3365+ WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3366+ WS_VISIBLE);
3367+ td->dwExStyle = 0;
3368+ td->visible = TRUE;
3369+
3370+ /* Sub windows (need these before term_getsize gets called) */
3371+ for (i = 1; i < MAX_TERM_DATA; i++)
3372+ {
3373+ td = &data[i];
3374+ td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3375+ td->dwExStyle = (WS_EX_TOOLWINDOW);
3376+ }
3377+
3378+
3379+ /* All windows */
3380+ for (i = 0; i < MAX_TERM_DATA; i++)
3381+ {
3382+ td = &data[i];
3383+
3384+#if 1 /* #ifdef JP */
3385+ strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3386+ td->lf.lfCharSet = DEFAULT_CHARSET;
3387+ td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3388+ /* Activate the chosen font */
3389+ term_force_font(td, NULL);
3390+ if(!td->tile_wid) td->tile_wid = td->font_wid;
3391+ if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3392+#else
3393+ /* Access the standard font file */
3394+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3395+
3396+ /* Activate the chosen font */
3397+ if (term_force_font(td, buf))
3398+ {
3399+ /* Access the standard font file */
3400+ path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3401+
3402+ /* Force the use of that font */
3403+ (void)term_force_font(td, buf);
3404+
3405+ /* Oops */
3406+ td->tile_wid = 8;
3407+ td->tile_hgt = 13;
3408+
3409+ /* Assume not bizarre */
3410+ td->bizarre = FALSE;
3411+ }
3412+#endif
3413+
3414+
3415+ /* Analyze the font */
3416+ term_getsize(td);
3417+
3418+ /* Resize the window */
3419+ term_window_resize(td);
3420+ }
3421+
3422+
3423+ /* Sub windows (reverse order) */
3424+ for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3425+ {
3426+ td = &data[i];
3427+
3428+ my_td = td;
3429+ td->w = CreateWindowEx(td->dwExStyle, AngList,
3430+ td->s, td->dwStyle,
3431+ td->pos_x, td->pos_y,
3432+ td->size_wid, td->size_hgt,
3433+ HWND_DESKTOP, NULL, hInstance, NULL);
3434+ my_td = NULL;
3435+ if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3436+
3437+ if (td->visible)
3438+ {
3439+ td->size_hack = TRUE;
3440+ ShowWindow(td->w, SW_SHOW);
3441+ td->size_hack = FALSE;
3442+ }
3443+
3444+ term_data_link(td);
3445+ angband_term[i] = &td->t;
3446+
3447+ if (td->visible)
3448+ {
3449+ /* Activate the window */
3450+ SetActiveWindow(td->w);
3451+ }
3452+
3453+ if (data[i].posfix)
3454+ {
3455+ term_window_pos(&data[i], HWND_TOPMOST);
3456+ }
3457+ else
3458+ {
3459+ term_window_pos(&data[i], td->w);
3460+ }
3461+ }
3462+
3463+
3464+ /* Main window */
3465+ td = &data[0];
3466+
3467+ /* Main window */
3468+ my_td = td;
3469+ td->w = CreateWindowEx(td->dwExStyle, AppName,
3470+ td->s, td->dwStyle,
3471+ td->pos_x, td->pos_y,
3472+ td->size_wid, td->size_hgt,
3473+ HWND_DESKTOP, NULL, hInstance, NULL);
3474+ my_td = NULL;
3475+ if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3476+
3477+ term_data_link(td);
3478+ angband_term[0] = &td->t;
3479+ normsize.x = td->cols;
3480+ normsize.y = td->rows;
3481+
3482+ /* Activate the main window */
3483+ if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3484+ else ShowWindow(td->w, SW_SHOW);
3485+
3486+ /* Bring main window back to top */
3487+ SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3488+
3489+
3490+ /* New palette XXX XXX XXX */
3491+ (void)new_palette();
3492+
3493+
3494+ /* Create a "brush" for drawing the "cursor" */
3495+ hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3496+
3497+
3498+ /* Process pending messages */
3499+ (void)Term_xtra_win_flush();
3500+}
3501+
3502+
3503+
3504+/*
3505+ * Prepare the menus
3506+ */
3507+static void setup_menus(void)
3508+{
3509+ int i;
3510+
3511+ HMENU hm = GetMenu(data[0].w);
3512+
3513+
3514+ /* Menu "File", Disable all */
3515+ EnableMenuItem(hm, IDM_FILE_NEW,
3516+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3517+ EnableMenuItem(hm, IDM_FILE_OPEN,
3518+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3519+ EnableMenuItem(hm, IDM_FILE_SAVE,
3520+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3521+ EnableMenuItem(hm, IDM_FILE_EXIT,
3522+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3523+ EnableMenuItem(hm, IDM_FILE_SCORE,
3524+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3525+
3526+
3527+ /* No character available */
3528+ if (!character_generated)
3529+ {
3530+ /* Menu "File", Item "New" */
3531+ EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3532+
3533+ /* Menu "File", Item "Open" */
3534+ EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3535+ }
3536+
3537+ /* A character available */
3538+ if (character_generated)
3539+ {
3540+ /* Menu "File", Item "Save" */
3541+ EnableMenuItem(hm, IDM_FILE_SAVE,
3542+ MF_BYCOMMAND | MF_ENABLED);
3543+ }
3544+
3545+ /* Menu "File", Item "Exit" */
3546+ EnableMenuItem(hm, IDM_FILE_EXIT,
3547+ MF_BYCOMMAND | MF_ENABLED);
3548+
3549+ EnableMenuItem(hm, IDM_FILE_SCORE,
3550+ MF_BYCOMMAND | MF_ENABLED);
3551+
3552+
3553+ /* Menu "Window::Visibility" */
3554+ for (i = 0; i < MAX_TERM_DATA; i++)
3555+ {
3556+ EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3557+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558+
3559+ CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3560+ (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3561+
3562+ EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3563+ MF_BYCOMMAND | MF_ENABLED);
3564+ }
3565+
3566+ /* Menu "Window::Font" */
3567+ for (i = 0; i < MAX_TERM_DATA; i++)
3568+ {
3569+ EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3570+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3571+
3572+ if (data[i].visible)
3573+ {
3574+ EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3575+ MF_BYCOMMAND | MF_ENABLED);
3576+ }
3577+ }
3578+
3579+ /* Menu "Window::Window Position Fix" */
3580+ for (i = 0; i < MAX_TERM_DATA; i++)
3581+ {
3582+ EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3583+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3584+
3585+ CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3586+ (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3587+
3588+ if (data[i].visible)
3589+ {
3590+ EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3591+ MF_BYCOMMAND | MF_ENABLED);
3592+ }
3593+ }
3594+
3595+ /* Menu "Window::Bizarre Display" */
3596+ for (i = 0; i < MAX_TERM_DATA; i++)
3597+ {
3598+ EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3599+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3600+
3601+ CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3602+ (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3603+
3604+ if (data[i].visible)
3605+ {
3606+ EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3607+ MF_BYCOMMAND | MF_ENABLED);
3608+
3609+ }
3610+ }
3611+
3612+ /* Menu "Window::Increase Tile Width" */
3613+ for (i = 0; i < MAX_TERM_DATA; i++)
3614+ {
3615+ EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3616+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3617+
3618+ if (data[i].visible)
3619+ {
3620+ EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3621+ MF_BYCOMMAND | MF_ENABLED);
3622+
3623+ }
3624+ }
3625+
3626+ /* Menu "Window::Decrease Tile Width" */
3627+ for (i = 0; i < MAX_TERM_DATA; i++)
3628+ {
3629+ EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3630+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3631+
3632+ if (data[i].visible)
3633+ {
3634+ EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3635+ MF_BYCOMMAND | MF_ENABLED);
3636+
3637+ }
3638+ }
3639+
3640+ /* Menu "Window::Increase Tile Height" */
3641+ for (i = 0; i < MAX_TERM_DATA; i++)
3642+ {
3643+ EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3644+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3645+
3646+ if (data[i].visible)
3647+ {
3648+ EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3649+ MF_BYCOMMAND | MF_ENABLED);
3650+
3651+ }
3652+ }
3653+
3654+ /* Menu "Window::Decrease Tile Height" */
3655+ for (i = 0; i < MAX_TERM_DATA; i++)
3656+ {
3657+ EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3658+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3659+
3660+ if (data[i].visible)
3661+ {
3662+ EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3663+ MF_BYCOMMAND | MF_ENABLED);
3664+
3665+ }
3666+ }
3667+
3668+ /* Menu "Options", disable all */
3669+ EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3670+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3671+ EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3672+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3673+ EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3674+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3675+ EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3676+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3677+ EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3678+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3679+#ifndef JP
3680+ EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3681+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3682+#endif
3683+
3684+ /* Menu "Options", Item "Map" */
3685+ if (use_graphics != GRAPHICS_NONE)
3686+ EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3687+ else
3688+ EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3689+ MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3690+
3691+ /* Menu "Options", update all */
3692+ CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3693+ (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3694+ CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3695+ (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3696+ CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3697+ (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3698+ CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3699+ (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3700+ CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3701+ (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3702+ CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3703+ (arg_music ? MF_CHECKED : MF_UNCHECKED));
3704+ CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3705+ (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3706+ CheckMenuItem(hm, IDM_OPTIONS_BG,
3707+ (use_bg ? MF_CHECKED : MF_UNCHECKED));
3708+#ifndef JP
3709+ CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3710+ (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3711+#endif
3712+
3713+#ifdef USE_GRAPHICS
3714+ /* Menu "Options", Item "Graphics" */
3715+ EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3716+ /* Menu "Options", Item "Graphics" */
3717+ EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3718+ /* Menu "Options", Item "Graphics" */
3719+ EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3720+ /* Menu "Options", Item "Graphics" */
3721+ EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3722+#endif /* USE_GRAPHICS */
3723+
3724+#ifdef USE_SOUND
3725+ /* Menu "Options", Item "Sound" */
3726+ EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3727+#endif /* USE_SOUND */
3728+
3729+#ifdef USE_SAVER
3730+ /* Menu "Options", Item "ScreenSaver" */
3731+ EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3732+ MF_BYCOMMAND | MF_ENABLED);
3733+#endif /* USE_SAVER */
3734+}
3735+
3736+
3737+/*
3738+ * Check for double clicked (or dragged) savefile
3739+ *
3740+ * Apparently, Windows copies the entire filename into the first
3741+ * piece of the "command line string". Perhaps we should extract
3742+ * the "basename" of that filename and append it to the "save" dir.
3743+ */
3744+static void check_for_save_file(LPSTR cmd_line)
3745+{
3746+ char *s;
3747+
3748+ /* First arg */
3749+ s = cmd_line;
3750+
3751+ /* No args */
3752+ if (!*s) return;
3753+
3754+ /* Extract filename */
3755+ strcat(savefile, s);
3756+
3757+ /* Validate the file */
3758+ validate_file(savefile);
3759+
3760+ /* Game in progress */
3761+ game_in_progress = TRUE;
3762+
3763+ /* Play game */
3764+ play_game(FALSE);
3765+}
3766+
3767+
3768+/*
3769+ * Process a menu command
3770+ */
3771+static void process_menus(WORD wCmd)
3772+{
3773+ int i;
3774+
3775+ term_data *td;
3776+
3777+ OPENFILENAME ofn;
3778+
3779+ /* Analyze */
3780+ switch (wCmd)
3781+ {
3782+ /* New game */
3783+ case IDM_FILE_NEW:
3784+ {
3785+ if (!initialized)
3786+ {
3787+ plog(_("まだ初期化中です...", "You cannot do that yet..."));
3788+ }
3789+ else if (game_in_progress)
3790+ {
3791+ plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3792+ }
3793+ else
3794+ {
3795+ game_in_progress = TRUE;
3796+ Term_flush();
3797+ play_game(TRUE);
3798+ quit(NULL);
3799+ }
3800+ break;
3801+ }
3802+
3803+ /* Open game */
3804+ case IDM_FILE_OPEN:
3805+ {
3806+ if (!initialized)
3807+ {
3808+ plog(_("まだ初期化中です...", "You cannot do that yet..."));
3809+ }
3810+ else if (game_in_progress)
3811+ {
3812+ plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3813+ }
3814+ else
3815+ {
3816+ memset(&ofn, 0, sizeof(ofn));
3817+ ofn.lStructSize = sizeof(ofn);
3818+ ofn.hwndOwner = data[0].w;
3819+ ofn.lpstrFilter = "Save Files (*.)\0*\0";
3820+ ofn.nFilterIndex = 1;
3821+ ofn.lpstrFile = savefile;
3822+ ofn.nMaxFile = 1024;
3823+ ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3824+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3825+
3826+ if (GetOpenFileName(&ofn))
3827+ {
3828+ /* Load 'savefile' */
3829+ validate_file(savefile);
3830+ game_in_progress = TRUE;
3831+ Term_flush();
3832+ play_game(FALSE);
3833+ quit(NULL);
3834+ }
3835+ }
3836+ break;
3837+ }
3838+
3839+ /* Save game */
3840+ case IDM_FILE_SAVE:
3841+ {
3842+ if (game_in_progress && character_generated)
3843+ {
3844+ /* Paranoia */
3845+ if (!can_save)
3846+ {
3847+ plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3848+ break;
3849+ }
3850+
3851+ /* Hack -- Forget messages */
3852+ msg_flag = FALSE;
3853+
3854+ /* Save the game */
3855+#ifdef ZANGBAND
3856+ do_cmd_save_game(FALSE);
3857+#else /* ZANGBAND */
3858+ do_cmd_save_game();
3859+#endif /* ZANGBAND */
3860+ }
3861+ else
3862+ {
3863+ plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3864+ }
3865+ break;
3866+ }
3867+
3868+ /* Exit */
3869+ case IDM_FILE_EXIT:
3870+ {
3871+ if (game_in_progress && character_generated)
3872+ {
3873+ /* Paranoia */
3874+ if (!can_save)
3875+ {
3876+ plog(_("今は終了できません。", "You may not do that right now."));
3877+ break;
3878+ }
3879+
3880+ /* Hack -- Forget messages */
3881+ msg_flag = FALSE;
3882+
3883+ forget_lite();
3884+ forget_view();
3885+ clear_mon_lite();
3886+
3887+ /* Save the game */
3888+#ifdef ZANGBAND
3889+ /* do_cmd_save_game(FALSE); */
3890+#else /* ZANGBAND */
3891+ /* do_cmd_save_game(); */
3892+#endif /* ZANGBAND */
3893+ Term_key_push(SPECIAL_KEY_QUIT);
3894+ break;
3895+ }
3896+ quit(NULL);
3897+ break;
3898+ }
3899+
3900+ /* Show scores */
3901+ case IDM_FILE_SCORE:
3902+ {
3903+ char buf[1024];
3904+
3905+ /* Build the filename */
3906+ path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3907+
3908+ /* Open the binary high score file, for reading */
3909+ highscore_fd = fd_open(buf, O_RDONLY);
3910+
3911+ /* Paranoia -- No score file */
3912+ if (highscore_fd < 0)
3913+ {
3914+ msg_print("Score file unavailable.");
3915+ }
3916+ else
3917+ {
3918+ /* Save Screen */
3919+ screen_save();
3920+
3921+ /* Clear screen */
3922+ Term_clear();
3923+
3924+ /* Display the scores */
3925+ display_scores_aux(0, MAX_HISCORES, -1, NULL);
3926+
3927+ /* Shut the high score file */
3928+ (void)fd_close(highscore_fd);
3929+
3930+ /* Forget the high score fd */
3931+ highscore_fd = -1;
3932+
3933+ /* Load screen */
3934+ screen_load();
3935+
3936+ /* Hack - Flush it */
3937+ Term_fresh();
3938+ }
3939+
3940+ break;
3941+ }
3942+
3943+ /* Open game */
3944+ case IDM_FILE_MOVIE:
3945+ {
3946+ if (!initialized)
3947+ {
3948+ plog(_("まだ初期化中です...", "You cannot do that yet..."));
3949+ }
3950+ else if (game_in_progress)
3951+ {
3952+ plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3953+ }
3954+ else
3955+ {
3956+ memset(&ofn, 0, sizeof(ofn));
3957+ ofn.lStructSize = sizeof(ofn);
3958+ ofn.hwndOwner = data[0].w;
3959+ ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3960+ ofn.nFilterIndex = 1;
3961+ ofn.lpstrFile = savefile;
3962+ ofn.nMaxFile = 1024;
3963+ ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3964+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3965+
3966+ if (GetOpenFileName(&ofn))
3967+ {
3968+ /* Load 'savefile' */
3969+ prepare_browse_movie_aux(savefile);
3970+ play_game(FALSE);
3971+ quit(NULL);
3972+ return;
3973+ }
3974+ }
3975+ break;
3976+ }
3977+
3978+
3979+ case IDM_WINDOW_VIS_0:
3980+ {
3981+ plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3982+ break;
3983+ }
3984+
3985+ /* Window visibility */
3986+ case IDM_WINDOW_VIS_1:
3987+ case IDM_WINDOW_VIS_2:
3988+ case IDM_WINDOW_VIS_3:
3989+ case IDM_WINDOW_VIS_4:
3990+ case IDM_WINDOW_VIS_5:
3991+ case IDM_WINDOW_VIS_6:
3992+ case IDM_WINDOW_VIS_7:
3993+ {
3994+ i = wCmd - IDM_WINDOW_VIS_0;
3995+
3996+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3997+
3998+ td = &data[i];
3999+
4000+ if (!td->visible)
4001+ {
4002+ td->visible = TRUE;
4003+ ShowWindow(td->w, SW_SHOW);
4004+ term_data_redraw(td);
4005+ }
4006+ else
4007+ {
4008+ td->visible = FALSE;
4009+ td->posfix = FALSE;
4010+ ShowWindow(td->w, SW_HIDE);
4011+ }
4012+
4013+ break;
4014+ }
4015+
4016+ /* Window fonts */
4017+ case IDM_WINDOW_FONT_0:
4018+ case IDM_WINDOW_FONT_1:
4019+ case IDM_WINDOW_FONT_2:
4020+ case IDM_WINDOW_FONT_3:
4021+ case IDM_WINDOW_FONT_4:
4022+ case IDM_WINDOW_FONT_5:
4023+ case IDM_WINDOW_FONT_6:
4024+ case IDM_WINDOW_FONT_7:
4025+ {
4026+ i = wCmd - IDM_WINDOW_FONT_0;
4027+
4028+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4029+
4030+ td = &data[i];
4031+
4032+ term_change_font(td);
4033+
4034+ break;
4035+ }
4036+
4037+ /* Window Z Position */
4038+ case IDM_WINDOW_POS_1:
4039+ case IDM_WINDOW_POS_2:
4040+ case IDM_WINDOW_POS_3:
4041+ case IDM_WINDOW_POS_4:
4042+ case IDM_WINDOW_POS_5:
4043+ case IDM_WINDOW_POS_6:
4044+ case IDM_WINDOW_POS_7:
4045+ {
4046+ i = wCmd - IDM_WINDOW_POS_0;
4047+
4048+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4049+
4050+ td = &data[i];
4051+
4052+ if (!td->posfix && td->visible)
4053+ {
4054+ td->posfix = TRUE;
4055+ term_window_pos(td, HWND_TOPMOST);
4056+ }
4057+ else
4058+ {
4059+ td->posfix = FALSE;
4060+ term_window_pos(td, data[0].w);
4061+ }
4062+
4063+ break;
4064+ }
4065+
4066+ /* Bizarre Display */
4067+ case IDM_WINDOW_BIZ_0:
4068+ case IDM_WINDOW_BIZ_1:
4069+ case IDM_WINDOW_BIZ_2:
4070+ case IDM_WINDOW_BIZ_3:
4071+ case IDM_WINDOW_BIZ_4:
4072+ case IDM_WINDOW_BIZ_5:
4073+ case IDM_WINDOW_BIZ_6:
4074+ case IDM_WINDOW_BIZ_7:
4075+ {
4076+ i = wCmd - IDM_WINDOW_BIZ_0;
4077+
4078+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4079+
4080+ td = &data[i];
4081+
4082+ td->bizarre = !td->bizarre;
4083+
4084+ term_getsize(td);
4085+
4086+ term_window_resize(td);
4087+
4088+ break;
4089+ }
4090+
4091+ /* Increase Tile Width */
4092+ case IDM_WINDOW_I_WID_0:
4093+ case IDM_WINDOW_I_WID_1:
4094+ case IDM_WINDOW_I_WID_2:
4095+ case IDM_WINDOW_I_WID_3:
4096+ case IDM_WINDOW_I_WID_4:
4097+ case IDM_WINDOW_I_WID_5:
4098+ case IDM_WINDOW_I_WID_6:
4099+ case IDM_WINDOW_I_WID_7:
4100+ {
4101+ i = wCmd - IDM_WINDOW_I_WID_0;
4102+
4103+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4104+
4105+ td = &data[i];
4106+
4107+ td->tile_wid += 1;
4108+
4109+ term_getsize(td);
4110+
4111+ term_window_resize(td);
4112+
4113+ break;
4114+ }
4115+
4116+ /* Decrease Tile Height */
4117+ case IDM_WINDOW_D_WID_0:
4118+ case IDM_WINDOW_D_WID_1:
4119+ case IDM_WINDOW_D_WID_2:
4120+ case IDM_WINDOW_D_WID_3:
4121+ case IDM_WINDOW_D_WID_4:
4122+ case IDM_WINDOW_D_WID_5:
4123+ case IDM_WINDOW_D_WID_6:
4124+ case IDM_WINDOW_D_WID_7:
4125+ {
4126+ i = wCmd - IDM_WINDOW_D_WID_0;
4127+
4128+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4129+
4130+ td = &data[i];
4131+
4132+ td->tile_wid -= 1;
4133+
4134+ term_getsize(td);
4135+
4136+ term_window_resize(td);
4137+
4138+ break;
4139+ }
4140+
4141+ /* Increase Tile Height */
4142+ case IDM_WINDOW_I_HGT_0:
4143+ case IDM_WINDOW_I_HGT_1:
4144+ case IDM_WINDOW_I_HGT_2:
4145+ case IDM_WINDOW_I_HGT_3:
4146+ case IDM_WINDOW_I_HGT_4:
4147+ case IDM_WINDOW_I_HGT_5:
4148+ case IDM_WINDOW_I_HGT_6:
4149+ case IDM_WINDOW_I_HGT_7:
4150+ {
4151+ i = wCmd - IDM_WINDOW_I_HGT_0;
4152+
4153+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4154+
4155+ td = &data[i];
4156+
4157+ td->tile_hgt += 1;
4158+
4159+ term_getsize(td);
4160+
4161+ term_window_resize(td);
4162+
4163+ break;
4164+ }
4165+
4166+ /* Decrease Tile Height */
4167+ case IDM_WINDOW_D_HGT_0:
4168+ case IDM_WINDOW_D_HGT_1:
4169+ case IDM_WINDOW_D_HGT_2:
4170+ case IDM_WINDOW_D_HGT_3:
4171+ case IDM_WINDOW_D_HGT_4:
4172+ case IDM_WINDOW_D_HGT_5:
4173+ case IDM_WINDOW_D_HGT_6:
4174+ case IDM_WINDOW_D_HGT_7:
4175+ {
4176+ i = wCmd - IDM_WINDOW_D_HGT_0;
4177+
4178+ if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4179+
4180+ td = &data[i];
4181+
4182+ td->tile_hgt -= 1;
4183+
4184+ term_getsize(td);
4185+
4186+ term_window_resize(td);
4187+
4188+ break;
4189+ }
4190+
4191+ case IDM_OPTIONS_NO_GRAPHICS:
4192+ {
4193+ /* Paranoia */
4194+ if (!inkey_flag)
4195+ {
4196+ plog("You may not do that right now.");
4197+ break;
4198+ }
4199+
4200+ /* Toggle "arg_graphics" */
4201+ if (arg_graphics != GRAPHICS_NONE)
4202+ {
4203+ arg_graphics = GRAPHICS_NONE;
4204+
4205+ /* React to changes */
4206+ Term_xtra_win_react();
4207+
4208+ /* Hack -- Force redraw */
4209+ Term_key_push(KTRL('R'));
4210+ }
4211+
4212+ break;
4213+ }
4214+
4215+ case IDM_OPTIONS_OLD_GRAPHICS:
4216+ {
4217+ /* Paranoia */
4218+ if (!inkey_flag)
4219+ {
4220+ plog("You may not do that right now.");
4221+ break;
4222+ }
4223+
4224+ /* Toggle "arg_graphics" */
4225+ if (arg_graphics != GRAPHICS_ORIGINAL)
4226+ {
4227+ arg_graphics = GRAPHICS_ORIGINAL;
4228+
4229+ /* React to changes */
4230+ Term_xtra_win_react();
4231+
4232+ /* Hack -- Force redraw */
4233+ Term_key_push(KTRL('R'));
4234+ }
4235+
4236+ break;
4237+ }
4238+
4239+ case IDM_OPTIONS_NEW_GRAPHICS:
4240+ {
4241+ /* Paranoia */
4242+ if (!inkey_flag)
4243+ {
4244+ plog("You may not do that right now.");
4245+ break;
4246+ }
4247+
4248+ /* Toggle "arg_graphics" */
4249+ if (arg_graphics != GRAPHICS_ADAM_BOLT)
4250+ {
4251+ arg_graphics = GRAPHICS_ADAM_BOLT;
4252+
4253+ /* React to changes */
4254+ Term_xtra_win_react();
4255+
4256+ /* Hack -- Force redraw */
4257+ Term_key_push(KTRL('R'));
4258+ }
4259+
4260+ break;
4261+ }
4262+
4263+ case IDM_OPTIONS_NEW2_GRAPHICS:
4264+ {
4265+ /* Paranoia */
4266+ if (!inkey_flag)
4267+ {
4268+ plog("You may not do that right now.");
4269+ break;
4270+ }
4271+
4272+ /* Toggle "arg_graphics" */
4273+ if (arg_graphics != GRAPHICS_HENGBAND)
4274+ {
4275+ arg_graphics = GRAPHICS_HENGBAND;
4276+
4277+ /* React to changes */
4278+ Term_xtra_win_react();
4279+
4280+ /* Hack -- Force redraw */
4281+ Term_key_push(KTRL('R'));
4282+ }
4283+
4284+ break;
4285+ }
4286+
4287+ case IDM_OPTIONS_BIGTILE:
4288+ {
4289+ term_data *td = &data[0];
4290+
4291+ /* Paranoia */
4292+ if (!inkey_flag)
4293+ {
4294+ plog("You may not do that right now.");
4295+ break;
4296+ }
4297+
4298+ /* Toggle "arg_sound" */
4299+ arg_bigtile = !arg_bigtile;
4300+
4301+ /* Activate */
4302+ Term_activate(&td->t);
4303+
4304+ /* Resize the term */
4305+ Term_resize(td->cols, td->rows);
4306+
4307+ /* Redraw later */
4308+ InvalidateRect(td->w, NULL, TRUE);
4309+
4310+ break;
4311+ }
4312+
4313+ case IDM_OPTIONS_MUSIC:
4314+ {
4315+ /* Paranoia */
4316+ if (!inkey_flag)
4317+ {
4318+ plog("You may not do that right now.");
4319+ break;
4320+ }
4321+
4322+ /* Toggle "arg_sound" */
4323+ arg_music = !arg_music;
4324+
4325+ /* React to changes */
4326+ Term_xtra_win_react();
4327+
4328+ /* Hack -- Force redraw */
4329+ Term_key_push(KTRL('R'));
4330+
4331+ break;
4332+ }
4333+
4334+ case IDM_OPTIONS_SOUND:
4335+ {
4336+ /* Paranoia */
4337+ if (!inkey_flag)
4338+ {
4339+ plog("You may not do that right now.");
4340+ break;
4341+ }
4342+
4343+ /* Toggle "arg_sound" */
4344+ arg_sound = !arg_sound;
4345+
4346+ /* React to changes */
4347+ Term_xtra_win_react();
4348+
4349+ /* Hack -- Force redraw */
4350+ Term_key_push(KTRL('R'));
4351+
4352+ break;
4353+ }
4354+
4355+ /* bg */
4356+ case IDM_OPTIONS_BG:
4357+ {
4358+ /* Paranoia */
4359+ if (!inkey_flag)
4360+ {
4361+ plog("You may not do that right now.");
4362+ break;
4363+ }
4364+
4365+ /* Toggle "use_bg" */
4366+ use_bg = !use_bg;
4367+
4368+ init_bg();
4369+
4370+ /* React to changes */
4371+ Term_xtra_win_react();
4372+
4373+ /* Hack -- Force redraw */
4374+ Term_key_push(KTRL('R'));
4375+
4376+ break;
4377+ }
4378+
4379+ /* bg */
4380+ case IDM_OPTIONS_OPEN_BG:
4381+ {
4382+ /* Paranoia */
4383+ if (!inkey_flag)
4384+ {
4385+ plog("You may not do that right now.");
4386+ break;
4387+ }
4388+ else
4389+ {
4390+ memset(&ofn, 0, sizeof(ofn));
4391+ ofn.lStructSize = sizeof(ofn);
4392+ ofn.hwndOwner = data[0].w;
4393+ ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4394+ ofn.nFilterIndex = 1;
4395+ ofn.lpstrFile = bg_bitmap_file;
4396+ ofn.nMaxFile = 1023;
4397+ ofn.lpstrInitialDir = NULL;
4398+ ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4399+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4400+
4401+ if (GetOpenFileName(&ofn))
4402+ {
4403+ /* Load 'savefile' */
4404+ use_bg = 1;
4405+ init_bg();
4406+ }
4407+
4408+ /* React to changes */
4409+ Term_xtra_win_react();
4410+
4411+ /* Hack -- Force redraw */
4412+ Term_key_push(KTRL('R'));
4413+ }
4414+ break;
4415+ }
4416+
4417+ case IDM_DUMP_SCREEN_HTML:
4418+ {
4419+ static char buf[1024] = "";
4420+ memset(&ofn, 0, sizeof(ofn));
4421+ ofn.lStructSize = sizeof(ofn);
4422+ ofn.hwndOwner = data[0].w;
4423+ ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4424+ ofn.nFilterIndex = 1;
4425+ ofn.lpstrFile = buf;
4426+ ofn.nMaxFile = 1023;
4427+ ofn.lpstrDefExt = "html";
4428+ ofn.lpstrInitialDir = NULL;
4429+ ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4430+ ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4431+
4432+ if (GetSaveFileName(&ofn))
4433+ {
4434+ do_cmd_save_screen_html_aux(buf, 0);
4435+ }
4436+ break;
4437+ }
4438+
4439+#ifdef USE_SAVER
4440+
4441+ case IDM_OPTIONS_SAVER:
4442+ {
4443+ if (hwndSaver)
4444+ {
4445+ DestroyWindow(hwndSaver);
4446+ hwndSaver = NULL;
4447+ }
4448+ else
4449+ {
4450+ /* Create a screen scaver window */
4451+ hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4452+ "Angband Screensaver",
4453+ WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4454+ 0, 0, GetSystemMetrics(SM_CXSCREEN),
4455+ GetSystemMetrics(SM_CYSCREEN),
4456+ NULL, NULL, hInstance, NULL);
4457+
4458+ if (hwndSaver)
4459+ {
4460+ /* Push the window to the bottom XXX XXX XXX */
4461+ SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4462+ }
4463+ else
4464+ {
4465+ plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4466+ }
4467+ }
4468+ break;
4469+ }
4470+
4471+#endif
4472+
4473+ case IDM_OPTIONS_MAP:
4474+ {
4475+ windows_map();
4476+ break;
4477+ }
4478+
4479+ case IDM_HELP_CONTENTS:
4480+ {
4481+#ifdef HTML_HELP
4482+ char tmp[1024];
4483+ path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4484+ if (check_file(tmp))
4485+ {
4486+ HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4487+ }
4488+ else
4489+ {
4490+#ifdef JP
4491+ plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4492+ plog("代わりにオンラインヘルプを使用してください。");
4493+#else
4494+ plog_fmt("Cannot find help file: %s", tmp);
4495+ plog("Use the online help files instead.");
4496+#endif
4497+
4498+ }
4499+ break;
4500+#else /* HTML_HELP */
4501+ char buf[1024];
4502+ char tmp[1024];
4503+ path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4504+ if (check_file(tmp))
4505+ {
4506+ sprintf(buf, "winhelp.exe %s", tmp);
4507+ WinExec(buf, SW_NORMAL);
4508+ }
4509+ else
4510+ {
4511+#ifdef JP
4512+ plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4513+ plog("代わりにオンラインヘルプを使用してください。");
4514+#else
4515+ plog_fmt("Cannot find help file: %s", tmp);
4516+ plog("Use the online help files instead.");
4517+#endif
4518+
4519+ }
4520+ break;
4521+#endif /* HTML_HELP */
4522+ }
4523+ }
4524+}
4525+
4526+
4527+static bool process_keydown(WPARAM wParam, LPARAM lParam)
4528+{
4529+ int i;
4530+ bool mc = FALSE;
4531+ bool ms = FALSE;
4532+ bool ma = FALSE;
4533+
4534+ /* Extract the modifiers */
4535+ if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4536+ if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4537+ if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4538+
4539+ Term_no_press = (ma) ? TRUE : FALSE;
4540+
4541+ /* Handle "special" keys */
4542+ if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4543+ {
4544+ bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4545+ bool numpad = FALSE;
4546+
4547+ /* Begin the macro trigger */
4548+ Term_keypress(31);
4549+
4550+ /* Send the modifiers */
4551+ if (mc) Term_keypress('C');
4552+ if (ms) Term_keypress('S');
4553+ if (ma) Term_keypress('A');
4554+
4555+ /* Extract "scan code" */
4556+ i = LOBYTE(HIWORD(lParam));
4557+
4558+ /* Introduce the scan code */
4559+ Term_keypress('x');
4560+
4561+ /* Extended key bit */
4562+ switch (wParam)
4563+ {
4564+ /* Numpad Enter and '/' are extended key */
4565+ case VK_DIVIDE:
4566+ Term_no_press = TRUE;
4567+ case VK_RETURN: /* Enter */
4568+ numpad = ext_key;
4569+ break;
4570+ /* Other extended keys are on full keyboard */
4571+ case VK_NUMPAD0:
4572+ case VK_NUMPAD1:
4573+ case VK_NUMPAD2:
4574+ case VK_NUMPAD3:
4575+ case VK_NUMPAD4:
4576+ case VK_NUMPAD5:
4577+ case VK_NUMPAD6:
4578+ case VK_NUMPAD7:
4579+ case VK_NUMPAD8:
4580+ case VK_NUMPAD9:
4581+ case VK_ADD:
4582+ case VK_MULTIPLY:
4583+ case VK_SUBTRACT:
4584+ case VK_SEPARATOR:
4585+ case VK_DECIMAL:
4586+ Term_no_press = TRUE;
4587+ case VK_CLEAR:
4588+ case VK_HOME:
4589+ case VK_END:
4590+ case VK_PRIOR: /* Page Up */
4591+ case VK_NEXT: /* Page Down */
4592+ case VK_INSERT:
4593+ case VK_DELETE:
4594+ case VK_UP:
4595+ case VK_DOWN:
4596+ case VK_LEFT:
4597+ case VK_RIGHT:
4598+ numpad = !ext_key;
4599+ }
4600+
4601+ /* Special modifiers for keypad keys */
4602+ if (numpad) Term_keypress('K');
4603+
4604+ /* Encode the hexidecimal scan code */
4605+ Term_keypress(hexsym[i/16]);
4606+ Term_keypress(hexsym[i%16]);
4607+
4608+ /* End the macro trigger */
4609+ Term_keypress(13);
4610+
4611+ return 1;
4612+ }
4613+
4614+ return 0;
4615+}
4616+
4617+
4618+#ifdef __MWERKS__
4619+LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4620+ WPARAM wParam, LPARAM lParam);
4621+LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4622+ WPARAM wParam, LPARAM lParam)
4623+#else /* __MWERKS__ */
4624+LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4625+ WPARAM wParam, LPARAM lParam)
4626+#endif /* __MWERKS__ */
4627+{
4628+ PAINTSTRUCT ps;
4629+ HDC hdc;
4630+ term_data *td;
4631+#if 0
4632+ MINMAXINFO FAR *lpmmi;
4633+ RECT rc;
4634+#endif
4635+ int i;
4636+
4637+
4638+ /* Acquire proper "term_data" info */
4639+ td = (term_data *)GetWindowLong(hWnd, 0);
4640+
4641+ /* Handle message */
4642+ switch (uMsg)
4643+ {
4644+ /* XXX XXX XXX */
4645+ case WM_NCCREATE:
4646+ {
4647+ SetWindowLong(hWnd, 0, (LONG)(my_td));
4648+ break;
4649+ }
4650+
4651+ /* XXX XXX XXX */
4652+ case WM_CREATE:
4653+ {
4654+#ifdef USE_MUSIC
4655+ mop.dwCallback=(DWORD)hWnd;
4656+#endif
4657+ return 0;
4658+ }
4659+
4660+ case WM_GETMINMAXINFO:
4661+ {
4662+ MINMAXINFO FAR *lpmmi;
4663+ RECT rc;
4664+
4665+ lpmmi = (MINMAXINFO FAR *)lParam;
4666+
4667+ /* this message was sent before WM_NCCREATE */
4668+ if (!td) return 1;
4669+
4670+ /* Minimum window size is 80x24 */
4671+ rc.left = rc.top = 0;
4672+ rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4673+ rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4674+
4675+ /* Adjust */
4676+ AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4677+
4678+ /* Save minimum size */
4679+ lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4680+ lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4681+
4682+ return 0;
4683+ }
4684+
4685+ case WM_PAINT:
4686+ {
4687+ BeginPaint(hWnd, &ps);
4688+ if (td) term_data_redraw(td);
4689+ EndPaint(hWnd, &ps);
4690+ ValidateRect(hWnd, NULL);
4691+ return 0;
4692+ }
4693+
4694+#ifdef USE_MUSIC
4695+ case MM_MCINOTIFY:
4696+ {
4697+ if(wParam == MCI_NOTIFY_SUCCESSFUL)
4698+ {
4699+ mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4700+ mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4701+ }
4702+ return 0;
4703+ }
4704+#endif
4705+
4706+ case WM_SYSKEYDOWN:
4707+ case WM_KEYDOWN:
4708+ {
4709+ if (process_keydown(wParam, lParam))
4710+ return 0;
4711+ break;
4712+ }
4713+
4714+ case WM_CHAR:
4715+ {
4716+ if (Term_no_press) Term_no_press = FALSE;
4717+ else Term_keypress(wParam);
4718+ return 0;
4719+ }
4720+
4721+ case WM_LBUTTONDOWN:
4722+ {
4723+ mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4724+ mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4725+ mouse_down = TRUE;
4726+ oldx = mousex;
4727+ oldy = mousey;
4728+ return 0;
4729+ }
4730+
4731+ case WM_LBUTTONUP:
4732+ {
4733+ HGLOBAL hGlobal;
4734+ LPSTR lpStr;
4735+ int i, j, sz;
4736+ int dx = abs(oldx - mousex) + 1;
4737+ int dy = abs(oldy - mousey) + 1;
4738+ int ox = (oldx > mousex) ? mousex : oldx;
4739+ int oy = (oldy > mousey) ? mousey : oldy;
4740+
4741+ mouse_down = FALSE;
4742+ paint_rect = FALSE;
4743+
4744+#ifdef JP
4745+ sz = (dx + 3) * dy;
4746+#else
4747+ sz = (dx + 2) * dy;
4748+#endif
4749+ hGlobal = GlobalAlloc(GHND, sz + 1);
4750+ if (hGlobal == NULL) return 0;
4751+ lpStr = (LPSTR)GlobalLock(hGlobal);
4752+
4753+ for (i = 0; i < dy; i++)
4754+ {
4755+#ifdef JP
4756+ char *s;
4757+ char **scr = data[0].t.scr->c;
4758+
4759+ C_MAKE(s, (dx + 1), char);
4760+ strncpy(s, &scr[oy + i][ox], dx);
4761+
4762+ if (ox > 0)
4763+ {
4764+ if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4765+ }
4766+
4767+ if (ox + dx < data[0].cols)
4768+ {
4769+ if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4770+ }
4771+
4772+ for (j = 0; j < dx; j++)
4773+ {
4774+ if (s[j] == 127) s[j] = '#';
4775+ *lpStr++ = s[j];
4776+ }
4777+#else
4778+ for (j = 0; j < dx; j++)
4779+ {
4780+ *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4781+ }
4782+#endif
4783+ if (dy > 1)
4784+ {
4785+ *lpStr++ = '\r';
4786+ *lpStr++ = '\n';
4787+ }
4788+ }
4789+
4790+ GlobalUnlock(hGlobal);
4791+ if (OpenClipboard(hWnd) == 0)
4792+ {
4793+ GlobalFree(hGlobal);
4794+ return 0;
4795+ }
4796+ EmptyClipboard();
4797+ SetClipboardData(CF_TEXT, hGlobal);
4798+ CloseClipboard();
4799+
4800+ Term_redraw();
4801+
4802+ return 0;
4803+ }
4804+
4805+ case WM_MOUSEMOVE:
4806+ {
4807+ if (mouse_down)
4808+ {
4809+ int dx, dy;
4810+ int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4811+ int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4812+ int ox, oy;
4813+
4814+ if (paint_rect)
4815+ {
4816+ dx = abs(oldx - mousex) + 1;
4817+ dy = abs(oldy - mousey) + 1;
4818+ ox = (oldx > mousex) ? mousex : oldx;
4819+ oy = (oldy > mousey) ? mousey : oldy;
4820+ Term_inversed_area(hWnd, ox, oy, dx, dy);
4821+ }
4822+ else
4823+ {
4824+ paint_rect = TRUE;
4825+ }
4826+
4827+ dx = abs(cx - mousex) + 1;
4828+ dy = abs(cy - mousey) + 1;
4829+ ox = (cx > mousex) ? mousex : cx;
4830+ oy = (cy > mousey) ? mousey : cy;
4831+ Term_inversed_area(hWnd, ox, oy, dx, dy);
4832+
4833+ oldx = cx;
4834+ oldy = cy;
4835+ }
4836+ return 0;
4837+ }
4838+
4839+ case WM_INITMENU:
4840+ {
4841+ setup_menus();
4842+ return 0;
4843+ }
4844+
4845+ case WM_CLOSE:
4846+ {
4847+ if (game_in_progress && character_generated)
4848+ {
4849+ if (!can_save)
4850+ {
4851+ plog(_("今は終了できません。", "You may not do that right now."));
4852+ return 0;
4853+ }
4854+
4855+ /* Hack -- Forget messages */
4856+ msg_flag = FALSE;
4857+
4858+ forget_lite();
4859+ forget_view();
4860+ clear_mon_lite();
4861+
4862+ /* Save the game */
4863+#ifdef ZANGBAND
4864+ /* do_cmd_save_game(FALSE); */
4865+#else /* ZANGBAND */
4866+ /* do_cmd_save_game(); */
4867+#endif /* ZANGBAND */
4868+ Term_key_push(SPECIAL_KEY_QUIT);
4869+ return 0;
4870+ }
4871+ quit(NULL);
4872+ return 0;
4873+ }
4874+
4875+ case WM_QUERYENDSESSION:
4876+ {
4877+ if (game_in_progress && character_generated)
4878+ {
4879+ /* Hack -- Forget messages */
4880+ msg_flag = FALSE;
4881+
4882+ /* Mega-Hack -- Delay death */
4883+ if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4884+ do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4885+
4886+ /* Hardcode panic save */
4887+ p_ptr->panic_save = 1;
4888+
4889+ /* Forbid suspend */
4890+ signals_ignore_tstp();
4891+
4892+ /* Indicate panic save */
4893+ (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4894+
4895+ /* Panic save */
4896+ (void)save_player();
4897+ }
4898+ quit(NULL);
4899+ return 0;
4900+ }
4901+
4902+ case WM_QUIT:
4903+ {
4904+ quit(NULL);
4905+ return 0;
4906+ }
4907+
4908+ case WM_COMMAND:
4909+ {
4910+ process_menus(LOWORD(wParam));
4911+ return 0;
4912+ }
4913+
4914+ case WM_SIZE:
4915+ {
4916+ /* this message was sent before WM_NCCREATE */
4917+ if (!td) return 1;
4918+
4919+ /* it was sent from inside CreateWindowEx */
4920+ if (!td->w) return 1;
4921+
4922+ /* was sent from WM_SIZE */
4923+ if (td->size_hack) return 1;
4924+
4925+ switch (wParam)
4926+ {
4927+ case SIZE_MINIMIZED:
4928+ {
4929+ /* Hide sub-windows */
4930+ for (i = 1; i < MAX_TERM_DATA; i++)
4931+ {
4932+ if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4933+ }
4934+ return 0;
4935+ }
4936+
4937+ case SIZE_MAXIMIZED:
4938+ {
4939+ /* fall through XXX XXX XXX */
4940+ }
4941+
4942+ case SIZE_RESTORED:
4943+ {
4944+ uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4945+ uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4946+
4947+ /* New size */
4948+ if ((td->cols != cols) || (td->rows != rows))
4949+ {
4950+ /* Save the new size */
4951+ td->cols = cols;
4952+ td->rows = rows;
4953+
4954+ if (!IsZoomed(td->w) && !IsIconic(td->w))
4955+ {
4956+ normsize.x = td->cols;
4957+ normsize.y = td->rows;
4958+ }
4959+
4960+ /* Activate */
4961+ Term_activate(&td->t);
4962+
4963+ /* Resize the term */
4964+ Term_resize(td->cols, td->rows);
4965+
4966+ /* Redraw later */
4967+ InvalidateRect(td->w, NULL, TRUE);
4968+ }
4969+
4970+ td->size_hack = TRUE;
4971+
4972+ /* Show sub-windows */
4973+ for (i = 1; i < MAX_TERM_DATA; i++)
4974+ {
4975+ if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4976+ }
4977+
4978+ td->size_hack = FALSE;
4979+
4980+ return 0;
4981+ }
4982+ }
4983+ break;
4984+ }
4985+
4986+ case WM_PALETTECHANGED:
4987+ {
4988+ /* Ignore if palette change caused by itself */
4989+ if ((HWND)wParam == hWnd) return 0;
4990+
4991+ /* Fall through... */
4992+ }
4993+
4994+ case WM_QUERYNEWPALETTE:
4995+ {
4996+ if (!paletted) return 0;
4997+
4998+ hdc = GetDC(hWnd);
4999+
5000+ SelectPalette(hdc, hPal, FALSE);
5001+
5002+ i = RealizePalette(hdc);
5003+
5004+ /* if any palette entries changed, repaint the window. */
5005+ if (i) InvalidateRect(hWnd, NULL, TRUE);
5006+
5007+ ReleaseDC(hWnd, hdc);
5008+
5009+ return 0;
5010+ }
5011+
5012+ case WM_ACTIVATE:
5013+ {
5014+ if (wParam && !HIWORD(lParam))
5015+ {
5016+ /* Do something to sub-windows */
5017+ for (i = 1; i < MAX_TERM_DATA; i++)
5018+ {
5019+ if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5020+ }
5021+
5022+ /* Focus on main window */
5023+ SetFocus(hWnd);
5024+
5025+ return 0;
5026+ }
5027+
5028+ break;
5029+ }
5030+
5031+ case WM_ACTIVATEAPP:
5032+ {
5033+ if (IsIconic(td->w)) break;
5034+
5035+ for (i = 1; i < MAX_TERM_DATA; i++)
5036+ {
5037+ if(data[i].visible)
5038+ {
5039+ if (wParam == TRUE)
5040+ {
5041+ ShowWindow(data[i].w, SW_SHOW);
5042+ }
5043+ else
5044+ {
5045+ ShowWindow(data[i].w, SW_HIDE);
5046+ }
5047+ }
5048+ }
5049+ }
5050+ }
5051+
5052+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
5053+}
5054+
5055+
5056+#ifdef __MWERKS__
5057+LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5058+ WPARAM wParam, LPARAM lParam);
5059+LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5060+ WPARAM wParam, LPARAM lParam)
5061+#else /* __MWERKS__ */
5062+LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5063+ WPARAM wParam, LPARAM lParam)
5064+#endif /* __MWERKS__ */
5065+{
5066+ term_data *td;
5067+#if 0
5068+ MINMAXINFO FAR *lpmmi;
5069+ RECT rc;
5070+#endif
5071+ PAINTSTRUCT ps;
5072+ HDC hdc;
5073+ int i;
5074+
5075+
5076+ /* Acquire proper "term_data" info */
5077+ td = (term_data *)GetWindowLong(hWnd, 0);
5078+
5079+ /* Process message */
5080+ switch (uMsg)
5081+ {
5082+ /* XXX XXX XXX */
5083+ case WM_NCCREATE:
5084+ {
5085+ SetWindowLong(hWnd, 0, (LONG)(my_td));
5086+ break;
5087+ }
5088+
5089+ /* XXX XXX XXX */
5090+ case WM_CREATE:
5091+ {
5092+ return 0;
5093+ }
5094+
5095+ case WM_GETMINMAXINFO:
5096+ {
5097+ MINMAXINFO FAR *lpmmi;
5098+ RECT rc;
5099+
5100+ lpmmi = (MINMAXINFO FAR *)lParam;
5101+
5102+ /* this message was sent before WM_NCCREATE */
5103+ if (!td) return 1;
5104+
5105+ /* Minimum window size is 80x24 */
5106+ rc.left = rc.top = 0;
5107+ rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5108+ rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5109+
5110+ /* Adjust */
5111+ AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5112+
5113+ /* Save minimum size */
5114+ lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5115+ lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5116+
5117+ return 0;
5118+ }
5119+
5120+ case WM_SIZE:
5121+ {
5122+ uint cols;
5123+ uint rows;
5124+
5125+ /* this message was sent before WM_NCCREATE */
5126+ if (!td) return 1;
5127+
5128+ /* it was sent from inside CreateWindowEx */
5129+ if (!td->w) return 1;
5130+
5131+ /* was sent from inside WM_SIZE */
5132+ if (td->size_hack) return 1;
5133+
5134+ td->size_hack = TRUE;
5135+
5136+ cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5137+ rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5138+
5139+ /* New size */
5140+ if ((td->cols != cols) || (td->rows != rows))
5141+ {
5142+ /* Save old term */
5143+ term *old_term = Term;
5144+
5145+ /* Save the new size */
5146+ td->cols = cols;
5147+ td->rows = rows;
5148+
5149+ /* Activate */
5150+ Term_activate(&td->t);
5151+
5152+ /* Resize the term */
5153+ Term_resize(td->cols, td->rows);
5154+
5155+ /* Activate */
5156+ Term_activate(old_term);
5157+
5158+ /* Redraw later */
5159+ InvalidateRect(td->w, NULL, TRUE);
5160+
5161+ /* HACK - Redraw all windows */
5162+ p_ptr->window = 0xFFFFFFFF;
5163+ window_stuff();
5164+ }
5165+
5166+ td->size_hack = FALSE;
5167+
5168+ return 0;
5169+ }
5170+
5171+ case WM_PAINT:
5172+ {
5173+ BeginPaint(hWnd, &ps);
5174+ if (td) term_data_redraw(td);
5175+ EndPaint(hWnd, &ps);
5176+ return 0;
5177+ }
5178+
5179+ case WM_SYSKEYDOWN:
5180+ case WM_KEYDOWN:
5181+ {
5182+ if (process_keydown(wParam, lParam))
5183+ return 0;
5184+ break;
5185+ }
5186+
5187+ case WM_CHAR:
5188+ {
5189+ if (Term_no_press) Term_no_press = FALSE;
5190+ else Term_keypress(wParam);
5191+ return 0;
5192+ }
5193+
5194+ case WM_PALETTECHANGED:
5195+ {
5196+ /* ignore if palette change caused by itself */
5197+ if ((HWND)wParam == hWnd) return FALSE;
5198+ /* otherwise, fall through!!! */
5199+ }
5200+
5201+ case WM_QUERYNEWPALETTE:
5202+ {
5203+ if (!paletted) return 0;
5204+ hdc = GetDC(hWnd);
5205+ SelectPalette(hdc, hPal, FALSE);
5206+ i = RealizePalette(hdc);
5207+ /* if any palette entries changed, repaint the window. */
5208+ if (i) InvalidateRect(hWnd, NULL, TRUE);
5209+ ReleaseDC(hWnd, hdc);
5210+ return 0;
5211+ }
5212+
5213+ case WM_NCLBUTTONDOWN:
5214+ {
5215+
5216+#ifdef HTCLOSE
5217+ if (wParam == HTCLOSE) wParam = HTSYSMENU;
5218+#endif /* HTCLOSE */
5219+
5220+ if (wParam == HTSYSMENU)
5221+ {
5222+ if (td->visible)
5223+ {
5224+ td->visible = FALSE;
5225+ ShowWindow(td->w, SW_HIDE);
5226+ }
5227+
5228+ return 0;
5229+ }
5230+
5231+ break;
5232+ }
5233+ }
5234+
5235+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
5236+}
5237+
5238+
5239+#ifdef USE_SAVER
5240+
5241+#define MOUSE_SENS 40
5242+
5243+#ifdef __MWERKS__
5244+LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5245+ WPARAM wParam, LPARAM lParam);
5246+LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5247+ WPARAM wParam, LPARAM lParam)
5248+#else /* __MWERKS__ */
5249+LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5250+ WPARAM wParam, LPARAM lParam)
5251+#endif /* __MWERKS__ */
5252+{
5253+ static int iMouse = 0;
5254+ static WORD xMouse = 0;
5255+ static WORD yMouse = 0;
5256+
5257+ int dx, dy;
5258+
5259+
5260+ /* Process */
5261+ switch (uMsg)
5262+ {
5263+ /* XXX XXX XXX */
5264+ case WM_NCCREATE:
5265+ {
5266+ break;
5267+ }
5268+
5269+ case WM_SETCURSOR:
5270+ {
5271+ SetCursor(NULL);
5272+ return 0;
5273+ }
5274+
5275+#if 0
5276+ case WM_ACTIVATE:
5277+ {
5278+ if (LOWORD(wParam) == WA_INACTIVE) break;
5279+
5280+ /* else fall through */
5281+ }
5282+#endif
5283+
5284+ case WM_LBUTTONDOWN:
5285+ case WM_MBUTTONDOWN:
5286+ case WM_RBUTTONDOWN:
5287+ case WM_KEYDOWN:
5288+ {
5289+ SendMessage(hWnd, WM_CLOSE, 0, 0);
5290+ return 0;
5291+ }
5292+
5293+ case WM_MOUSEMOVE:
5294+ {
5295+ if (iMouse)
5296+ {
5297+ dx = LOWORD(lParam) - xMouse;
5298+ dy = HIWORD(lParam) - yMouse;
5299+
5300+ if (dx < 0) dx = -dx;
5301+ if (dy < 0) dy = -dy;
5302+
5303+ if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5304+ {
5305+ SendMessage(hWnd, WM_CLOSE, 0, 0);
5306+ }
5307+ }
5308+
5309+ /* Save last location */
5310+ iMouse = 1;
5311+ xMouse = LOWORD(lParam);
5312+ yMouse = HIWORD(lParam);
5313+
5314+ return 0;
5315+ }
5316+
5317+ case WM_CLOSE:
5318+ {
5319+ DestroyWindow(hwndSaver);
5320+ hwndSaver = NULL;
5321+ return 0;
5322+ }
5323+ }
5324+
5325+ /* Oops */
5326+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
5327+}
5328+
5329+#endif /* USE_SAVER */
5330+
5331+
5332+
5333+
5334+
5335+/*** Temporary Hooks ***/
5336+
5337+
5338+/*
5339+ * Display warning message (see "z-util.c")
5340+ */
5341+static void hack_plog(cptr str)
5342+{
5343+ /* Give a warning */
5344+ if (str)
5345+ {
5346+#ifdef JP
5347+ MessageBox(NULL, str, "警告!",
5348+ MB_ICONEXCLAMATION | MB_OK);
5349+#else
5350+ MessageBox(NULL, str, "Warning",
5351+ MB_ICONEXCLAMATION | MB_OK);
5352+#endif
5353+
5354+ }
5355+}
5356+
5357+
5358+/*
5359+ * Display error message and quit (see "z-util.c")
5360+ */
5361+static void hack_quit(cptr str)
5362+{
5363+ /* Give a warning */
5364+ if (str)
5365+ {
5366+#ifdef JP
5367+ MessageBox(NULL, str, "エラー!",
5368+ MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5369+#else
5370+ MessageBox(NULL, str, "Error",
5371+ MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5372+#endif
5373+
5374+ }
5375+
5376+ /* Unregister the classes */
5377+ UnregisterClass(AppName, hInstance);
5378+
5379+ /* Destroy the icon */
5380+ if (hIcon) DestroyIcon(hIcon);
5381+
5382+ /* Exit */
5383+ exit(0);
5384+}
5385+
5386+
5387+
5388+/*** Various hooks ***/
5389+
5390+
5391+/*
5392+ * Display warning message (see "z-util.c")
5393+ */
5394+static void hook_plog(cptr str)
5395+{
5396+ /* Warning */
5397+ if (str)
5398+ {
5399+#ifdef JP
5400+ MessageBox(data[0].w, str, "警告!",
5401+ MB_ICONEXCLAMATION | MB_OK);
5402+#else
5403+ MessageBox(data[0].w, str, "Warning",
5404+ MB_ICONEXCLAMATION | MB_OK);
5405+#endif
5406+
5407+ }
5408+}
5409+
5410+
5411+/*
5412+ * Display error message and quit (see "z-util.c")
5413+ */
5414+static void hook_quit(cptr str)
5415+{
5416+ int i;
5417+
5418+
5419+ /* Give a warning */
5420+ if (str)
5421+ {
5422+#ifdef JP
5423+ MessageBox(data[0].w, str, "エラー!",
5424+ MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5425+#else
5426+ MessageBox(data[0].w, str, "Error",
5427+ MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5428+#endif
5429+
5430+ }
5431+
5432+
5433+ /* Save the preferences */
5434+ save_prefs();
5435+
5436+
5437+ /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5438+
5439+ /* Destroy all windows */
5440+ for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5441+ {
5442+ term_force_font(&data[i], NULL);
5443+ if (data[i].font_want) string_free(data[i].font_want);
5444+ if (data[i].w) DestroyWindow(data[i].w);
5445+ data[i].w = 0;
5446+ }
5447+
5448+ /* Free the bitmap stuff */
5449+#ifdef USE_GRAPHICS
5450+ if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5451+ if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5452+
5453+ if (infMask.hPalette) DeleteObject(infMask.hPalette);
5454+ if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5455+
5456+#endif /* USE_GRAPHICS */
5457+
5458+ /*** Free some other stuff ***/
5459+
5460+ DeleteObject(hbrYellow);
5461+
5462+ /* bg */
5463+ delete_bg();
5464+
5465+ if (hPal) DeleteObject(hPal);
5466+
5467+ UnregisterClass(AppName, hInstance);
5468+
5469+ if (hIcon) DestroyIcon(hIcon);
5470+
5471+ exit(0);
5472+}
5473+
5474+
5475+
5476+/*** Initialize ***/
5477+
5478+
5479+/*
5480+ * Init some stuff
5481+ */
5482+static void init_stuff(void)
5483+{
5484+ int i;
5485+
5486+ char path[1024];
5487+
5488+
5489+ /* Get program name with full path */
5490+ GetModuleFileName(hInstance, path, 512);
5491+
5492+ /* Save the "program name" XXX XXX XXX */
5493+ argv0 = path;
5494+
5495+ /* Get the name of the "*.ini" file */
5496+ strcpy(path + strlen(path) - 4, ".INI");
5497+
5498+ /* Save the the name of the ini-file */
5499+ ini_file = string_make(path);
5500+
5501+ /* Analyze the path */
5502+ i = strlen(path);
5503+
5504+ /* Get the path */
5505+ for (; i > 0; i--)
5506+ {
5507+ if (path[i] == '\\')
5508+ {
5509+ /* End of path */
5510+ break;
5511+ }
5512+ }
5513+
5514+ /* Add "lib" to the path */
5515+ strcpy(path + i + 1, "lib\\");
5516+
5517+ /* Validate the path */
5518+ validate_dir(path, TRUE);
5519+
5520+ /* Init the file paths */
5521+ init_file_paths(path);
5522+
5523+ /* Hack -- Validate the paths */
5524+ validate_dir(ANGBAND_DIR_APEX, FALSE);
5525+ validate_dir(ANGBAND_DIR_BONE, FALSE);
5526+
5527+ /* Allow missing 'edit' directory */
5528+ if (!check_dir(ANGBAND_DIR_EDIT))
5529+ {
5530+ /* Must have 'data'! */
5531+ validate_dir(ANGBAND_DIR_DATA, TRUE);
5532+ }
5533+ else
5534+ {
5535+ /* Don't need 'data' */
5536+ validate_dir(ANGBAND_DIR_DATA, FALSE);
5537+ }
5538+
5539+ validate_dir(ANGBAND_DIR_FILE, TRUE);
5540+ validate_dir(ANGBAND_DIR_HELP, FALSE);
5541+ validate_dir(ANGBAND_DIR_INFO, FALSE);
5542+ validate_dir(ANGBAND_DIR_PREF, TRUE);
5543+ validate_dir(ANGBAND_DIR_SAVE, FALSE);
5544+ validate_dir(ANGBAND_DIR_USER, TRUE);
5545+ validate_dir(ANGBAND_DIR_XTRA, TRUE);
5546+
5547+ /* Build the filename */
5548+ path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5549+
5550+ /* Hack -- Validate the "news.txt" file */
5551+ validate_file(path);
5552+
5553+
5554+#if 0 /* #ifndef JP */
5555+ /* Build the "font" path */
5556+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5557+
5558+ /* Allocate the path */
5559+ ANGBAND_DIR_XTRA_FONT = string_make(path);
5560+
5561+ /* Validate the "font" directory */
5562+ validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5563+
5564+ /* Build the filename */
5565+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5566+
5567+ /* Hack -- Validate the basic font */
5568+ validate_file(path);
5569+#endif
5570+
5571+
5572+#ifdef USE_GRAPHICS
5573+
5574+ /* Build the "graf" path */
5575+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5576+
5577+ /* Allocate the path */
5578+ ANGBAND_DIR_XTRA_GRAF = string_make(path);
5579+
5580+ /* Validate the "graf" directory */
5581+ validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5582+
5583+#endif /* USE_GRAPHICS */
5584+
5585+
5586+#ifdef USE_SOUND
5587+
5588+ /* Build the "sound" path */
5589+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5590+
5591+ /* Allocate the path */
5592+ ANGBAND_DIR_XTRA_SOUND = string_make(path);
5593+
5594+ /* Validate the "sound" directory */
5595+ validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5596+
5597+#endif /* USE_SOUND */
5598+
5599+#ifdef USE_MUSIC
5600+
5601+ /* Build the "music" path */
5602+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5603+
5604+ /* Allocate the path */
5605+ ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5606+
5607+ /* Validate the "music" directory */
5608+ validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5609+
5610+#endif /* USE_MUSIC */
5611+
5612+ /* Build the "help" path */
5613+ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5614+
5615+ /* Allocate the path */
5616+ ANGBAND_DIR_XTRA_HELP = string_make(path);
5617+
5618+ /* Validate the "help" directory */
5619+ /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5620+}
5621+
5622+bool is_already_running()
5623+{
5624+ bool result = FALSE;
5625+ HANDLE hMutex;
5626+
5627+ hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5628+ if (GetLastError() == ERROR_ALREADY_EXISTS)
5629+ {
5630+ result = TRUE;
5631+ }
5632+ return result;
5633+}
5634+
5635+
5636+int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5637+ LPSTR lpCmdLine, int nCmdShow)
5638+{
5639+ int i;
5640+
5641+ WNDCLASS wc;
5642+ HDC hdc;
5643+ MSG msg;
5644+
5645+ setlocale( LC_ALL, "ja_JP" );
5646+
5647+ /* Unused */
5648+ (void)nCmdShow;
5649+
5650+ /* Save globally */
5651+ hInstance = hInst;
5652+
5653+
5654+ /* Prevent multiple run */
5655+ if (is_already_running())
5656+ {
5657+ MessageBox(NULL,
5658+ _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5659+ _("エラー!", "Error") ,
5660+ MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5661+ return FALSE;
5662+ }
5663+
5664+ /* Initialize */
5665+ if (hPrevInst == NULL)
5666+ {
5667+ wc.style = CS_CLASSDC;
5668+ wc.lpfnWndProc = AngbandWndProc;
5669+ wc.cbClsExtra = 0;
5670+ wc.cbWndExtra = 4; /* one long pointer to term_data */
5671+ wc.hInstance = hInst;
5672+ wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5673+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5674+ wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5675+ wc.lpszMenuName = AppName;
5676+ wc.lpszClassName = AppName;
5677+
5678+ if (!RegisterClass(&wc)) exit(1);
5679+
5680+ wc.lpfnWndProc = AngbandListProc;
5681+ wc.lpszMenuName = NULL;
5682+ wc.lpszClassName = AngList;
5683+
5684+ if (!RegisterClass(&wc)) exit(2);
5685+
5686+#ifdef USE_SAVER
5687+
5688+ wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5689+ wc.lpfnWndProc = AngbandSaverProc;
5690+ wc.hCursor = NULL;
5691+ wc.lpszMenuName = NULL;
5692+ wc.lpszClassName = "WindowsScreenSaverClass";
5693+
5694+ if (!RegisterClass(&wc)) exit(3);
5695+
5696+#endif
5697+
5698+ }
5699+
5700+ /* Temporary hooks */
5701+ plog_aux = hack_plog;
5702+ quit_aux = hack_quit;
5703+ core_aux = hack_quit;
5704+
5705+ /* Prepare the filepaths */
5706+ init_stuff();
5707+
5708+ /* Initialize the keypress analyzer */
5709+ for (i = 0; special_key_list[i]; ++i)
5710+ {
5711+ special_key[special_key_list[i]] = TRUE;
5712+ }
5713+ /* Initialize the keypress analyzer */
5714+ for (i = 0; ignore_key_list[i]; ++i)
5715+ {
5716+ ignore_key[ignore_key_list[i]] = TRUE;
5717+ }
5718+
5719+ /* Determine if display is 16/256/true color */
5720+ hdc = GetDC(NULL);
5721+ colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5722+ paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5723+ ReleaseDC(NULL, hdc);
5724+
5725+ /* Initialize the colors */
5726+ for (i = 0; i < 256; i++)
5727+ {
5728+ byte rv, gv, bv;
5729+
5730+ /* Extract desired values */
5731+ rv = angband_color_table[i][1];
5732+ gv = angband_color_table[i][2];
5733+ bv = angband_color_table[i][3];
5734+
5735+ /* Extract the "complex" code */
5736+ win_clr[i] = PALETTERGB(rv, gv, bv);
5737+
5738+ /* Save the "simple" code */
5739+ angband_color_table[i][0] = win_pal[i];
5740+ }
5741+
5742+ /* Prepare the windows */
5743+ init_windows();
5744+
5745+ /* bg */
5746+ init_bg();
5747+
5748+ /* Activate hooks */
5749+ plog_aux = hook_plog;
5750+ quit_aux = hook_quit;
5751+ core_aux = hook_quit;
5752+
5753+ /* Set the system suffix */
5754+ ANGBAND_SYS = "win";
5755+
5756+ /* Set the keyboard suffix */
5757+ if (7 != GetKeyboardType(0))
5758+ ANGBAND_KEYBOARD = "0";
5759+ else
5760+ {
5761+ /* Japanese keyboard */
5762+ switch (GetKeyboardType(1))
5763+ {
5764+ case 0x0D01: case 0x0D02:
5765+ case 0x0D03: case 0x0D04:
5766+ case 0x0D05: case 0x0D06:
5767+ /* NEC PC-98x1 */
5768+ ANGBAND_KEYBOARD = "NEC98";
5769+ break;
5770+ default:
5771+ /* PC/AT */
5772+ ANGBAND_KEYBOARD = "JAPAN";
5773+ }
5774+ }
5775+
5776+ /* Catch nasty signals */
5777+ signals_init();
5778+
5779+ /* Initialize */
57805780 Term_activate(term_screen);
5781- init_angband();
5782-
5783- /* We are now initialized */
5784- initialized = TRUE;
5785-#ifdef CHUUKEI
5786- if(lpCmdLine[0] == '-'){
5787- switch(lpCmdLine[1])
5788- {
5789- case 'p':
5790- case 'P':
5791- {
5792- if (!lpCmdLine[2]) break;
5793- chuukei_server = TRUE;
5794- if(connect_chuukei_server(&lpCmdLine[2])<0){
5795- msg_print("connect fail");
5796- return 0;
5797- }
5798- msg_print("connect");
5799- msg_print(NULL);
5800- break;
5801- }
5802-
5803- case 'c':
5804- case 'C':
5805- {
5806- if (!lpCmdLine[2]) break;
5807- chuukei_client = TRUE;
5808- connect_chuukei_server(&lpCmdLine[2]);
5809- play_game(FALSE);
5810- quit(NULL);
5811- return 0;
5812- }
5813- case 'X':
5814- case 'x':
5815- {
5816- if (!lpCmdLine[2]) break;
5817- prepare_browse_movie(&lpCmdLine[2]);
5818- play_game(FALSE);
5819- quit(NULL);
5820- return 0;
5821- }
5822- }
5823- }
5824-#endif
5825-
5826-#ifdef CHUUKEI
5827- /* Did the user double click on a save file? */
5828- if(!chuukei_server) check_for_save_file(lpCmdLine);
5829-#else
5830- /* Did the user double click on a save file? */
5831- check_for_save_file(lpCmdLine);
5832-#endif
5833-
5834- /* Prompt the user */
5835- prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5836-
5837- Term_fresh();
5838-
5839- /* Process messages forever */
5840- while (GetMessage(&msg, NULL, 0, 0))
5841- {
5842- TranslateMessage(&msg);
5843- DispatchMessage(&msg);
5844- }
5845-
5846- /* Paranoia */
5847- quit(NULL);
5848-
5849- /* Paranoia */
5850- return (0);
5851-}
5852-
5853-
5854-#endif /* WINDOWS */
5855-
5781+ init_angband();
5782+
5783+ /* We are now initialized */
5784+ initialized = TRUE;
5785+#ifdef CHUUKEI
5786+ if(lpCmdLine[0] == '-'){
5787+ switch(lpCmdLine[1])
5788+ {
5789+ case 'p':
5790+ case 'P':
5791+ {
5792+ if (!lpCmdLine[2]) break;
5793+ chuukei_server = TRUE;
5794+ if(connect_chuukei_server(&lpCmdLine[2])<0){
5795+ msg_print("connect fail");
5796+ return 0;
5797+ }
5798+ msg_print("connect");
5799+ msg_print(NULL);
5800+ break;
5801+ }
5802+
5803+ case 'c':
5804+ case 'C':
5805+ {
5806+ if (!lpCmdLine[2]) break;
5807+ chuukei_client = TRUE;
5808+ connect_chuukei_server(&lpCmdLine[2]);
5809+ play_game(FALSE);
5810+ quit(NULL);
5811+ return 0;
5812+ }
5813+ case 'X':
5814+ case 'x':
5815+ {
5816+ if (!lpCmdLine[2]) break;
5817+ prepare_browse_movie(&lpCmdLine[2]);
5818+ play_game(FALSE);
5819+ quit(NULL);
5820+ return 0;
5821+ }
5822+ }
5823+ }
5824+#endif
5825+
5826+#ifdef CHUUKEI
5827+ /* Did the user double click on a save file? */
5828+ if(!chuukei_server) check_for_save_file(lpCmdLine);
5829+#else
5830+ /* Did the user double click on a save file? */
5831+ check_for_save_file(lpCmdLine);
5832+#endif
5833+
5834+ /* Prompt the user */
5835+ prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5836+
5837+ Term_fresh();
5838+
5839+ /* Process messages forever */
5840+ while (GetMessage(&msg, NULL, 0, 0))
5841+ {
5842+ TranslateMessage(&msg);
5843+ DispatchMessage(&msg);
5844+ }
5845+
5846+ /* Paranoia */
5847+ quit(NULL);
5848+
5849+ /* Paranoia */
5850+ return (0);
5851+}
5852+
5853+
5854+#endif /* WINDOWS */
5855+
--- a/src/main.c
+++ b/src/main.c
@@ -99,13 +99,6 @@ static void init_stuff(void)
9999 {
100100 char path[1024];
101101
102-#if defined(VM)
103-
104- /* Hack -- prepare "path" */
105- strcpy(path, "Angband:");
106-
107-#else /* VM */
108-
109102 cptr tail;
110103
111104 /* Get the environment variable */
@@ -120,8 +113,6 @@ static void init_stuff(void)
120113 /* Hack -- Add a path separator (only if needed) */
121114 if (!suffix(path, PATH_SEP)) strcat(path, PATH_SEP);
122115
123-#endif /* VM */
124-
125116 /* Initialize */
126117 init_file_paths(path);
127118 }
--- a/src/save.c
+++ b/src/save.c
@@ -1667,12 +1667,6 @@ bool save_player(void)
16671667 strcpy(safe, savefile);
16681668 strcat(safe, ".new");
16691669
1670-#ifdef VM
1671- /* Hack -- support "flat directory" usage on VM/ESA */
1672- strcpy(safe, savefile);
1673- strcat(safe, "n");
1674-#endif /* VM */
1675-
16761670 /* Grab permissions */
16771671 safe_setuid_grab();
16781672
@@ -1693,12 +1687,6 @@ bool save_player(void)
16931687 strcpy(temp, savefile);
16941688 strcat(temp, ".old");
16951689
1696-#ifdef VM
1697- /* Hack -- support "flat directory" usage on VM/ESA */
1698- strcpy(temp, savefile);
1699- strcat(temp, "o");
1700-#endif /* VM */
1701-
17021690 /* Grab permissions */
17031691 safe_setuid_grab();
17041692
@@ -1811,7 +1799,7 @@ bool load_player(void)
18111799 if (!savefile[0]) return (TRUE);
18121800
18131801
1814-#if !defined(MACINTOSH) && !defined(WINDOWS) && !defined(VM)
1802+#if !defined(MACINTOSH) && !defined(WINDOWS)
18151803
18161804 /* XXX XXX XXX Fix this */
18171805