📄 main-win.c
字号:
Term_activate(old);
}
}
/* Success */
return (0);
}
/*
* Process at least one event
*/
static errr Term_xtra_win_event(int v)
{
MSG msg;
/* Wait for an event */
if (v)
{
/* Block */
if (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* Check for an event */
else
{
/* Check */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* Success */
return 0;
}
/*
* Process all pending events
*/
static errr Term_xtra_win_flush(void)
{
MSG msg;
/* Process all pending events */
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* Success */
return (0);
}
/*
* Hack -- clear the screen
*
* Make this more efficient XXX XXX XXX
*/
static errr Term_xtra_win_clear(void)
{
term_data *td = (term_data*)(Term->data);
HDC hdc;
RECT rc;
/* Rectangle to erase */
rc.left = td->size_ow1;
rc.right = rc.left + td->cols * td->tile_wid;
rc.top = td->size_oh1;
rc.bottom = rc.top + td->rows * td->tile_hgt;
/* Erase it */
hdc = GetDC(td->w);
SetBkColor(hdc, RGB(0, 0, 0));
SelectObject(hdc, td->font_id);
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
ReleaseDC(td->w, hdc);
/* Success */
return 0;
}
/*
* Hack -- make a noise
*/
static errr Term_xtra_win_noise(void)
{
MessageBeep(MB_ICONASTERISK);
return (0);
}
/*
* Hack -- make a sound
*/
static errr Term_xtra_win_sound(int v)
{
int i;
char buf[1024];
/* Sound disabled */
if (!use_sound) return (1);
/* Illegal sound */
if ((v < 0) || (v >= SOUND_MAX)) return (1);
#ifdef USE_SOUND
/* Count the samples */
for (i = 0; i < SAMPLE_MAX; i++)
{
if (!sound_file[v][i])
break;
}
/* No sample */
if (i == 0) return (1);
/* Build the path */
path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][rand_int(i)]);
#ifdef WIN32
/* Play the sound, catch errors */
return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
#else /* WIN32 */
/* Play the sound, catch errors */
return (sndPlaySound(buf, SND_ASYNC));
#endif /* WIN32 */
#else /* USE_SOUND */
/* Oops */
return (1);
#endif /* USE_SOUND */
}
/*
* Delay for "x" milliseconds
*/
static int Term_xtra_win_delay(int v)
{
#ifdef WIN32
/* Sleep */
Sleep(v);
#else /* WIN32 */
DWORD t;
MSG msg;
/* Final count */
t = GetTickCount() + v;
/* Wait for it */
while (GetTickCount() < t)
{
/* Handle messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif /* WIN32 */
/* Success */
return (0);
}
/*
* Do a "special thing"
*/
static errr Term_xtra_win(int n, int v)
{
/* Handle a subset of the legal requests */
switch (n)
{
/* Make a bell sound */
case TERM_XTRA_NOISE:
{
return (Term_xtra_win_noise());
}
/* Make a special sound */
case TERM_XTRA_SOUND:
{
return (Term_xtra_win_sound(v));
}
/* Process random events */
case TERM_XTRA_BORED:
{
return (Term_xtra_win_event(0));
}
/* Process an event */
case TERM_XTRA_EVENT:
{
return (Term_xtra_win_event(v));
}
/* Flush all events */
case TERM_XTRA_FLUSH:
{
return (Term_xtra_win_flush());
}
/* Clear the screen */
case TERM_XTRA_CLEAR:
{
return (Term_xtra_win_clear());
}
/* React to global changes */
case TERM_XTRA_REACT:
{
return (Term_xtra_win_react());
}
/* Delay for some milliseconds */
case TERM_XTRA_DELAY:
{
return (Term_xtra_win_delay(v));
}
}
/* Oops */
return 1;
}
/*
* Low level graphics (Assumes valid input).
*
* Draw a "cursor" at (x,y), using a "yellow box".
*/
static errr Term_curs_win(int x, int y)
{
term_data *td = (term_data*)(Term->data);
RECT rc;
HDC hdc;
int tile_wid, tile_hgt;
if (td->map_active)
{
tile_wid = td->map_tile_wid;
tile_hgt = td->map_tile_hgt;
}
else
{
tile_wid = td->tile_wid;
tile_hgt = td->tile_hgt;
}
/* Frame the grid */
rc.left = x * tile_wid + td->size_ow1;
rc.right = rc.left + tile_wid;
rc.top = y * tile_hgt + td->size_oh1;
rc.bottom = rc.top + tile_hgt;
/* Cursor is done as a yellow "box" */
hdc = GetDC(td->w);
FrameRect(hdc, &rc, hbrYellow);
ReleaseDC(td->w, hdc);
/* Success */
return 0;
}
/*
* Low level graphics (Assumes valid input).
*
* Erase a "block" of "n" characters starting at (x,y).
*/
static errr Term_wipe_win(int x, int y, int n)
{
term_data *td = (term_data*)(Term->data);
HDC hdc;
RECT rc;
/* Rectangle to erase in client coords */
rc.left = x * td->tile_wid + td->size_ow1;
rc.right = rc.left + n * td->tile_wid;
rc.top = y * td->tile_hgt + td->size_oh1;
rc.bottom = rc.top + td->tile_hgt;
hdc = GetDC(td->w);
SetBkColor(hdc, RGB(0, 0, 0));
SelectObject(hdc, td->font_id);
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
ReleaseDC(td->w, hdc);
/* Success */
return 0;
}
/*
* Low level graphics. Assumes valid input.
*
* Draw several ("n") chars, with an attr, at a given location.
*
* All "graphic" data is handled by "Term_pict_win()", below.
*
* One would think there is a more efficient method for telling a window
* what color it should be using to draw with, but perhaps simply changing
* it every time is not too inefficient. XXX XXX XXX
*/
static errr Term_text_win(int x, int y, int n, byte a, const char *s)
{
term_data *td = (term_data*)(Term->data);
RECT rc;
HDC hdc;
/* Total rectangle */
rc.left = x * td->tile_wid + td->size_ow1;
rc.right = rc.left + n * td->tile_wid;
rc.top = y * td->tile_hgt + td->size_oh1;
rc.bottom = rc.top + td->tile_hgt;
/* Acquire DC */
hdc = GetDC(td->w);
/* Background color */
SetBkColor(hdc, RGB(0, 0, 0));
/* Foreground color */
if (colors16)
{
SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
}
else if (paletted)
{
SetTextColor(hdc, win_clr[a&0x0F]);
}
else
{
SetTextColor(hdc, win_clr[a]);
}
/* Use the font */
SelectObject(hdc, td->font_id);
/* Bizarre size */
if (td->bizarre ||
(td->tile_hgt != td->font_hgt) ||
(td->tile_wid != td->font_wid))
{
int i;
/* Erase complete rectangle */
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
/* New rectangle */
rc.left += ((td->tile_wid - td->font_wid) / 2);
rc.right = rc.left + td->font_wid;
rc.top += ((td->tile_hgt - td->font_hgt) / 2);
rc.bottom = rc.top + td->font_hgt;
/* Dump each character */
for (i = 0; i < n; i++)
{
/* Dump the text */
ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
s+i, 1, NULL);
/* Advance */
rc.left += td->tile_wid;
rc.right += td->tile_wid;
}
}
/* Normal size */
else
{
/* Dump the text */
ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
s, n, NULL);
}
/* Release DC */
ReleaseDC(td->w, hdc);
/* Success */
return 0;
}
/*
* Low level graphics. Assumes valid input.
*
* Draw an array of "special" attr/char pairs at the given location.
*
* We use the "Term_pict_win()" function for "graphic" data, which are
* encoded by setting the "high-bits" of both the "attr" and the "char"
* data. We use the "attr" to represent the "row" of the main bitmap,
* and the "char" to represent the "col" of the main bitmap. The use
* of this function is induced by the "higher_pict" flag.
*
* If "graphics" is not available, we simply "wipe" the given grids.
*/
# ifdef USE_TRANSPARENCY
static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
# else /* USE_TRANSPARENCY */
static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
# endif /* USE_TRANSPARENCY */
{
term_data *td = (term_data*)(Term->data);
#ifdef USE_GRAPHICS
int i;
int x1, y1, w1, h1;
int x2, y2, w2, h2;
# ifdef USE_TRANSPARENCY
int x3, y3;
HDC hdcMask;
# endif /* USE_TRANSPARENCY */
HDC hdc;
HDC hdcSrc;
HBITMAP hbmSrcOld;
/* Paranoia */
if (!use_graphics)
{
/* Erase the grids */
return (Term_wipe_win(x, y, n));
}
/* Size of bitmap cell */
w1 = infGraph.CellWidth;
h1 = infGraph.CellHeight;
/* Size of window cell */
if (td->map_active)
{
w2 = td->map_tile_wid;
h2 = td->map_tile_hgt;
}
else
{
w2 = td->tile_wid;
h2 = td->tile_hgt;
}
/* Location of window cell */
x2 = x * w2 + td->size_ow1;
y2 = y * h2 + td->size_oh1;
/* Info */
hdc = GetDC(td->w);
/* More info */
hdcSrc = CreateCompatibleDC(hdc);
hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
# ifdef USE_TRANSPARENCY
if (arg_graphics == GRAPHICS_ADAM_BOLT)
{
hdcMask = CreateCompatibleDC(hdc);
SelectObject(hdcMask, infMask.hBitmap);
}
# endif /* USE_TRANSPARENCY */
/* Draw attr/char pairs */
for (i = 0; i < n; i++, x2 += w2)
{
byte a = ap[i];
char c = cp[i];
/* Extract picture */
int row = (a & 0x7F);
int col = (c & 0x7F);
/* Location of bitmap cell */
x1 = col * w1;
y1 = row * h1;
# ifdef USE_TRANSPARENCY
if (arg_graphics == GRAPHICS_ADAM_BOLT)
{
x3 = (tcp[i] & 0x7F) * w1;
y3 = (tap[i] & 0x7F) * h1;
/* Perfect size */
if ((w1 == w2) && (h1 == h2))
{
/* Copy the terrain picture from the bitmap to the window */
BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x3, y3, SRCCOPY);
/* Mask out the tile */
BitBlt(hdc, x2, y2, w2, h2, hdcMask, x1, y1, SRCAND);
/* Draw the tile */
BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, SRCPAINT);
}
/* Need to stretch */
else
{
/* Set the correct mode for stretching the tiles */
SetStretchBltMode(hdc, COLORONCOLOR);
/* Copy the terrain picture from the bitmap to the window */
StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
/* Only draw if terrain and overlay are different */
if ((x1 != x3) || (y1 != y3))
{
/* Mask out the tile */
StretchBlt(hdc, x2, y2, w2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
/* Draw the tile */
StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
}
}
}
else
# endif /* USE_TRANSPARENCY */
{
/* Perfect size */
if ((w1 == w2) && (h1 == h2))
{
/* Copy the picture from the bitmap to the window */
BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, SRCCOPY);
}
/* Need to stretch */
else
{
/* Set the correct mode for stretching the tiles */
SetStretchBltMode(hdc, COLORONCOLOR);
/* Copy the picture from the bitmap to the window */
StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
}
}
}
/* Release */
SelectObject(hdcSrc, hbmSrcOld);
DeleteDC(hdcSrc);
# ifdef USE_TRANSPARENCY
if (arg_graphics == GRAPHICS_ADAM_BOLT)
{
/* Release */
SelectObject(hdcMask, hbmSrcOld);
DeleteDC(hdcMask);
}
# endif /* USE_TRANSPARENCY */
/* Release */
ReleaseDC(td->w, hdc);
#else /* USE_GRAPHICS */
/* Just erase this grid */
return (Term_wipe_win(x, y, n));
#endif /* USE_GRAPHICS */
/* Success */
return 0;
}
static void windows_map_aux(void)
{
term_data *td = &data[0];
byte a;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -