]> git.lizzy.rs Git - irrlicht.git/commitdiff
Add WindowMaximized creation parameter and isWindowMaximized() (#142)
authorDS <vorunbekannt75@web.de>
Mon, 6 Feb 2023 14:05:44 +0000 (15:05 +0100)
committerGitHub <noreply@github.com>
Mon, 6 Feb 2023 14:05:44 +0000 (15:05 +0100)
include/IrrlichtDevice.h
include/SIrrCreationParameters.h
source/Irrlicht/CIrrDeviceLinux.cpp
source/Irrlicht/CIrrDeviceLinux.h
source/Irrlicht/CIrrDeviceSDL.cpp
source/Irrlicht/CIrrDeviceSDL.h
source/Irrlicht/CIrrDeviceStub.cpp
source/Irrlicht/CIrrDeviceStub.h
source/Irrlicht/CIrrDeviceWin32.cpp
source/Irrlicht/CIrrDeviceWin32.h

index 43107eb5d1cdadcf6cb4ca0e0df0b4475f9640b1..b967d70bf9efd44091345a02030e4b6afb9fb0dd 100644 (file)
@@ -156,6 +156,12 @@ namespace irr
                /** \return True if window is minimized. */\r
                virtual bool isWindowMinimized() const = 0;\r
 \r
+               //! Checks if the Irrlicht window is maximized\r
+               //! Only fully works on SDL. Returns false, or the last value set via\r
+               //! maximizeWindow() and restoreWindow(), on other backends.\r
+               /** \return True if window is maximized. */\r
+               virtual bool isWindowMaximized() const = 0;\r
+\r
                //! Checks if the Irrlicht window is running in fullscreen mode\r
                /** \return True if window is fullscreen. */\r
                virtual bool isFullscreen() const = 0;\r
index 66165732b1b700503a1f8e66758a017687f44cc0..f99fce58d6b19facd51b456344a23b49e98b908e 100644 (file)
@@ -30,6 +30,7 @@ namespace irr
                        Bits(32),\r
                        ZBufferBits(24),\r
                        Fullscreen(false),\r
+                       WindowMaximized(false),\r
                        WindowResizable(2),\r
                        Stencilbuffer(true),\r
                        Vsync(false),\r
@@ -73,6 +74,7 @@ namespace irr
                        Bits = other.Bits;\r
                        ZBufferBits = other.ZBufferBits;\r
                        Fullscreen = other.Fullscreen;\r
+                       WindowMaximized = other.WindowMaximized;\r
                        WindowResizable = other.WindowResizable;\r
                        Stencilbuffer = other.Stencilbuffer;\r
                        Vsync = other.Vsync;\r
@@ -127,6 +129,9 @@ namespace irr
                /** Otherwise the device runs in windowed mode. Default: false. */\r
                bool Fullscreen;\r
 \r
+               //! Maximised window. (Only supported on SDL.) Default: false\r
+               bool WindowMaximized;\r
+\r
                //! Should a non-fullscreen window be resizable.\r
                /** Might not be supported by all devices. Ignored when Fullscreen is true.\r
                Values: 0 = not resizable, 1 = resizable, 2 = system decides default itself\r
index 91d1e4700b0602dabd222a1596574cc47712cc5b..b447015bcac4d8978f3a6af847d657b80649006c 100644 (file)
@@ -118,7 +118,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
        currentTouchedCount(0),\r
 #endif\r
        Width(param.WindowSize.Width), Height(param.WindowSize.Height),\r
-       WindowHasFocus(false), WindowMinimized(false),\r
+       WindowHasFocus(false), WindowMinimized(false), WindowMaximized(param.WindowMaximized),\r
        ExternalWindow(false), AutorepeatSupport(0)\r
 {\r
        #ifdef _DEBUG\r
@@ -168,6 +168,9 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
                return;\r
 \r
        createGUIAndScene();\r
+\r
+       if (param.WindowMaximized)\r
+               maximizeWindow();\r
 }\r
 \r
 \r
@@ -1200,6 +1203,13 @@ bool CIrrDeviceLinux::isWindowMinimized() const
 }\r
 \r
 \r
+//! returns last state from maximizeWindow() and restoreWindow()\r
+bool CIrrDeviceLinux::isWindowMaximized() const\r
+{\r
+       return WindowMaximized;\r
+}\r
+\r
+\r
 //! returns color format of the window.\r
 video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const\r
 {\r
@@ -1284,6 +1294,8 @@ void CIrrDeviceLinux::maximizeWindow()
        }\r
 \r
        XMapWindow(XDisplay, XWindow);\r
+\r
+       WindowMaximized = true;\r
 #endif\r
 }\r
 \r
@@ -1310,6 +1322,8 @@ void CIrrDeviceLinux::restoreWindow()
        }\r
 \r
        XMapWindow(XDisplay, XWindow);\r
+\r
+       WindowMaximized = false;\r
 #endif\r
 }\r
 \r
index fe1ede035f57506c9bd9ed38e762f8b296cb94fe..c456a1a7954fff41608313ad5abb8f9566ab017a 100644 (file)
@@ -64,6 +64,9 @@ namespace irr
                //! returns if window is minimized.\r
                bool isWindowMinimized() const override;\r
 \r
+               //! returns last state from maximizeWindow() and restoreWindow()\r
+               bool isWindowMaximized() const override;\r
+\r
                //! returns color format of the window.\r
                video::ECOLOR_FORMAT getColorFormat() const override;\r
 \r
@@ -415,6 +418,7 @@ namespace irr
                u32 Width, Height;\r
                bool WindowHasFocus;\r
                bool WindowMinimized;\r
+               bool WindowMaximized;\r
                bool ExternalWindow;\r
                int AutorepeatSupport;\r
 \r
index 8452c6b9cfe4903edfbbfd312163ee70230958eb..83c763c61d91a3260b85e98110ca0a0034103c81 100644 (file)
@@ -111,7 +111,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
        Window((SDL_Window*)param.WindowId), SDL_Flags(0),\r
        MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),\r
        Width(param.WindowSize.Width), Height(param.WindowSize.Height),\r
-       Resizable(param.WindowResizable == 1 ? true : false), WindowMinimized(false)\r
+       Resizable(param.WindowResizable == 1 ? true : false)\r
 {\r
        #ifdef _DEBUG\r
        setDebugName("CIrrDeviceSDL");\r
@@ -139,10 +139,14 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
        // create keymap\r
        createKeyMap();\r
 \r
-       if ( CreationParams.Fullscreen )\r
+       if (CreationParams.Fullscreen) {\r
                SDL_Flags |= SDL_WINDOW_FULLSCREEN;\r
-       else if ( Resizable )\r
-               SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
+       } else  {\r
+               if (Resizable)\r
+                       SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
+               if (CreationParams.WindowMaximized)\r
+                       SDL_Flags |= SDL_WINDOW_MAXIMIZED;\r
+       }\r
        if (CreationParams.DriverType == video::EDT_OPENGL)\r
        {\r
                SDL_Flags |= SDL_WINDOW_OPENGL;\r
@@ -160,6 +164,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
                createWindow();\r
        }\r
 \r
+\r
        SDL_VERSION(&Info.version);\r
 \r
 #ifndef _IRR_EMSCRIPTEN_PLATFORM_\r
@@ -636,12 +641,6 @@ bool CIrrDeviceSDL::run()
                case SDL_WINDOWEVENT:\r
                        switch (SDL_event.window.event)\r
                        {\r
-                       case SDL_WINDOWEVENT_MAXIMIZED:\r
-                               WindowMinimized = true;\r
-                               break;\r
-                       case SDL_WINDOWEVENT_RESTORED:\r
-                               WindowMinimized = false;\r
-                               break;\r
                        case SDL_WINDOWEVENT_RESIZED:\r
                                if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height))\r
                                {\r
@@ -862,16 +861,16 @@ void CIrrDeviceSDL::setResizable(bool resize)
 //! Minimizes window if possible\r
 void CIrrDeviceSDL::minimizeWindow()\r
 {\r
-       if (Window) {\r
+       if (Window)\r
                SDL_MinimizeWindow(Window);\r
-       }\r
 }\r
 \r
 \r
 //! Maximize window\r
 void CIrrDeviceSDL::maximizeWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_MaximizeWindow(Window);\r
 }\r
 \r
 //! Get the position of this window on screen\r
@@ -884,7 +883,13 @@ core::position2di CIrrDeviceSDL::getWindowPosition()
 //! Restore original window size\r
 void CIrrDeviceSDL::restoreWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_RestoreWindow(Window);\r
+}\r
+\r
+bool CIrrDeviceSDL::isWindowMaximized() const\r
+{\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0;\r
 }\r
 \r
 bool CIrrDeviceSDL::isFullscreen() const\r
@@ -919,14 +924,14 @@ bool CIrrDeviceSDL::isWindowActive() const
 //! returns if window has focus.\r
 bool CIrrDeviceSDL::isWindowFocused() const\r
 {\r
-       return SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0;\r
 }\r
 \r
 \r
 //! returns if window is minimized.\r
 bool CIrrDeviceSDL::isWindowMinimized() const\r
 {\r
-       return WindowMinimized;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0;\r
 }\r
 \r
 \r
index 5a38d774337ef0f4d2a6ec1ef3fee4c011b2720b..299271823d1d4dc177ecc848cd758ce873375af7 100644 (file)
@@ -76,6 +76,9 @@ namespace irr
                //! Restores the window size.\r
                void restoreWindow() override;\r
 \r
+               //! Checks if the window is maximized.\r
+               bool isWindowMaximized() const override;\r
+\r
                //! Checks if the Irrlicht window is running in fullscreen mode\r
                /** \return True if window is fullscreen. */\r
                bool isFullscreen() const override;\r
@@ -283,7 +286,6 @@ namespace irr
                u32 Width, Height;\r
 \r
                bool Resizable;\r
-               bool WindowMinimized;\r
 \r
                struct SKeyMap\r
                {\r
index 95e7c5d144053db0ee41a952aab2af5dc92ca847..877a4bf34ffff7a257fc68915e380005bd99fa26 100644 (file)
@@ -272,6 +272,13 @@ void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneMa
 }\r
 \r
 \r
+//! Checks if the window is maximized.\r
+bool CIrrDeviceStub::isWindowMaximized() const\r
+{\r
+       return false;\r
+}\r
+\r
+\r
 //! Checks if the window is running in fullscreen mode\r
 bool CIrrDeviceStub::isFullscreen() const\r
 {\r
index c6e005935cddd5d1f4716151949b6aee22f3ac5c..5b7d92ff589b234f43391a1831cabebd8b824fc6 100644 (file)
@@ -94,6 +94,9 @@ namespace irr
                //! Returns the operation system opertator object.\r
                IOSOperator* getOSOperator() override;\r
 \r
+               //! Checks if the window is maximized.\r
+               bool isWindowMaximized() const override;\r
+\r
                //! Checks if the window is running in fullscreen mode.\r
                bool isFullscreen() const override;\r
 \r
@@ -103,41 +106,41 @@ namespace irr
                //! Activate any joysticks, and generate events for them.\r
                bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo) override;\r
 \r
-        //! Activate accelerometer.\r
-        bool activateAccelerometer(float updateInterval = 0.016666f) override;\r
-        \r
-        //! Deactivate accelerometer.\r
-        bool deactivateAccelerometer() override;\r
-        \r
-        //! Is accelerometer active.\r
-        bool isAccelerometerActive() override;\r
-        \r
-        //! Is accelerometer available.\r
-        bool isAccelerometerAvailable() override;\r
-        \r
-        //! Activate gyroscope.\r
-        bool activateGyroscope(float updateInterval = 0.016666f) override;\r
-        \r
-        //! Deactivate gyroscope.\r
-        bool deactivateGyroscope() override;\r
-        \r
-        //! Is gyroscope active.\r
-        bool isGyroscopeActive() override;\r
-        \r
-        //! Is gyroscope available.\r
-        bool isGyroscopeAvailable() override;\r
-        \r
-        //! Activate device motion.\r
-        bool activateDeviceMotion(float updateInterval = 0.016666f) override;\r
-        \r
-        //! Deactivate device motion.\r
-        bool deactivateDeviceMotion() override;\r
-        \r
-        //! Is device motion active.\r
-        bool isDeviceMotionActive() override;\r
-        \r
-        //! Is device motion available.\r
-        bool isDeviceMotionAvailable() override;\r
+               //! Activate accelerometer.\r
+               bool activateAccelerometer(float updateInterval = 0.016666f) override;\r
+\r
+               //! Deactivate accelerometer.\r
+               bool deactivateAccelerometer() override;\r
+\r
+               //! Is accelerometer active.\r
+               bool isAccelerometerActive() override;\r
+\r
+               //! Is accelerometer available.\r
+               bool isAccelerometerAvailable() override;\r
+\r
+               //! Activate gyroscope.\r
+               bool activateGyroscope(float updateInterval = 0.016666f) override;\r
+\r
+               //! Deactivate gyroscope.\r
+               bool deactivateGyroscope() override;\r
+\r
+               //! Is gyroscope active.\r
+               bool isGyroscopeActive() override;\r
+\r
+               //! Is gyroscope available.\r
+               bool isGyroscopeAvailable() override;\r
+\r
+               //! Activate device motion.\r
+               bool activateDeviceMotion(float updateInterval = 0.016666f) override;\r
+\r
+               //! Deactivate device motion.\r
+               bool deactivateDeviceMotion() override;\r
+\r
+               //! Is device motion active.\r
+               bool isDeviceMotionActive() override;\r
+\r
+               //! Is device motion available.\r
+               bool isDeviceMotionAvailable() override;\r
 \r
                //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.\r
                //! When set to 0 no double- and tripleclicks will be generated.\r
index 0c513040c0038f12cfde67c218323067a5cf7bf7..ddff014b3ce1cd82afd40e633b9709be206fe865 100644 (file)
@@ -784,7 +784,8 @@ namespace irr
 //! constructor\r
 CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)\r
 : CIrrDeviceStub(params), HWnd(0), Resized(false),\r
-       ExternalWindow(false), Win32CursorControl(0), JoyControl(0)\r
+       ExternalWindow(false), Win32CursorControl(0), JoyControl(0),\r
+       WindowMaximized(params.WindowMaximized)\r
 {\r
        #ifdef _DEBUG\r
        setDebugName("CIrrDeviceWin32");\r
@@ -923,6 +924,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
 \r
        // inform driver about the window size etc.\r
        resizeIfNecessary();\r
+\r
+       if (params.WindowMaximized)\r
+               maximizeWindow();\r
 }\r
 \r
 \r
@@ -1154,6 +1158,13 @@ bool CIrrDeviceWin32::isWindowMinimized() const
 }\r
 \r
 \r
+//! returns last state from maximizeWindow() and restoreWindow()\r
+bool CIrrDeviceWin32::isWindowMaximized() const\r
+{\r
+       return WindowMaximized;\r
+}\r
+\r
+\r
 //! switches to fullscreen\r
 bool CIrrDeviceWin32::switchToFullScreen()\r
 {\r
@@ -1278,6 +1289,8 @@ void CIrrDeviceWin32::maximizeWindow()
        GetWindowPlacement(HWnd, &wndpl);\r
        wndpl.showCmd = SW_SHOWMAXIMIZED;\r
        SetWindowPlacement(HWnd, &wndpl);\r
+\r
+       WindowMaximized = true;\r
 }\r
 \r
 \r
@@ -1289,6 +1302,8 @@ void CIrrDeviceWin32::restoreWindow()
        GetWindowPlacement(HWnd, &wndpl);\r
        wndpl.showCmd = SW_SHOWNORMAL;\r
        SetWindowPlacement(HWnd, &wndpl);\r
+\r
+       WindowMaximized = false;\r
 }\r
 \r
 core::position2di CIrrDeviceWin32::getWindowPosition()\r
index 8cd324bc16b6ae2a0b1d634d61009937d34ec5a0..4af8d02773ec1e470c6d2470ea0fd2193c71fe01 100644 (file)
@@ -57,6 +57,9 @@ namespace irr
                //! returns if window is minimized\r
                bool isWindowMinimized() const override;\r
 \r
+               //! returns last state from maximizeWindow() and restoreWindow()\r
+               bool isWindowMaximized() const override;\r
+\r
                //! notifies the device that it should close itself\r
                void closeDevice() override;\r
 \r
@@ -413,6 +416,8 @@ namespace irr
                CCursorControl* Win32CursorControl;\r
 \r
                SJoystickWin32Control* JoyControl;\r
+\r
+               bool WindowMaximized;\r
        };\r
 \r
 } // end namespace irr\r