Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-// gl_vidnt.c -- NT GL vid component
+// vid_wgl.c -- NT GL vid component
-// we don't need a very new dinput
-#define DIRECTINPUT_VERSION 0x0300
+#ifdef SUPPORTDIRECTX
+// Include DX libs
+#pragma comment(lib, "dinput8.lib")
+#pragma comment(lib, "dxguid.lib")
+#ifndef DIRECTINPUT_VERSION
+# define DIRECTINPUT_VERSION 0x0500 /* Version 5.0 */
+#endif
+#endif
#include "quakedef.h"
#include <windows.h>
static qboolean vid_initialized = false;
static qboolean vid_wassuspended = false;
static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
static qboolean vid_usingvsync = false;
static qboolean vid_usevsync = false;
static HICON hIcon;
static int window_x, window_y;
-static void IN_Activate (qboolean grab);
-
static qboolean mouseinitialized;
#ifdef SUPPORTDIRECTX
//====================================
-void VID_Finish (qboolean allowmousegrab)
+void VID_Finish (void)
{
- qboolean vid_usemouse;
-
vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
{
qwglSwapIntervalEXT (vid_usevsync);
}
-// handle the mouse state when windowed if that's changed
- vid_usemouse = false;
- if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))
- vid_usemouse = true;
- if (vid_isfullscreen)
- vid_usemouse = true;
- if (!vid_activewindow)
- vid_usemouse = false;
- IN_Activate(vid_usemouse);
-
if (r_render.integer && !vid_hidden)
{
CHECKGLERROR
- if (r_speeds.integer || gl_finish.integer)
+ if (r_speeds.integer == 2 || gl_finish.integer)
{
qglFinish();CHECKGLERROR
}
{
static qboolean sound_active = false; // initially blocked by Sys_InitConsole()
- vid_activewindow = fActive;
- vid_hidden = minimize;
+ vid_activewindow = fActive != FALSE;
+ vid_hidden = minimize != FALSE;
// enable/disable sound on focus gain/loss
- if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
+ if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
{
if (!sound_active)
{
if (!fActive)
{
- IN_Activate (false);
+ VID_SetMouse(false, false, false);
if (vid_isfullscreen)
{
ChangeDisplaySettings (NULL, 0);
{
LONG lRet = 1;
int fActive, fMinimized, temp;
- char state[256];
- char asciichar[4];
+ unsigned char state[256];
+ unsigned char asciichar[4];
int vkey;
int charlength;
qboolean down = false;
case WM_MOVE:
window_x = (int) LOWORD(lParam);
window_y = (int) HIWORD(lParam);
- IN_Activate(false);
+ VID_SetMouse(false, false, false);
break;
case WM_KEYDOWN:
temp |= 512;
#ifdef SUPPORTDIRECTX
- if (vid_usingmouse && !dinput_acquired)
-#else
- if (vid_usingmouse)
+ if (!dinput_acquired)
#endif
{
// perform button actions
IN_Init();
}
-int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
+int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
{
int i;
HDC hdc;
};
int windowpass;
int pixelformat, newpixelformat;
- int numpixelformats;
+ UINT numpixelformats;
DWORD WindowStyle, ExWindowStyle;
int CenterX, CenterY;
const char *gldrivername;
foundmode = true;
gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
gdevmode.dmBitsPerPel = bpp;
- gdevmode.dmPelsWidth = width;
- gdevmode.dmPelsHeight = height;
+ gdevmode.dmPelsWidth = *width;
+ gdevmode.dmPelsHeight = *height;
gdevmode.dmSize = sizeof (gdevmode);
if(refreshrate)
{
Con_Printf("wrong bpp\n");
continue;
}
- if(thismode.dmPelsWidth != (DWORD)width)
+ if(thismode.dmPelsWidth != (DWORD)*width)
{
if(developer.integer >= 100)
Con_Printf("wrong width\n");
continue;
}
- if(thismode.dmPelsHeight != (DWORD)height)
+ if(thismode.dmPelsHeight != (DWORD)*height)
{
if(developer.integer >= 100)
Con_Printf("wrong height\n");
if (!foundmode)
{
VID_Shutdown();
- Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
+ Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", *width, *height, bpp);
return false;
}
else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
VID_Shutdown();
- Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
+ Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", *width, *height, bpp);
return false;
}
rect.top = 0;
rect.left = 0;
- rect.right = width;
- rect.bottom = height;
+ rect.right = *width;
+ rect.bottom = *height;
AdjustWindowRectEx(&rect, WindowStyle, false, 0);
if (fullscreen)
if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL)
Con_Print("wglGetExtensionsStringARB not found\n");
- gl_renderer = (const char *)qglGetString(GL_RENDERER);
- gl_vendor = (const char *)qglGetString(GL_VENDOR);
- gl_version = (const char *)qglGetString(GL_VERSION);
gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
gl_platform = "WGL";
gl_platformextensions = "";
}
}
- Con_DPrintf("GL_VENDOR: %s\n", gl_vendor);
- Con_DPrintf("GL_RENDERER: %s\n", gl_renderer);
- Con_DPrintf("GL_VERSION: %s\n", gl_version);
- Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
- Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
-
/*
if (!fullscreen)
SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
//vid_menudrawfn = VID_MenuDraw;
//vid_menukeyfn = VID_MenuKey;
vid_usingmouse = false;
+ vid_usinghidecursor = false;
vid_usingvsync = false;
vid_hidden = false;
vid_initialized = true;
if (gl_videosyncavailable)
{
- vid_usevsync = vid_vsync.integer;
- vid_usingvsync = vid_vsync.integer;
+ vid_usevsync = vid_vsync.integer != 0;
+ vid_usingvsync = vid_vsync.integer != 0;
qwglSwapIntervalEXT (vid_usevsync);
}
if(vid_initialized == false)
return;
+ VID_SetMouse(false, false, false);
VID_RestoreSystemGamma();
vid_initialized = false;
vid_isfullscreen = false;
}
-static void IN_Activate (qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
{
static qboolean restore_spi;
static int originalmouseparms[3];
if (!mouseinitialized)
return;
- if (grab)
+ if (relative)
{
if (!vid_usingmouse)
{
newmouseparms[0] = 0; // threshold to double movement (only if accel level is >= 1)
newmouseparms[1] = 0; // threshold to quadruple movement (only if accel level is >= 2)
newmouseparms[2] = 0; // maximum level of acceleration (0 = off)
- restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
+ restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0) != FALSE;
}
else
restore_spi = false;
SetCapture (mainwindow);
ClipCursor (&window_rect);
}
- ShowCursor (false);
}
}
else
ClipCursor (NULL);
ReleaseCapture ();
}
- ShowCursor (true);
}
}
+
+ if (vid_usinghidecursor != hidecursor)
+ {
+ vid_usinghidecursor = hidecursor;
+ ShowCursor (!hidecursor);
+ }
}
if (!pDirectInputCreate)
{
- pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
+ pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD,LPDIRECTINPUT *,LPUNKNOWN))GetProcAddress(hInstDI,"DirectInputCreateA");
if (!pDirectInputCreate)
{
}
// obtain an interface to the system mouse device.
+#ifdef __cplusplus
+ hr = IDirectInput_CreateDevice(g_pdi, GUID_SysMouse, &g_pMouse, NULL);
+#else
hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
+#endif
if (FAILED(hr))
{
*/
static void IN_MouseMove (void)
{
- int mx, my;
POINT current_pos;
+ GetCursorPos (¤t_pos);
+ in_windowmouse_x = current_pos.x - window_x;
+ in_windowmouse_y = current_pos.y - window_y;
+
if (!vid_usingmouse)
- {
- //GetCursorPos (¤t_pos);
- //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
return;
- }
#ifdef SUPPORTDIRECTX
if (dinput_acquired)
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
- mx = 0;
- my = 0;
for (;;)
{
switch (od.dwOfs)
{
case DIMOFS_X:
- mx += (LONG) od.dwData;
+ in_mouse_x += (LONG) od.dwData;
break;
case DIMOFS_Y:
- my += (LONG) od.dwData;
+ in_mouse_y += (LONG) od.dwData;
break;
case DIMOFS_Z:
if ((mstate_di ^ mouse_oldbuttonstate) & (1<<i))
Key_Event (buttonremap[i], 0, (mstate_di & (1<<i)) != 0);
mouse_oldbuttonstate = mstate_di;
-
- in_mouse_x = mx;
- in_mouse_y = my;
}
else
#endif
{
- GetCursorPos (¤t_pos);
- mx = current_pos.x - (window_x + vid.width / 2);
- my = current_pos.y - (window_y + vid.height / 2);
-
- in_mouse_x = mx;
- in_mouse_y = my;
+ in_mouse_x += in_windowmouse_x - (int)(vid.width / 2);
+ in_mouse_y += in_windowmouse_y - (int)(vid.height / 2);
// if the mouse has moved, force it to the center, so there's room to move
- if (!cl.csqc_wantsmousemove)
- if (mx || my)
+ if (in_mouse_x || in_mouse_y)
SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2));
}
}
// save the joystick's number of buttons and POV status
joy_numbuttons = jc.wNumButtons;
- joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
+ joy_haspov = (jc.wCaps & JOYCAPS_HASPOV) != 0;
// old button and POV states default to no buttons pressed
joy_oldbuttonstate = joy_oldpovstate = 0;
static void IN_Shutdown(void)
{
- IN_Activate (false);
-
#ifdef SUPPORTDIRECTX
if (g_pMouse)
IDirectInputDevice_Release(g_pMouse);
g_pdi = NULL;
#endif
}
+
+size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
+{
+ int i;
+ size_t k;
+ DEVMODE thismode;
+
+ thismode.dmSize = sizeof(thismode);
+ thismode.dmDriverExtra = 0;
+ k = 0;
+ for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
+ {
+ if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
+ {
+ Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
+ continue;
+ }
+ if(k >= maxcount)
+ break;
+ modes[k].width = thismode.dmPelsWidth;
+ modes[k].height = thismode.dmPelsHeight;
+ modes[k].bpp = thismode.dmBitsPerPel;
+ modes[k].refreshrate = thismode.dmDisplayFrequency;
+ modes[k].pixelheight_num = 1;
+ modes[k].pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME)
+ ++k;
+ }
+ return k;
+}