📄 vid_win.c
字号:
{
if (vid_stretched)
{
MGL_stretchBltCoord(mgldc, memdc,
rects->x,
rects->y,
rects->x + rects->width,
rects->y + rects->height,
rects->x << 1,
rects->y << 1,
(rects->x + rects->width) << 1,
(rects->y + rects->height) << 1);
}
else
{
MGL_bitBltCoord(mgldc, memdc,
rects->x, rects->y,
(rects->x + rects->width),
(rects->y + rects->height),
rects->x, rects->y, MGL_REPLACE_MODE);
}
rects = rects->pnext;
}
}
if (vid.numpages > 1)
{
// We have a flipping surface, so do a hard page flip
aPage = (aPage+1) % vid.numpages;
vPage = (vPage+1) % vid.numpages;
MGL_setActivePage(mgldc,aPage);
MGL_setVisualPage(mgldc,vPage,waitVRT);
}
}
}
else
{
HDC hdcScreen;
hdcScreen = GetDC(mainwindow);
if (windc && dibdc)
{
MGL_setWinDC(windc,hdcScreen);
while (rects)
{
if (vid_stretched)
{
MGL_stretchBltCoord(windc,dibdc,
rects->x, rects->y,
rects->x + rects->width, rects->y + rects->height,
rects->x << 1, rects->y << 1,
(rects->x + rects->width) << 1,
(rects->y + rects->height) << 1);
}
else
{
MGL_bitBltCoord(windc,dibdc,
rects->x, rects->y,
rects->x + rects->width, rects->y + rects->height,
rects->x, rects->y, MGL_REPLACE_MODE);
}
rects = rects->pnext;
}
}
ReleaseDC(mainwindow, hdcScreen);
}
}
void VID_Update (vrect_t *rects)
{
vrect_t rect;
RECT trect;
if (!vid_palettized && palette_changed)
{
palette_changed = false;
rect.x = 0;
rect.y = 0;
rect.width = vid.width;
rect.height = vid.height;
rect.pnext = NULL;
rects = ▭
}
if (firstupdate)
{
if (modestate == MS_WINDOWED)
{
GetWindowRect (mainwindow, &trect);
if ((trect.left != (int)vid_window_x->value) ||
(trect.top != (int)vid_window_y->value))
{
if (COM_CheckParm ("-resetwinpos"))
{
Cvar_Set (vid_window_x, "0");
Cvar_Set (vid_window_y, "0");
}
VID_CheckWindowXY ();
SetWindowPos (mainwindow, NULL, (int)vid_window_x->value,
(int)vid_window_y->value, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
}
}
if ((_vid_default_mode_win->value != vid_default) &&
(!startwindowed || (_vid_default_mode_win->value < MODE_FULLSCREEN_DEFAULT)))
{
firstupdate = 0;
if (COM_CheckParm ("-resetwinpos"))
{
Cvar_Set (vid_window_x, "0");
Cvar_Set (vid_window_y, "0");
}
if ((_vid_default_mode_win->value < 0) ||
(_vid_default_mode_win->value >= nummodes))
{
Cvar_SetValue (_vid_default_mode_win, windowed_default);
}
Cvar_SetValue (vid_mode, _vid_default_mode_win->value);
}
}
// We've drawn the frame; copy it to the screen
FlipScreen (rects);
if (vid_testingmode)
{
if (realtime >= vid_testendtime)
{
VID_SetMode (vid_realmode, vid_curpal);
vid_testingmode = 0;
}
}
else
{
if ((int)vid_mode->value != vid_realmode)
{
VID_SetMode ((int)vid_mode->value, vid_curpal);
Cvar_SetValue (vid_mode, (float)vid_modenum);
// so if mode set fails, we don't keep on
// trying to set that mode
vid_realmode = vid_modenum;
}
}
// handle the mouse state when windowed if that's changed
if (modestate == MS_WINDOWED)
{
if ((int)_windowed_mouse->value != windowed_mouse)
{
if (_windowed_mouse->value)
{
IN_ActivateMouse ();
IN_HideMouse ();
}
else
{
IN_DeactivateMouse ();
IN_ShowMouse ();
}
windowed_mouse = (int)_windowed_mouse->value;
}
}
}
/*
================
D_BeginDirectRect
================
*/
void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
int i, j, reps, repshift;
vrect_t rect;
if (!vid_initialized)
return;
if (vid.aspect > 1.5)
{
reps = 2;
repshift = 1;
}
else
{
reps = 1;
repshift = 0;
}
if (vid.numpages == 1)
{
VID_LockBuffer ();
if (!vid.direct)
Sys_Error ("NULL vid.direct pointer");
for (i=0 ; i<(height << repshift) ; i += reps)
{
for (j=0 ; j<reps ; j++)
{
memcpy (&backingbuf[(i + j) * 24],
vid.direct + x + ((y << repshift) + i + j) * vid.rowbytes,
width);
memcpy (vid.direct + x + ((y << repshift) + i + j) * vid.rowbytes,
&pbitmap[(i >> repshift) * width],
width);
}
}
VID_UnlockBuffer ();
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height << repshift;
rect.pnext = NULL;
FlipScreen (&rect);
}
else
{
// unlock if locked
if (lockcount > 0)
MGL_endDirectAccess();
// set the active page to the displayed page
MGL_setActivePage (mgldc, vPage);
// lock the screen
MGL_beginDirectAccess ();
// save from and draw to screen
for (i=0 ; i<(height << repshift) ; i += reps)
{
for (j=0 ; j<reps ; j++)
{
memcpy (&backingbuf[(i + j) * 24],
(byte *)mgldc->surface + x +
((y << repshift) + i + j) * mgldc->mi.bytesPerLine,
width);
memcpy ((byte *)mgldc->surface + x +
((y << repshift) + i + j) * mgldc->mi.bytesPerLine,
&pbitmap[(i >> repshift) * width],
width);
}
}
// unlock the screen
MGL_endDirectAccess ();
// restore the original active page
MGL_setActivePage (mgldc, aPage);
// relock the screen if it was locked
if (lockcount > 0)
MGL_beginDirectAccess();
}
}
/*
================
D_EndDirectRect
================
*/
void D_EndDirectRect (int x, int y, int width, int height)
{
int i, j, reps, repshift;
vrect_t rect;
if (!vid_initialized)
return;
if (vid.aspect > 1.5)
{
reps = 2;
repshift = 1;
}
else
{
reps = 1;
repshift = 0;
}
if (vid.numpages == 1)
{
VID_LockBuffer ();
if (!vid.direct)
Sys_Error ("NULL vid.direct pointer");
for (i=0 ; i<(height << repshift) ; i += reps)
{
for (j=0 ; j<reps ; j++)
{
memcpy (vid.direct + x + ((y << repshift) + i + j) * vid.rowbytes,
&backingbuf[(i + j) * 24],
width);
}
}
VID_UnlockBuffer ();
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height << repshift;
rect.pnext = NULL;
FlipScreen (&rect);
}
else
{
// unlock if locked
if (lockcount > 0)
MGL_endDirectAccess();
// set the active page to the displayed page
MGL_setActivePage (mgldc, vPage);
// lock the screen
MGL_beginDirectAccess ();
// restore to the screen
for (i=0 ; i<(height << repshift) ; i += reps)
{
for (j=0 ; j<reps ; j++)
{
memcpy ((byte *)mgldc->surface + x +
((y << repshift) + i + j) * mgldc->mi.bytesPerLine,
&backingbuf[(i + j) * 24],
width);
}
}
// unlock the screen
MGL_endDirectAccess ();
// restore the original active page
MGL_setActivePage (mgldc, aPage);
// relock the screen if it was locked
if (lockcount > 0)
MGL_beginDirectAccess();
}
}
//==========================================================================
byte scantokey[128] =
{
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0 , 27, '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', 13 , K_CTRL,'a', 's', // 1
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'' , '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2
'b', 'n', 'm', ',', '.', '/', K_SHIFT,'*',
K_ALT,' ', 0 , K_F1, K_F2, K_F3, K_F4, K_F5, // 3
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0 , K_HOME,
K_UPARROW,K_PGUP,'-',K_LEFTARROW,'5',K_RIGHTARROW,'+',K_END, //4
K_DOWNARROW,K_PGDN,K_INS,K_DEL,0,0, 0, K_F11,
K_F12,0 , 0 , 0 , 0 , 0 , 0 , 0, // 5
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, // 6
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7
};
/*
=======
MapKey
Map from windows to quake keynums
=======
*/
int MapKey (int key)
{
key = (key>>16)&255;
if (key > 127)
return 0;
return scantokey[key];
}
void AppActivate(BOOL fActive, BOOL minimize)
/****************************************************************************
*
* Function: AppActivate
* Parameters: fActive - True if app is activating
*
* Description: If the application is activating, then swap the system
* into SYSPAL_NOSTATIC mode so that our palettes will display
* correctly.
*
****************************************************************************/
{
HDC hdc;
int i, t;
static BOOL sound_active;
ActiveApp = fActive;
// messy, but it seems to work
if (vid_fulldib_on_focus_mode)
{
Minimized = minimize;
if (Minimized)
ActiveApp = false;
}
MGL_appActivate(windc, ActiveApp);
if (vid_initialized)
{
// yield the palette if we're losing the focus
hdc = GetDC(NULL);
if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
{
if (ActiveApp)
{
if ((modestate == MS_WINDOWED) || (modestate == MS_FULLDIB))
{
if (GetSystemPaletteUse(hdc) == SYSPAL_STATIC)
{
// switch to SYSPAL_NOSTATIC and remap the colors
SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC);
syscolchg = true;
pal_is_nostatic = true;
}
}
}
else if (pal_is_nostatic)
{
if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
{
// switch back to SYSPAL_STATIC and the old mapping
SetSystemPaletteUse(hdc, SYSPAL_STATIC);
syscolchg = true;
}
pal_is_nostatic = false;
}
}
if (!Minimized)
VID_SetPalette (vid_curpal);
scr_fullupdate = 0;
ReleaseDC(NULL,hdc);
}
// enable/disable sound on focus gain/loss
if (!ActiveApp && sound_active)
{
S_BlockSound ();
S_ClearBuffer ();
sound_active = false;
}
else if (ActiveApp && !sound_active)
{
S_UnblockSound ();
S_ClearBuffer ();
sound_active = true;
}
// minimize/restore fulldib windows/mouse-capture normal windows on demand
if (!in_mode_set)
{
if (ActiveApp)
{
if (vid_fulldib_on_focus_mode)
{
if (vid_initialized)
{
msg_suppress_1 = true; // don't want to see normal mode set message
VID_SetMode (vid_fulldib_on_focus_mode, vid_curpal);
msg_suppress_1 = false;
t = in_mode_set;
in_mode_set = true;
AppActivate (true, false);
in_mode_set = t;
}
IN_ActivateMouse ();
IN_HideMouse ();
}
else if ((modestate == MS_WINDOWED) && _windowed_mouse->value)
{
IN_ActivateMouse ();
IN_HideMouse ();
}
}
if (!ActiveApp)
{
if (modestate == MS_FULLDIB)
{
if (vid_initialized)
{
force_minimized = true;
i = vid_fulldib_on_focus_mode;
msg_suppress_1 = true; // don't want to see normal mode set message
VID_SetMode (windowed_default, vid_curpal);
msg_suppress_1 = false;
vid_fulldib_on_focus_mode = i;
force_minimized = false;
// we never seem to get WM_ACTIVATE inactive from this mode set, so we'll
// do it manually
t = in_mode_set;
in_mode_set = true;
AppActivate (false, true);
in_mode_set = t;
}
IN_DeactivateMouse ();
IN_ShowMouse ();
}
else if ((modestate == MS_WINDOWED) && _windowed_mouse->value)
{
IN_DeactivateMouse ();
IN_ShowMouse ();
}
}
}
}
/*
================
VID_HandlePause
================
*/
void VID_HandlePause (qboolean pause)
{
if ((modestate == MS_WINDOWED) && _windowed_mouse->value)
{
if (pause)
{
IN_Deac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -