]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
Fix sv_jumpstep cvar, whose behavior was completely inverted (jump stepping worked...
[xonotic/darkplaces.git] / vid_sdl.c
index abb90970eac7c6a031a2f21e582424473331f36f..ea1ab82f0a0f4949cf3521463a621fa988eb6a09 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1066,13 +1066,19 @@ static void sdl_newmap(void)
 }
 #endif
 
-static keynum_t buttonremap[18] =
+static keynum_t buttonremap[] =
 {
        K_MOUSE1,
        K_MOUSE3,
        K_MOUSE2,
+#if SDL_MAJOR_VERSION == 1
+       // TODO Find out how SDL maps these buttons. It looks like we should
+       // still include these for sdl2? At least the button indexes don't
+       // differ between SDL1 and SDL2 for me, thus this array should stay the
+       // same (in X11 button order).
        K_MWHEELUP,
        K_MWHEELDOWN,
+#endif
        K_MOUSE4,
        K_MOUSE5,
        K_MOUSE6,
@@ -1121,7 +1127,7 @@ void Sys_SendKeyEvents( void )
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
                                if (!vid_touchscreen.integer)
-                               if (event.button.button <= 18)
+                               if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
                                break;
                        case SDL_JOYBUTTONDOWN:
@@ -1143,8 +1149,8 @@ void Sys_SendKeyEvents( void )
                                        {
                                                SDL_FreeSurface(vid_softsurface);
                                                vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
-                                               vid.softpixels = (unsigned int *)vid_softsurface->pixels;
                                                SDL_SetAlpha(vid_softsurface, 0, 255);
+                                               vid.softpixels = (unsigned int *)vid_softsurface->pixels;
                                                if (vid.softdepthpixels)
                                                        free(vid.softdepthpixels);
                                                vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
@@ -1237,9 +1243,23 @@ void Sys_SendKeyEvents( void )
                                        Con_DPrintf("SDL_Event: SDL_MOUSEBUTTONUP\n");
 #endif
                                if (!vid_touchscreen.integer)
-                               if (event.button.button <= 18)
+                               if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
                                break;
+                       case SDL_MOUSEWHEEL:
+                               // TODO support wheel x direction.
+                               i = event.wheel.y;
+                               while (i > 0) {
+                                       --i;
+                                       Key_Event( K_MWHEELUP, 0, true );
+                                       Key_Event( K_MWHEELUP, 0, false );
+                               }
+                               while (i < 0) {
+                                       ++i;
+                                       Key_Event( K_MWHEELDOWN, 0, true );
+                                       Key_Event( K_MWHEELDOWN, 0, false );
+                               }
+                               break;
                        case SDL_JOYBUTTONDOWN:
                        case SDL_JOYBUTTONUP:
                        case SDL_JOYAXISMOTION:
@@ -1279,6 +1299,7 @@ void Sys_SendKeyEvents( void )
                                                        {
                                                                SDL_FreeSurface(vid_softsurface);
                                                                vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
+                                                               SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
                                                                vid.softpixels = (unsigned int *)vid_softsurface->pixels;
                                                                if (vid.softdepthpixels)
                                                                        free(vid.softdepthpixels);
@@ -2477,7 +2498,7 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode)
        vid_isfullscreen = false;
 #if SDL_MAJOR_VERSION == 1
        {
-               SDL_VideoInfo *vi = SDL_GetVideoInfo();
+               const SDL_VideoInfo *vi = SDL_GetVideoInfo();
                desktop_mode.width = vi->current_w;
                desktop_mode.height = vi->current_h;
                desktop_mode.bpp = vi->vfmt->BitsPerPixel;
@@ -2643,7 +2664,7 @@ static qboolean VID_InitModeSoft(viddef_mode_t *mode)
        vid_isfullscreen = false;
        if (mode->fullscreen) {
 #if SDL_MAJOR_VERSION == 1
-               SDL_VideoInfo *vi = SDL_GetVideoInfo();
+               const SDL_VideoInfo *vi = SDL_GetVideoInfo();
                mode->width = vi->current_w;
                mode->height = vi->current_h;
                mode->bitsperpixel = vi->vfmt->BitsPerPixel;
@@ -2691,6 +2712,8 @@ static qboolean VID_InitModeSoft(viddef_mode_t *mode)
        }
 #if SDL_MAJOR_VERSION == 1
        SDL_SetAlpha(vid_softsurface, 0, 255);
+#else
+       SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
 #endif
 
        vid.softpixels = (unsigned int *)vid_softsurface->pixels;
@@ -2879,12 +2902,12 @@ vid_mode_t *VID_GetDesktopMode(void)
        Uint32 rmask, gmask, bmask, amask;
        SDL_GetDesktopDisplayMode(0, &mode);
        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask);
-       modes[k].width = mode.w;
-       modes[k].height = mode.h;
-       modes[k].bpp = bpp;
-       modes[k].refreshrate = mode.refreshrate;
-       modes[k].pixelheight_num = 1;
-       modes[k].pixelheight_denom = 1; // SDL does not provide this
+       desktop_mode.width = mode.w;
+       desktop_mode.height = mode.h;
+       desktop_mode.bpp = bpp;
+       desktop_mode.refreshrate = mode.refresh_rate;
+       desktop_mode.pixelheight_num = 1;
+       desktop_mode.pixelheight_denom = 1; // SDL does not provide this
        // TODO check whether this actually works, or whether we do still need
        // a read-window-size-after-entering-desktop-fullscreen hack for
        // multiscreen setups.