]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
allow .rtlights files to have style values outside the range
[xonotic/darkplaces.git] / vid_sdl.c
index c9600ce713fa23da753196dfa3e30f9e83949c95..b090c2bc17ad6e7ad3698aa1965e4a03152906a5 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:
@@ -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:
@@ -2477,7 +2497,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 +2663,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;
@@ -2879,12 +2899,15 @@ 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.
 #endif
        return &desktop_mode;
 }