Add WindowMaximized creation parameter and isWindowMaximized() (#142)

This commit is contained in:
DS 2023-02-06 15:05:44 +01:00 committed by GitHub
parent 8f13ae81e5
commit 51dffc416a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 120 additions and 54 deletions

@ -156,6 +156,12 @@ namespace irr
/** \return True if window is minimized. */ /** \return True if window is minimized. */
virtual bool isWindowMinimized() const = 0; virtual bool isWindowMinimized() const = 0;
//! Checks if the Irrlicht window is maximized
//! Only fully works on SDL. Returns false, or the last value set via
//! maximizeWindow() and restoreWindow(), on other backends.
/** \return True if window is maximized. */
virtual bool isWindowMaximized() const = 0;
//! Checks if the Irrlicht window is running in fullscreen mode //! Checks if the Irrlicht window is running in fullscreen mode
/** \return True if window is fullscreen. */ /** \return True if window is fullscreen. */
virtual bool isFullscreen() const = 0; virtual bool isFullscreen() const = 0;

@ -30,6 +30,7 @@ namespace irr
Bits(32), Bits(32),
ZBufferBits(24), ZBufferBits(24),
Fullscreen(false), Fullscreen(false),
WindowMaximized(false),
WindowResizable(2), WindowResizable(2),
Stencilbuffer(true), Stencilbuffer(true),
Vsync(false), Vsync(false),
@ -73,6 +74,7 @@ namespace irr
Bits = other.Bits; Bits = other.Bits;
ZBufferBits = other.ZBufferBits; ZBufferBits = other.ZBufferBits;
Fullscreen = other.Fullscreen; Fullscreen = other.Fullscreen;
WindowMaximized = other.WindowMaximized;
WindowResizable = other.WindowResizable; WindowResizable = other.WindowResizable;
Stencilbuffer = other.Stencilbuffer; Stencilbuffer = other.Stencilbuffer;
Vsync = other.Vsync; Vsync = other.Vsync;
@ -127,6 +129,9 @@ namespace irr
/** Otherwise the device runs in windowed mode. Default: false. */ /** Otherwise the device runs in windowed mode. Default: false. */
bool Fullscreen; bool Fullscreen;
//! Maximised window. (Only supported on SDL.) Default: false
bool WindowMaximized;
//! Should a non-fullscreen window be resizable. //! Should a non-fullscreen window be resizable.
/** Might not be supported by all devices. Ignored when Fullscreen is true. /** Might not be supported by all devices. Ignored when Fullscreen is true.
Values: 0 = not resizable, 1 = resizable, 2 = system decides default itself Values: 0 = not resizable, 1 = resizable, 2 = system decides default itself

@ -118,7 +118,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
currentTouchedCount(0), currentTouchedCount(0),
#endif #endif
Width(param.WindowSize.Width), Height(param.WindowSize.Height), Width(param.WindowSize.Width), Height(param.WindowSize.Height),
WindowHasFocus(false), WindowMinimized(false), WindowHasFocus(false), WindowMinimized(false), WindowMaximized(param.WindowMaximized),
ExternalWindow(false), AutorepeatSupport(0) ExternalWindow(false), AutorepeatSupport(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -168,6 +168,9 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
return; return;
createGUIAndScene(); createGUIAndScene();
if (param.WindowMaximized)
maximizeWindow();
} }
@ -1200,6 +1203,13 @@ bool CIrrDeviceLinux::isWindowMinimized() const
} }
//! returns last state from maximizeWindow() and restoreWindow()
bool CIrrDeviceLinux::isWindowMaximized() const
{
return WindowMaximized;
}
//! returns color format of the window. //! returns color format of the window.
video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const
{ {
@ -1284,6 +1294,8 @@ void CIrrDeviceLinux::maximizeWindow()
} }
XMapWindow(XDisplay, XWindow); XMapWindow(XDisplay, XWindow);
WindowMaximized = true;
#endif #endif
} }
@ -1310,6 +1322,8 @@ void CIrrDeviceLinux::restoreWindow()
} }
XMapWindow(XDisplay, XWindow); XMapWindow(XDisplay, XWindow);
WindowMaximized = false;
#endif #endif
} }

@ -64,6 +64,9 @@ namespace irr
//! returns if window is minimized. //! returns if window is minimized.
bool isWindowMinimized() const override; bool isWindowMinimized() const override;
//! returns last state from maximizeWindow() and restoreWindow()
bool isWindowMaximized() const override;
//! returns color format of the window. //! returns color format of the window.
video::ECOLOR_FORMAT getColorFormat() const override; video::ECOLOR_FORMAT getColorFormat() const override;
@ -415,6 +418,7 @@ namespace irr
u32 Width, Height; u32 Width, Height;
bool WindowHasFocus; bool WindowHasFocus;
bool WindowMinimized; bool WindowMinimized;
bool WindowMaximized;
bool ExternalWindow; bool ExternalWindow;
int AutorepeatSupport; int AutorepeatSupport;

@ -111,7 +111,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
Window((SDL_Window*)param.WindowId), SDL_Flags(0), Window((SDL_Window*)param.WindowId), SDL_Flags(0),
MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0), MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),
Width(param.WindowSize.Width), Height(param.WindowSize.Height), Width(param.WindowSize.Width), Height(param.WindowSize.Height),
Resizable(param.WindowResizable == 1 ? true : false), WindowMinimized(false) Resizable(param.WindowResizable == 1 ? true : false)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CIrrDeviceSDL"); setDebugName("CIrrDeviceSDL");
@ -139,10 +139,14 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
// create keymap // create keymap
createKeyMap(); createKeyMap();
if ( CreationParams.Fullscreen ) if (CreationParams.Fullscreen) {
SDL_Flags |= SDL_WINDOW_FULLSCREEN; SDL_Flags |= SDL_WINDOW_FULLSCREEN;
else if ( Resizable ) } else {
if (Resizable)
SDL_Flags |= SDL_WINDOW_RESIZABLE; SDL_Flags |= SDL_WINDOW_RESIZABLE;
if (CreationParams.WindowMaximized)
SDL_Flags |= SDL_WINDOW_MAXIMIZED;
}
if (CreationParams.DriverType == video::EDT_OPENGL) if (CreationParams.DriverType == video::EDT_OPENGL)
{ {
SDL_Flags |= SDL_WINDOW_OPENGL; SDL_Flags |= SDL_WINDOW_OPENGL;
@ -160,6 +164,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
createWindow(); createWindow();
} }
SDL_VERSION(&Info.version); SDL_VERSION(&Info.version);
#ifndef _IRR_EMSCRIPTEN_PLATFORM_ #ifndef _IRR_EMSCRIPTEN_PLATFORM_
@ -636,12 +641,6 @@ bool CIrrDeviceSDL::run()
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (SDL_event.window.event) switch (SDL_event.window.event)
{ {
case SDL_WINDOWEVENT_MAXIMIZED:
WindowMinimized = true;
break;
case SDL_WINDOWEVENT_RESTORED:
WindowMinimized = false;
break;
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height)) if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height))
{ {
@ -862,16 +861,16 @@ void CIrrDeviceSDL::setResizable(bool resize)
//! Minimizes window if possible //! Minimizes window if possible
void CIrrDeviceSDL::minimizeWindow() void CIrrDeviceSDL::minimizeWindow()
{ {
if (Window) { if (Window)
SDL_MinimizeWindow(Window); SDL_MinimizeWindow(Window);
} }
}
//! Maximize window //! Maximize window
void CIrrDeviceSDL::maximizeWindow() void CIrrDeviceSDL::maximizeWindow()
{ {
// do nothing if (Window)
SDL_MaximizeWindow(Window);
} }
//! Get the position of this window on screen //! Get the position of this window on screen
@ -884,7 +883,13 @@ core::position2di CIrrDeviceSDL::getWindowPosition()
//! Restore original window size //! Restore original window size
void CIrrDeviceSDL::restoreWindow() void CIrrDeviceSDL::restoreWindow()
{ {
// do nothing if (Window)
SDL_RestoreWindow(Window);
}
bool CIrrDeviceSDL::isWindowMaximized() const
{
return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0;
} }
bool CIrrDeviceSDL::isFullscreen() const bool CIrrDeviceSDL::isFullscreen() const
@ -919,14 +924,14 @@ bool CIrrDeviceSDL::isWindowActive() const
//! returns if window has focus. //! returns if window has focus.
bool CIrrDeviceSDL::isWindowFocused() const bool CIrrDeviceSDL::isWindowFocused() const
{ {
return SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS; return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0;
} }
//! returns if window is minimized. //! returns if window is minimized.
bool CIrrDeviceSDL::isWindowMinimized() const bool CIrrDeviceSDL::isWindowMinimized() const
{ {
return WindowMinimized; return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0;
} }

@ -76,6 +76,9 @@ namespace irr
//! Restores the window size. //! Restores the window size.
void restoreWindow() override; void restoreWindow() override;
//! Checks if the window is maximized.
bool isWindowMaximized() const override;
//! Checks if the Irrlicht window is running in fullscreen mode //! Checks if the Irrlicht window is running in fullscreen mode
/** \return True if window is fullscreen. */ /** \return True if window is fullscreen. */
bool isFullscreen() const override; bool isFullscreen() const override;
@ -283,7 +286,6 @@ namespace irr
u32 Width, Height; u32 Width, Height;
bool Resizable; bool Resizable;
bool WindowMinimized;
struct SKeyMap struct SKeyMap
{ {

@ -272,6 +272,13 @@ void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneMa
} }
//! Checks if the window is maximized.
bool CIrrDeviceStub::isWindowMaximized() const
{
return false;
}
//! Checks if the window is running in fullscreen mode //! Checks if the window is running in fullscreen mode
bool CIrrDeviceStub::isFullscreen() const bool CIrrDeviceStub::isFullscreen() const
{ {

@ -94,6 +94,9 @@ namespace irr
//! Returns the operation system opertator object. //! Returns the operation system opertator object.
IOSOperator* getOSOperator() override; IOSOperator* getOSOperator() override;
//! Checks if the window is maximized.
bool isWindowMaximized() const override;
//! Checks if the window is running in fullscreen mode. //! Checks if the window is running in fullscreen mode.
bool isFullscreen() const override; bool isFullscreen() const override;

@ -784,7 +784,8 @@ namespace irr
//! constructor //! constructor
CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), HWnd(0), Resized(false), : CIrrDeviceStub(params), HWnd(0), Resized(false),
ExternalWindow(false), Win32CursorControl(0), JoyControl(0) ExternalWindow(false), Win32CursorControl(0), JoyControl(0),
WindowMaximized(params.WindowMaximized)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CIrrDeviceWin32"); setDebugName("CIrrDeviceWin32");
@ -923,6 +924,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
// inform driver about the window size etc. // inform driver about the window size etc.
resizeIfNecessary(); resizeIfNecessary();
if (params.WindowMaximized)
maximizeWindow();
} }
@ -1154,6 +1158,13 @@ bool CIrrDeviceWin32::isWindowMinimized() const
} }
//! returns last state from maximizeWindow() and restoreWindow()
bool CIrrDeviceWin32::isWindowMaximized() const
{
return WindowMaximized;
}
//! switches to fullscreen //! switches to fullscreen
bool CIrrDeviceWin32::switchToFullScreen() bool CIrrDeviceWin32::switchToFullScreen()
{ {
@ -1278,6 +1289,8 @@ void CIrrDeviceWin32::maximizeWindow()
GetWindowPlacement(HWnd, &wndpl); GetWindowPlacement(HWnd, &wndpl);
wndpl.showCmd = SW_SHOWMAXIMIZED; wndpl.showCmd = SW_SHOWMAXIMIZED;
SetWindowPlacement(HWnd, &wndpl); SetWindowPlacement(HWnd, &wndpl);
WindowMaximized = true;
} }
@ -1289,6 +1302,8 @@ void CIrrDeviceWin32::restoreWindow()
GetWindowPlacement(HWnd, &wndpl); GetWindowPlacement(HWnd, &wndpl);
wndpl.showCmd = SW_SHOWNORMAL; wndpl.showCmd = SW_SHOWNORMAL;
SetWindowPlacement(HWnd, &wndpl); SetWindowPlacement(HWnd, &wndpl);
WindowMaximized = false;
} }
core::position2di CIrrDeviceWin32::getWindowPosition() core::position2di CIrrDeviceWin32::getWindowPosition()

@ -57,6 +57,9 @@ namespace irr
//! returns if window is minimized //! returns if window is minimized
bool isWindowMinimized() const override; bool isWindowMinimized() const override;
//! returns last state from maximizeWindow() and restoreWindow()
bool isWindowMaximized() const override;
//! notifies the device that it should close itself //! notifies the device that it should close itself
void closeDevice() override; void closeDevice() override;
@ -413,6 +416,8 @@ namespace irr
CCursorControl* Win32CursorControl; CCursorControl* Win32CursorControl;
SJoystickWin32Control* JoyControl; SJoystickWin32Control* JoyControl;
bool WindowMaximized;
}; };
} // end namespace irr } // end namespace irr