📄 main-win.c
字号:
/* Warn the user */
plog("Please switch to high- or true-color mode.");
/* Cleanup */
rnfree(lppe, lppeSize);
/* Fail */
return (FALSE);
}
}
#endif /* USE_GRAPHICS */
/* Size of palette */
pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
/* Allocate palette */
pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
/* Version */
pLogPal->palVersion = 0x300;
/* Make room for bitmap and normal data */
pLogPal->palNumEntries = nEntries + 16;
/* Save the bitmap data */
for (i = 0; i < nEntries; i++)
{
pLogPal->palPalEntry[i] = lppe[i];
}
/* Save the normal data */
for (i = 0; i < 16; i++)
{
LPPALETTEENTRY p;
/* Access the entry */
p = &(pLogPal->palPalEntry[i+nEntries]);
/* Save the colors */
p->peRed = GetRValue(win_clr[i]);
p->peGreen = GetGValue(win_clr[i]);
p->peBlue = GetBValue(win_clr[i]);
#ifdef SUPPORT_GAMMA
if (gamma_correction > 0)
{
p->peRed = gamma_table[p->peRed];
p->peGreen = gamma_table[p->peGreen];
p->peBlue = gamma_table[p->peBlue];
}
#endif /* SUPPORT_GAMMA */
/* Save the flags */
p->peFlags = PC_NOCOLLAPSE;
}
/* Free something */
if (lppe) rnfree(lppe, lppeSize);
/* Create a new palette, or fail */
hNewPal = CreatePalette(pLogPal);
if (!hNewPal) quit("Cannot create palette!");
/* Free the palette */
rnfree(pLogPal, pLogPalSize);
/* Main window */
td = &data[0];
/* Realize the palette */
hdc = GetDC(td->w);
SelectPalette(hdc, hNewPal, 0);
i = RealizePalette(hdc);
ReleaseDC(td->w, hdc);
if (i == 0) quit("Cannot realize palette!");
/* Sub-windows */
for (i = 1; i < MAX_TERM_DATA; i++)
{
td = &data[i];
hdc = GetDC(td->w);
SelectPalette(hdc, hNewPal, 0);
ReleaseDC(td->w, hdc);
}
/* Delete old palette */
if (hPal) DeleteObject(hPal);
/* Save new palette */
hPal = hNewPal;
/* Success */
return (TRUE);
}
#ifdef USE_GRAPHICS
/*
* Initialize graphics
*/
static bool init_graphics(void)
{
/* Initialize once */
/* if (can_use_graphics != arg_graphics) */
{
char buf[1024];
int wid, hgt;
cptr name;
if (arg_graphics == GRAPHICS_ADAM_BOLT)
{
wid = 16;
hgt = 16;
name = "16X16.BMP";
ANGBAND_GRAF = "new";
use_transparency = TRUE;
}
else
{
wid = 8;
hgt = 8;
name = "8X8.BMP";
ANGBAND_GRAF = "old";
}
/* Access the bitmap file */
path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name);
/* Load the bitmap or quit */
if (!ReadDIB(data[0].w, buf, &infGraph))
{
plog_fmt("Cannot read bitmap file '%s'", name);
return (FALSE);
}
/* Save the new sizes */
infGraph.CellWidth = wid;
infGraph.CellHeight = hgt;
#ifdef USE_TRANSPARENCY
if (arg_graphics == GRAPHICS_ADAM_BOLT)
{
/* Access the mask file */
path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
/* Load the bitmap or quit */
if (!ReadDIB(data[0].w, buf, &infMask))
{
plog_fmt("Cannot read bitmap file '%s'", buf);
return (FALSE);
}
}
#endif /* USE_TRANSPARENCY */
/* Activate a palette */
if (!new_palette())
{
/* Free bitmap XXX XXX XXX */
/* Oops */
plog("Cannot activate palette!");
return (FALSE);
}
/* Graphics available */
can_use_graphics = arg_graphics;
}
/* Result */
return (can_use_graphics);
}
#endif /* USE_GRAPHICS */
#ifdef USE_SOUND
/*
* Initialize sound
*/
static bool init_sound(void)
{
/* Initialize once */
if (!can_use_sound)
{
/* Load the prefs */
load_sound_prefs();
/* Sound available */
can_use_sound = TRUE;
}
/* Result */
return (can_use_sound);
}
#endif /* USE_SOUND */
/*
* Resize a window
*/
static void term_window_resize(term_data *td)
{
/* Require window */
if (!td->w) return;
/* Resize the window */
SetWindowPos(td->w, 0, 0, 0,
td->size_wid, td->size_hgt,
SWP_NOMOVE | SWP_NOZORDER);
/* Redraw later */
InvalidateRect(td->w, NULL, TRUE);
}
/*
* Force the use of a new "font file" for a term_data
*
* This function may be called before the "window" is ready
*
* This function returns zero only if everything succeeds.
*
* Note that the "font name" must be capitalized!!!
*/
static errr term_force_font(term_data *td, cptr path)
{
int i;
int wid, hgt;
char *base;
char buf[1024];
/* Forget the old font (if needed) */
if (td->font_id) DeleteObject(td->font_id);
/* Forget old font */
if (td->font_file)
{
bool used = FALSE;
/* Scan windows */
for (i = 0; i < MAX_TERM_DATA; i++)
{
/* Don't check when closing the application */
if (!path) break;
/* Check "screen" */
if ((td != &data[i]) &&
(data[i].font_file) &&
(streq(data[i].font_file, td->font_file)))
{
used = TRUE;
}
}
/* Remove unused font resources */
if (!used) RemoveFontResource(td->font_file);
/* Free the old name */
string_free(td->font_file);
/* Forget it */
td->font_file = NULL;
}
/* No path given */
if (!path) return (1);
/* Local copy */
strcpy(buf, path);
/* Analyze font path */
base = analyze_font(buf, &wid, &hgt);
/* Verify suffix */
if (!suffix(base, ".FON")) return (1);
/* Verify file */
if (!check_file(buf)) return (1);
/* Load the new font */
if (!AddFontResource(buf)) return (1);
/* Save new font name */
td->font_file = string_make(base);
/* Remove the "suffix" */
base[strlen(base)-4] = '\0';
/* Create the font (using the 'base' of the font file name!) */
td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FIXED_PITCH | FF_DONTCARE, base);
/* Hack -- Unknown size */
if (!wid || !hgt)
{
HDC hdcDesktop;
HFONT hfOld;
TEXTMETRIC tm;
/* all this trouble to get the cell size */
hdcDesktop = GetDC(HWND_DESKTOP);
hfOld = SelectObject(hdcDesktop, td->font_id);
GetTextMetrics(hdcDesktop, &tm);
SelectObject(hdcDesktop, hfOld);
ReleaseDC(HWND_DESKTOP, hdcDesktop);
/* Font size info */
wid = tm.tmAveCharWidth;
hgt = tm.tmHeight;
}
/* Save the size info */
td->font_wid = wid;
td->font_hgt = hgt;
/* Success */
return (0);
}
/*
* Allow the user to change the font for this window.
*/
static void term_change_font(term_data *td)
{
OPENFILENAME ofn;
char tmp[1024] = "";
/* Extract a default if possible */
if (td->font_file) strcpy(tmp, td->font_file);
/* Ask for a choice */
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = data[0].w;
ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
ofn.nFilterIndex = 1;
ofn.lpstrFile = tmp;
ofn.nMaxFile = 128;
ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
ofn.lpstrDefExt = "fon";
/* Force choice if legal */
if (GetOpenFileName(&ofn))
{
/* Force the font */
if (term_force_font(td, tmp))
{
/* Access the standard font file */
path_build(tmp, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
/* Force the use of that font */
(void)term_force_font(td, tmp);
}
/* Assume not bizarre */
td->bizarre = FALSE;
/* Reset the tile info */
td->tile_wid = td->font_wid;
td->tile_hgt = td->font_hgt;
/* Analyze the font */
term_getsize(td);
/* Resize the window */
term_window_resize(td);
}
}
extern void windows_map_aux(void);
/*
* Hack -- redraw a term_data
*/
static void term_data_redraw(term_data *td)
{
if (td->map_active)
{
/* Redraw the map */
windows_map_aux();
}
else
{
/* Activate the term */
Term_activate(&td->t);
/* Redraw the contents */
Term_redraw();
/* Restore the term */
Term_activate(term_screen);
}
}
/*
* Hack -- redraw a term_data
*/
static void term_data_redraw_section(term_data *td, int x1, int y1, int x2, int y2)
{
/* Activate the term */
Term_activate(&td->t);
/* Redraw the area */
Term_redraw_section(x1, y1, x2, y2);
/* Restore the term */
Term_activate(term_screen);
}
/*** Function hooks needed by "Term" ***/
#if 0
/*
* Initialize a new Term
*/
static void Term_init_win(term *t)
{
/* XXX Unused */
}
/*
* Nuke an old Term
*/
static void Term_nuke_win(term *t)
{
/* XXX Unused */
}
#endif /* 0 */
/*
* Interact with the User
*/
static errr Term_user_win(int n)
{
/* Success */
return (0);
}
/*
* React to global changes
*/
static errr Term_xtra_win_react(void)
{
int i;
/* Simple color */
if (colors16)
{
/* Save the default colors */
for (i = 0; i < 256; i++)
{
/* Simply accept the desired colors */
win_pal[i] = angband_color_table[i][0];
}
}
/* Complex color */
else
{
COLORREF code;
byte rv, gv, bv;
bool change = FALSE;
/* Save the default colors */
for (i = 0; i < 256; i++)
{
/* Extract desired values */
rv = angband_color_table[i][1];
gv = angband_color_table[i][2];
bv = angband_color_table[i][3];
#ifdef SUPPORT_GAMMA
if (gamma_correction > 0)
{
rv = gamma_table[rv];
gv = gamma_table[gv];
bv = gamma_table[bv];
}
#endif /* SUPPORT_GAMMA */
/* Extract a full color code */
code = PALETTERGB(rv, gv, bv);
/* Activate changes */
if (win_clr[i] != code)
{
/* Note the change */
change = TRUE;
/* Apply the desired color */
win_clr[i] = code;
}
}
/* Activate the palette if needed */
if (change) (void)new_palette();
}
#ifdef USE_SOUND
/* Handle "arg_sound" */
if (use_sound != arg_sound)
{
/* Initialize (if needed) */
if (arg_sound && !init_sound())
{
/* Warning */
plog("Cannot initialize sound!");
/* Cannot enable */
arg_sound = FALSE;
}
/* Change setting */
use_sound = arg_sound;
}
#endif /* USE_SOUND */
#ifdef USE_GRAPHICS
/* Handle "arg_graphics" */
if (use_graphics != arg_graphics)
{
/* Switch off transparency */
use_transparency = FALSE;
/* Initialize (if needed) */
if (arg_graphics && !init_graphics())
{
/* Warning */
plog("Cannot initialize graphics!");
/* Cannot enable */
arg_graphics = GRAPHICS_NONE;
}
/* Change setting */
use_graphics = arg_graphics;
/* Reset visuals */
#ifdef ANGBAND_2_8_1
reset_visuals();
#else /* ANGBAND_2_8_1 */
reset_visuals(TRUE);
#endif /* ANGBAND_2_8_1 */
}
#endif /* USE_GRAPHICS */
/* Clean up windows */
for (i = 0; i < MAX_TERM_DATA; i++)
{
term *old = Term;
term_data *td = &data[i];
/* Update resized windows */
if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
{
/* Activate */
Term_activate(&td->t);
/* Hack -- Resize the term */
Term_resize(td->cols, td->rows);
/* Redraw the contents */
Term_redraw();
/* Restore */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -