X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backends/graphics/sdl/sdl-graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions backends/graphics/sdl/sdl-graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class SdlGraphicsManager : virtual public WindowedGraphicsManager, public Common
enum CustomEventAction {
kActionToggleFullscreen = 100,
kActionToggleMouseCapture,
kActionToggleResizableWindow,
kActionSaveScreenshot,
kActionToggleAspectRatioCorrection,
kActionToggleFilteredScaling,
Expand Down
37 changes: 26 additions & 11 deletions backends/platform/sdl/sdl-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions backends/platform/sdl/sdl-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class SdlWindow {
*/
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.
Expand Down Expand Up @@ -110,6 +117,15 @@ class SdlWindow {
*/
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) {
Expand All @@ -135,6 +151,7 @@ class SdlWindow {

private:
Common::Rect _desktopRes;
bool _resizable;
bool _inputGrabState, _inputLockState;
SDL_Rect grabRect;

Expand Down
Loading
X Tutup