[Scummvm-git-logs] scummvm master -> 93d95047984d5a991cf4f4d62f67a8d4d8364973
bluegr
noreply at scummvm.org
Sat Feb 22 23:10:07 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
93d9504798 BACKENDS: SDL: Let the user prevent resizing of the window
Commit: 93d95047984d5a991cf4f4d62f67a8d4d8364973
https://github.com/scummvm/scummvm/commit/93d95047984d5a991cf4f4d62f67a8d4d8364973
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2025-02-23T01:10:03+02:00
Commit Message:
BACKENDS: SDL: Let the user prevent resizing of the window
This adds a new shortcut (Ctrl+R) which toggles the resizable state of
the window and allows the user to lock the window size and prevents
resizing.
Closes bug:15124.
Changed paths:
backends/graphics/sdl/sdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.h
backends/platform/sdl/sdl-window.cpp
backends/platform/sdl/sdl-window.h
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index acf84aaf91b..f82d5a52716 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -483,6 +483,10 @@ bool SdlGraphicsManager::notifyEvent(const Common::Event &event) {
getWindow()->grabMouse(!getWindow()->mouseIsGrabbed());
return true;
+ case kActionToggleResizableWindow:
+ getWindow()->setResizable(!getWindow()->resizable());
+ return true;
+
case kActionToggleFullscreen:
toggleFullScreen();
return true;
@@ -538,6 +542,11 @@ Common::Keymap *SdlGraphicsManager::getKeymap() {
act->setCustomBackendActionEvent(kActionToggleMouseCapture);
keymap->addAction(act);
+ act = new Action("RSZW", _("Toggle resizable window"));
+ act->addDefaultInputMapping("C+r");
+ act->setCustomBackendActionEvent(kActionToggleResizableWindow);
+ keymap->addAction(act);
+
act = new Action("SCRS", _("Save screenshot"));
act->addDefaultInputMapping("A+s");
act->setCustomBackendActionEvent(kActionSaveScreenshot);
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 8225b2d4046..591b3df6640 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -141,6 +141,7 @@ protected:
enum CustomEventAction {
kActionToggleFullscreen = 100,
kActionToggleMouseCapture,
+ kActionToggleResizableWindow,
kActionSaveScreenshot,
kActionToggleAspectRatioCorrection,
kActionToggleFilteredScaling,
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 16efad4d9a8..1509fd126d4 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -40,7 +40,8 @@ SdlWindow::SdlWindow() :
_window(nullptr), _windowCaption("ScummVM"),
_lastFlags(0), _lastX(SDL_WINDOWPOS_UNDEFINED), _lastY(SDL_WINDOWPOS_UNDEFINED),
#endif
- _inputGrabState(false), _inputLockState(false)
+ _inputGrabState(false), _inputLockState(false),
+ _resizable(true)
{
memset(&grabRect, 0, sizeof(grabRect));
@@ -161,6 +162,15 @@ void SdlWindow::setWindowCaption(const Common::String &caption) {
#endif
}
+void SdlWindow::setResizable(bool resizable) {
+#if SDL_VERSION_ATLEAST(2, 0, 5)
+ if (_window) {
+ SDL_SetWindowResizable(_window, resizable ? SDL_TRUE : SDL_FALSE);
+ }
+#endif
+ _resizable = resizable;
+}
+
void SdlWindow::grabMouse(bool grab) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
@@ -413,17 +423,18 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
}
#endif
- // SDL_WINDOW_RESIZABLE can also be updated without recreating the window
- // starting with SDL 2.0.5, but it is not treated as updateable here
- // because:
- // 1. It is currently only changed in conjunction with the SDL_WINDOW_OPENGL
- // flag, so the window will always be recreated anyway when changing
- // resizability; and
- // 2. Users (particularly on Windows) will sometimes swap older SDL DLLs
- // to avoid bugs, which would be impossible if the feature was enabled
- // at compile time using SDL_VERSION_ATLEAST.
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_resizable) {
+ flags |= SDL_WINDOW_RESIZABLE;
+ }
+#endif
+
#if SDL_VERSION_ATLEAST(3, 0, 0)
- const uint32 updateableFlagsMask = fullscreenMask | SDL_WINDOW_MOUSE_GRABBED;
+ const uint32 updateableFlagsMask = fullscreenMask | SDL_WINDOW_MOUSE_GRABBED | SDL_WINDOW_RESIZABLE;
+#elif SDL_VERSION_ATLEAST(2, 0, 5)
+ // SDL_WINDOW_RESIZABLE can be updated without recreating the window starting with SDL 2.0.5
+ // Even though some users may switch the SDL version when it's linked dynamically, 2.0.5 is now getting quite old
+ const uint32 updateableFlagsMask = fullscreenMask | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_RESIZABLE;
#else
const uint32 updateableFlagsMask = fullscreenMask | SDL_WINDOW_INPUT_GRABBED;
#endif
@@ -527,6 +538,10 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
SDL_SetWindowMouseRect(_window, shouldGrab ? &grabRect : NULL);
#endif
+#if SDL_VERSION_ATLEAST(2, 0, 5)
+ SDL_SetWindowResizable(_window, _resizable ? SDL_TRUE : SDL_FALSE);
+#endif
+
if (!_window) {
return false;
}
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index 1aabe99df90..87ff992a5ce 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -44,6 +44,13 @@ public:
*/
void setWindowCaption(const Common::String &caption);
+ /**
+ * Allows the window to be resized or not
+ *
+ * @param resizable Whether the window can be resizable or not.
+ */
+ void setResizable(bool resizable);
+
/**
* Grab or ungrab the mouse cursor. This decides whether the cursor can leave
* the window or not.
@@ -110,6 +117,15 @@ public:
*/
virtual float getDpiScalingFactor() const;
+ bool resizable() const {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ return SDL_GetWindowFlags(_window) & SDL_WINDOW_RESIZABLE;
+ }
+#endif
+ return _resizable;
+ }
+
bool mouseIsGrabbed() const {
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (_window) {
@@ -135,6 +151,7 @@ public:
private:
Common::Rect _desktopRes;
+ bool _resizable;
bool _inputGrabState, _inputLockState;
SDL_Rect grabRect;
More information about the Scummvm-git-logs
mailing list