]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
improved setinfo handling so that quakeworld works much better now (name/topcolor...
[xonotic/darkplaces.git] / vid_sdl.c
index 9047dd36e5176ab34ddaf507eb18c2e7004a87ca..fe09e99dba859635675ebb9c1404c0a6a47141d1 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
+#undef WIN32_LEAN_AND_MEAN  //hush a warning, SDL.h redefines this
 #include <SDL.h>
 #include <stdio.h>
 
@@ -23,6 +24,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 // Tell startup code that we have a client
 int cl_available = true;
+
+qboolean vid_supportrefreshrate = false;
+
 static qboolean vid_usingmouse;
 static qboolean vid_isfullscreen;
 
@@ -177,7 +181,7 @@ static unsigned int tbl_sdltoquake[] =
        0,                      //SDLK_LMETA    = 310,
        0,                      //SDLK_LSUPER   = 311,          /* Left "Windows" key */
        0,                      //SDLK_RSUPER   = 312,          /* Right "Windows" key */
-       0,                      //SDLK_MODE             = 313,          /* "Alt Gr" key */
+       K_ALT,                  //SDLK_MODE             = 313,          /* "Alt Gr" key */
        0,                      //SDLK_COMPOSE  = 314,          /* Multi-key compose key */
        0,                      //SDLK_HELP             = 315,
        0,                      //SDLK_PRINT    = 316,
@@ -251,11 +255,13 @@ static int Sys_EventFilter( SDL_Event *event )
 #endif
 }
 
-static int buttonremap[16] =
+static keynum_t buttonremap[18] =
 {
        K_MOUSE1,
        K_MOUSE3,
        K_MOUSE2,
+       K_MWHEELUP,
+       K_MWHEELDOWN,
        K_MOUSE4,
        K_MOUSE5,
        K_MOUSE6,
@@ -294,11 +300,11 @@ void Sys_SendKeyEvents( void )
                                }
                                break;
                        case SDL_MOUSEBUTTONDOWN:
-                               if (event.button.button <= 16)
+                               if (event.button.button <= 18)
                                        Key_Event( buttonremap[event.button.button - 1], 0, true );
                                break;
                        case SDL_MOUSEBUTTONUP:
-                               if (event.button.button <= 16)
+                               if (event.button.button <= 18)
                                        Key_Event( buttonremap[event.button.button - 1], 0, false );
                                break;
                }
@@ -341,7 +347,12 @@ static void VID_SetCaption()
                return;
 
        icon = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDI_ICON1 ) );
-       SetClassLong( info.window, GCL_HICON, (LONG) icon );
+#ifndef _W64 //If Windows 64bit data types don't exist
+#define SetClassLongPtr SetClassLong
+#define GCLP_HICON GCL_HICON
+#define LONG_PTR LONG
+#endif
+       SetClassLongPtr( info.window, GCLP_HICON, (LONG_PTR)icon );
 }
 #else
 static void VID_SetCaption()
@@ -360,7 +371,7 @@ static void VID_OutputVersion()
                                        version->major, version->minor, version->patch );
 }
 
-int VID_InitMode(int fullscreen, int width, int height, int bpp)
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate)
 {
        int i;
        int flags = SDL_OPENGL;
@@ -462,35 +473,40 @@ void VID_Shutdown (void)
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
-int VID_SetGamma (unsigned short *ramps)
+int VID_SetGamma (unsigned short *ramps, int rampsize)
 {
-       return !SDL_SetGammaRamp (ramps, ramps + 256, ramps + 512);
+       return !SDL_SetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
 }
 
-int VID_GetGamma (unsigned short *ramps)
+int VID_GetGamma (unsigned short *ramps, int rampsize)
 {
-       return !SDL_GetGammaRamp( ramps, ramps + 256, ramps + 512);
+       return !SDL_GetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2);
 }
 
-void VID_Finish (void)
+void VID_Finish (qboolean allowmousegrab)
 {
        Uint8 appstate;
        qboolean vid_usemouse;
 
+       CHECKGLERROR
        if (r_speeds.integer || gl_finish.integer)
-               qglFinish();
+       {
+               qglFinish();CHECKGLERROR
+       }
        SDL_GL_SwapBuffers();
 
        //react on appstate changes
        appstate = SDL_GetAppState();
 
-       if( !( appstate & SDL_APPMOUSEFOCUS ) || !( appstate & SDL_APPINPUTFOCUS ) )
+       vid_hidden = !(appstate & SDL_APPACTIVE);
+
+       if( vid_hidden || !( appstate & SDL_APPMOUSEFOCUS ) || !( appstate & SDL_APPINPUTFOCUS ) )
                vid_activewindow = false;
        else
                vid_activewindow = true;
 
        vid_usemouse = false;
-       if( vid_mouse.integer && !key_consoleactive && !cls.demoplayback )
+       if( allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback) )
                vid_usemouse = true;
        if( vid_isfullscreen )
                vid_usemouse = true;
@@ -498,4 +514,6 @@ void VID_Finish (void)
                vid_usemouse = false;
 
        IN_Activate(vid_usemouse);
+
+       VID_UpdateGamma(false, 256);
 }