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

View File

@ -156,6 +156,12 @@ namespace irr
/** \return True if window is minimized. */
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
/** \return True if window is fullscreen. */
virtual bool isFullscreen() const = 0;

View File

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

View File

@ -118,7 +118,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
currentTouchedCount(0),
#endif
Width(param.WindowSize.Width), Height(param.WindowSize.Height),
WindowHasFocus(false), WindowMinimized(false),
WindowHasFocus(false), WindowMinimized(false), WindowMaximized(param.WindowMaximized),
ExternalWindow(false), AutorepeatSupport(0)
{
#ifdef _DEBUG
@ -168,6 +168,9 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param)
return;
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.
video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const
{
@ -1284,6 +1294,8 @@ void CIrrDeviceLinux::maximizeWindow()
}
XMapWindow(XDisplay, XWindow);
WindowMaximized = true;
#endif
}
@ -1310,6 +1322,8 @@ void CIrrDeviceLinux::restoreWindow()
}
XMapWindow(XDisplay, XWindow);
WindowMaximized = false;
#endif
}

View File

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

View File

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

View File

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

View File

@ -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
bool CIrrDeviceStub::isFullscreen() const
{

View File

@ -94,6 +94,9 @@ namespace irr
//! Returns the operation system opertator object.
IOSOperator* getOSOperator() override;
//! Checks if the window is maximized.
bool isWindowMaximized() const override;
//! Checks if the window is running in fullscreen mode.
bool isFullscreen() const override;
@ -103,41 +106,41 @@ namespace irr
//! Activate any joysticks, and generate events for them.
bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo) override;
//! Activate accelerometer.
bool activateAccelerometer(float updateInterval = 0.016666f) override;
//! Deactivate accelerometer.
bool deactivateAccelerometer() override;
//! Is accelerometer active.
bool isAccelerometerActive() override;
//! Is accelerometer available.
bool isAccelerometerAvailable() override;
//! Activate gyroscope.
bool activateGyroscope(float updateInterval = 0.016666f) override;
//! Deactivate gyroscope.
bool deactivateGyroscope() override;
//! Is gyroscope active.
bool isGyroscopeActive() override;
//! Is gyroscope available.
bool isGyroscopeAvailable() override;
//! Activate device motion.
bool activateDeviceMotion(float updateInterval = 0.016666f) override;
//! Deactivate device motion.
bool deactivateDeviceMotion() override;
//! Is device motion active.
bool isDeviceMotionActive() override;
//! Is device motion available.
bool isDeviceMotionAvailable() override;
//! Activate accelerometer.
bool activateAccelerometer(float updateInterval = 0.016666f) override;
//! Deactivate accelerometer.
bool deactivateAccelerometer() override;
//! Is accelerometer active.
bool isAccelerometerActive() override;
//! Is accelerometer available.
bool isAccelerometerAvailable() override;
//! Activate gyroscope.
bool activateGyroscope(float updateInterval = 0.016666f) override;
//! Deactivate gyroscope.
bool deactivateGyroscope() override;
//! Is gyroscope active.
bool isGyroscopeActive() override;
//! Is gyroscope available.
bool isGyroscopeAvailable() override;
//! Activate device motion.
bool activateDeviceMotion(float updateInterval = 0.016666f) override;
//! Deactivate device motion.
bool deactivateDeviceMotion() override;
//! Is device motion active.
bool isDeviceMotionActive() override;
//! Is device motion available.
bool isDeviceMotionAvailable() override;
//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
//! When set to 0 no double- and tripleclicks will be generated.

View File

@ -784,7 +784,8 @@ namespace irr
//! constructor
CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), HWnd(0), Resized(false),
ExternalWindow(false), Win32CursorControl(0), JoyControl(0)
ExternalWindow(false), Win32CursorControl(0), JoyControl(0),
WindowMaximized(params.WindowMaximized)
{
#ifdef _DEBUG
setDebugName("CIrrDeviceWin32");
@ -923,6 +924,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
// inform driver about the window size etc.
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
bool CIrrDeviceWin32::switchToFullScreen()
{
@ -1278,6 +1289,8 @@ void CIrrDeviceWin32::maximizeWindow()
GetWindowPlacement(HWnd, &wndpl);
wndpl.showCmd = SW_SHOWMAXIMIZED;
SetWindowPlacement(HWnd, &wndpl);
WindowMaximized = true;
}
@ -1289,6 +1302,8 @@ void CIrrDeviceWin32::restoreWindow()
GetWindowPlacement(HWnd, &wndpl);
wndpl.showCmd = SW_SHOWNORMAL;
SetWindowPlacement(HWnd, &wndpl);
WindowMaximized = false;
}
core::position2di CIrrDeviceWin32::getWindowPosition()

View File

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