diff --git a/config.lib b/config.lib index 1c3fc2c94ecdf..6130a9b290845 100644 --- a/config.lib +++ b/config.lib @@ -2500,7 +2500,7 @@ detect_sdl() { sleep 5 fi - detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2" + detect_pkg_config "$with_sdl" "sdl2" "sdl_config" "2.0" } detect_osx_sdk() { diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 78d9b1465b662..46413a601c9af 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -269,12 +269,15 @@ char *CrashLog::LogLibraries(char *buffer, const char *last) const #ifdef WITH_SDL #ifdef DYNAMICALLY_LOADED_SDL - if (SDL_CALL SDL_Linked_Version != NULL) { + SDL_version linked; + SDL_CALL SDL_GetVersion(&linked); + if (linked != NULL) { #else { #endif - const SDL_version *v = SDL_CALL SDL_Linked_Version(); - buffer += seprintf(buffer, last, " SDL: %d.%d.%d\n", v->major, v->minor, v->patch); + SDL_version v; + SDL_CALL SDL_GetVersion(&v); + buffer += seprintf(buffer, last, " SDL: %d.%d.%d\n", v.major, v.minor, v.patch); } #endif /* WITH_SDL */ diff --git a/src/sdl.cpp b/src/sdl.cpp index 79e9ed2927410..93b8030fb965a 100644 --- a/src/sdl.cpp +++ b/src/sdl.cpp @@ -94,7 +94,7 @@ const char *SdlOpen(uint32 x) } #endif if (_sdl_usage++ == 0) { - if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError(); + if (SDL_CALL SDL_Init(x) == -1) return SDL_CALL SDL_GetError(); } else if (x != 0) { if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError(); } diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index e96decb451d4b..5dc9eb3e19bd8 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -31,8 +31,10 @@ static FVideoDriver_SDL iFVideoDriver_SDL; +static SDL_Window *_sdl_window; +static SDL_Texture *_sdl_texture; +static SDL_Renderer *_sdl_renderer; static SDL_Surface *_sdl_screen; -static SDL_Surface *_sdl_realscreen; static bool _all_modes; /** Whether the drawing is/may be done in a separate thread. */ @@ -44,6 +46,7 @@ static ThreadMutex *_draw_mutex = NULL; /** Should we keep continue drawing? */ static volatile bool _draw_continue; static Palette _local_palette; +static SDL_Palette *_sdl_palette; #define MAX_DIRTY_RECTS 100 static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS]; @@ -70,12 +73,12 @@ static void UpdatePalette(bool init = false) pal[i].r = _local_palette.palette[_local_palette.first_dirty + i].r; pal[i].g = _local_palette.palette[_local_palette.first_dirty + i].g; pal[i].b = _local_palette.palette[_local_palette.first_dirty + i].b; - pal[i].unused = 0; + pal[i].a = 0; } - SDL_CALL SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty); + SDL_CALL SDL_SetPaletteColors(_sdl_palette, pal, _local_palette.first_dirty, _local_palette.count_dirty); - if (_sdl_screen != _sdl_realscreen && init) { + if (init) { /* When using a shadow surface, also set our palette on the real screen. This lets SDL * allocate as much colors (or approximations) as * possible, instead of using only the default SDL @@ -96,10 +99,12 @@ static void UpdatePalette(bool init = false) * palette change and the blitting below, so we only set * the real palette during initialisation. */ - SDL_CALL SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty); + SDL_CALL SDL_SetPaletteColors(_sdl_palette, pal, _local_palette.first_dirty, _local_palette.count_dirty); } - if (_sdl_screen != _sdl_realscreen && !init) { + SDL_CALL SDL_SetSurfacePalette(_sdl_screen, _sdl_palette); + + if (!init) { /* We're not using real hardware palette, but are letting SDL * approximate the palette during shadow -> screen copy. To * change the palette, we need to recopy the entire screen. @@ -110,8 +115,13 @@ static void UpdatePalette(bool init = false) * best mapping of shadow palette colors to real palette * colors from scratch. */ - SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL); - SDL_CALL SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); + if (_sdl_texture != NULL) { + SDL_CALL SDL_DestroyTexture(_sdl_texture); + } + _sdl_texture = SDL_CALL SDL_CreateTextureFromSurface(_sdl_renderer, _sdl_screen); + SDL_CALL SDL_RenderClear(_sdl_renderer); + SDL_CALL SDL_RenderCopy(_sdl_renderer, _sdl_texture, nullptr, nullptr); + SDL_CALL SDL_RenderPresent(_sdl_renderer); } } @@ -155,19 +165,14 @@ static void DrawSurfaceToScreen() if (n == 0) return; _num_dirty_rects = 0; - if (n > MAX_DIRTY_RECTS) { - if (_sdl_screen != _sdl_realscreen) { - SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL); - } - SDL_CALL SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); - } else { - if (_sdl_screen != _sdl_realscreen) { - for (int i = 0; i < n; i++) { - SDL_CALL SDL_BlitSurface(_sdl_screen, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); - } - } - SDL_CALL SDL_UpdateRects(_sdl_realscreen, n, _dirty_rects); - } + + // Just update the entire screen. Updating only the _dirty_rects + // seems to cause screen flickering, but that's how the SDL 1.2 + // code worked. + SDL_CALL SDL_UpdateTexture(_sdl_texture, NULL, _sdl_screen->pixels, _sdl_screen->pitch); + SDL_CALL SDL_RenderClear(_sdl_renderer); + SDL_CALL SDL_RenderCopy(_sdl_renderer, _sdl_texture, NULL, NULL); + SDL_CALL SDL_RenderPresent(_sdl_renderer); } static void DrawSurfaceToScreenThread(void *) @@ -206,38 +211,30 @@ static const Dimension _default_resolutions[] = { static void GetVideoModes() { - SDL_Rect **modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE | SDL_FULLSCREEN); - if (modes == NULL) usererror("sdl: no modes available"); - - _all_modes = (SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE | (_fullscreen ? SDL_FULLSCREEN : 0)) == (void*)-1); - if (modes == (void*)-1) { - int n = 0; - for (uint i = 0; i < lengthof(_default_resolutions); i++) { - if (SDL_CALL SDL_VideoModeOK(_default_resolutions[i].width, _default_resolutions[i].height, 8, SDL_FULLSCREEN) != 0) { - _resolutions[n] = _default_resolutions[i]; - if (++n == lengthof(_resolutions)) break; - } + int modes = SDL_CALL SDL_GetNumDisplayModes(0); + if (modes == 0) usererror("sdl: no modes available"); + + SDL_DisplayMode mode; + int n = 0; + for (int i = 0; i < modes; i++) { + SDL_CALL SDL_GetDisplayMode(0, i, &mode); + + uint w = mode.w; + uint h = mode.h; + + int j; + for (j = 0; j < n; j++) { + if (_resolutions[j].width == w && _resolutions[j].height == h) break; } - _num_resolutions = n; - } else { - int n = 0; - for (int i = 0; modes[i]; i++) { - uint w = modes[i]->w; - uint h = modes[i]->h; - int j; - for (j = 0; j < n; j++) { - if (_resolutions[j].width == w && _resolutions[j].height == h) break; - } - if (j == n) { - _resolutions[j].width = w; - _resolutions[j].height = h; - if (++n == lengthof(_resolutions)) break; - } + if (j == n) { + _resolutions[j].width = w; + _resolutions[j].height = h; + if (++n == lengthof(_resolutions)) break; } - _num_resolutions = n; - SortResolutions(_num_resolutions); } + _num_resolutions = n; + SortResolutions(_num_resolutions); } static void GetAvailableVideoMode(uint *w, uint *h) @@ -292,8 +289,8 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) /* Get the colourkey, which will be magenta */ uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255); - SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap); - SDL_CALL SDL_WM_SetIcon(icon, NULL); + SDL_CALL SDL_SetColorKey(icon, SDL_TRUE, rgbmap); + SDL_CALL SDL_SetWindowIcon(_sdl_window, icon); SDL_CALL SDL_FreeSurface(icon); } } @@ -328,25 +325,22 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palette"); - /* Free any previously allocated shadow surface */ - if (_sdl_screen != NULL && _sdl_screen != _sdl_realscreen) SDL_CALL SDL_FreeSurface(_sdl_screen); - - if (_sdl_realscreen != NULL) { - if (_requested_hwpalette != want_hwpalette) { - /* SDL (at least the X11 driver), reuses the - * same window and palette settings when the bpp - * (and a few flags) are the same. Since we need - * to hwpalette value to change (in particular - * when switching between fullscreen and - * windowed), we restart the entire video - * subsystem to force creating a new window. - */ - DEBUG(driver, 0, "SDL: Restarting SDL video subsystem, to force hwpalette change"); - SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO); - SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO); - ClaimMousePointer(); - SetupKeyboard(); - } + /* Free any previously allocated surface */ + if (_sdl_screen != NULL) SDL_CALL SDL_FreeSurface(_sdl_screen); + + if (_requested_hwpalette != want_hwpalette) { + /* SDL (at least the X11 driver), reuses the + * same window and palette settings when the bpp + * (and a few flags) are the same. Since we need + * to hwpalette value to change (in particular + * when switching between fullscreen and + * windowed), we restart the entire video + * subsystem to force creating a new window. + */ + DEBUG(driver, 0, "SDL: Restarting SDL video subsystem, to force hwpalette change"); + SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO); + ClaimMousePointer(); } /* Remember if we wanted a hwpalette. We can't reliably query * SDL for the SDL_HWPALETTE flag, since it might get set even @@ -354,15 +348,77 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) * surface, for example). */ _requested_hwpalette = want_hwpalette; - /* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */ - newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); - if (newscreen == NULL) { + seprintf(caption, lastof(caption), "OpenTTD %s", _openttd_revision); + + if (_sdl_window == NULL) { + _sdl_window = SDL_CALL SDL_CreateWindow( + caption, + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + w, h, + SDL_WINDOW_SHOWN); + } + + if (_sdl_window == NULL) { DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on"); return false; } - _sdl_realscreen = newscreen; - if (bpp == 8 && (_sdl_realscreen->flags & SDL_HWPALETTE) != SDL_HWPALETTE) { + SDL_CALL SDL_SetWindowSize(_sdl_window, w, h); + + if (_sdl_renderer == NULL) { + _sdl_renderer = SDL_CALL SDL_CreateRenderer( + _sdl_window, + -1, + SDL_RENDERER_ACCELERATED); + } + + if (_sdl_renderer == NULL) { + DEBUG(driver, 0, "SDL: Couldn't allocate a renderer to draw on"); + return false; + } + + newscreen = SDL_CALL SDL_CreateRGBSurface( + 0, w, h, bpp, + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + + if (newscreen == NULL) { + DEBUG(driver, 0, "SDL_CreateRGBSurface() failed: %s", SDL_CALL SDL_GetError()); + return false; + } + + _sdl_screen = newscreen; + + if (_sdl_palette == NULL) { + _sdl_palette = SDL_CALL SDL_AllocPalette(256); + } + + if (_sdl_palette == NULL) { + DEBUG(driver, 0, "SDL_AllocPalette() failed: %s", SDL_CALL SDL_GetError()); + return false; + } + + SDL_CALL SDL_SetSurfacePalette(_sdl_screen, _sdl_palette); + + if (_sdl_texture != NULL) { + SDL_CALL SDL_DestroyTexture(_sdl_texture); + } + + _sdl_texture = SDL_CALL SDL_CreateTexture( + _sdl_renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + w, h); + + if (_sdl_texture == NULL) { + DEBUG(driver, 0, "SDL: Couldn't allocate a texture to draw on"); + return false; + } + + if (bpp == 8) { /* Using an 8bpp blitter, if we didn't get a hardware * palette (most likely because we didn't request one, * see above), we'll have to set up a shadow surface to @@ -382,8 +438,9 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) * we won't create a second shadow surface in this case. */ DEBUG(driver, 1, "SDL: using shadow surface"); - newscreen = SDL_CALL SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bpp, 0, 0, 0, 0); - if (newscreen == NULL) { + _sdl_screen = SDL_CALL SDL_CreateRGBSurface(0, w, h, bpp, 0, 0, 0, 0); + + if (_sdl_screen == NULL) { DEBUG(driver, 0, "SDL: Couldn't allocate a shadow surface to draw on"); return false; } @@ -392,11 +449,10 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) /* Delay drawing for this cycle; the next cycle will redraw the whole screen */ _num_dirty_rects = 0; - _screen.width = newscreen->w; - _screen.height = newscreen->h; - _screen.pitch = newscreen->pitch / (bpp / 8); - _screen.dst_ptr = newscreen->pixels; - _sdl_screen = newscreen; + _screen.width = _sdl_screen->w; + _screen.height = _sdl_screen->h; + _screen.pitch = _sdl_screen->pitch / (bpp / 8); + _screen.dst_ptr = _sdl_screen->pixels; /* When in full screen, we will always have the mouse cursor * within the window, even though SDL does not give us the @@ -408,9 +464,6 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) InitPalette(); - seprintf(caption, lastof(caption), "OpenTTD %s", _openttd_revision); - SDL_CALL SDL_WM_SetCaption(caption, caption); - GameSizeChanged(); return true; @@ -423,11 +476,7 @@ bool VideoDriver_SDL::ClaimMousePointer() } struct VkMapping { -#if SDL_VERSION_ATLEAST(1, 3, 0) SDL_Keycode vk_from; -#else - uint16 vk_from; -#endif byte vk_count; byte map_to; }; @@ -465,7 +514,7 @@ static const VkMapping _vk_mapping[] = { AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12), /* Numeric part. */ - AM(SDLK_KP0, SDLK_KP9, '0', '9'), + AM(SDLK_KP_0, SDLK_KP_9, '0', '9'), AS(SDLK_KP_DIVIDE, WKC_NUM_DIV), AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL), AS(SDLK_KP_MINUS, WKC_NUM_MINUS), @@ -487,7 +536,7 @@ static const VkMapping _vk_mapping[] = { AS(SDLK_PERIOD, WKC_PERIOD) }; -static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character) +static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, WChar *character) { const VkMapping *map; uint key = 0; @@ -518,12 +567,32 @@ static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character) #endif /* META are the command keys on mac */ - if (sym->mod & KMOD_META) key |= WKC_META; + if (sym->mod & KMOD_GUI) key |= WKC_META; if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT; if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; if (sym->mod & KMOD_ALT) key |= WKC_ALT; - *character = sym->unicode; + *character = sym->sym; + + return key; +} + +/** + * Like ConvertSdlKeyIntoMy(), but takes an SDL_Keycode as input + * instead of an SDL_Keysym. + */ +static uint ConvertSdlKeycodeIntoMy(SDL_Keycode kc) +{ + const VkMapping *map; + uint key = 0; + + for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { + if ((uint)(kc - map->vk_from) <= map->vk_count) { + key = kc - map->vk_from + map->map_to; + break; + } + } + return key; } @@ -536,11 +605,19 @@ int VideoDriver_SDL::PollEvent() switch (ev.type) { case SDL_MOUSEMOTION: if (_cursor.UpdateCursorPosition(ev.motion.x, ev.motion.y, true)) { - SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); + SDL_CALL SDL_WarpMouseInWindow(_sdl_window, _cursor.pos.x, _cursor.pos.y); } HandleMouseEvents(); break; + case SDL_MOUSEWHEEL: + if (ev.wheel.y > 0) { + _cursor.wheel--; + } else if (ev.wheel.y < 0) { + _cursor.wheel++; + } + break; + case SDL_MOUSEBUTTONDOWN: if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) { ev.button.button = SDL_BUTTON_RIGHT; @@ -556,9 +633,6 @@ int VideoDriver_SDL::PollEvent() _right_button_clicked = true; break; - case SDL_BUTTON_WHEELUP: _cursor.wheel--; break; - case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break; - default: break; } HandleMouseEvents(); @@ -578,15 +652,15 @@ int VideoDriver_SDL::PollEvent() HandleMouseEvents(); break; - case SDL_ACTIVEEVENT: - if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; + case SDL_WINDOWEVENT_ENTER: + // mouse entered the window, enable cursor + _cursor.in_window = true; + break; - if (ev.active.gain) { // mouse entered the window, enable cursor - _cursor.in_window = true; - } else { - UndrawMouseCursor(); // mouse left the window, undraw cursor - _cursor.in_window = false; - } + case SDL_WINDOWEVENT_LEAVE: + // mouse left the window, undraw cursor + UndrawMouseCursor(); + _cursor.in_window = false; break; case SDL_QUIT: @@ -594,27 +668,41 @@ int VideoDriver_SDL::PollEvent() break; case SDL_KEYDOWN: // Toggle full-screen on ALT + ENTER/F - if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && + if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_GUI)) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { ToggleFullScreen(!_fullscreen); } else { WChar character; + uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character); - HandleKeypress(keycode, character); + // Only handle non-text keys here. Text is handled in + // SDL_TEXTINPUT below. + if (ev.key.keysym.sym == SDLK_DELETE || + !IsValidChar(character, CS_ALPHANUMERAL)) { + HandleKeypress(keycode, character); + } } break; - case SDL_VIDEORESIZE: { - int w = max(ev.resize.w, 64); - int h = max(ev.resize.h, 64); + case SDL_TEXTINPUT: { + WChar character; + SDL_Keycode kc = SDL_CALL SDL_GetKeyFromName(ev.text.text); + uint keycode = ConvertSdlKeycodeIntoMy(kc); + Utf8Decode(&character, ev.text.text); + HandleKeypress(keycode, character); + break; + } + case SDL_WINDOWEVENT_RESIZED: { + int w = max(ev.window.data1, 64); + int h = max(ev.window.data2, 64); CreateMainSurface(w, h); break; } - case SDL_VIDEOEXPOSE: { + case SDL_WINDOWEVENT_EXPOSED: { /* Force a redraw of the entire screen. Note * that SDL 1.2 seems to do this automatically * in most cases, but 1.3 / 2.0 does not. */ - _num_dirty_rects = MAX_DIRTY_RECTS + 1; + _num_dirty_rects = MAX_DIRTY_RECTS + 1; break; } } @@ -623,7 +711,6 @@ int VideoDriver_SDL::PollEvent() const char *VideoDriver_SDL::Start(const char * const *parm) { - char buf[30]; _use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2); const char *s = SdlOpen(SDL_INIT_VIDEO); @@ -634,23 +721,16 @@ const char *VideoDriver_SDL::Start(const char * const *parm) return SDL_CALL SDL_GetError(); } - SDL_CALL SDL_VideoDriverName(buf, sizeof buf); - DEBUG(driver, 1, "SDL: using driver '%s'", buf); + const char *dname = SDL_CALL SDL_GetVideoDriver(0); + DEBUG(driver, 1, "SDL: using driver '%s'", dname); MarkWholeScreenDirty(); - SetupKeyboard(); _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; return NULL; } -void VideoDriver_SDL::SetupKeyboard() -{ - SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - SDL_CALL SDL_EnableUNICODE(1); -} - void VideoDriver_SDL::Stop() { SdlClose(SDL_INIT_VIDEO); @@ -663,7 +743,7 @@ void VideoDriver_SDL::MainLoop() uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK; uint32 mod; int numkeys; - Uint8 *keys; + const Uint8 *keys; CheckPaletteAnim(); @@ -701,21 +781,14 @@ void VideoDriver_SDL::MainLoop() if (_exit_game) break; mod = SDL_CALL SDL_GetModState(); -#if SDL_VERSION_ATLEAST(1, 3, 0) keys = SDL_CALL SDL_GetKeyboardState(&numkeys); -#else - keys = SDL_CALL SDL_GetKeyState(&numkeys); -#endif + #if defined(_DEBUG) if (_shift_pressed) #else /* Speedup when pressing tab, except when using ALT+TAB * to switch to another application */ -#if SDL_VERSION_ATLEAST(1, 3, 0) if (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 0) -#else - if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0) -#endif /* SDL_VERSION_ATLEAST(1, 3, 0) */ #endif /* defined(_DEBUG) */ { if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; @@ -736,17 +809,10 @@ void VideoDriver_SDL::MainLoop() /* determine which directional keys are down */ _dirkeys = -#if SDL_VERSION_ATLEAST(1, 3, 0) (keys[SDL_SCANCODE_LEFT] ? 1 : 0) | (keys[SDL_SCANCODE_UP] ? 2 : 0) | (keys[SDL_SCANCODE_RIGHT] ? 4 : 0) | (keys[SDL_SCANCODE_DOWN] ? 8 : 0); -#else - (keys[SDLK_LEFT] ? 1 : 0) | - (keys[SDLK_UP] ? 2 : 0) | - (keys[SDLK_RIGHT] ? 4 : 0) | - (keys[SDLK_DOWN] ? 8 : 0); -#endif if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); /* The gameloop is the part that can run asynchronously. The rest @@ -808,7 +874,9 @@ bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen) if (_draw_mutex != NULL) _draw_mutex->BeginCritical(true); _fullscreen = fullscreen; GetVideoModes(); // get the list of available video modes - bool ret = _num_resolutions != 0 && CreateMainSurface(_cur_resolution.width, _cur_resolution.height); + bool ret = _num_resolutions != 0 && + SDL_CALL SDL_SetWindowFullscreen( + _sdl_window, fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP) > -1; if (!ret) { /* switching resolution failed, put back full_screen to original status */ @@ -821,7 +889,9 @@ bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen) bool VideoDriver_SDL::AfterBlitterChange() { - return CreateMainSurface(_screen.width, _screen.height); + int w, h; + SDL_CALL SDL_GetWindowSize(_sdl_window, &w, &h); + return CreateMainSurface(w, h); } void VideoDriver_SDL::AcquireBlitterLock() diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h index 8855c3566e9dd..6ce41ea866cfb 100644 --- a/src/video/sdl_v.h +++ b/src/video/sdl_v.h @@ -41,7 +41,6 @@ class VideoDriver_SDL : public VideoDriver { private: int PollEvent(); bool CreateMainSurface(uint w, uint h); - void SetupKeyboard(); }; /** Factory for the SDL video driver. */