From df9494e60c72ac9c2432a1b3f802d9238088b21a Mon Sep 17 00:00:00 2001 From: Amaryllis Kulla Date: Thu, 30 Oct 2025 23:10:51 +0100 Subject: [PATCH] Add Graphics#restore_window Requested by matias1lol. --- binding-mri/graphics-binding.cpp | 10 ++++++++++ doc/extension_doc.md | 4 ++++ src/eventthread.cpp | 12 ++++++++++++ src/eventthread.h | 1 + 4 files changed, 27 insertions(+) diff --git a/binding-mri/graphics-binding.cpp b/binding-mri/graphics-binding.cpp index bcb44b6..f924098 100644 --- a/binding-mri/graphics-binding.cpp +++ b/binding-mri/graphics-binding.cpp @@ -218,6 +218,15 @@ RB_METHOD(graphicsMaximizeWindow) return Qnil; } +RB_METHOD(graphicsRestoreWindow) +{ + RB_UNUSED_PARAM; + + shState->eThread().requestWindowRestore(); + + return Qnil; +} + DEF_GRA_PROP_I(FrameRate) DEF_GRA_PROP_I(FrameCount) DEF_GRA_PROP_I(Brightness) @@ -278,4 +287,5 @@ void graphicsBindingInit() _rb_define_module_function(module, "resize_window", graphicsResizeWindow); _rb_define_module_function(module, "maximize_window", graphicsMaximizeWindow); + _rb_define_module_function(module, "restore_window", graphicsRestoreWindow); } diff --git a/doc/extension_doc.md b/doc/extension_doc.md index 4c25f2f..ee8d32a 100644 --- a/doc/extension_doc.md +++ b/doc/extension_doc.md @@ -13,6 +13,10 @@ Resizes the game window to width x height. If `recenter` is **true**, also cente Maximizes the game window, ignoring the `winResizable` config option. +## Graphics.restore_window() + +Restores the game window from a maximized or minimized state. + ## Bitmap.write_to_png(filename) filename: String returns: self diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 8be64df..989c89a 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -81,6 +81,7 @@ enum REQUEST_SETFULLSCREEN = 0, REQUEST_WINRESIZE, REQUEST_WINMAXIMIZE, + REQUEST_WINRESTORE, REQUEST_MESSAGEBOX, REQUEST_SETCURSORVISIBLE, @@ -464,6 +465,10 @@ void EventThread::process(RGSSThreadData &rtData) SDL_MaximizeWindow(win); break; + case REQUEST_WINRESTORE : + SDL_RestoreWindow(win); + break; + case UPDATE_FPS : if (rtData.config.printFPS) Debug() << "FPS:" << event.user.code; @@ -634,6 +639,13 @@ void EventThread::requestWindowMaximize() SDL_PushEvent(&event); } +void EventThread::requestWindowRestore() +{ + SDL_Event event; + event.type = usrIdStart + REQUEST_WINRESTORE; + SDL_PushEvent(&event); +} + void EventThread::requestShowCursor(bool mode) { SDL_Event event; diff --git a/src/eventthread.h b/src/eventthread.h index 2352f79..88d3f98 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -90,6 +90,7 @@ public: void requestFullscreenMode(bool mode); void requestWindowResize(int width, int height, bool recenter = false); void requestWindowMaximize(); + void requestWindowRestore(); void requestShowCursor(bool mode); void requestTerminate();