X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_sdl.c;h=c3cfda10a498ba8b0891a70512c0477b391d26ff;hb=da29a8beeb35293e2fd38b51883c91b5cf4cf4ad;hp=42dbd46a83736164bb5aa0b805796b18ad8bc10f;hpb=656d8440b1ca6afe0b55650fba3b8ca4b01c9511;p=xonotic%2Fdarkplaces.git diff --git a/vid_sdl.c b/vid_sdl.c index 42dbd46a..c3cfda10 100644 --- 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 #include @@ -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,8 +255,31 @@ static int Sys_EventFilter( SDL_Event *event ) #endif } +static keynum_t buttonremap[18] = +{ + K_MOUSE1, + K_MOUSE3, + K_MOUSE2, + K_MWHEELUP, + K_MWHEELDOWN, + K_MOUSE4, + K_MOUSE5, + K_MOUSE6, + K_MOUSE7, + K_MOUSE8, + K_MOUSE9, + K_MOUSE10, + K_MOUSE11, + K_MOUSE12, + K_MOUSE13, + K_MOUSE14, + K_MOUSE15, + K_MOUSE16, +}; + void Sys_SendKeyEvents( void ) { + static qboolean sound_active = true; SDL_Event event; while( SDL_PollEvent( &event ) ) @@ -274,20 +301,26 @@ void Sys_SendKeyEvents( void ) } break; case SDL_MOUSEBUTTONDOWN: - if( event.button.button == SDL_BUTTON_MIDDLE ) - event.button.button = SDL_BUTTON_RIGHT; - else if( event.button.button == SDL_BUTTON_RIGHT ) - event.button.button = SDL_BUTTON_MIDDLE; - Key_Event( K_MOUSE1 + event.button.button - 1, 0, true ); + if (event.button.button <= 18) + Key_Event( buttonremap[event.button.button - 1], 0, true ); break; case SDL_MOUSEBUTTONUP: - if( event.button.button == SDL_BUTTON_MIDDLE ) - event.button.button = SDL_BUTTON_RIGHT; - else if( event.button.button == SDL_BUTTON_RIGHT ) - event.button.button = SDL_BUTTON_MIDDLE; - Key_Event( K_MOUSE1 + event.button.button - 1, 0, false ); + if (event.button.button <= 18) + Key_Event( buttonremap[event.button.button - 1], 0, false ); break; } + + // enable/disable sound on focus gain/loss + if (!vid_activewindow && sound_active) + { + S_BlockSound (); + sound_active = false; + } + else if (vid_activewindow && !sound_active) + { + S_UnblockSound (); + sound_active = true; + } } ///////////////// @@ -305,14 +338,8 @@ static int Sys_EventFilter( SDL_Event *event ); void VID_Init (void) { if (SDL_Init(SDL_INIT_VIDEO) < 0) - Sys_Error ("Failed to init video: %s\n", SDL_GetError()); + Sys_Error ("Failed to init video: %s", SDL_GetError()); vid_isfullscreen = false; - - SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter ); - // init keyboard - SDL_EnableUNICODE( SDL_ENABLE ); - // enable key repeat since everyone expects it - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); } // set the icon (we dont use SDL here since it would be too much a PITA) @@ -333,7 +360,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() @@ -352,7 +384,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; @@ -365,9 +397,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp) We cant switch from one OpenGL video mode to another. Thus we first switch to some stupid 2D mode and then back to OpenGL. */ -#ifndef MACOSX SDL_SetVideoMode( 0, 0, 0, 0 ); -#endif // SDL usually knows best drivername = NULL; @@ -382,17 +412,15 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp) return false; } - qglGetString = GL_GetProcAddress("glGetString"); - - // Knghtbrd: should do platform-specific extension string function here - - if (qglGetString == NULL) + if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL) { VID_Shutdown(); Con_Print("Required OpenGL function glGetString not found\n"); return false; } + // Knghtbrd: should do platform-specific extension string function here + vid_isfullscreen = false; if (fullscreen) { flags |= SDL_FULLSCREEN; @@ -424,12 +452,20 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp) VID_Shutdown(); return false; } + + // set window title VID_SetCaption(); + // set up an event filter to ask confirmation on close button in WIN32 + SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter ); + // init keyboard + SDL_EnableUNICODE( SDL_ENABLE ); + // enable key repeat since everyone expects it + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - gl_renderer = qglGetString(GL_RENDERER); - gl_vendor = qglGetString(GL_VENDOR); - gl_version = qglGetString(GL_VERSION); - gl_extensions = qglGetString(GL_EXTENSIONS); + 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 = "SDL"; // Knghtbrd: should assign platform-specific extensions here //TODO: maybe ;) @@ -450,42 +486,33 @@ void VID_Shutdown (void) SDL_QuitSubSystem(SDL_INIT_VIDEO); } -int VID_SetGamma (unsigned short *ramps) -{ - return !SDL_SetGammaRamp (ramps, ramps + 256, ramps + 512); -} - -int VID_GetGamma (unsigned short *ramps) +int VID_SetGamma (unsigned short *ramps, int rampsize) { - return !SDL_GetGammaRamp( ramps, ramps + 256, ramps + 512); + return !SDL_SetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2); } -void VID_GetWindowSize (int *x, int *y, int *width, int *height) +int VID_GetGamma (unsigned short *ramps, int rampsize) { - *x = *y = 0; - *width = screen->w; - *height = screen->h; + return !SDL_GetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2); } -void VID_Finish (void) +void VID_Finish (qboolean allowmousegrab) { Uint8 appstate; qboolean vid_usemouse; - if (r_speeds.integer || gl_finish.integer) - qglFinish(); - 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; @@ -493,4 +520,16 @@ void VID_Finish (void) vid_usemouse = false; IN_Activate(vid_usemouse); + + VID_UpdateGamma(false, 256); + + if (r_render.integer && !vid_hidden) + { + CHECKGLERROR + if (r_speeds.integer || gl_finish.integer) + { + qglFinish();CHECKGLERROR + } + SDL_GL_SwapBuffers(); + } }