X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=4405533d6312422beed076fcccde81668b7a7d6e;hb=c4d44b47444f564991cc836ea072e15b77314f93;hp=7b39e2289da548a44ebbf93e3f66c001f985c31d;hpb=058a0200acb4cc6e3f161da224f24a65f77f6675;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index 7b39e228..4405533d 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -17,10 +17,16 @@ along with this program; if not, write to the Free Software 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 @@ -95,6 +101,7 @@ static DEVMODE gdevmode, initialdevmode; 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; @@ -250,10 +257,10 @@ void VID_Finish (void) qwglSwapIntervalEXT (vid_usevsync); } - if (r_render.integer && !vid_hidden) + if (!vid_hidden) { CHECKGLERROR - if (r_speeds.integer || gl_finish.integer) + if (r_speeds.integer == 2 || gl_finish.integer) { qglFinish();CHECKGLERROR } @@ -388,11 +395,11 @@ void AppActivate(BOOL fActive, BOOL minimize) { 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) { @@ -427,7 +434,7 @@ void AppActivate(BOOL fActive, BOOL minimize) if (!fActive) { - VID_GrabMouse(false); + VID_SetMouse(false, false, false); if (vid_isfullscreen) { ChangeDisplaySettings (NULL, 0); @@ -479,8 +486,8 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 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; @@ -501,7 +508,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOVE: window_x = (int) LOWORD(lParam); window_y = (int) HIWORD(lParam); - VID_GrabMouse(false); + VID_SetMouse(false, false, false); break; case WM_KEYDOWN: @@ -578,9 +585,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) temp |= 512; #ifdef SUPPORTDIRECTX - if (vid_usingmouse && !dinput_acquired) -#else - if (vid_usingmouse) + if (!dinput_acquired) #endif { // perform button actions @@ -782,7 +787,7 @@ void VID_Init(void) 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; @@ -811,7 +816,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat }; int windowpass; int pixelformat, newpixelformat; - int numpixelformats; + UINT numpixelformats; DWORD WindowStyle, ExWindowStyle; int CenterX, CenterY; const char *gldrivername; @@ -923,8 +928,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat 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) { @@ -957,13 +962,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat 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"); @@ -1015,13 +1020,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat 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; } @@ -1054,8 +1059,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat 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) @@ -1220,6 +1225,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat //vid_menudrawfn = VID_MenuDraw; //vid_menukeyfn = VID_MenuKey; vid_usingmouse = false; + vid_usinghidecursor = false; vid_usingvsync = false; vid_hidden = false; vid_initialized = true; @@ -1229,8 +1235,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat 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); } @@ -1243,7 +1249,7 @@ void VID_Shutdown (void) if(vid_initialized == false) return; - VID_GrabMouse(false); + VID_SetMouse(false, false, false); VID_RestoreSystemGamma(); vid_initialized = false; @@ -1265,7 +1271,7 @@ void VID_Shutdown (void) vid_isfullscreen = false; } -void VID_GrabMouse(qboolean grab) +void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor) { static qboolean restore_spi; static int originalmouseparms[3]; @@ -1273,7 +1279,7 @@ void VID_GrabMouse(qboolean grab) if (!mouseinitialized) return; - if (grab) + if (relative) { if (!vid_usingmouse) { @@ -1302,7 +1308,7 @@ void VID_GrabMouse(qboolean grab) 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; @@ -1311,7 +1317,6 @@ void VID_GrabMouse(qboolean grab) SetCapture (mainwindow); ClipCursor (&window_rect); } - ShowCursor (false); } } else @@ -1336,9 +1341,14 @@ void VID_GrabMouse(qboolean grab) ClipCursor (NULL); ReleaseCapture (); } - ShowCursor (true); } } + + if (vid_usinghidecursor != hidecursor) + { + vid_usinghidecursor = hidecursor; + ShowCursor (!hidecursor); + } } @@ -1374,7 +1384,7 @@ static qboolean IN_InitDInput (void) if (!pDirectInputCreate) { - pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA"); + pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD,LPDIRECTINPUT *,LPUNKNOWN))GetProcAddress(hInstDI,"DirectInputCreateA"); if (!pDirectInputCreate) { @@ -1392,7 +1402,11 @@ static qboolean IN_InitDInput (void) } // 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)) { @@ -1475,7 +1489,7 @@ static void IN_MouseMove (void) in_windowmouse_x = current_pos.x - window_x; in_windowmouse_y = current_pos.y - window_y; - if (!vid.mouseaim) + if (!vid_usingmouse) return; #ifdef SUPPORTDIRECTX @@ -1648,7 +1662,7 @@ static void IN_StartupJoystick (void) // 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; @@ -2064,3 +2078,32 @@ static void IN_Shutdown(void) 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; +}