📄 main-win.c
字号:
* keys which I do not recognize, but which are listed among keys which we
* do catch, so they should be harmless to catch.
*/
static byte special_key_list[] =
{
VK_CLEAR, /* 0x0C (KP<5>) */
VK_PAUSE, /* 0x13 (pause) */
VK_PRIOR, /* 0x21 (KP<9>) */
VK_NEXT, /* 0x22 (KP<3>) */
VK_END, /* 0x23 (KP<1>) */
VK_HOME, /* 0x24 (KP<7>) */
VK_LEFT, /* 0x25 (KP<4>) */
VK_UP, /* 0x26 (KP<8>) */
VK_RIGHT, /* 0x27 (KP<6>) */
VK_DOWN, /* 0x28 (KP<2>) */
VK_SELECT, /* 0x29 (?????) */
VK_PRINT, /* 0x2A (?????) */
VK_EXECUTE, /* 0x2B (?????) */
VK_SNAPSHOT, /* 0x2C (?????) */
VK_INSERT, /* 0x2D (KP<0>) */
VK_DELETE, /* 0x2E (KP<.>) */
VK_HELP, /* 0x2F (?????) */
#if 0
VK_NUMPAD0, /* 0x60 (KP<0>) */
VK_NUMPAD1, /* 0x61 (KP<1>) */
VK_NUMPAD2, /* 0x62 (KP<2>) */
VK_NUMPAD3, /* 0x63 (KP<3>) */
VK_NUMPAD4, /* 0x64 (KP<4>) */
VK_NUMPAD5, /* 0x65 (KP<5>) */
VK_NUMPAD6, /* 0x66 (KP<6>) */
VK_NUMPAD7, /* 0x67 (KP<7>) */
VK_NUMPAD8, /* 0x68 (KP<8>) */
VK_NUMPAD9, /* 0x69 (KP<9>) */
VK_MULTIPLY, /* 0x6A (KP<*>) */
VK_ADD, /* 0x6B (KP<+>) */
VK_SEPARATOR, /* 0x6C (?????) */
VK_SUBTRACT, /* 0x6D (KP<->) */
VK_DECIMAL, /* 0x6E (KP<.>) */
VK_DIVIDE, /* 0x6F (KP</>) */
#endif /* 0 */
VK_F1, /* 0x70 */
VK_F2, /* 0x71 */
VK_F3, /* 0x72 */
VK_F4, /* 0x73 */
VK_F5, /* 0x74 */
VK_F6, /* 0x75 */
VK_F7, /* 0x76 */
VK_F8, /* 0x77 */
VK_F9, /* 0x78 */
VK_F10, /* 0x79 */
VK_F11, /* 0x7A */
VK_F12, /* 0x7B */
VK_F13, /* 0x7C */
VK_F14, /* 0x7D */
VK_F15, /* 0x7E */
VK_F16, /* 0x7F */
VK_F17, /* 0x80 */
VK_F18, /* 0x81 */
VK_F19, /* 0x82 */
VK_F20, /* 0x83 */
VK_F21, /* 0x84 */
VK_F22, /* 0x85 */
VK_F23, /* 0x86 */
VK_F24, /* 0x87 */
0
};
#if 0
/*
* Hack -- given a pathname, point at the filename
*/
static cptr extract_file_name(cptr s)
{
cptr p;
/* Start at the end */
p = s + strlen(s) - 1;
/* Back up to divider */
while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
/* Return file name */
return (p+1);
}
#endif /* 0 */
/*
* Hack -- given a simple filename, extract the "font size" info
*
* Return a pointer to a static buffer holding the capitalized base name.
*/
static char *analyze_font(char *path, int *wp, int *hp)
{
int wid, hgt;
char *s, *p;
/* Start at the end */
p = path + strlen(path) - 1;
/* Back up to divider */
while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
/* Advance to file name */
++p;
/* Capitalize */
for (s = p; *s; ++s)
{
/* Capitalize (be paranoid) */
if (islower(*s)) *s = toupper(*s);
}
/* Find first 'X' */
s = strchr(p, 'X');
/* Extract font width */
wid = atoi(p);
/* Extract height */
hgt = s ? atoi(s+1) : 0;
/* Save results */
(*wp) = wid;
(*hp) = hgt;
/* Result */
return (p);
}
/*
* Check for existance of a file
*/
static bool check_file(cptr s)
{
char path[1024];
#ifdef WIN32
DWORD attrib;
#else /* WIN32 */
unsigned int attrib;
#endif /* WIN32 */
/* Copy it */
strcpy(path, s);
#ifdef WIN32
/* Examine */
attrib = GetFileAttributes(path);
/* Require valid filename */
if (attrib == INVALID_FILE_NAME) return (FALSE);
/* Prohibit directory */
if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
#else /* WIN32 */
/* Examine and verify */
if (_dos_getfileattr(path, &attrib)) return (FALSE);
/* Prohibit something */
if (attrib & FA_LABEL) return (FALSE);
/* Prohibit directory */
if (attrib & FA_DIREC) return (FALSE);
#endif /* WIN32 */
/* Success */
return (TRUE);
}
/*
* Check for existance of a directory
*/
static bool check_dir(cptr s)
{
int i;
char path[1024];
#ifdef WIN32
DWORD attrib;
#else /* WIN32 */
unsigned int attrib;
#endif /* WIN32 */
/* Copy it */
strcpy(path, s);
/* Check length */
i = strlen(path);
/* Remove trailing backslash */
if (i && (path[i-1] == '\\')) path[--i] = '\0';
#ifdef WIN32
/* Examine */
attrib = GetFileAttributes(path);
/* Require valid filename */
if (attrib == INVALID_FILE_NAME) return (FALSE);
/* Require directory */
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
#else /* WIN32 */
/* Examine and verify */
if (_dos_getfileattr(path, &attrib)) return (FALSE);
/* Prohibit something */
if (attrib & FA_LABEL) return (FALSE);
/* Require directory */
if (!(attrib & FA_DIREC)) return (FALSE);
#endif /* WIN32 */
/* Success */
return (TRUE);
}
/*
* Validate a file
*/
static void validate_file(cptr s)
{
/* Verify or fail */
if (!check_file(s))
{
quit_fmt("Cannot find required file:\n%s", s);
}
}
/*
* Validate a directory
*/
static void validate_dir(cptr s)
{
/* Verify or fail */
if (!check_dir(s))
{
quit_fmt("Cannot find required directory:\n%s", s);
}
}
/*
* Get the "size" for a window
*/
static void term_getsize(term_data *td)
{
RECT rc;
int wid, hgt;
/* Paranoia */
if (td->cols < 1) td->cols = 1;
if (td->rows < 1) td->rows = 1;
/* Window sizes */
wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
/* Fake window size */
rc.left = 0;
rc.right = rc.left + wid;
rc.top = 0;
rc.bottom = rc.top + hgt;
/* XXX XXX XXX */
/* rc.right += 1; */
/* rc.bottom += 1; */
/* Adjust */
AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
/* Total size */
td->size_wid = rc.right - rc.left;
td->size_hgt = rc.bottom - rc.top;
/* See CreateWindowEx */
if (!td->w) return;
/* Extract actual location */
GetWindowRect(td->w, &rc);
/* Save the location */
td->pos_x = rc.left;
td->pos_y = rc.top;
}
/*
* Write the "prefs" for a single term
*/
static void save_prefs_aux(term_data *td, cptr sec_name)
{
char buf[1024];
RECT rc;
WINDOWPLACEMENT lpwndpl;
/* Paranoia */
if (!td->w) return;
/* Visible */
strcpy(buf, td->visible ? "1" : "0");
WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
/* Font */
strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
WritePrivateProfileString(sec_name, "Font", buf, ini_file);
/* Bizarre */
strcpy(buf, td->bizarre ? "1" : "0");
WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
/* Tile size (x) */
wsprintf(buf, "%d", td->tile_wid);
WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
/* Tile size (y) */
wsprintf(buf, "%d", td->tile_hgt);
WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
/* Window size (x) */
wsprintf(buf, "%d", td->cols);
WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
/* Window size (y) */
wsprintf(buf, "%d", td->rows);
WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
/* Get window placement and dimensions */
lpwndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(td->w, &lpwndpl);
/* Acquire position in *normal* mode (not minimized) */
rc = lpwndpl.rcNormalPosition;
/* Window position (x) */
wsprintf(buf, "%d", rc.left);
WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
/* Window position (y) */
wsprintf(buf, "%d", rc.top);
WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
}
/*
* Write the "prefs"
*
* We assume that the windows have all been initialized
*/
static void save_prefs(void)
{
int i;
char buf[128];
/* Save the "arg_graphics" flag */
sprintf(buf, "%d", arg_graphics);
WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
/* Save the "arg_sound" flag */
strcpy(buf, arg_sound ? "1" : "0");
WritePrivateProfileString("Angband", "Sound", buf, ini_file);
/* Save window prefs */
for (i = 0; i < MAX_TERM_DATA; ++i)
{
term_data *td = &data[i];
sprintf(buf, "Term-%d", i);
save_prefs_aux(td, buf);
}
}
/*
* Load the "prefs" for a single term
*/
static void load_prefs_aux(term_data *td, cptr sec_name)
{
char tmp[1024];
int wid, hgt;
/* Visible */
td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
/* Desired font, with default */
GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
/* Bizarre */
td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
/* Analyze font, save desired font name */
td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
/* Tile size */
td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
/* Window size */
td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
/* Window position */
td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
}
/*
* Load the "prefs"
*/
static void load_prefs(void)
{
int i;
char buf[1024];
/* Extract the "arg_graphics" flag */
arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
/* Extract the "arg_sound" flag */
arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
#ifdef SUPPORT_GAMMA
/* Extract the gamma correction */
gamma_correction = GetPrivateProfileInt("Angband", "Gamma", 0, ini_file);
#endif /* SUPPORT_GAMMA */
/* Load window prefs */
for (i = 0; i < MAX_TERM_DATA; ++i)
{
term_data *td = &data[i];
sprintf(buf, "Term-%d", i);
load_prefs_aux(td, buf);
}
/* Paranoia */
if (data[0].cols < 80) data[0].cols = 80;
if (data[0].rows < 24) data[0].rows = 24;
}
#ifdef USE_SOUND
/*
* XXX XXX XXX - Taken from files.c.
*
* Extract "tokens" from a buffer
*
* This function uses "whitespace" as delimiters, and treats any amount of
* whitespace as a single delimiter. We will never return any empty tokens.
* When given an empty buffer, or a buffer containing only "whitespace", we
* will return no tokens. We will never extract more than "num" tokens.
*
* By running a token through the "text_to_ascii()" function, you can allow
* that token to include (encoded) whitespace, using "\s" to encode spaces.
*
* We save pointers to the tokens in "tokens", and return the number found.
*/
static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
{
int k = 0;
char *s = buf;
/* Process */
while (k < num)
{
char *t;
/* Skip leading whitespace */
for ( ; *s && isspace(*s); ++s) /* loop */;
/* All done */
if (!*s) break;
/* Find next whitespace, if any */
for (t = s; *t && !isspace(*t); ++t) /* loop */;
/* Nuke and advance (if necessary) */
if (*t) *t++ = '\0';
/* Save the token */
tokens[k++] = s;
/* Advance */
s = t;
}
/* Count */
return (k);
}
static void load_sound_prefs(void)
{
int i, j, num;
char tmp[1024];
char ini_path[1024];
char wav_path[1024];
char *zz[SAMPLE_MAX];
/* Access the sound.cfg */
path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
for (i = 0; i < SOUND_MAX; i++)
{
GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
for (j = 0; j < num; j++)
{
/* Access the sound */
path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
/* Save the sound filename, if it exists */
if (check_file(wav_path))
sound_file[i][j] = string_make(zz[j]);
}
}
}
#endif /* USE_SOUND */
/*
* Create the new global palette based on the bitmap palette
* (if any), and the standard 16 entry palette derived from
* "win_clr[]" which is used for the basic 16 Angband colors.
*
* This function is never called before all windows are ready.
*
* This function returns FALSE if the new palette could not be
* prepared, which should normally be a fatal error. XXX XXX
*
* Note that only some machines actually use a "palette".
*/
static int new_palette(void)
{
HPALETTE hBmPal;
HPALETTE hNewPal;
HDC hdc;
int i, nEntries;
int pLogPalSize;
int lppeSize;
LPLOGPALETTE pLogPal;
LPPALETTEENTRY lppe;
term_data *td;
/* This makes no sense */
if (!paletted) return (TRUE);
/* No bitmap */
lppeSize = 0;
lppe = NULL;
nEntries = 0;
#ifdef USE_GRAPHICS
/* Check the bitmap palette */
hBmPal = infGraph.hPalette;
/* Use the bitmap */
if (hBmPal)
{
lppeSize = 256 * sizeof(PALETTEENTRY);
lppe = (LPPALETTEENTRY)ralloc(lppeSize);
nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
if ((nEntries == 0) || (nEntries > 220))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -