]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_wgl.c
made darkplaces compile successfully with g++ to test for errors C doesn't care about...
[xonotic/darkplaces.git] / vid_wgl.c
index 7c415bba527f96d23011ae8bea2eeb48032902ca..afb773f5d97c8df395ce5e11e4be285cf74d29d8 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -19,6 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 // gl_vidnt.c -- NT GL vid component
 
+// we don't need a very new dinput
+#define DIRECTINPUT_VERSION 0x0300
+
 #include "quakedef.h"
 #include <windows.h>
 #include <dsound.h>
@@ -78,7 +81,6 @@ static qboolean vid_initialized = false;
 static qboolean vid_wassuspended = false;
 static qboolean vid_usingmouse = false;
 static qboolean vid_usingvsync = false;
-static qboolean vid_usemouse = false;
 static qboolean vid_usevsync = false;
 static HICON hIcon;
 
@@ -102,8 +104,7 @@ static qboolean vid_isfullscreen;
 
 //====================================
 
-static int window_x, window_y, window_width, window_height;
-static int window_center_x, window_center_y;
+static int window_x, window_y;
 
 static void IN_Activate (qboolean grab);
 
@@ -147,7 +148,7 @@ static qboolean     restore_spi;
 static int             originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
 
 static unsigned int uiWheelMessage;
-static qboolean        mouseparmsvalid, mouseactivatetoggle;
+static qboolean        mouseparmsvalid;
 static qboolean        dinput_acquired;
 
 static unsigned int            mstate_di;
@@ -256,46 +257,13 @@ static void Joy_AdvancedUpdate_f (void);
 static void IN_JoyMove (void);
 static void IN_StartupMouse (void);
 
-/*
-================
-VID_UpdateWindowStatus
-================
-*/
-static void VID_UpdateWindowStatus (void)
-{
-       window_center_x = window_x + window_width / 2;
-       window_center_y = window_y + window_height / 2;
-
-       if (mouseinitialized && vid_usingmouse && !dinput_acquired)
-       {
-               RECT window_rect;
-               window_rect.left = window_x;
-               window_rect.top = window_y;
-               window_rect.right = window_x + window_width;
-               window_rect.bottom = window_y + window_height;
-               ClipCursor (&window_rect);
-       }
-}
-
 
 //====================================
 
-/*
-=================
-VID_GetWindowSize
-=================
-*/
-void VID_GetWindowSize (int *x, int *y, int *width, int *height)
-{
-       *x = 0;
-       *y = 0;
-       *width = window_width;
-       *height = window_height;
-}
-
-
 void VID_Finish (void)
 {
+       qboolean vid_usemouse;
+
        vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
        if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
        {
@@ -311,22 +279,7 @@ void VID_Finish (void)
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
-       if (vid_usemouse)
-       {
-               if (!vid_usingmouse)
-               {
-                       vid_usingmouse = true;
-                       IN_Activate (true);
-               }
-       }
-       else
-       {
-               if (vid_usingmouse)
-               {
-                       vid_usingmouse = false;
-                       IN_Activate (false);
-               }
-       }
+       IN_Activate(vid_usemouse);
 
        if (r_render.integer && !vid_hidden)
        {
@@ -489,7 +442,6 @@ void AppActivate(BOOL fActive, BOOL minimize)
 
        if (!fActive)
        {
-               vid_usingmouse = false;
                IN_Activate (false);
                if (vid_isfullscreen)
                {
@@ -525,6 +477,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
        char    state[256];
        char    asciichar[4];
        int             vkey;
+       int             charlength;
        qboolean down = false;
 
        if ( uMsg == uiWheelMessage )
@@ -543,7 +496,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_UpdateWindowStatus ();
+                       IN_Activate(false);
                        break;
 
                case WM_KEYDOWN:
@@ -555,8 +508,12 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
                        GetKeyboardState (state);
                        // alt/ctrl/shift tend to produce funky ToAscii values,
                        // and if it's not a single character we don't know care about it
-                       if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0) != 1)
+                       charlength = ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0);
+                       if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0)
                                asciichar[0] = 0;
+                       else if( charlength == 2 ) {
+                               asciichar[0] = asciichar[1];
+                       }
                        Key_Event (vkey, asciichar[0], down);
                        break;
 
@@ -741,7 +698,7 @@ void VID_Init(void)
        wc.lpszClassName = "DarkPlacesWindowClass";
 
        if (!RegisterClass (&wc))
-               Sys_Error("Couldn't register window class\n");
+               Con_Printf ("Couldn't register window class\n");
 
        IN_Init();
 }
@@ -871,8 +828,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp)
        // x and y may be changed by WM_MOVE messages
        window_x = CenterX;
        window_y = CenterY;
-       window_width = width;
-       window_height = height;
        rect.left += CenterX;
        rect.right += CenterX;
        rect.top += CenterY;
@@ -894,8 +849,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp)
        ShowWindow (mainwindow, SW_SHOWDEFAULT);
        UpdateWindow (mainwindow);
 
-       VID_UpdateWindowStatus ();
-
        // 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
@@ -956,14 +909,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp)
                return false;
        }
 
-       qglGetString = GL_GetProcAddress("glGetString");
-       qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
-       if (qglGetString == NULL)
+       if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
        {
                VID_Shutdown();
                Con_Print("glGetString not found\n");
                return false;
        }
+       if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL)
+               Con_Print("wglGetExtensionsStringARB not found\n");
        gl_renderer = qglGetString(GL_RENDERER);
        gl_vendor = qglGetString(GL_VENDOR);
        gl_version = qglGetString(GL_VERSION);
@@ -1001,6 +954,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp)
        IN_StartupMouse ();
        IN_StartupJoystick ();
 
+       if (gl_videosyncavailable)
+       {
+               vid_usevsync = vid_vsync.integer;
+               vid_usingvsync = vid_vsync.integer;
+               qwglSwapIntervalEXT (vid_usevsync);
+       }
+
        return true;
 }
 
@@ -1031,12 +991,6 @@ void VID_Shutdown (void)
        vid_isfullscreen = false;
 }
 
-
-/*
-===========
-IN_Activate
-===========
-*/
 static void IN_Activate (qboolean grab)
 {
        if (!mouseinitialized)
@@ -1044,45 +998,51 @@ static void IN_Activate (qboolean grab)
 
        if (grab)
        {
-               mouseactivatetoggle = true;
-               if (dinput && g_pMouse)
-               {
-                       IDirectInputDevice_Acquire(g_pMouse);
-                       dinput_acquired = true;
-               }
-               else
+               if (!vid_usingmouse)
                {
-                       RECT window_rect;
-                       window_rect.left = window_x;
-                       window_rect.top = window_y;
-                       window_rect.right = window_x + window_width;
-                       window_rect.bottom = window_y + window_height;
-                       if (mouseparmsvalid)
-                               restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
-                       SetCursorPos (window_center_x, window_center_y);
-                       SetCapture (mainwindow);
-                       ClipCursor (&window_rect);
+                       vid_usingmouse = true;
+                       cl_ignoremousemove = true;
+                       if (dinput && g_pMouse)
+                       {
+                               IDirectInputDevice_Acquire(g_pMouse);
+                               dinput_acquired = true;
+                       }
+                       else
+                       {
+                               RECT window_rect;
+                               window_rect.left = window_x;
+                               window_rect.top = window_y;
+                               window_rect.right = window_x + vid.width;
+                               window_rect.bottom = window_y + vid.height;
+                               if (mouseparmsvalid)
+                                       restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
+                               SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2));
+                               SetCapture (mainwindow);
+                               ClipCursor (&window_rect);
+                       }
+                       ShowCursor (false);
                }
-               vid_usingmouse = true;
-               ShowCursor (false);
        }
        else
        {
-               mouseactivatetoggle = false;
-               if (dinput_acquired)
-               {
-                       IDirectInputDevice_Unacquire(g_pMouse);
-                       dinput_acquired = false;
-               }
-               else
+               if (vid_usingmouse)
                {
-                       if (restore_spi)
-                               SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
-                       ClipCursor (NULL);
-                       ReleaseCapture ();
+                       vid_usingmouse = false;
+                       cl_ignoremousemove = true;
+                       if (dinput_acquired)
+                       {
+                               IDirectInputDevice_Unacquire(g_pMouse);
+                               dinput_acquired = false;
+                       }
+                       else
+                       {
+                               if (restore_spi)
+                                       SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
+                               ClipCursor (NULL);
+                               ReleaseCapture ();
+                       }
+                       ShowCursor (true);
                }
-               vid_usingmouse = false;
-               ShowCursor (true);
        }
 }
 
@@ -1224,11 +1184,6 @@ static void IN_StartupMouse (void)
        }
 
        mouse_buttons = 10;
-
-// if a fullscreen video mode was set before the mouse was initialized,
-// set the mouse state appropriately
-       if (mouseactivatetoggle)
-               IN_Activate (true);
 }
 
 
@@ -1321,15 +1276,15 @@ static void IN_MouseMove (void)
        else
        {
                GetCursorPos (&current_pos);
-               mx = current_pos.x - window_center_x;
-               my = current_pos.y - window_center_y;
+               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;
 
                // if the mouse has moved, force it to the center, so there's room to move
                if (mx || my)
-                       SetCursorPos (window_center_x, window_center_y);
+                       SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2));
        }
 }