2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
vid_win.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "winquake.h"
|
|
|
|
#include "d_local.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
#define MAX_MODE_LIST 30
|
|
|
|
#define VID_ROW_SIZE 3
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean dibonly;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extern int Minimized;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
HWND mainwindow;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int DIBWidth, DIBHeight;
|
|
|
|
qboolean DDActive;
|
|
|
|
RECT WindowRect;
|
|
|
|
DWORD WindowStyle, ExWindowStyle;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int window_center_x, window_center_y, window_x, window_y, window_width,
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
window_height;
|
|
|
|
RECT window_rect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static DEVMODE gdevmode;
|
|
|
|
static qboolean startwindowed = 0, windowed_mode_set;
|
|
|
|
static int firstupdate = 1;
|
|
|
|
static qboolean vid_initialized = false, vid_palettized;
|
|
|
|
static int lockcount;
|
|
|
|
static int vid_fulldib_on_focus_mode;
|
|
|
|
static qboolean force_minimized, in_mode_set, is_mode0x13, force_mode_set;
|
|
|
|
static int vid_stretched, windowed_mouse;
|
|
|
|
static qboolean palette_changed, syscolchg, vid_mode_set, hide_window,
|
|
|
|
|
|
|
|
pal_is_nostatic;
|
|
|
|
static HICON hIcon;
|
|
|
|
|
|
|
|
viddef_t vid; // global video state
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MODE_WINDOWED 0
|
|
|
|
#define MODE_SETTABLE_WINDOW 2
|
|
|
|
#define NO_MODE (MODE_WINDOWED - 1)
|
|
|
|
#define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 3)
|
|
|
|
|
|
|
|
// Note that 0 is MODE_WINDOWED
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *vid_mode;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// Note that 0 is MODE_WINDOWED
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *_vid_default_mode;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// Note that 3 is MODE_FULLSCREEN_DEFAULT
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *_vid_default_mode_win;
|
|
|
|
cvar_t *vid_wait;
|
|
|
|
cvar_t *vid_nopageflip;
|
|
|
|
cvar_t *_vid_wait_override;
|
|
|
|
cvar_t *vid_config_x;
|
|
|
|
cvar_t *vid_config_y;
|
|
|
|
cvar_t *vid_stretch_by_2;
|
|
|
|
cvar_t *_windowed_mouse;
|
|
|
|
cvar_t *vid_fullscreen_mode;
|
|
|
|
cvar_t *vid_windowed_mode;
|
|
|
|
cvar_t *block_switch;
|
|
|
|
cvar_t *vid_window_x;
|
|
|
|
cvar_t *vid_window_y;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
2001-02-19 21:15:25 +00:00
|
|
|
} lmode_t;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
lmode_t lowresmodes[] = {
|
2001-02-19 21:15:25 +00:00
|
|
|
{320, 200},
|
|
|
|
{320, 240},
|
|
|
|
{400, 300},
|
|
|
|
{512, 384},
|
|
|
|
};
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int vid_modenum = NO_MODE;
|
|
|
|
int vid_testingmode, vid_realmode;
|
|
|
|
double vid_testendtime;
|
|
|
|
int vid_default = MODE_WINDOWED;
|
|
|
|
static int windowed_default;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
modestate_t modestate = MS_UNINIT;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static byte *vid_surfcache;
|
|
|
|
static int vid_surfcachesize;
|
|
|
|
static int VID_highhunkmark;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned char vid_curpal[256 * 3];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned short d_8to16table[256];
|
|
|
|
unsigned d_8to24table[256];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int driver = grDETECT, mode;
|
|
|
|
bool useWinDirect = true, useDirectDraw = true;
|
|
|
|
MGLDC *mgldc = NULL, *memdc = NULL, *dibdc = NULL, *windc = NULL;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2001-02-26 06:48:02 +00:00
|
|
|
modestate_t type;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int modenum;
|
|
|
|
int mode13;
|
|
|
|
int stretched;
|
|
|
|
int dib;
|
|
|
|
int fullscreen;
|
|
|
|
int bpp;
|
|
|
|
int halfscreen;
|
|
|
|
char modedesc[13];
|
2001-02-19 21:15:25 +00:00
|
|
|
} vmode_t;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static vmode_t modelist[MAX_MODE_LIST];
|
|
|
|
static int nummodes;
|
|
|
|
static vmode_t *pcurrentmode;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int aPage; // Current active display page
|
|
|
|
int vPage; // Current visible display page
|
|
|
|
int waitVRT = true; // True to wait for retrace on flip
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static vmode_t badmode;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static byte backingbuf[48 * 24];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void VID_MenuDraw (void);
|
|
|
|
void VID_MenuKey (int key);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
2001-02-26 06:48:02 +00:00
|
|
|
void AppActivate (BOOL fActive, BOOL minimize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_InitCvars (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_RememberWindowPos
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_RememberWindowPos (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
RECT rect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (GetWindowRect (mainwindow, &rect)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((rect.left < GetSystemMetrics (SM_CXSCREEN)) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(rect.top < GetSystemMetrics (SM_CYSCREEN)) &&
|
|
|
|
(rect.right > 0) && (rect.bottom > 0)) {
|
|
|
|
Cvar_SetValue (vid_window_x, (float) rect.left);
|
|
|
|
Cvar_SetValue (vid_window_y, (float) rect.top);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_CheckWindowXY
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_CheckWindowXY (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if ((vid_window_x->int_val > (GetSystemMetrics (SM_CXSCREEN) - 160)) ||
|
|
|
|
(vid_window_y->int_val > (GetSystemMetrics (SM_CYSCREEN) - 120)) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(vid_window_x->int_val < 0) || (vid_window_y->int_val < 0)) {
|
|
|
|
Cvar_SetValue (vid_window_x, 0.0);
|
|
|
|
Cvar_SetValue (vid_window_y, 0.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_UpdateWindowStatus
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_UpdateWindowStatus (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
window_rect.left = window_x;
|
|
|
|
window_rect.top = window_y;
|
|
|
|
window_rect.right = window_x + window_width;
|
|
|
|
window_rect.bottom = window_y + window_height;
|
|
|
|
window_center_x = (window_rect.left + window_rect.right) / 2;
|
|
|
|
window_center_y = (window_rect.top + window_rect.bottom) / 2;
|
|
|
|
|
|
|
|
IN_UpdateClipCursor ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
ClearAllStates
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
ClearAllStates (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// send an up event for each key, to make sure the server clears them all
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Key_Event (i, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Key_ClearStates ();
|
|
|
|
IN_ClearStates ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_CheckAdequateMem
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_CheckAdequateMem (int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int tbuffersize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
tbuffersize = width * height * sizeof (*d_pzbuffer);
|
|
|
|
|
|
|
|
tbuffersize += D_SurfaceCacheForRes (width, height);
|
|
|
|
|
|
|
|
// see if there's enough memory, allowing for the normal mode 0x13 pixel,
|
|
|
|
// z, and surface buffers
|
|
|
|
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
|
2001-02-26 06:48:02 +00:00
|
|
|
0x10000 * 3) < minimum_memory) {
|
|
|
|
return false; // not enough memory for mode
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_AllocBuffers
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_AllocBuffers (int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int tsize, tbuffersize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
tbuffersize = width * height * sizeof (*d_pzbuffer);
|
|
|
|
|
|
|
|
tsize = D_SurfaceCacheForRes (width, height);
|
|
|
|
|
|
|
|
tbuffersize += tsize;
|
|
|
|
|
|
|
|
// see if there's enough memory, allowing for the normal mode 0x13 pixel,
|
|
|
|
// z, and surface buffers
|
|
|
|
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
|
2001-02-26 06:48:02 +00:00
|
|
|
0x10000 * 3) < minimum_memory) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_SafePrintf ("Not enough memory for video mode\n");
|
2001-02-26 06:48:02 +00:00
|
|
|
return false; // not enough memory for mode
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vid_surfcachesize = tsize;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (d_pzbuffer) {
|
2001-02-19 21:15:25 +00:00
|
|
|
D_FlushCaches ();
|
|
|
|
Hunk_FreeToHighMark (VID_highhunkmark);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_highhunkmark = Hunk_HighMark ();
|
|
|
|
|
|
|
|
d_pzbuffer = Hunk_HighAllocName (tbuffersize, "video");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vid_surfcache = (byte *) d_pzbuffer + width * height * sizeof (*d_pzbuffer);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
initFatalError (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_exit ();
|
|
|
|
MGL_fatalError (MGL_errorMsg (MGL_result ()));
|
|
|
|
exit (EXIT_FAILURE);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VID_Suspend (MGLDC * dc, m_int flags)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (flags & MGL_DEACTIVATE) {
|
|
|
|
// FIXME: this doesn't currently work on NT
|
|
|
|
if (block_switch->int_val && !WinNT) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return MGL_NO_DEACTIVATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
S_BlockSound ();
|
|
|
|
S_ClearBuffer ();
|
|
|
|
|
|
|
|
IN_RestoreOriginalMouseState ();
|
|
|
|
CDAudio_Pause ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// keep WM_PAINT from trying to redraw
|
2001-02-19 21:15:25 +00:00
|
|
|
in_mode_set = true;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
block_drawing = true; // so we don't try to draw while
|
|
|
|
// switched away
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return MGL_NO_SUSPEND_APP;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (flags & MGL_REACTIVATE) {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_SetQuakeMouseState ();
|
2001-02-26 06:48:02 +00:00
|
|
|
// fix the leftover Alt from any Alt-Tab or the like that switched us
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// away
|
2001-02-19 21:15:25 +00:00
|
|
|
ClearAllStates ();
|
|
|
|
CDAudio_Resume ();
|
|
|
|
S_UnblockSound ();
|
|
|
|
|
|
|
|
in_mode_set = false;
|
|
|
|
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
|
|
|
|
block_drawing = false;
|
|
|
|
|
|
|
|
return MGL_NO_SUSPEND_APP;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
registerAllDispDrivers (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
/* Event though these driver require WinDirect, we register * them so
|
|
|
|
that they will still be available even if DirectDraw * is present and
|
|
|
|
the user has disable the high performance * WinDirect modes. */
|
|
|
|
MGL_registerDriver (MGL_VGA8NAME, VGA8_driver);
|
|
|
|
// MGL_registerDriver(MGL_VGAXNAME,VGAX_driver);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* Register display drivers */
|
2001-02-26 06:48:02 +00:00
|
|
|
if (useWinDirect) {
|
|
|
|
//we don't want VESA 1.X drivers MGL_registerDriver(MGL_SVGA8NAME,SVGA8_driver);
|
|
|
|
MGL_registerDriver (MGL_LINEAR8NAME, LINEAR8_driver);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!COM_CheckParm ("-novbeaf"))
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_registerDriver (MGL_ACCEL8NAME, ACCEL8_driver);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (useDirectDraw) {
|
|
|
|
MGL_registerDriver (MGL_DDRAW8NAME, DDRAW8_driver);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
registerAllMemDrivers (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
/* Register memory context drivers */
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_registerDriver (MGL_PACKED8NAME, PACKED8_driver);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_InitMGLFull (HINSTANCE hInstance)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, xRes, yRes, bits, vMode, lowres, curmode, temp;
|
|
|
|
int lowstretchedres, stretchedmode, lowstretched;
|
|
|
|
uchar *m;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// FIXME: NT is checked for because MGL currently has a bug that causes it
|
|
|
|
// to try to use WinDirect modes even on NT
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-nowindirect") ||
|
|
|
|
COM_CheckParm ("-nowd") || COM_CheckParm ("-novesa") || WinNT) {
|
2001-02-19 21:15:25 +00:00
|
|
|
useWinDirect = false;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-nodirectdraw") || COM_CheckParm ("-noddraw")
|
|
|
|
|| COM_CheckParm ("-nodd"))
|
2001-02-19 21:15:25 +00:00
|
|
|
useDirectDraw = false;
|
|
|
|
|
|
|
|
// Initialise the MGL
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_unregisterAllDrivers ();
|
|
|
|
registerAllDispDrivers ();
|
|
|
|
registerAllMemDrivers ();
|
|
|
|
MGL_detectGraph (&driver, &mode);
|
|
|
|
m = MGL_availableModes ();
|
|
|
|
|
|
|
|
if (m[0] != 0xFF) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lowres = lowstretchedres = 99999;
|
|
|
|
lowstretched = 0;
|
|
|
|
curmode = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// find the lowest-res mode, or a mode we can stretch up to and get
|
|
|
|
// lowest-res that way
|
|
|
|
for (i = 0; m[i] != 0xFF; i++) {
|
|
|
|
MGL_modeResolution (m[i], &xRes, &yRes, &bits);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((bits == 8) &&
|
|
|
|
(xRes <= MAXWIDTH) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(yRes <= MAXHEIGHT) && (curmode < MAX_MODE_LIST)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (m[i] == grVGA_320x200x256)
|
|
|
|
is_mode0x13 = true;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!COM_CheckParm ("-noforcevga")) {
|
|
|
|
if (m[i] == grVGA_320x200x256) {
|
2001-02-19 21:15:25 +00:00
|
|
|
mode = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (xRes < lowres) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lowres = xRes;
|
|
|
|
mode = i;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((xRes < lowstretchedres) && ((xRes >> 1) >= 320)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lowstretchedres = xRes >> 1;
|
|
|
|
stretchedmode = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curmode++;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// if there's a mode we can stretch by 2 up to, thereby effectively
|
|
|
|
// getting
|
|
|
|
// a lower-res mode than the lowest-res real but still at least
|
|
|
|
// 320x200, that
|
|
|
|
// will be our default mode
|
|
|
|
if (lowstretchedres < lowres) {
|
2001-02-19 21:15:25 +00:00
|
|
|
mode = stretchedmode;
|
|
|
|
lowres = lowstretchedres;
|
|
|
|
lowstretched = 1;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// build the mode list, leaving room for the low-res stretched mode,
|
|
|
|
// if any
|
|
|
|
nummodes++; // leave room for default mode
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; m[i] != 0xFF; i++) {
|
|
|
|
MGL_modeResolution (m[i], &xRes, &yRes, &bits);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((bits == 8) &&
|
|
|
|
(xRes <= MAXWIDTH) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(yRes <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST)) {
|
|
|
|
if (i == mode) {
|
|
|
|
if (lowstretched) {
|
2001-02-19 21:15:25 +00:00
|
|
|
stretchedmode = nummodes;
|
|
|
|
curmode = nummodes++;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
curmode = MODE_FULLSCREEN_DEFAULT;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
curmode = nummodes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
modelist[curmode].type = MS_FULLSCREEN;
|
|
|
|
modelist[curmode].width = xRes;
|
|
|
|
modelist[curmode].height = yRes;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[curmode].modedesc,
|
|
|
|
sizeof (modelist[curmode].modedesc), "%dx%d", xRes,
|
|
|
|
yRes);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (m[i] == grVGA_320x200x256)
|
|
|
|
modelist[curmode].mode13 = 1;
|
|
|
|
else
|
|
|
|
modelist[curmode].mode13 = 0;
|
|
|
|
|
|
|
|
modelist[curmode].modenum = m[i];
|
|
|
|
modelist[curmode].stretched = 0;
|
|
|
|
modelist[curmode].dib = 0;
|
|
|
|
modelist[curmode].fullscreen = 1;
|
|
|
|
modelist[curmode].halfscreen = 0;
|
|
|
|
modelist[curmode].bpp = 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lowstretched) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT] = modelist[stretchedmode];
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].stretched = 1;
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].width >>= 1;
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].height >>= 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[MODE_FULLSCREEN_DEFAULT].modedesc,
|
|
|
|
sizeof (modelist[MODE_FULLSCREEN_DEFAULT].modedesc),
|
|
|
|
"%dx%d", modelist[MODE_FULLSCREEN_DEFAULT].width,
|
|
|
|
modelist[MODE_FULLSCREEN_DEFAULT].height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vid_default = MODE_FULLSCREEN_DEFAULT;
|
|
|
|
|
|
|
|
temp = m[0];
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!MGL_init (&driver, &temp, "")) {
|
|
|
|
initFatalError ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setSuspendAppCallback (VID_Suspend);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGLDC *
|
|
|
|
createDisplayDC (int forcemem)
|
2001-02-19 21:15:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Function: createDisplayDC
|
|
|
|
* Returns: Pointer to the MGL device context to use for the application
|
|
|
|
*
|
|
|
|
* Description: Initialises the MGL and creates an appropriate display
|
|
|
|
* device context to be used by the GUI. This creates and
|
|
|
|
* apropriate device context depending on the system being
|
|
|
|
* compile for, and should be the only place where system
|
|
|
|
* specific code is required.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
MGLDC *dc;
|
|
|
|
pixel_format_t pf;
|
|
|
|
int npages;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Start the specified video mode
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!MGL_changeDisplayMode (mode))
|
|
|
|
initFatalError ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
npages = MGL_availablePages (mode);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (npages > 3)
|
|
|
|
npages = 3;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!COM_CheckParm ("-notriplebuf")) {
|
|
|
|
if (npages > 2) {
|
2001-02-19 21:15:25 +00:00
|
|
|
npages = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((dc = MGL_createDisplayDC (npages)) == NULL)
|
2001-02-19 21:15:25 +00:00
|
|
|
return NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!forcemem && (MGL_surfaceAccessType (dc)) == MGL_LINEAR_ACCESS
|
|
|
|
&& (dc->mi.maxPage > 0)) {
|
|
|
|
MGL_makeCurrentDC (dc);
|
2001-02-19 21:15:25 +00:00
|
|
|
memdc = NULL;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
// Set up for blitting from a memory buffer
|
2001-02-26 06:48:02 +00:00
|
|
|
memdc =
|
|
|
|
MGL_createMemoryDC (MGL_sizex (dc) + 1, MGL_sizey (dc) + 1, 8, &pf);
|
|
|
|
MGL_makeCurrentDC (memdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable page flipping even for even for blitted surfaces
|
2001-02-26 06:48:02 +00:00
|
|
|
if (forcemem) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.numpages = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid.numpages = dc->mi.maxPage + 1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.numpages > 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// Set up for page flipping
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setActivePage (dc, aPage = 1);
|
|
|
|
MGL_setVisualPage (dc, vPage = 0, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vid.numpages > 3)
|
|
|
|
vid.numpages = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vid.numpages == 2)
|
|
|
|
waitVRT = true;
|
|
|
|
else
|
|
|
|
waitVRT = false;
|
|
|
|
|
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_InitMGLDIB (HINSTANCE hInstance)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
WNDCLASS wc;
|
|
|
|
HDC hdc;
|
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON2));
|
|
|
|
|
|
|
|
/* Register the frame class */
|
2001-02-26 06:48:02 +00:00
|
|
|
wc.style = 0;
|
|
|
|
wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = 0;
|
|
|
|
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
2001-02-19 21:15:25 +00:00
|
|
|
wc.hbrBackground = NULL;
|
2001-02-26 06:48:02 +00:00
|
|
|
wc.lpszMenuName = 0;
|
|
|
|
wc.lpszClassName = "WinQuake";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!RegisterClass (&wc))
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't register window class");
|
|
|
|
|
|
|
|
/* Find the size for the DIB window */
|
|
|
|
/* Initialise the MGL for windowed operation */
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setAppInstance (hInstance);
|
|
|
|
registerAllMemDrivers ();
|
|
|
|
MGL_initWindowed ("");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
modelist[0].type = MS_WINDOWED;
|
|
|
|
modelist[0].width = 320;
|
|
|
|
modelist[0].height = 240;
|
|
|
|
strcpy (modelist[0].modedesc, "320x240");
|
|
|
|
modelist[0].mode13 = 0;
|
|
|
|
modelist[0].modenum = MODE_WINDOWED;
|
|
|
|
modelist[0].stretched = 0;
|
|
|
|
modelist[0].dib = 1;
|
|
|
|
modelist[0].fullscreen = 0;
|
|
|
|
modelist[0].halfscreen = 0;
|
|
|
|
modelist[0].bpp = 8;
|
|
|
|
|
|
|
|
modelist[1].type = MS_WINDOWED;
|
|
|
|
modelist[1].width = 640;
|
|
|
|
modelist[1].height = 480;
|
|
|
|
strcpy (modelist[1].modedesc, "640x480");
|
|
|
|
modelist[1].mode13 = 0;
|
|
|
|
modelist[1].modenum = MODE_WINDOWED + 1;
|
|
|
|
modelist[1].stretched = 1;
|
|
|
|
modelist[1].dib = 1;
|
|
|
|
modelist[1].fullscreen = 0;
|
|
|
|
modelist[1].halfscreen = 0;
|
|
|
|
modelist[1].bpp = 8;
|
|
|
|
|
|
|
|
modelist[2].type = MS_WINDOWED;
|
|
|
|
modelist[2].width = 800;
|
|
|
|
modelist[2].height = 600;
|
|
|
|
strcpy (modelist[2].modedesc, "800x600");
|
|
|
|
modelist[2].mode13 = 0;
|
|
|
|
modelist[2].modenum = MODE_WINDOWED + 2;
|
|
|
|
modelist[2].stretched = 1;
|
|
|
|
modelist[2].dib = 1;
|
|
|
|
modelist[2].fullscreen = 0;
|
|
|
|
modelist[2].halfscreen = 0;
|
|
|
|
modelist[2].bpp = 8;
|
|
|
|
|
|
|
|
// automatically stretch the default mode up if > 640x480 desktop resolution
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((GetDeviceCaps (hdc, HORZRES) > 640)
|
|
|
|
&& !COM_CheckParm ("-noautostretch")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_default = MODE_WINDOWED + 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_default = MODE_WINDOWED;
|
|
|
|
}
|
|
|
|
|
|
|
|
windowed_default = vid_default;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
nummodes = 3; // reserve space for windowed mode
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
DDActive = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_InitFullDIB
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_InitFullDIB (HINSTANCE hInstance)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
DEVMODE devmode;
|
|
|
|
int i, j, modenum, cmodes, existingmode, originalnummodes,
|
|
|
|
|
|
|
|
lowestres;
|
|
|
|
int numlowresmodes, bpp, done;
|
|
|
|
int cstretch, istretch, mstretch;
|
|
|
|
BOOL stat;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// enumerate 8 bpp modes
|
|
|
|
originalnummodes = nummodes;
|
|
|
|
modenum = 0;
|
|
|
|
lowestres = 99999;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
stat = EnumDisplaySettings (NULL, modenum, &devmode);
|
|
|
|
|
|
|
|
if ((devmode.dmBitsPerPel == 8) &&
|
|
|
|
(devmode.dmPelsWidth <= MAXWIDTH) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(devmode.dmPelsHeight <= MAXHEIGHT) && (nummodes < MAX_MODE_LIST)) {
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
|
2001-02-26 06:48:02 +00:00
|
|
|
DISP_CHANGE_SUCCESSFUL) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = devmode.dmPelsWidth;
|
|
|
|
modelist[nummodes].height = devmode.dmPelsHeight;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].mode13 = 0;
|
|
|
|
modelist[nummodes].stretched = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = devmode.dmBitsPerPel;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc), "%dx%d",
|
|
|
|
devmode.dmPelsWidth, devmode.dmPelsHeight);
|
|
|
|
|
|
|
|
// if the width is more than twice the height, reduce it by
|
|
|
|
// half because this
|
|
|
|
// is probably a dual-screen monitor
|
|
|
|
if (!COM_CheckParm ("-noadjustaspect")) {
|
|
|
|
if (modelist[nummodes].width >
|
|
|
|
(modelist[nummodes].height << 1)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[nummodes].width >>= 1;
|
|
|
|
modelist[nummodes].halfscreen = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc), "%dx%d",
|
|
|
|
modelist[nummodes].width,
|
|
|
|
modelist[nummodes].height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = originalnummodes, existingmode = 0; i < nummodes; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((modelist[nummodes].width == modelist[i].width) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(modelist[nummodes].height == modelist[i].height)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!existingmode) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modelist[nummodes].width < lowestres)
|
|
|
|
lowestres = modelist[nummodes].width;
|
|
|
|
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
modenum++;
|
|
|
|
} while (stat);
|
|
|
|
|
|
|
|
// see if any of them were actually settable; if so, this is our mode list,
|
|
|
|
// else enumerate all modes; our mode list is whichever ones are settable
|
|
|
|
// with > 8 bpp
|
2001-02-26 06:48:02 +00:00
|
|
|
if (nummodes == originalnummodes) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modenum = 0;
|
|
|
|
lowestres = 99999;
|
|
|
|
|
|
|
|
Con_SafePrintf ("No 8-bpp fullscreen DIB modes found\n");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
stat = EnumDisplaySettings (NULL, modenum, &devmode);
|
|
|
|
|
|
|
|
if ((((devmode.dmPelsWidth <= MAXWIDTH) &&
|
|
|
|
(devmode.dmPelsHeight <= MAXHEIGHT)) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(!COM_CheckParm ("-noadjustaspect") &&
|
|
|
|
(devmode.dmPelsWidth <= (MAXWIDTH * 2)) &&
|
|
|
|
(devmode.dmPelsWidth > (devmode.dmPelsHeight * 2)))) &&
|
|
|
|
(nummodes < MAX_MODE_LIST) && (devmode.dmBitsPerPel > 8)) {
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN)
|
|
|
|
== DISP_CHANGE_SUCCESSFUL) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = devmode.dmPelsWidth;
|
|
|
|
modelist[nummodes].height = devmode.dmPelsHeight;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].mode13 = 0;
|
|
|
|
modelist[nummodes].stretched = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = devmode.dmBitsPerPel;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc), "%dx%d",
|
|
|
|
devmode.dmPelsWidth, devmode.dmPelsHeight);
|
|
|
|
|
|
|
|
// if the width is more than twice the height, reduce it
|
|
|
|
// by half because this
|
|
|
|
// is probably a dual-screen monitor
|
|
|
|
if (!COM_CheckParm ("-noadjustaspect")) {
|
|
|
|
if (modelist[nummodes].width >
|
|
|
|
(modelist[nummodes].height * 2)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[nummodes].width >>= 1;
|
|
|
|
modelist[nummodes].halfscreen = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc),
|
|
|
|
"%dx%d", modelist[nummodes].width,
|
|
|
|
modelist[nummodes].height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = originalnummodes, existingmode = 0; i < nummodes;
|
|
|
|
i++) {
|
|
|
|
if ((modelist[nummodes].width == modelist[i].width)
|
|
|
|
&& (modelist[nummodes].height ==
|
|
|
|
modelist[i].height)) {
|
|
|
|
// pick the lowest available bpp
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modelist[nummodes].bpp < modelist[i].bpp)
|
|
|
|
modelist[i] = modelist[nummodes];
|
|
|
|
|
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!existingmode) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modelist[nummodes].width < lowestres)
|
|
|
|
lowestres = modelist[nummodes].width;
|
|
|
|
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
modenum++;
|
|
|
|
} while (stat);
|
|
|
|
}
|
|
|
|
// see if there are any low-res modes that aren't being reported
|
2001-02-26 06:48:02 +00:00
|
|
|
numlowresmodes = sizeof (lowresmodes) / sizeof (lowresmodes[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
bpp = 8;
|
|
|
|
done = 0;
|
|
|
|
|
|
|
|
// first make sure the driver doesn't just answer yes to all tests
|
|
|
|
devmode.dmBitsPerPel = 8;
|
|
|
|
devmode.dmPelsWidth = 42;
|
|
|
|
devmode.dmPelsHeight = 37;
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
|
2001-02-26 06:48:02 +00:00
|
|
|
DISP_CHANGE_SUCCESSFUL) {
|
2001-02-19 21:15:25 +00:00
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (!done) {
|
|
|
|
for (j = 0; (j < numlowresmodes) && (nummodes < MAX_MODE_LIST); j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
devmode.dmBitsPerPel = bpp;
|
|
|
|
devmode.dmPelsWidth = lowresmodes[j].width;
|
|
|
|
devmode.dmPelsHeight = lowresmodes[j].height;
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
if (ChangeDisplaySettings (&devmode, CDS_TEST | CDS_FULLSCREEN) ==
|
2001-02-26 06:48:02 +00:00
|
|
|
DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
modelist[nummodes].type = MS_FULLDIB;
|
|
|
|
modelist[nummodes].width = devmode.dmPelsWidth;
|
|
|
|
modelist[nummodes].height = devmode.dmPelsHeight;
|
|
|
|
modelist[nummodes].modenum = 0;
|
|
|
|
modelist[nummodes].mode13 = 0;
|
|
|
|
modelist[nummodes].stretched = 0;
|
|
|
|
modelist[nummodes].halfscreen = 0;
|
|
|
|
modelist[nummodes].dib = 1;
|
|
|
|
modelist[nummodes].fullscreen = 1;
|
|
|
|
modelist[nummodes].bpp = devmode.dmBitsPerPel;
|
|
|
|
snprintf (modelist[nummodes].modedesc,
|
|
|
|
sizeof (modelist[nummodes].modedesc), "%dx%d",
|
|
|
|
devmode.dmPelsWidth, devmode.dmPelsHeight);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// we only want the lowest-bpp version of each mode
|
|
|
|
for (i = originalnummodes, existingmode = 0; i < nummodes; i++) {
|
|
|
|
if ((modelist[nummodes].width == modelist[i].width) &&
|
2001-02-19 21:15:25 +00:00
|
|
|
(modelist[nummodes].height == modelist[i].height) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(modelist[nummodes].bpp >= modelist[i].bpp)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
existingmode = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!existingmode) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modelist[nummodes].width < lowestres)
|
|
|
|
lowestres = modelist[nummodes].width;
|
|
|
|
|
|
|
|
nummodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (bpp) {
|
2001-02-19 21:15:25 +00:00
|
|
|
case 8:
|
2001-02-26 06:48:02 +00:00
|
|
|
bpp = 16;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case 16:
|
2001-02-26 06:48:02 +00:00
|
|
|
bpp = 32;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case 32:
|
2001-02-26 06:48:02 +00:00
|
|
|
done = 1;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now add the lowest stretch-by-2 pseudo-modes between 320-wide
|
|
|
|
// (inclusive) and lowest real res (not inclusive)
|
|
|
|
// don't bother if we have a real VGA mode 0x13 mode
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!is_mode0x13) {
|
|
|
|
for (i = originalnummodes, cstretch = 0; i < nummodes; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (((modelist[i].width >> 1) < lowestres) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
((modelist[i].width >> 1) >= 320)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lowestres = modelist[i].width >> 1;
|
|
|
|
cstretch = 1;
|
|
|
|
mstretch = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nummodes + cstretch) > MAX_MODE_LIST)
|
|
|
|
cstretch = MAX_MODE_LIST - nummodes;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (cstretch > 0) {
|
|
|
|
for (i = (nummodes - 1); i >= originalnummodes; i--)
|
|
|
|
modelist[i + cstretch] = modelist[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
nummodes += cstretch;
|
|
|
|
istretch = originalnummodes;
|
|
|
|
|
|
|
|
modelist[istretch] = modelist[mstretch];
|
|
|
|
modelist[istretch].width >>= 1;
|
|
|
|
modelist[istretch].height >>= 1;
|
|
|
|
modelist[istretch].stretched = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[istretch].modedesc,
|
|
|
|
sizeof (modelist[istretch].modedesc), "%dx%d",
|
|
|
|
modelist[istretch].width, modelist[istretch].height);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nummodes != originalnummodes)
|
|
|
|
vid_default = MODE_FULLSCREEN_DEFAULT;
|
|
|
|
else
|
|
|
|
Con_SafePrintf ("No fullscreen DIB modes found\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_NumModes
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VID_NumModes (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return nummodes;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_GetModePtr
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
vmode_t *
|
|
|
|
VID_GetModePtr (int modenum)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if ((modenum >= 0) && (modenum < nummodes))
|
|
|
|
return &modelist[modenum];
|
|
|
|
else
|
|
|
|
return &badmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_CheckModedescFixup
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_CheckModedescFixup (int mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int x, y, stretch;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (mode == MODE_SETTABLE_WINDOW) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[mode].stretched = vid_stretch_by_2->int_val;
|
|
|
|
stretch = modelist[mode].stretched;
|
|
|
|
|
|
|
|
if (vid_config_x->int_val < (320 << stretch))
|
|
|
|
Cvar_SetValue (vid_config_x, 320 << stretch);
|
|
|
|
|
|
|
|
if (vid_config_y->int_val < (200 << stretch))
|
|
|
|
Cvar_SetValue (vid_config_y, 200 << stretch);
|
|
|
|
|
|
|
|
x = vid_config_x->int_val;
|
|
|
|
y = vid_config_y->int_val;
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (modelist[mode].modedesc, sizeof (modelist[mode].modedesc),
|
|
|
|
"%dx%d", x, y);
|
2001-02-19 21:15:25 +00:00
|
|
|
modelist[mode].width = x;
|
|
|
|
modelist[mode].height = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_GetModeDescriptionMemCheck
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
VID_GetModeDescriptionMemCheck (int mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *pinfo;
|
|
|
|
vmode_t *pv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VID_CheckModedescFixup (mode);
|
|
|
|
|
|
|
|
pv = VID_GetModePtr (mode);
|
|
|
|
pinfo = pv->modedesc;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (VID_CheckAdequateMem (pv->width, pv->height)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return pinfo;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_GetModeDescription
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
VID_GetModeDescription (int mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *pinfo;
|
|
|
|
vmode_t *pv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VID_CheckModedescFixup (mode);
|
|
|
|
|
|
|
|
pv = VID_GetModePtr (mode);
|
|
|
|
pinfo = pv->modedesc;
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_GetModeDescription2
|
|
|
|
|
|
|
|
Tacks on "windowed" or "fullscreen"
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
VID_GetModeDescription2 (int mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char pinfo[40];
|
|
|
|
vmode_t *pv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VID_CheckModedescFixup (mode);
|
|
|
|
|
|
|
|
pv = VID_GetModePtr (mode);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modelist[mode].type == MS_FULLSCREEN) {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s fullscreen", pv->modedesc);
|
|
|
|
} else if (modelist[mode].type == MS_FULLDIB) {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s fullscreen", pv->modedesc);
|
|
|
|
} else {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s windowed", pv->modedesc);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// KJB: Added this to return the mode driver name in description for console
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
VID_GetExtModeDescription (int mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char pinfo[40];
|
|
|
|
vmode_t *pv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if ((mode < 0) || (mode >= nummodes))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VID_CheckModedescFixup (mode);
|
|
|
|
|
|
|
|
pv = VID_GetModePtr (mode);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modelist[mode].type == MS_FULLSCREEN) {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s fullscreen %s", pv->modedesc,
|
|
|
|
MGL_modeDriverName (pv->modenum));
|
|
|
|
} else if (modelist[mode].type == MS_FULLDIB) {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s fullscreen DIB", pv->modedesc);
|
|
|
|
} else {
|
|
|
|
snprintf (pinfo, sizeof (pinfo), "%s windowed", pv->modedesc);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
DestroyDIBWindow (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modestate == MS_WINDOWED) {
|
|
|
|
// destroy the associated MGL DC's; the window gets reused
|
2001-02-19 21:15:25 +00:00
|
|
|
if (windc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (windc);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dibdc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
windc = dibdc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
DestroyFullscreenWindow (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modestate == MS_FULLSCREEN) {
|
|
|
|
// destroy the existing fullscreen mode and DC's
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mgldc)
|
|
|
|
MGL_destroyDC (mgldc);
|
|
|
|
if (memdc)
|
|
|
|
MGL_destroyDC (memdc);
|
|
|
|
mgldc = memdc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
DestroyFullDIBWindow (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modestate == MS_FULLDIB) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ChangeDisplaySettings (NULL, CDS_FULLSCREEN);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// Destroy the fullscreen DIB window and associated MGL DC's
|
2001-02-19 21:15:25 +00:00
|
|
|
if (windc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (windc);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dibdc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
windc = dibdc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_SetWindowedMode (int modenum)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
HDC hdc;
|
|
|
|
pixel_format_t pf;
|
|
|
|
qboolean stretched;
|
|
|
|
int lastmodestate;
|
|
|
|
LONG wlong;
|
|
|
|
|
|
|
|
if (!windowed_mode_set) {
|
|
|
|
if (COM_CheckParm ("-resetwinpos")) {
|
|
|
|
Cvar_SetValue (vid_window_x, 0.0);
|
|
|
|
Cvar_SetValue (vid_window_y, 0.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
windowed_mode_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_CheckModedescFixup (modenum);
|
|
|
|
|
|
|
|
DDActive = 0;
|
|
|
|
lastmodestate = modestate;
|
|
|
|
|
|
|
|
DestroyFullscreenWindow ();
|
|
|
|
DestroyFullDIBWindow ();
|
|
|
|
|
|
|
|
if (windc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (windc);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dibdc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
windc = dibdc = NULL;
|
|
|
|
|
|
|
|
// KJB: Signal to the MGL that we are going back to windowed mode
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!MGL_changeDisplayMode (grWINDOWED))
|
|
|
|
initFatalError ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
WindowRect.top = WindowRect.left = 0;
|
|
|
|
|
|
|
|
WindowRect.right = modelist[modenum].width;
|
|
|
|
WindowRect.bottom = modelist[modenum].height;
|
|
|
|
stretched = modelist[modenum].stretched;
|
|
|
|
|
|
|
|
DIBWidth = modelist[modenum].width;
|
|
|
|
DIBHeight = modelist[modenum].height;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (stretched) {
|
2001-02-19 21:15:25 +00:00
|
|
|
DIBWidth >>= 1;
|
|
|
|
DIBHeight >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU |
|
2001-02-26 06:48:02 +00:00
|
|
|
WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
2001-02-19 21:15:25 +00:00
|
|
|
ExWindowStyle = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
AdjustWindowRectEx (&WindowRect, WindowStyle, FALSE, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// the first time we're called to set the mode, create the window we'll use
|
|
|
|
// for the rest of the session
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!vid_mode_set) {
|
|
|
|
mainwindow = CreateWindowEx (ExWindowStyle,
|
|
|
|
"WinQuake",
|
|
|
|
"WinQuake",
|
|
|
|
WindowStyle,
|
|
|
|
0, 0,
|
|
|
|
WindowRect.right - WindowRect.left,
|
|
|
|
WindowRect.bottom - WindowRect.top,
|
|
|
|
NULL, NULL, global_hInstance, NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!mainwindow)
|
|
|
|
Sys_Error ("Couldn't create DIB window");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// tell MGL to use this window for fullscreen modes
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_registerFullScreenWindow (mainwindow);
|
|
|
|
|
|
|
|
vid_mode_set = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
SetWindowLong (mainwindow, GWL_STYLE, WindowStyle | WS_VISIBLE);
|
|
|
|
SetWindowLong (mainwindow, GWL_EXSTYLE, ExWindowStyle);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetWindowPos (mainwindow,
|
|
|
|
NULL,
|
|
|
|
0, 0,
|
|
|
|
WindowRect.right - WindowRect.left,
|
|
|
|
WindowRect.bottom - WindowRect.top,
|
2001-02-26 06:48:02 +00:00
|
|
|
SWP_NOCOPYBITS | SWP_NOZORDER | SWP_HIDEWINDOW)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't resize DIB window");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hide_window)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// position and show the DIB window
|
|
|
|
VID_CheckWindowXY ();
|
|
|
|
SetWindowPos (mainwindow, NULL, vid_window_x->int_val,
|
|
|
|
vid_window_y->int_val, 0, 0,
|
|
|
|
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
|
|
|
|
|
|
|
|
if (force_minimized)
|
|
|
|
ShowWindow (mainwindow, SW_MINIMIZE);
|
|
|
|
else
|
|
|
|
ShowWindow (mainwindow, SW_SHOWDEFAULT);
|
|
|
|
|
|
|
|
UpdateWindow (mainwindow);
|
|
|
|
|
|
|
|
modestate = MS_WINDOWED;
|
|
|
|
vid_fulldib_on_focus_mode = 0;
|
|
|
|
|
|
|
|
// because we have set the background brush for the window to NULL
|
|
|
|
// (to avoid flickering when re-sizing the window on the desktop),
|
|
|
|
// we clear the window to black when created, otherwise it will be
|
|
|
|
// empty while Quake starts up.
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (mainwindow);
|
|
|
|
PatBlt (hdc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
|
|
|
|
ReleaseDC (mainwindow, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* Create the MGL window DC and the MGL memory DC */
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((windc = MGL_createWindowedDC (mainwindow)) == NULL)
|
|
|
|
MGL_fatalError ("Unable to create Windowed DC!");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((dibdc = MGL_createMemoryDC (DIBWidth, DIBHeight, 8, &pf)) == NULL)
|
|
|
|
MGL_fatalError ("Unable to create Memory DC!");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_makeCurrentDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = dibdc->surface;
|
|
|
|
vid.rowbytes = vid.conrowbytes = dibdc->mi.bytesPerLine;
|
|
|
|
vid.numpages = 1;
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.height = vid.conheight = DIBHeight;
|
|
|
|
vid.width = vid.conwidth = DIBWidth;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_stretched = stretched;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) TRUE, (LPARAM) hIcon);
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) FALSE, (LPARAM) hIcon);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_SetFullscreenMode (int modenum)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
DDActive = 1;
|
|
|
|
|
|
|
|
DestroyDIBWindow ();
|
|
|
|
DestroyFullDIBWindow ();
|
|
|
|
|
|
|
|
mode = modelist[modenum].modenum;
|
|
|
|
|
|
|
|
// Destroy old DC's, resetting back to fullscreen mode
|
|
|
|
if (mgldc)
|
|
|
|
MGL_destroyDC (mgldc);
|
|
|
|
if (memdc)
|
|
|
|
MGL_destroyDC (memdc);
|
|
|
|
mgldc = memdc = NULL;
|
|
|
|
|
|
|
|
if ((mgldc = createDisplayDC (modelist[modenum].stretched ||
|
2001-02-26 06:48:02 +00:00
|
|
|
vid_nopageflip->int_val)) == NULL) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
modestate = MS_FULLSCREEN;
|
|
|
|
vid_fulldib_on_focus_mode = 0;
|
|
|
|
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = NULL;
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
DIBHeight = vid.height = vid.conheight = modelist[modenum].height;
|
|
|
|
DIBWidth = vid.width = vid.conwidth = modelist[modenum].width;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_stretched = modelist[modenum].stretched;
|
|
|
|
|
|
|
|
// needed because we're not getting WM_MOVE messages fullscreen on NT
|
|
|
|
window_x = 0;
|
|
|
|
window_y = 0;
|
|
|
|
|
|
|
|
// set the large icon, so the Quake icon will show up in the taskbar
|
2001-02-26 06:48:02 +00:00
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) 1, (LPARAM) hIcon);
|
|
|
|
SendMessage (mainwindow, WM_SETICON, (WPARAM) 0, (LPARAM) hIcon);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// shouldn't be needed, but Kendall needs to let us get the activation
|
|
|
|
// message for this not to be needed on NT
|
|
|
|
AppActivate (true, false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
VID_SetFullDIBMode (int modenum)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
HDC hdc;
|
|
|
|
pixel_format_t pf;
|
|
|
|
int lastmodestate;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
DDActive = 0;
|
|
|
|
|
|
|
|
DestroyFullscreenWindow ();
|
|
|
|
DestroyDIBWindow ();
|
|
|
|
|
|
|
|
if (windc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (windc);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dibdc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_destroyDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
windc = dibdc = NULL;
|
|
|
|
|
|
|
|
// KJB: Signal to the MGL that we are going back to windowed mode
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!MGL_changeDisplayMode (grWINDOWED))
|
|
|
|
initFatalError ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
|
|
|
gdevmode.dmBitsPerPel = modelist[modenum].bpp;
|
2001-02-26 06:48:02 +00:00
|
|
|
gdevmode.dmPelsWidth =
|
|
|
|
modelist[modenum].width << modelist[modenum].
|
|
|
|
stretched << modelist[modenum].halfscreen;
|
|
|
|
gdevmode.dmPelsHeight =
|
|
|
|
modelist[modenum].height << modelist[modenum].stretched;
|
2001-02-19 21:15:25 +00:00
|
|
|
gdevmode.dmSize = sizeof (gdevmode);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) !=
|
|
|
|
DISP_CHANGE_SUCCESSFUL) Sys_Error ("Couldn't set fullscreen DIB mode");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
lastmodestate = modestate;
|
|
|
|
modestate = MS_FULLDIB;
|
|
|
|
vid_fulldib_on_focus_mode = modenum;
|
|
|
|
|
|
|
|
WindowRect.top = WindowRect.left = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
WindowRect.right = modelist[modenum].width << modelist[modenum].stretched;
|
|
|
|
WindowRect.bottom = modelist[modenum].height << modelist[modenum].stretched;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
DIBWidth = modelist[modenum].width;
|
|
|
|
DIBHeight = modelist[modenum].height;
|
|
|
|
|
|
|
|
WindowStyle = WS_POPUP | WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
|
|
ExWindowStyle = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
AdjustWindowRectEx (&WindowRect, WindowStyle, FALSE, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
SetWindowLong (mainwindow, GWL_STYLE, WindowStyle | WS_VISIBLE);
|
|
|
|
SetWindowLong (mainwindow, GWL_EXSTYLE, ExWindowStyle);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!SetWindowPos (mainwindow,
|
|
|
|
NULL,
|
|
|
|
0, 0,
|
|
|
|
WindowRect.right - WindowRect.left,
|
|
|
|
WindowRect.bottom - WindowRect.top,
|
2001-02-26 06:48:02 +00:00
|
|
|
SWP_NOCOPYBITS | SWP_NOZORDER)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't resize DIB window");
|
|
|
|
}
|
|
|
|
// position and show the DIB window
|
|
|
|
SetWindowPos (mainwindow, HWND_TOPMOST, 0, 0, 0, 0,
|
|
|
|
SWP_NOSIZE | SWP_SHOWWINDOW | SWP_DRAWFRAME);
|
|
|
|
ShowWindow (mainwindow, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow (mainwindow);
|
|
|
|
|
|
|
|
// Because we have set the background brush for the window to NULL
|
|
|
|
// (to avoid flickering when re-sizing the window on the desktop), we
|
|
|
|
// clear the window to black when created, otherwise it will be
|
|
|
|
// empty while Quake starts up.
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (mainwindow);
|
|
|
|
PatBlt (hdc, 0, 0, WindowRect.right, WindowRect.bottom, BLACKNESS);
|
|
|
|
ReleaseDC (mainwindow, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* Create the MGL window DC and the MGL memory DC */
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((windc = MGL_createWindowedDC (mainwindow)) == NULL)
|
|
|
|
MGL_fatalError ("Unable to create Fullscreen DIB DC!");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((dibdc = MGL_createMemoryDC (DIBWidth, DIBHeight, 8, &pf)) == NULL)
|
|
|
|
MGL_fatalError ("Unable to create Memory DC!");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_makeCurrentDC (dibdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = dibdc->surface;
|
|
|
|
vid.rowbytes = vid.conrowbytes = dibdc->mi.bytesPerLine;
|
|
|
|
vid.numpages = 1;
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.height = vid.conheight = DIBHeight;
|
|
|
|
vid.width = vid.conwidth = DIBWidth;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_stretched = modelist[modenum].stretched;
|
|
|
|
|
|
|
|
// needed because we're not getting WM_MOVE messages fullscreen on NT
|
|
|
|
window_x = 0;
|
|
|
|
window_y = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_RestoreOldMode (int original_mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean inerror = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (inerror)
|
|
|
|
return;
|
|
|
|
|
|
|
|
in_mode_set = false;
|
|
|
|
inerror = true;
|
|
|
|
|
|
|
|
// make sure mode set happens (video mode changes)
|
|
|
|
vid_modenum = original_mode - 1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!VID_SetMode (original_mode, vid_curpal)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_modenum = MODE_WINDOWED - 1;
|
|
|
|
|
|
|
|
if (!VID_SetMode (windowed_default, vid_curpal))
|
|
|
|
Sys_Error ("Can't set any video mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
inerror = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_SetDefaultMode (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (vid_initialized)
|
|
|
|
VID_SetMode (0, vid_curpal);
|
|
|
|
|
|
|
|
IN_DeactivateMouse ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VID_SetMode (int modenum, unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int original_mode, temp, dummy;
|
|
|
|
qboolean stat;
|
|
|
|
MSG msg;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
while ((modenum >= nummodes) || (modenum < 0)) {
|
|
|
|
if (vid_modenum == NO_MODE) {
|
|
|
|
if (modenum == vid_default) {
|
2001-02-19 21:15:25 +00:00
|
|
|
modenum = windowed_default;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
modenum = vid_default;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (vid_mode, (float) modenum);
|
|
|
|
} else {
|
|
|
|
Cvar_SetValue (vid_mode, (float) vid_modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!force_mode_set && (modenum == vid_modenum))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// so Con_Printfs don't mess us up by forcing vid and snd updates
|
|
|
|
temp = scr_disabled_for_loading;
|
|
|
|
scr_disabled_for_loading = true;
|
|
|
|
in_mode_set = true;
|
|
|
|
|
|
|
|
CDAudio_Pause ();
|
|
|
|
S_ClearBuffer ();
|
|
|
|
|
|
|
|
if (vid_modenum == NO_MODE)
|
|
|
|
original_mode = windowed_default;
|
|
|
|
else
|
|
|
|
original_mode = vid_modenum;
|
|
|
|
|
|
|
|
// Set either the fullscreen or windowed mode
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modelist[modenum].type == MS_WINDOWED) {
|
|
|
|
if (_windowed_mouse->int_val) {
|
|
|
|
stat = VID_SetWindowedMode (modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
stat = VID_SetWindowedMode (modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (modelist[modenum].type == MS_FULLDIB) {
|
|
|
|
stat = VID_SetFullDIBMode (modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
stat = VID_SetFullscreenMode (modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
|
|
|
}
|
|
|
|
|
|
|
|
window_width = vid.width << vid_stretched;
|
|
|
|
window_height = vid.height << vid_stretched;
|
|
|
|
VID_UpdateWindowStatus ();
|
|
|
|
|
|
|
|
CDAudio_Resume ();
|
|
|
|
scr_disabled_for_loading = temp;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!stat) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_RestoreOldMode (original_mode);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hide_window)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// now we try to make sure we get the focus on the mode switch, because
|
|
|
|
// sometimes in some systems we don't. We grab the foreground, then
|
|
|
|
// finish setting up, pump all our messages, and sleep for a little while
|
|
|
|
// to let messages finish bouncing around the system, then we put
|
|
|
|
// ourselves at the top of the z order, then grab the foreground again,
|
|
|
|
// Who knows if it helps, but it probably doesn't hurt
|
|
|
|
if (!force_minimized)
|
|
|
|
SetForegroundWindow (mainwindow);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE)
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_palettized = true;
|
|
|
|
else
|
|
|
|
vid_palettized = false;
|
|
|
|
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_modenum = modenum;
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (vid_mode, (float) vid_modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!VID_AllocBuffers (vid.width, vid.height)) {
|
|
|
|
// couldn't get memory for this mode; try to fall back to previous
|
|
|
|
// mode
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_RestoreOldMode (original_mode);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D_InitCaches (vid_surfcache, vid_surfcachesize);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
TranslateMessage (&msg);
|
|
|
|
DispatchMessage (&msg);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sleep (100);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!force_minimized) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0,
|
2001-02-26 06:48:02 +00:00
|
|
|
SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW |
|
|
|
|
SWP_NOCOPYBITS);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
SetForegroundWindow (mainwindow);
|
|
|
|
}
|
|
|
|
// fix the leftover Alt from any Alt-Tab or the like that switched us away
|
|
|
|
ClearAllStates ();
|
|
|
|
|
|
|
|
if (!msg_suppress_1)
|
|
|
|
Con_SafePrintf ("%s\n", VID_GetModeDescription (vid_modenum));
|
|
|
|
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
|
|
|
in_mode_set = false;
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_LockBuffer (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (dibdc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lockcount++;
|
|
|
|
|
|
|
|
if (lockcount > 1)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_beginDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (memdc) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// Update surface pointer for linear access modes
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = memdc->surface;
|
|
|
|
vid.rowbytes = vid.conrowbytes = memdc->mi.bytesPerLine;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (mgldc) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// Update surface pointer for linear access modes
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = mgldc->surface;
|
|
|
|
vid.rowbytes = vid.conrowbytes = mgldc->mi.bytesPerLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_dowarp)
|
|
|
|
d_viewbuffer = r_warpbuffer;
|
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
d_viewbuffer = (void *) (byte *) vid.buffer;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (r_dowarp)
|
|
|
|
screenwidth = WARP_WIDTH;
|
|
|
|
else
|
|
|
|
screenwidth = vid.rowbytes;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_UnlockBuffer (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (dibdc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lockcount--;
|
|
|
|
|
|
|
|
if (lockcount > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (lockcount < 0)
|
|
|
|
Sys_Error ("Unbalanced unlock");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_endDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// to turn up any unlocked accesses
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = d_viewbuffer = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VID_ForceUnlockedAndReturnState (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int lk;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!lockcount)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lk = lockcount;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dibdc) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lockcount = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
lockcount = 1;
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return lk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_ForceLockState (int lk)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!dibdc && lk) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lockcount = 0;
|
|
|
|
VID_LockBuffer ();
|
|
|
|
}
|
|
|
|
|
|
|
|
lockcount = lk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_SetPalette (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
INT i;
|
|
|
|
palette_t pal[256];
|
|
|
|
HDC hdc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!Minimized) {
|
2001-02-19 21:15:25 +00:00
|
|
|
palette_changed = true;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// make sure we have the static colors if we're the active app
|
|
|
|
hdc = GetDC (NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_palettized && ActiveApp) {
|
|
|
|
if (GetSystemPaletteUse (hdc) == SYSPAL_STATIC) {
|
|
|
|
// switch to SYSPAL_NOSTATIC and remap the colors
|
|
|
|
SetSystemPaletteUse (hdc, SYSPAL_NOSTATIC);
|
2001-02-19 21:15:25 +00:00
|
|
|
syscolchg = true;
|
|
|
|
pal_is_nostatic = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Translate the palette values to an MGL palette array and
|
|
|
|
// set the values.
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
pal[i].red = palette[i * 3];
|
|
|
|
pal[i].green = palette[i * 3 + 1];
|
|
|
|
pal[i].blue = palette[i * 3 + 2];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (DDActive) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!mgldc)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setPalette (mgldc, pal, 256, 0);
|
|
|
|
MGL_realizePalette (mgldc, 256, 0, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (memdc)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setPalette (memdc, pal, 256, 0);
|
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!windc)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_setPalette (windc, pal, 256, 0);
|
|
|
|
MGL_realizePalette (windc, 256, 0, false);
|
|
|
|
if (dibdc) {
|
|
|
|
MGL_setPalette (dibdc, pal, 256, 0);
|
|
|
|
MGL_realizePalette (dibdc, 256, 0, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy (vid_curpal, palette, sizeof (vid_curpal));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (syscolchg) {
|
|
|
|
PostMessage (HWND_BROADCAST, WM_SYSCOLORCHANGE, (WPARAM) 0, (LPARAM) 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
syscolchg = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_ShiftPalette (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_DescribeCurrentMode_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_DescribeCurrentMode_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("%s\n", VID_GetExtModeDescription (vid_modenum));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_NumModes_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_NumModes_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (nummodes == 1)
|
|
|
|
Con_Printf ("%d video mode is available\n", nummodes);
|
|
|
|
else
|
|
|
|
Con_Printf ("%d video modes are available\n", nummodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_DescribeMode_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_DescribeMode_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int modenum;
|
|
|
|
|
|
|
|
modenum = Q_atoi (Cmd_Argv (1));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Con_Printf ("%s\n", VID_GetExtModeDescription (modenum));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_DescribeModes_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_DescribeModes_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, lnummodes;
|
|
|
|
char *pinfo;
|
|
|
|
qboolean na;
|
|
|
|
vmode_t *pv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
na = false;
|
|
|
|
|
|
|
|
lnummodes = VID_NumModes ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnummodes; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pv = VID_GetModePtr (i);
|
|
|
|
pinfo = VID_GetExtModeDescription (i);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (VID_CheckAdequateMem (pv->width, pv->height)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("%2d: %s\n", i, pinfo);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("**: %s\n", pinfo);
|
|
|
|
na = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (na) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("\n[**: not enough system RAM for mode]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_TestMode_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_TestMode_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int modenum;
|
|
|
|
double testduration;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!vid_testingmode) {
|
|
|
|
modenum = Q_atoi (Cmd_Argv (1));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (VID_SetMode (modenum, vid_curpal)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_testingmode = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
testduration = Q_atof (Cmd_Argv (2));
|
2001-02-19 21:15:25 +00:00
|
|
|
if (testduration == 0)
|
|
|
|
testduration = 5.0;
|
|
|
|
vid_testendtime = realtime + testduration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_Windowed_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Windowed_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
VID_SetMode (vid_windowed_mode->int_val, vid_curpal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_Fullscreen_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Fullscreen_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
VID_SetMode (vid_fullscreen_mode->int_val, vid_curpal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_Minimize_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Minimize_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// we only support minimizing windows; if you're fullscreen,
|
|
|
|
// switch to windowed first
|
|
|
|
if (modestate == MS_WINDOWED)
|
|
|
|
ShowWindow (mainwindow, SW_MINIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
VID_ForceMode_f
|
|
|
|
=================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_ForceMode_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int modenum;
|
|
|
|
double testduration;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!vid_testingmode) {
|
|
|
|
modenum = Q_atoi (Cmd_Argv (1));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
force_mode_set = 1;
|
|
|
|
VID_SetMode (modenum, vid_curpal);
|
|
|
|
force_mode_set = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Init (unsigned char *palette)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, bestmatch, bestmatchmetric, t, dr, dg, db;
|
|
|
|
int basenummodes;
|
|
|
|
byte *ptmp;
|
|
|
|
|
2001-04-10 23:39:30 +00:00
|
|
|
vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, NULL, "None");
|
|
|
|
vid_wait = Cvar_Get ("vid_wait", "0", CVAR_NONE, NULL, "None");
|
|
|
|
vid_nopageflip = Cvar_Get ("vid_nopageflip", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"None");
|
2001-02-26 06:48:02 +00:00
|
|
|
_vid_wait_override =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("_vid_wait_override", "0", CVAR_ARCHIVE, NULL, "None");
|
2001-02-26 06:48:02 +00:00
|
|
|
_vid_default_mode =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("_vid_default_mode", "0", CVAR_ARCHIVE, NULL, "None");
|
2001-02-26 06:48:02 +00:00
|
|
|
_vid_default_mode_win =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("_vid_default_mode_win", "3", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
vid_config_x = Cvar_Get ("vid_config_x", "800", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
vid_config_y = Cvar_Get ("vid_config_y", "600", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
vid_stretch_by_2 = Cvar_Get ("vid_stretch_by_2", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"None");
|
|
|
|
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
|
|
|
|
"None");
|
2001-02-26 06:48:02 +00:00
|
|
|
vid_fullscreen_mode =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("vid_fullscreen_mode", "3", CVAR_ARCHIVE, NULL, "None");
|
2001-02-26 06:48:02 +00:00
|
|
|
vid_windowed_mode =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("vid_windowed_mode", "0", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
block_switch = Cvar_Get ("block_switch", "0", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
vid_window_x = Cvar_Get ("vid_window_x", "0", CVAR_ARCHIVE, NULL, "None");
|
|
|
|
vid_window_y = Cvar_Get ("vid_window_y", "0", CVAR_ARCHIVE, NULL, "None");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_AddCommand ("vid_testmode", VID_TestMode_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
|
2001-02-26 06:48:02 +00:00
|
|
|
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f,
|
|
|
|
"No Description");
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_forcemode", VID_ForceMode_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_windowed", VID_Windowed_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_fullscreen", VID_Fullscreen_f, "No Description");
|
|
|
|
Cmd_AddCommand ("vid_minimize", VID_Minimize_f, "No Description");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (COM_CheckParm ("-dibonly"))
|
|
|
|
dibonly = true;
|
|
|
|
|
|
|
|
VID_InitMGLDIB (global_hInstance);
|
|
|
|
|
|
|
|
basenummodes = nummodes;
|
|
|
|
|
|
|
|
if (!dibonly)
|
|
|
|
VID_InitMGLFull (global_hInstance);
|
|
|
|
|
|
|
|
// if there are no non-windowed modes, or only windowed and mode 0x13, then use
|
|
|
|
// fullscreen DIBs as well
|
|
|
|
if (((nummodes == basenummodes) ||
|
|
|
|
((nummodes == (basenummodes + 1)) && is_mode0x13)) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
!COM_CheckParm ("-nofulldib")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_InitFullDIB (global_hInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap = host_colormap;
|
2001-02-26 06:48:02 +00:00
|
|
|
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_testingmode = 0;
|
|
|
|
|
|
|
|
// GDI doesn't let us remap palette index 0, so we'll remap color
|
|
|
|
// mappings from that black to another one
|
2001-02-26 06:48:02 +00:00
|
|
|
bestmatchmetric = 256 * 256 * 3;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 1; i < 256; i++) {
|
|
|
|
dr = palette[0] - palette[i * 3];
|
|
|
|
dg = palette[1] - palette[i * 3 + 1];
|
|
|
|
db = palette[2] - palette[i * 3 + 2];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
t = (dr * dr) + (dg * dg) + (db * db);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (t < bestmatchmetric) {
|
2001-02-19 21:15:25 +00:00
|
|
|
bestmatchmetric = t;
|
|
|
|
bestmatch = i;
|
|
|
|
|
|
|
|
if (t == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, ptmp = vid.colormap; i < (1 << (VID_CBITS + 8)); i++, ptmp++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (*ptmp == 0)
|
|
|
|
*ptmp = bestmatch;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-startwindowed")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
startwindowed = 1;
|
|
|
|
vid_default = windowed_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hwnd_dialog)
|
|
|
|
DestroyWindow (hwnd_dialog);
|
|
|
|
|
|
|
|
// sound initialization has to go here, preceded by a windowed mode set,
|
|
|
|
// so there's a window for DirectSound to work with but we're not yet
|
|
|
|
// fullscreen so the "hardware already in use" dialog is visible if it
|
|
|
|
// gets displayed
|
|
|
|
|
|
|
|
// keep the window minimized until we're ready for the first real mode set
|
|
|
|
hide_window = true;
|
|
|
|
VID_SetMode (MODE_WINDOWED, palette);
|
|
|
|
hide_window = false;
|
|
|
|
S_Init ();
|
|
|
|
|
|
|
|
vid_initialized = true;
|
|
|
|
|
|
|
|
force_mode_set = true;
|
|
|
|
VID_SetMode (vid_default, palette);
|
|
|
|
force_mode_set = false;
|
|
|
|
|
|
|
|
vid_realmode = vid_modenum;
|
|
|
|
|
|
|
|
VID_SetPalette (palette);
|
|
|
|
|
|
|
|
vid_menudrawfn = VID_MenuDraw;
|
|
|
|
vid_menukeyfn = VID_MenuKey;
|
|
|
|
|
|
|
|
strcpy (badmode.modedesc, "Bad mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
HDC hdc;
|
|
|
|
int dummy;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_initialized) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modestate == MS_FULLDIB)
|
|
|
|
ChangeDisplaySettings (NULL, CDS_FULLSCREEN);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
PostMessage (HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM) mainwindow,
|
|
|
|
(LPARAM) 0);
|
|
|
|
PostMessage (HWND_BROADCAST, WM_SYSCOLORCHANGE, (WPARAM) 0, (LPARAM) 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
AppActivate (false, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
DestroyDIBWindow ();
|
|
|
|
DestroyFullscreenWindow ();
|
|
|
|
DestroyFullDIBWindow ();
|
|
|
|
|
|
|
|
if (hwnd_dialog)
|
|
|
|
DestroyWindow (hwnd_dialog);
|
|
|
|
|
|
|
|
if (mainwindow)
|
2001-02-26 06:48:02 +00:00
|
|
|
DestroyWindow (mainwindow);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_exit ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
vid_testingmode = 0;
|
|
|
|
vid_initialized = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
FlipScreen
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
FlipScreen (vrect_t *rects)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
HRESULT ddrval;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Flip the surfaces
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (DDActive) {
|
|
|
|
if (mgldc) {
|
|
|
|
if (memdc) {
|
|
|
|
while (rects) {
|
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.numpages > 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// We have a flipping surface, so do a hard page flip
|
2001-02-26 06:48:02 +00:00
|
|
|
aPage = (aPage + 1) % vid.numpages;
|
|
|
|
vPage = (vPage + 1) % vid.numpages;
|
|
|
|
MGL_setActivePage (mgldc, aPage);
|
|
|
|
MGL_setVisualPage (mgldc, vPage, waitVRT);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} 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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rects = rects->pnext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (mainwindow, hdcScreen);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_Update (vrect_t *rects)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
vrect_t rect;
|
|
|
|
RECT trect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!vid_palettized && palette_changed) {
|
2001-02-19 21:15:25 +00:00
|
|
|
palette_changed = false;
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = vid.width;
|
|
|
|
rect.height = vid.height;
|
|
|
|
rect.pnext = NULL;
|
|
|
|
rects = ▭
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (firstupdate) {
|
|
|
|
if (modestate == MS_WINDOWED) {
|
2001-02-19 21:15:25 +00:00
|
|
|
GetWindowRect (mainwindow, &trect);
|
|
|
|
|
|
|
|
if ((trect.left != vid_window_x->int_val) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(trect.top != vid_window_y->int_val)) {
|
|
|
|
if (COM_CheckParm ("-resetwinpos")) {
|
|
|
|
Cvar_SetValue (vid_window_x, 0.0);
|
|
|
|
Cvar_SetValue (vid_window_y, 0.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VID_CheckWindowXY ();
|
|
|
|
SetWindowPos (mainwindow, NULL, vid_window_x->int_val,
|
2001-02-26 06:48:02 +00:00
|
|
|
vid_window_y->int_val, 0, 0,
|
|
|
|
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW |
|
|
|
|
SWP_DRAWFRAME);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((_vid_default_mode_win->int_val != vid_default) &&
|
2001-02-26 06:48:02 +00:00
|
|
|
(!startwindowed
|
|
|
|
|| (_vid_default_mode_win->int_val < MODE_FULLSCREEN_DEFAULT))) {
|
2001-02-19 21:15:25 +00:00
|
|
|
firstupdate = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-resetwinpos")) {
|
|
|
|
Cvar_SetValue (vid_window_x, 0.0);
|
|
|
|
Cvar_SetValue (vid_window_y, 0.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((_vid_default_mode_win->int_val < 0) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(_vid_default_mode_win->int_val >= nummodes)) {
|
|
|
|
Cvar_SetValue (_vid_default_mode_win, windowed_default);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (vid_mode, _vid_default_mode_win->int_val);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// We've drawn the frame; copy it to the screen
|
|
|
|
FlipScreen (rects);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_testingmode) {
|
|
|
|
if (realtime >= vid_testendtime) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_SetMode (vid_realmode, vid_curpal);
|
|
|
|
vid_testingmode = 0;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
if (vid_mode->int_val != vid_realmode) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_SetMode (vid_mode->int_val, vid_curpal);
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (vid_mode, (float) vid_modenum);
|
|
|
|
// so if mode set fails, we don't keep on
|
|
|
|
// trying to set that mode
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_realmode = vid_modenum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle the mouse state when windowed if that's changed
|
2001-02-26 06:48:02 +00:00
|
|
|
if (modestate == MS_WINDOWED) {
|
|
|
|
if (_windowed_mouse->int_val != windowed_mouse) {
|
|
|
|
if (_windowed_mouse->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
}
|
|
|
|
|
|
|
|
windowed_mouse = _windowed_mouse->int_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_BeginDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j, reps, repshift;
|
|
|
|
vrect_t rect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!vid_initialized)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.aspect > 1.5) {
|
2001-02-19 21:15:25 +00:00
|
|
|
reps = 2;
|
|
|
|
repshift = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
reps = 1;
|
|
|
|
repshift = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.numpages == 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_LockBuffer ();
|
|
|
|
|
|
|
|
if (!vid.direct)
|
|
|
|
Sys_Error ("NULL vid.direct pointer");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < (height << repshift); i += reps) {
|
|
|
|
for (j = 0; j < reps; j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
memcpy (&backingbuf[(i + j) * 24],
|
2001-02-26 06:48:02 +00:00
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height << repshift;
|
|
|
|
rect.pnext = NULL;
|
|
|
|
|
|
|
|
FlipScreen (&rect);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// unlock if locked
|
2001-02-19 21:15:25 +00:00
|
|
|
if (lockcount > 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_endDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// set the active page to the displayed page
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_setActivePage (mgldc, vPage);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// lock the screen
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_beginDirectAccess ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// save from and draw to screen
|
|
|
|
for (i = 0; i < (height << repshift); i += reps) {
|
|
|
|
for (j = 0; j < reps; j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
memcpy (&backingbuf[(i + j) * 24],
|
2001-02-26 06:48:02 +00:00
|
|
|
(byte *) mgldc->surface + x +
|
|
|
|
((y << repshift) + i + j) * mgldc->mi.bytesPerLine,
|
2001-02-19 21:15:25 +00:00
|
|
|
width);
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy ((byte *) mgldc->surface + x +
|
|
|
|
((y << repshift) + i + j) * mgldc->mi.bytesPerLine,
|
|
|
|
&pbitmap[(i >> repshift) * width], width);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// unlock the screen
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_endDirectAccess ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// restore the original active page
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_setActivePage (mgldc, aPage);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// relock the screen if it was locked
|
2001-02-19 21:15:25 +00:00
|
|
|
if (lockcount > 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_beginDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
D_EndDirectRect
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j, reps, repshift;
|
|
|
|
vrect_t rect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!vid_initialized)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.aspect > 1.5) {
|
2001-02-19 21:15:25 +00:00
|
|
|
reps = 2;
|
|
|
|
repshift = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
reps = 1;
|
|
|
|
repshift = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid.numpages == 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_LockBuffer ();
|
|
|
|
|
|
|
|
if (!vid.direct)
|
|
|
|
Sys_Error ("NULL vid.direct pointer");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height << repshift;
|
|
|
|
rect.pnext = NULL;
|
|
|
|
|
|
|
|
FlipScreen (&rect);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// unlock if locked
|
2001-02-19 21:15:25 +00:00
|
|
|
if (lockcount > 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_endDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// set the active page to the displayed page
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_setActivePage (mgldc, vPage);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// lock the screen
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_beginDirectAccess ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// 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);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// unlock the screen
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_endDirectAccess ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// restore the original active page
|
2001-02-19 21:15:25 +00:00
|
|
|
MGL_setActivePage (mgldc, aPage);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// relock the screen if it was locked
|
2001-02-19 21:15:25 +00:00
|
|
|
if (lockcount > 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_beginDirectAccess ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte scantokey[128] = {
|
2001-02-19 21:15:25 +00:00
|
|
|
// 0 1 2 3 4 5 6 7
|
|
|
|
// 8 9 A B C D E F
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
=======
|
|
|
|
MapKey
|
|
|
|
|
|
|
|
Map from windows to quake keynums
|
|
|
|
=======
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
MapKey (int key)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
key = (key >> 16) & 255;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (key > 127)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return scantokey[key];
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
AppActivate (BOOL fActive, BOOL minimize)
|
2001-02-19 21:15:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
HDC hdc;
|
|
|
|
int i, t;
|
|
|
|
static BOOL sound_active;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
ActiveApp = fActive;
|
|
|
|
|
|
|
|
// messy, but it seems to work
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_fulldib_on_focus_mode) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Minimized = minimize;
|
|
|
|
|
|
|
|
if (Minimized)
|
|
|
|
ActiveApp = false;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
MGL_appActivate (windc, ActiveApp);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
syscolchg = true;
|
|
|
|
pal_is_nostatic = true;
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (pal_is_nostatic) {
|
|
|
|
if (GetSystemPaletteUse (hdc) == SYSPAL_NOSTATIC) {
|
|
|
|
// switch back to SYSPAL_STATIC and the old mapping
|
|
|
|
SetSystemPaletteUse (hdc, SYSPAL_STATIC);
|
2001-02-19 21:15:25 +00:00
|
|
|
syscolchg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pal_is_nostatic = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Minimized)
|
|
|
|
VID_SetPalette (vid_curpal);
|
|
|
|
|
|
|
|
scr_fullupdate = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// enable/disable sound on focus gain/loss
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!ActiveApp && sound_active) {
|
2001-02-19 21:15:25 +00:00
|
|
|
S_BlockSound ();
|
|
|
|
S_ClearBuffer ();
|
|
|
|
sound_active = false;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (ActiveApp && !sound_active) {
|
2001-02-19 21:15:25 +00:00
|
|
|
S_UnblockSound ();
|
|
|
|
S_ClearBuffer ();
|
|
|
|
sound_active = true;
|
|
|
|
}
|
|
|
|
// minimize/restore fulldib windows/mouse-capture normal windows on demand
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
2001-02-19 21:15:25 +00:00
|
|
|
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 ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!ActiveApp) {
|
|
|
|
if (modestate == MS_FULLDIB) {
|
|
|
|
if (vid_initialized) {
|
2001-02-19 21:15:25 +00:00
|
|
|
force_minimized = true;
|
|
|
|
i = vid_fulldib_on_focus_mode;
|
2001-02-26 06:48:02 +00:00
|
|
|
msg_suppress_1 = true; // don't want to see normal mode
|
|
|
|
// set message
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_SetMode (windowed_default, vid_curpal);
|
|
|
|
msg_suppress_1 = false;
|
|
|
|
vid_fulldib_on_focus_mode = i;
|
|
|
|
force_minimized = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// we never seem to get WM_ACTIVATE inactive from this
|
|
|
|
// mode set, so we'll
|
|
|
|
// do it manually
|
2001-02-19 21:15:25 +00:00
|
|
|
t = in_mode_set;
|
|
|
|
in_mode_set = true;
|
|
|
|
AppActivate (false, true);
|
|
|
|
in_mode_set = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_HandlePause
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_HandlePause (qboolean pause)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) {
|
|
|
|
if (pause) {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_DeactivateMouse ();
|
|
|
|
IN_ShowMouse ();
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
IN_ActivateMouse ();
|
|
|
|
IN_HideMouse ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================================================================
|
|
|
|
|
|
|
|
MAIN WINDOW
|
|
|
|
|
|
|
|
===================================================================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam,
|
|
|
|
|
|
|
|
LPARAM lParam);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/* main window procedure */
|
2001-02-26 06:48:02 +00:00
|
|
|
LONG WINAPI
|
|
|
|
MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
LONG lRet = 0;
|
|
|
|
int fwKeys, xPos, yPos, fActive, fMinimized, temp;
|
|
|
|
HDC hdc;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
static int recursiveflag;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
2001-02-19 21:15:25 +00:00
|
|
|
case WM_CREATE:
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
|
|
|
|
// Check for maximize being hit
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (wParam & ~0x0F) {
|
|
|
|
case SC_MAXIMIZE:
|
|
|
|
// if minimized, bring up as a window before going fullscreen,
|
|
|
|
// so MGL will have the right state to restore
|
|
|
|
if (Minimized) {
|
|
|
|
force_mode_set = true;
|
|
|
|
VID_SetMode (vid_modenum, vid_curpal);
|
|
|
|
force_mode_set = false;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetMode (vid_fullscreen_mode->int_val, vid_curpal);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
if (modestate != MS_WINDOWED) {
|
|
|
|
// don't call DefWindowProc() because we don't want to start
|
|
|
|
// the screen saver fullscreen
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through windowed and allow the screen saver to start
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
default:
|
|
|
|
if (!in_mode_set) {
|
|
|
|
S_BlockSound ();
|
|
|
|
S_ClearBuffer ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set) {
|
|
|
|
S_UnblockSound ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_MOVE:
|
2001-02-26 06:48:02 +00:00
|
|
|
window_x = (int) LOWORD (lParam);
|
|
|
|
window_y = (int) HIWORD (lParam);
|
|
|
|
VID_UpdateWindowStatus ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((modestate == MS_WINDOWED) && !in_mode_set && !Minimized)
|
|
|
|
VID_RememberWindowPos ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_SIZE:
|
2001-02-26 06:48:02 +00:00
|
|
|
Minimized = false;
|
|
|
|
|
|
|
|
if (!(wParam & SIZE_RESTORED)) {
|
|
|
|
if (wParam & SIZE_MINIMIZED)
|
|
|
|
Minimized = true;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_SYSCHAR:
|
|
|
|
// keep Alt-Space from happening
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_ACTIVATE:
|
2001-02-26 06:48:02 +00:00
|
|
|
fActive = LOWORD (wParam);
|
|
|
|
fMinimized = (BOOL) HIWORD (wParam);
|
|
|
|
AppActivate (!(fActive == WA_INACTIVE), fMinimized);
|
|
|
|
|
|
|
|
// fix the leftover Alt from any Alt-Tab or the like that switched us
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// away
|
|
|
|
ClearAllStates ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set) {
|
|
|
|
if (windc)
|
|
|
|
MGL_activatePalette (windc, true);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_SetPalette (vid_curpal);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_PAINT:
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = BeginPaint (hWnd, &ps);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set && host_initialized)
|
|
|
|
SCR_UpdateWholeScreen ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
EndPaint (hWnd, &ps);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set)
|
|
|
|
Key_Event (MapKey (lParam), true);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set)
|
|
|
|
Key_Event (MapKey (lParam), false);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// this is complicated because Win32 seems to pack multiple mouse
|
|
|
|
// events into
|
|
|
|
// one update sometimes, so we always check all states and look for
|
|
|
|
// events
|
2001-02-19 21:15:25 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
case WM_MOUSEMOVE:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set) {
|
|
|
|
temp = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (wParam & MK_LBUTTON)
|
|
|
|
temp |= 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (wParam & MK_RBUTTON)
|
|
|
|
temp |= 2;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (wParam & MK_MBUTTON)
|
|
|
|
temp |= 4;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
IN_MouseEvent (temp);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// JACK: This is the mouse wheel with the Intellimouse
|
|
|
|
// Its delta is either positive or neg, and we generate the proper
|
|
|
|
// Event.
|
2001-02-26 06:48:02 +00:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
if ((short) HIWORD (wParam) > 0) {
|
|
|
|
Key_Event (K_MWHEELUP, true);
|
|
|
|
Key_Event (K_MWHEELUP, false);
|
|
|
|
} else {
|
|
|
|
Key_Event (K_MWHEELDOWN, true);
|
|
|
|
Key_Event (K_MWHEELDOWN, false);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
// KJB: Added these new palette functions
|
|
|
|
case WM_PALETTECHANGED:
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((HWND) wParam == hWnd)
|
|
|
|
break;
|
|
|
|
/* Fall through to WM_QUERYNEWPALETTE */
|
2001-02-19 21:15:25 +00:00
|
|
|
case WM_QUERYNEWPALETTE:
|
2001-02-26 06:48:02 +00:00
|
|
|
hdc = GetDC (NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE)
|
|
|
|
vid_palettized = true;
|
|
|
|
else
|
|
|
|
vid_palettized = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ReleaseDC (NULL, hdc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
scr_fullupdate = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_initialized && !in_mode_set && windc
|
|
|
|
&& MGL_activatePalette (windc, false) && !Minimized) {
|
|
|
|
VID_SetPalette (vid_curpal);
|
|
|
|
InvalidateRect (mainwindow, NULL, false);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// specifically required if WM_QUERYNEWPALETTE realizes a new
|
|
|
|
// palette
|
|
|
|
lRet = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set && (modestate == MS_WINDOWED)
|
|
|
|
&& !vid_fulldib_on_focus_mode) {
|
|
|
|
force_mode_set = true;
|
|
|
|
VID_SetMode (vid_modenum, vid_curpal);
|
|
|
|
force_mode_set = false;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
// this causes Close in the right-click task bar menu not to work,
|
|
|
|
// but right
|
|
|
|
// now bad things happen if Close is handled in that case (garbage
|
|
|
|
// and a
|
2001-02-19 21:15:25 +00:00
|
|
|
// crash on Win95)
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_mode_set) {
|
|
|
|
if (MessageBox
|
|
|
|
(mainwindow, "Are you sure you want to quit?", "Confirm Exit",
|
|
|
|
MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES) {
|
|
|
|
Sys_Quit ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case MM_MCINOTIFY:
|
2001-02-26 06:48:02 +00:00
|
|
|
lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
/* pass all unhandled messages to DefWindowProc */
|
|
|
|
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
/* return 0 if handled message, 1 if not */
|
|
|
|
return lRet;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void M_Menu_Options_f (void);
|
|
|
|
extern void M_Print (int cx, int cy, char *str);
|
|
|
|
extern void M_PrintWhite (int cx, int cy, char *str);
|
|
|
|
extern void M_DrawCharacter (int cx, int line, int num);
|
|
|
|
extern void M_DrawTransPic (int x, int y, qpic_t *pic);
|
|
|
|
extern void M_DrawPic (int x, int y, qpic_t *pic);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int vid_line, vid_wmodes;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef struct {
|
|
|
|
int modenum;
|
|
|
|
char *desc;
|
|
|
|
int iscur;
|
|
|
|
int ismode13;
|
|
|
|
int width;
|
2001-02-19 21:15:25 +00:00
|
|
|
} modedesc_t;
|
|
|
|
|
|
|
|
#define MAX_COLUMN_SIZE 5
|
|
|
|
#define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 6)
|
|
|
|
#define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static modedesc_t modedescs[MAX_MODEDESCS];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_MenuDraw
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_MenuDraw (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
qpic_t *p;
|
|
|
|
char *ptr;
|
|
|
|
int lnummodes, i, j, k, column, row, dup, dupmode;
|
|
|
|
char temp[100];
|
|
|
|
vmode_t *pv;
|
|
|
|
modedesc_t tmodedesc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
p = Draw_CachePic ("gfx/vidmodes.lmp");
|
2001-02-26 06:48:02 +00:00
|
|
|
M_DrawPic ((320 - p->width) / 2, 4, p);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ptr = VID_GetModeDescriptionMemCheck (i);
|
|
|
|
modedescs[i].modenum = modelist[i].modenum;
|
|
|
|
modedescs[i].desc = ptr;
|
|
|
|
modedescs[i].ismode13 = 0;
|
|
|
|
modedescs[i].iscur = 0;
|
|
|
|
|
|
|
|
if (vid_modenum == i)
|
|
|
|
modedescs[i].iscur = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vid_wmodes = 3;
|
|
|
|
lnummodes = VID_NumModes ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 3; i < lnummodes; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ptr = VID_GetModeDescriptionMemCheck (i);
|
|
|
|
pv = VID_GetModePtr (i);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// we only have room for 15 fullscreen modes, so don't allow
|
|
|
|
// 360-wide modes, because if there are 5 320-wide modes and
|
|
|
|
// 5 360-wide modes, we'll run out of space
|
|
|
|
if (ptr && ((pv->width != 360) || COM_CheckParm ("-allow360"))) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dup = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 3; j < vid_wmodes; j++) {
|
|
|
|
if (!strcmp (modedescs[j].desc, ptr)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dup = 1;
|
|
|
|
dupmode = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dup || (vid_wmodes < MAX_MODEDESCS)) {
|
|
|
|
if (!dup || !modedescs[dupmode].ismode13
|
|
|
|
|| COM_CheckParm ("-noforcevga")) {
|
|
|
|
if (dup) {
|
2001-02-19 21:15:25 +00:00
|
|
|
k = dupmode;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
k = vid_wmodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
modedescs[k].modenum = i;
|
|
|
|
modedescs[k].desc = ptr;
|
|
|
|
modedescs[k].ismode13 = pv->mode13;
|
|
|
|
modedescs[k].iscur = 0;
|
|
|
|
modedescs[k].width = pv->width;
|
|
|
|
|
|
|
|
if (i == vid_modenum)
|
|
|
|
modedescs[k].iscur = 1;
|
|
|
|
|
|
|
|
if (!dup)
|
|
|
|
vid_wmodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort the modes on width (to handle picking up oddball dibonly modes
|
|
|
|
// after all the others)
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 3; i < (vid_wmodes - 1); i++) {
|
|
|
|
for (j = (i + 1); j < vid_wmodes; j++) {
|
|
|
|
if (modedescs[i].width > modedescs[j].width) {
|
2001-02-19 21:15:25 +00:00
|
|
|
tmodedesc = modedescs[i];
|
|
|
|
modedescs[i] = modedescs[j];
|
|
|
|
modedescs[j] = tmodedesc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
M_Print (13 * 8, 36, "Windowed Modes");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
column = 16;
|
2001-02-26 06:48:02 +00:00
|
|
|
row = 36 + 2 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modedescs[i].iscur)
|
|
|
|
M_PrintWhite (column, row, modedescs[i].desc);
|
|
|
|
else
|
|
|
|
M_Print (column, row, modedescs[i].desc);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
column += 13 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_wmodes > 3) {
|
|
|
|
M_Print (12 * 8, 36 + 4 * 8, "Fullscreen Modes");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
column = 16;
|
2001-02-26 06:48:02 +00:00
|
|
|
row = 36 + 6 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 3; i < vid_wmodes; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (modedescs[i].iscur)
|
|
|
|
M_PrintWhite (column, row, modedescs[i].desc);
|
|
|
|
else
|
|
|
|
M_Print (column, row, modedescs[i].desc);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
column += 13 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (((i - 3) % VID_ROW_SIZE) == (VID_ROW_SIZE - 1)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
column = 16;
|
|
|
|
row += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// line cursor
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_testingmode) {
|
|
|
|
snprintf (temp, sizeof (temp), "TESTING %s", modedescs[vid_line].desc);
|
|
|
|
M_Print (13 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 4, temp);
|
|
|
|
M_Print (9 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 6,
|
|
|
|
"Please wait 5 seconds...");
|
|
|
|
} else {
|
|
|
|
M_Print (9 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8,
|
|
|
|
"Press Enter to set mode");
|
|
|
|
M_Print (6 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 3,
|
|
|
|
"T to test mode for 5 seconds");
|
2001-02-19 21:15:25 +00:00
|
|
|
ptr = VID_GetModeDescription2 (vid_modenum);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ptr) {
|
|
|
|
snprintf (temp, sizeof (temp), "D to set default: %s", ptr);
|
|
|
|
M_Print (2 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 5, temp);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = VID_GetModeDescription2 (_vid_default_mode_win->int_val);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ptr) {
|
|
|
|
snprintf (temp, sizeof (temp), "Current default: %s", ptr);
|
|
|
|
M_Print (3 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 6, temp);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
M_Print (15 * 8, 36 + MODE_AREA_HEIGHT * 8 + 8 * 8, "Esc to exit");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
row = 36 + 2 * 8 + (vid_line / VID_ROW_SIZE) * 8;
|
|
|
|
column = 8 + (vid_line % VID_ROW_SIZE) * 13 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (vid_line >= 3)
|
2001-02-26 06:48:02 +00:00
|
|
|
row += 3 * 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
M_DrawCharacter (column, row, 12 + ((int) (realtime * 4) & 1));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_MenuKey
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VID_MenuKey (int key)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (vid_testingmode)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (key) {
|
|
|
|
case K_ESCAPE:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
M_Menu_Options_f ();
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case K_LEFTARROW:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
vid_line = ((vid_line / VID_ROW_SIZE) * VID_ROW_SIZE) +
|
2001-02-26 06:48:02 +00:00
|
|
|
((vid_line + 2) % VID_ROW_SIZE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (vid_line >= vid_wmodes)
|
|
|
|
vid_line = vid_wmodes - 1;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case K_RIGHTARROW:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
vid_line = ((vid_line / VID_ROW_SIZE) * VID_ROW_SIZE) +
|
2001-02-26 06:48:02 +00:00
|
|
|
((vid_line + 4) % VID_ROW_SIZE);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (vid_line >= vid_wmodes)
|
|
|
|
vid_line = (vid_line / VID_ROW_SIZE) * VID_ROW_SIZE;
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case K_UPARROW:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
vid_line -= VID_ROW_SIZE;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_line < 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_line += ((vid_wmodes + (VID_ROW_SIZE - 1)) /
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_ROW_SIZE) * VID_ROW_SIZE;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
while (vid_line >= vid_wmodes)
|
|
|
|
vid_line -= VID_ROW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case K_DOWNARROW:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
vid_line += VID_ROW_SIZE;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vid_line >= vid_wmodes) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_line -= ((vid_wmodes + (VID_ROW_SIZE - 1)) /
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_ROW_SIZE) * VID_ROW_SIZE;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
while (vid_line < 0)
|
|
|
|
vid_line += VID_ROW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case K_ENTER:
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
VID_SetMode (modedescs[vid_line].modenum, vid_curpal);
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case 'T':
|
|
|
|
case 't':
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
2001-02-26 06:48:02 +00:00
|
|
|
// have to set this before setting the mode because WM_PAINT
|
|
|
|
// happens during the mode set and does a VID_Update, which
|
|
|
|
// checks vid_testingmode
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_testingmode = 1;
|
|
|
|
vid_testendtime = realtime + 5.0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!VID_SetMode (modedescs[vid_line].modenum, vid_curpal)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vid_testingmode = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case 'D':
|
|
|
|
case 'd':
|
2001-02-19 21:15:25 +00:00
|
|
|
S_LocalSound ("misc/menu1.wav");
|
|
|
|
firstupdate = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (_vid_default_mode_win, vid_modenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
default:
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|