remove source code support for SDL2

This commit is contained in:
Sasha Szpakowski
2024-10-18 20:22:26 -03:00
parent caca6196fc
commit 337d8fa048
38 changed files with 161 additions and 2419 deletions
+4 -307
View File
@@ -43,17 +43,8 @@
// C
#include <cstdio>
// SDL
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#include <SDL_syswm.h>
#endif
#ifdef LOVE_GRAPHICS_VULKAN
#if __has_include(<SDL3/SDL_vulkan.h>)
#include <SDL3/SDL_vulkan.h>
#else
#include <SDL_vulkan.h>
#endif
#endif
#if defined(LOVE_WINDOWS)
@@ -84,6 +75,7 @@ void setHighDPIAllowedImplementation(bool enable)
#if defined(LOVE_WINDOWS)
// Windows uses a different API than SDL_WINDOW_ALLOW_HIGHDPI.
// This must be set before the video subsystem is initialized.
// FIXME: How does this work in SDL3?
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, enable ? "1" : "0");
#else
LOVE_UNUSED(enable);
@@ -105,11 +97,7 @@ Window::Window()
, displayedWindowError(false)
, contextAttribs()
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_InitSubSystem(SDL_INIT_VIDEO))
#else
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
#endif
throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
// Make sure the screensaver doesn't activate by default.
@@ -118,11 +106,7 @@ Window::Window()
#ifdef LOVE_WINDOWS
// Turned off by default, because it (ironically) causes stuttering issues
// on some setups. More investigation is needed before enabling it.
#if SDL_VERSION_ATLEAST(3, 0, 0)
canUseDwmFlush = SDL_GetHintBoolean("LOVE_GRAPHICS_VSYNC_DWM", false);
#else
canUseDwmFlush = SDL_GetHintBoolean("LOVE_GRAPHICS_VSYNC_DWM", SDL_FALSE) != SDL_FALSE;
#endif
#endif
}
@@ -329,11 +313,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
{
if (glcontext)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GL_DestroyContext(glcontext);
#else
SDL_GL_DeleteContext(glcontext);
#endif
glcontext = nullptr;
}
@@ -348,19 +328,11 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
if (window)
{
SDL_DestroyWindow(window);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_FlushEvents(SDL_EVENT_WINDOW_FIRST, SDL_EVENT_WINDOW_LAST);
#else
SDL_FlushEvent(SDL_WINDOWEVENT);
#endif
window = nullptr;
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
window = SDL_CreateWindow(title.c_str(), w, h, windowflags);
#else
window = SDL_CreateWindow(title.c_str(), x, y, w, h, windowflags);
#endif
if (!window)
{
@@ -368,9 +340,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
return false;
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SetWindowPosition(window, x, y);
#endif
if (attribs != nullptr && renderer == love::graphics::Renderer::RENDERER_OPENGL)
{
@@ -386,11 +356,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
// Make sure the context's version is at least what we requested.
if (glcontext && !checkGLVersion(*attribs, glversion))
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GL_DestroyContext(glcontext);
#else
SDL_GL_DeleteContext(glcontext);
#endif
glcontext = nullptr;
}
@@ -494,7 +460,6 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
return true;
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
struct SDLDisplayIDs
{
SDLDisplayIDs()
@@ -519,7 +484,6 @@ static SDL_DisplayID GetSDLDisplayIDForIndex(int displayindex)
return (SDL_DisplayID) 0;
return displayids.ids[displayindex];
}
#endif
bool Window::setWindow(int width, int height, WindowSettings *settings)
{
@@ -542,28 +506,17 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
f.minwidth = std::max(f.minwidth, 1);
f.minheight = std::max(f.minheight, 1);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDLDisplayIDs displays;
int displaycount = displays.count;
#else
int displaycount = getDisplayCount();
#endif
f.displayindex = std::min(std::max(f.displayindex, 0), displaycount - 1);
// Use the desktop resolution if a width or height of 0 is specified.
if (width == 0 || height == 0)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(displays.ids[f.displayindex]);
width = mode->w;
height = mode->h;
#else
SDL_DisplayMode mode = {};
SDL_GetDesktopDisplayMode(f.displayindex, &mode);
width = mode.w;
height = mode.h;
#endif
}
// On Android, disable fullscreen first on window creation so it's
@@ -599,15 +552,10 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
}
Uint32 sdlflags = 0;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_DisplayMode fsmode = {};
#else
SDL_DisplayMode fsmode = {0, width, height, 0, nullptr};
#endif
if (f.fullscreen)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
sdlflags |= SDL_WINDOW_FULLSCREEN;
if (f.fstype == FULLSCREEN_EXCLUSIVE)
@@ -627,28 +575,6 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
return false;
}
}
#else
if (f.fstype == FULLSCREEN_EXCLUSIVE)
{
// Fullscreen window creation will bug out if no mode can be used.
if (SDL_GetClosestDisplayMode(f.displayindex, &fsmode, &fsmode) == nullptr)
{
// GetClosestDisplayMode will fail if we request a size larger
// than the largest available display mode, so we'll try to use
// the largest (first) mode in that case.
if (SDL_GetDisplayMode(f.displayindex, 0, &fsmode) < 0)
return false;
}
sdlflags |= SDL_WINDOW_FULLSCREEN;
width = fsmode.w;
height = fsmode.h;
}
else
{
sdlflags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
#endif
}
bool needsetmode = false;
@@ -658,34 +584,22 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
if (isOpen())
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (fsmode.w > 0 && fsmode.h > 0)
SDL_SetWindowFullscreenMode(window, &fsmode);
else
SDL_SetWindowFullscreenMode(window, nullptr);
if (SDL_SetWindowFullscreen(window, (sdlflags & SDL_WINDOW_FULLSCREEN) != 0) && renderer == graphics::RENDERER_OPENGL)
#else
if (f.fullscreen && f.fstype == FULLSCREEN_EXCLUSIVE)
SDL_SetWindowDisplayMode(window, &fsmode);
if (SDL_SetWindowFullscreen(window, sdlflags) == 0 && renderer == graphics::RENDERER_OPENGL)
#endif
SDL_GL_MakeCurrent(window, glcontext);
// TODO: should we make this conditional, to avoid love.resize events when the size doesn't change?
SDL_SetWindowSize(window, width, height);
if (this->settings.resizable != f.resizable)
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SetWindowResizable(window, f.resizable);
#else
SDL_SetWindowResizable(window, f.resizable ? SDL_TRUE : SDL_FALSE);
#endif
if (this->settings.borderless != f.borderless)
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SetWindowBordered(window, !f.borderless);
#else
SDL_SetWindowBordered(window, f.borderless ? SDL_FALSE : SDL_TRUE);
#endif
}
else
{
@@ -706,15 +620,9 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
sdlflags |= SDL_WINDOW_BORDERLESS;
// Note: this flag is ignored on Windows.
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (isHighDPIAllowed())
sdlflags |= SDL_WINDOW_HIGH_PIXEL_DENSITY;
#else
if (isHighDPIAllowed())
sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
#if SDL_VERSION_ATLEAST(3, 0, 0)
Uint32 createflags = sdlflags & (~SDL_WINDOW_FULLSCREEN);
if (!createWindowAndContext(x, y, width, height, createflags, renderer))
@@ -728,10 +636,6 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
SDL_SetWindowFullscreenMode(window, nullptr);
SDL_SetWindowFullscreen(window, true);
}
#else
if (!createWindowAndContext(x, y, width, height, sdlflags, renderer))
return false;
#endif
needsetmode = true;
}
@@ -771,6 +675,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
context = (void *) SDL_Metal_GetLayer(metalView);
#endif
// TODO: try/catch
graphics->setMode(context, (int) scaledw, (int) scaledh, pixelWidth, pixelHeight, f.stencil, f.depth, f.msaa);
}
else
@@ -788,9 +693,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
love::android::setImmersive(fullscreen);
#endif
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SyncWindow(window);
#endif
return true;
}
@@ -800,29 +703,9 @@ bool Window::onSizeChanged(int width, int height)
if (!window)
return false;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
#else
windowWidth = width;
windowHeight = height;
#endif
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight))
#else
// TODO: Use SDL_GetWindowSizeInPixels here when supported.
if (glcontext != nullptr)
SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#ifdef LOVE_GRAPHICS_METAL
else if (metalView != nullptr)
SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif
#ifdef LOVE_GRAPHICS_VULKAN
else if (windowRenderer == graphics::RENDERER_VULKAN)
SDL_Vulkan_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif
else
#endif
{
pixelWidth = width;
pixelHeight = height;
@@ -840,9 +723,7 @@ bool Window::onSizeChanged(int width, int height)
void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SyncWindow(window);
#endif
Uint32 wflags = SDL_GetWindowFlags(window);
@@ -852,27 +733,9 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
pixelWidth = windowWidth;
pixelHeight = windowHeight;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
#else
// TODO: Use SDL_GetWindowSizeInPixels here when supported.
if ((wflags & SDL_WINDOW_OPENGL) != 0)
SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#ifdef LOVE_GRAPHICS_METAL
else if ((wflags & SDL_WINDOW_METAL) != 0)
SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif
#ifdef LOVE_GRAPHICS_VULKAN
else if ((wflags & SDL_WINDOW_VULKAN) != 0)
SDL_Vulkan_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif
#endif
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (((wflags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) && SDL_GetWindowFullscreenMode(window) == nullptr)
#else
if ((wflags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
#endif
{
settings.fullscreen = true;
settings.fstype = FULLSCREEN_DESKTOP;
@@ -902,11 +765,7 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
getPosition(settings.x, settings.y, settings.displayindex);
#if SDL_VERSION_ATLEAST(3, 0, 0)
setHighDPIAllowed((wflags & SDL_WINDOW_HIGH_PIXEL_DENSITY) != 0);
#else
setHighDPIAllowed((wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0);
#endif
settings.usedpiscale = newsettings.usedpiscale;
@@ -921,19 +780,11 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
settings.stencil = newsettings.stencil;
settings.depth = newsettings.depth;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDLDisplayIDs displayids;
const SDL_DisplayMode *dmode = SDL_GetCurrentDisplayMode(displayids.ids[settings.displayindex]);
// May be 0 if the refresh rate can't be determined.
settings.refreshrate = dmode->refresh_rate;
#else
SDL_DisplayMode dmode = {};
SDL_GetCurrentDisplayMode(settings.displayindex, &dmode);
// May be 0 if the refresh rate can't be determined.
settings.refreshrate = (double) dmode.refresh_rate;
#endif
// Update the viewport size now instead of waiting for event polling.
if (updateGraphicsViewport && graphics.get())
@@ -972,11 +823,7 @@ void Window::close(bool allowExceptions)
if (glcontext)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GL_DestroyContext(glcontext);
#else
SDL_GL_DeleteContext(glcontext);
#endif
glcontext = nullptr;
}
@@ -995,11 +842,7 @@ void Window::close(bool allowExceptions)
// The old window may have generated pending events which are no longer
// relevant. Destroy them all!
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_FlushEvents(SDL_EVENT_WINDOW_FIRST, SDL_EVENT_WINDOW_LAST);
#else
SDL_FlushEvent(SDL_WINDOWEVENT);
#endif
}
open = false;
@@ -1017,7 +860,6 @@ bool Window::setFullscreen(bool fullscreen, FullscreenType fstype)
newsettings.fullscreen = fullscreen;
newsettings.fstype = fstype;
#if SDL_VERSION_ATLEAST(3, 0, 0)
bool sdlflags = fullscreen;
if (fullscreen)
{
@@ -1031,36 +873,12 @@ bool Window::setFullscreen(bool fullscreen, FullscreenType fstype)
SDL_SetWindowFullscreenMode(window, &mode);
}
}
#else
Uint32 sdlflags = 0;
if (fullscreen)
{
if (fstype == FULLSCREEN_DESKTOP)
sdlflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
else
{
sdlflags = SDL_WINDOW_FULLSCREEN;
SDL_DisplayMode mode = {};
mode.w = windowWidth;
mode.h = windowHeight;
SDL_GetClosestDisplayMode(SDL_GetWindowDisplayIndex(window), &mode, &mode);
SDL_SetWindowDisplayMode(window, &mode);
}
}
#endif
#ifdef LOVE_ANDROID
love::android::setImmersive(fullscreen);
#endif
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (SDL_SetWindowFullscreen(window, sdlflags))
#else
if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
#endif
{
if (glcontext)
SDL_GL_MakeCurrent(window, glcontext);
@@ -1079,21 +897,13 @@ bool Window::setFullscreen(bool fullscreen)
int Window::getDisplayCount() const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDLDisplayIDs displayids;
return displayids.count;
#else
return SDL_GetNumVideoDisplays();
#endif
}
const char *Window::getDisplayName(int displayindex) const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
const char *name = SDL_GetDisplayName(GetSDLDisplayIDForIndex(displayindex));
#else
const char *name = SDL_GetDisplayName(displayindex);
#endif
if (name == nullptr)
throw love::Exception("Invalid display index: %d", displayindex + 1);
@@ -1103,11 +913,7 @@ const char *Window::getDisplayName(int displayindex) const
Window::DisplayOrientation Window::getDisplayOrientation(int displayindex) const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
switch (SDL_GetCurrentDisplayOrientation(GetSDLDisplayIDForIndex(displayindex)))
#else
switch (SDL_GetDisplayOrientation(displayindex))
#endif
{
case SDL_ORIENTATION_UNKNOWN: return ORIENTATION_UNKNOWN;
case SDL_ORIENTATION_LANDSCAPE: return ORIENTATION_LANDSCAPE;
@@ -1123,7 +929,6 @@ std::vector<Window::WindowSize> Window::getFullscreenSizes(int displayindex) con
{
std::vector<WindowSize> sizes;
#if SDL_VERSION_ATLEAST(3, 0, 0)
int count = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(GetSDLDisplayIDForIndex(displayindex), &count);
@@ -1131,14 +936,6 @@ std::vector<Window::WindowSize> Window::getFullscreenSizes(int displayindex) con
{
// TODO: other mode properties?
WindowSize w = {modes[i]->w, modes[i]->h};
#else
for (int i = 0; i < SDL_GetNumDisplayModes(displayindex); i++)
{
SDL_DisplayMode mode = {};
SDL_GetDisplayMode(displayindex, i, &mode);
WindowSize w = {mode.w, mode.h};
#endif
// SDL2's display mode list has multiple entries for modes of the same
// size with different bits per pixel, so we need to filter those out.
@@ -1146,16 +943,13 @@ std::vector<Window::WindowSize> Window::getFullscreenSizes(int displayindex) con
sizes.push_back(w);
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_free(modes);
#endif
return sizes;
}
void Window::getDesktopDimensions(int displayindex, int &width, int &height) const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(GetSDLDisplayIDForIndex(displayindex));
if (mode != nullptr)
{
@@ -1163,15 +957,6 @@ void Window::getDesktopDimensions(int displayindex, int &width, int &height) con
width = mode->w;
height = mode->h;
}
#else
if (displayindex >= 0 && displayindex < getDisplayCount())
{
SDL_DisplayMode mode = {};
SDL_GetDesktopDisplayMode(displayindex, &mode);
width = mode.w;
height = mode.h;
}
#endif
else
{
width = 0;
@@ -1194,10 +979,7 @@ void Window::setPosition(int x, int y, int displayindex)
y += displaybounds.y;
SDL_SetWindowPosition(window, x, y);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SyncWindow(window);
#endif
settings.useposition = true;
}
@@ -1211,7 +993,6 @@ void Window::getPosition(int &x, int &y, int &displayindex)
return;
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_DisplayID displayid = SDL_GetDisplayForWindow(window);
SDLDisplayIDs displayids;
displayindex = 0;
@@ -1223,9 +1004,6 @@ void Window::getPosition(int &x, int &y, int &displayindex)
break;
}
}
#else
displayindex = std::max(SDL_GetWindowDisplayIndex(window), 0);
#endif
SDL_GetWindowPosition(window, &x, &y);
@@ -1235,11 +1013,7 @@ void Window::getPosition(int &x, int &y, int &displayindex)
if (x != 0 || y != 0)
{
SDL_Rect displaybounds = {};
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_GetDisplayBounds(displayid, &displaybounds);
#else
SDL_GetDisplayBounds(displayindex, &displaybounds);
#endif
x -= displaybounds.x;
y -= displaybounds.y;
@@ -1304,41 +1078,18 @@ bool Window::setIcon(love::image::ImageData *imgd)
if (!window)
return false;
#if !SDL_VERSION_ATLEAST(3, 0, 0)
Uint32 rmask, gmask, bmask, amask;
#ifdef LOVE_BIG_ENDIAN
rmask = 0xFF000000;
gmask = 0x00FF0000;
bmask = 0x0000FF00;
amask = 0x000000FF;
#else
rmask = 0x000000FF;
gmask = 0x0000FF00;
bmask = 0x00FF0000;
amask = 0xFF000000;
#endif
#endif
int w = imgd->getWidth();
int h = imgd->getHeight();
int bytesperpixel = (int) getPixelFormatBlockSize(imgd->getFormat());
int pitch = w * bytesperpixel;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_Surface *sdlicon = SDL_CreateSurfaceFrom(w, h, SDL_PIXELFORMAT_RGBA8888, imgd->getData(), pitch);
#else
SDL_Surface *sdlicon = SDL_CreateRGBSurfaceFrom(imgd->getData(), w, h, bytesperpixel * 8, pitch, rmask, gmask, bmask, amask);
#endif
if (!sdlicon)
return false;
SDL_SetWindowIcon(window, sdlicon);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_DestroySurface(sdlicon);
#else
SDL_FreeSurface(sdlicon);
#endif
return true;
}
@@ -1356,7 +1107,6 @@ void Window::setVSync(int vsync)
// Check if adaptive vsync was requested but not supported, and fall
// back to regular vsync if so.
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (vsync == -1)
{
int actualvsync = 0;
@@ -1364,10 +1114,6 @@ void Window::setVSync(int vsync)
if (actualvsync != -1)
SDL_GL_SetSwapInterval(1);
}
#else
if (vsync == -1 && SDL_GL_GetSwapInterval() != -1)
SDL_GL_SetSwapInterval(1);
#endif
}
#ifdef LOVE_GRAPHICS_VULKAN
@@ -1391,13 +1137,9 @@ int Window::getVSync() const
{
if (glcontext != nullptr)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
int interval = 0;
SDL_GL_GetSwapInterval(&interval);
return interval;
#else
return SDL_GL_GetSwapInterval();
#endif
}
#if defined(LOVE_GRAPHICS_METAL)
@@ -1433,11 +1175,7 @@ void Window::setDisplaySleepEnabled(bool enable)
bool Window::isDisplaySleepEnabled() const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
return SDL_ScreenSaverEnabled();
#else
return SDL_IsScreenSaverEnabled() != SDL_FALSE;
#endif
}
void Window::minimize()
@@ -1515,27 +1253,16 @@ void Window::swapBuffers()
dwmRefreshRate = (double)info.rateRefresh.uiNumerator / (double)info.rateRefresh.uiDenominator;
SDL_DisplayMode dmode = {};
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_DisplayID display = SDL_GetDisplayForWindow(window);
const SDL_DisplayMode* modePtr = SDL_GetCurrentDisplayMode(display);
if (modePtr)
dmode = *modePtr;
#else
int displayindex = SDL_GetWindowDisplayIndex(window);
if (displayindex >= 0)
SDL_GetCurrentDisplayMode(displayindex, &dmode);
#endif
if (dmode.refresh_rate > 0 && dwmRefreshRate > 0 && (fabs(dmode.refresh_rate - dwmRefreshRate) < 2))
{
SDL_GL_SetSwapInterval(0);
#if SDL_VERSION_ATLEAST(3, 0, 0)
int interval = 0;
if (SDL_GL_GetSwapInterval(&interval) == 0 && interval == 0)
#else
if (SDL_GL_GetSwapInterval() == 0)
#endif
useDwmFlush = true;
else
SDL_GL_SetSwapInterval(swapInterval);
@@ -1568,32 +1295,20 @@ bool Window::hasMouseFocus() const
bool Window::isVisible() const
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
return window && (SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN) == 0;
#else
return window && (SDL_GetWindowFlags(window) & SDL_WINDOW_SHOWN) != 0;
#endif
}
void Window::setMouseGrab(bool grab)
{
mouseGrabbed = grab;
if (window)
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SetWindowMouseGrab(window, grab);
#else
SDL_SetWindowGrab(window, (SDL_bool) grab);
#endif
}
bool Window::isMouseGrabbed() const
{
if (window)
#if SDL_VERSION_ATLEAST(3, 0, 0)
return SDL_GetWindowMouseGrab(window);
#else
return SDL_GetWindowGrab(window) != SDL_FALSE;
#endif
else
return mouseGrabbed;
}
@@ -1739,11 +1454,7 @@ bool Window::showMessageBox(const std::string &title, const std::string &message
SDL_MessageBoxFlags flags = convertMessageBoxType(type);
SDL_Window *sdlwindow = attachtowindow ? window : nullptr;
#if SDL_VERSION_ATLEAST(3, 0, 0)
return SDL_ShowSimpleMessageBox(flags, title.c_str(), message.c_str(), sdlwindow);
#else
return SDL_ShowSimpleMessageBox(flags, title.c_str(), message.c_str(), sdlwindow) >= 0;
#endif
}
int Window::showMessageBox(const MessageBoxData &data)
@@ -1763,11 +1474,7 @@ int Window::showMessageBox(const MessageBoxData &data)
{
SDL_MessageBoxButtonData sdlbutton = {};
#if SDL_VERSION_ATLEAST(3, 0, 0)
sdlbutton.buttonID = i;
#else
sdlbutton.buttonid = i;
#endif
sdlbutton.text = data.buttons[i].c_str();
if (i == data.enterButtonIndex)
@@ -1796,17 +1503,7 @@ void Window::requestAttention(bool continuous)
FLASHWINFO flashinfo = { sizeof(FLASHWINFO) };
#if SDL_VERSION_ATLEAST(3, 0, 0)
flashinfo.hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
#else
SDL_SysWMinfo wminfo = {};
SDL_VERSION(&wminfo.version);
if (!SDL_GetWindowWMInfo(window, &wminfo))
return;
flashinfo.hwnd = wminfo.info.win.window;
#endif
flashinfo.uCount = 1;
flashinfo.dwFlags = FLASHW_ALL;
-4
View File
@@ -27,11 +27,7 @@
#include "graphics/Graphics.h"
// SDL
#if __has_include(<SDL3/SDL.h>)
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
namespace love
{