From a5c809a7381874d264790e86eb0c4910d497d776 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Thu, 13 May 2021 20:52:04 -0400 Subject: [PATCH 1/5] Limit fullscreen resolution to options that match the monitor aspect ratio. --- Templates/BaseGame/game/core/gui/scripts/canvas.tscript | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 9f040f1e9..efb98b7c4 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -184,6 +184,12 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu return true; } + else if (%deviceMode == $Video::ModeFullscreen) + { // Fullscreen must match the aspect ratio of the monitor + %deviceRes = getWords(%this.getMonitorRect(%deviceId), 2); + if (mRoundColour(%resX / %resY, 2) != mRoundColour(%deviceRes.x / %deviceRes.y, 2)) + return false; + } if (!%startup) return true; From de1e6df64b7ab6951770cb0989f2683877f395e3 Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:50:28 -0400 Subject: [PATCH 2/5] Removes redundant ScreenResChangeSignal trigger. --- Engine/source/windowManager/sdl/sdlWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Engine/source/windowManager/sdl/sdlWindow.cpp b/Engine/source/windowManager/sdl/sdlWindow.cpp index 2faccb555..2c725a2d1 100644 --- a/Engine/source/windowManager/sdl/sdlWindow.cpp +++ b/Engine/source/windowManager/sdl/sdlWindow.cpp @@ -207,7 +207,6 @@ void PlatformWindowSDL::_setVideoMode( const GFXVideoMode &mode ) SDL_MaximizeWindow(mWindowHandle); } - getScreenResChangeSignal().trigger(this, true); mSuppressReset = false; } From 1ba7070bb674c82e8032a8d6c8eca2bc83479e7f Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:52:43 -0400 Subject: [PATCH 3/5] Maintains window position when updating video mode for LightManager compatibility. --- Engine/source/gui/core/guiCanvas.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index f50cc0152..abbf10561 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -1760,7 +1760,9 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) const char *pref = Con::getVariable( "$pref::Video::mode" ); mode.parseFromString( pref ); mode.antialiasLevel = 0; + Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been disabled; it is not compatible with AdvancedLighting." ); } @@ -1772,7 +1774,9 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) if ( prefAA != mode.antialiasLevel ) { mode.parseFromString( pref ); + Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been enabled while running BasicLighting." ); } From dd665496d1d62fce5f8b5971974f6cdf07696d3e Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 03:57:00 -0400 Subject: [PATCH 4/5] Borderless window defaults. Limits borderless windows to the monitor usable area on non windows platforms to prevent the window from rendering behind taskbar/title bars. --- .../BaseGame/game/core/gui/scripts/canvas.tscript | 15 +++++++++++++++ .../rendering/scripts/graphicsOptions.tscript | 7 +++++++ .../game/data/ui/guis/optionsMenu.tscript | 9 +++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index efb98b7c4..5a22d909a 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -120,6 +120,13 @@ function configureCanvas() // Actually set the new video mode Canvas.setVideoMode(%resX, %resY, %fs, %bpp, %rate, %aa); + + // For borderless on non-windows OS, move the window into position. + if (($pref::Video::deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %borderlessPos = getWords(Canvas.getMonitorUsableRect($pref::Video::deviceId), 0, 1); + Canvas.setWindowPosition(%borderlessPos); + } Canvas.setFocus(); // Lock and unlock the mouse to force the position to sync with the platform window @@ -244,5 +251,13 @@ function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) %bestRes = %testRes; } + // Borderless on non-windows OS should be the usable screen area. + if ((%deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %deviceRect = getWords(%this.getMonitorUsableRect(%deviceId), 2); + %bestRes = setWord(%bestRes, $WORD::RES_X, %deviceRect.x); + %bestRes = setWord(%bestRes, $WORD::RES_Y, %deviceRect.y); + } + return %bestRes; } diff --git a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript index 353b9b795..21b5ae9c2 100644 --- a/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript +++ b/Templates/BaseGame/game/core/rendering/scripts/graphicsOptions.tscript @@ -845,6 +845,13 @@ function getScreenResolutionList(%deviceID, %deviceMode) { %returnsList = ""; + // For borderless on non-windows OS only add the usable area. + if ((%deviceMode == $Video::ModeBorderless) && ($platform !$= "windows")) + { + %borderlessRes = getWords(Canvas.getMonitorUsableRect(%newDeviceID), 2); + return _makePrettyResString(%borderlessRes); + } + %resCount = Canvas.getModeCount(); for (%i = 0; %i < %resCount; %i++) { diff --git a/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript b/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript index eba6e173b..416bbe36b 100644 --- a/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript +++ b/Templates/BaseGame/game/data/ui/guis/optionsMenu.tscript @@ -634,9 +634,14 @@ function onDisplayModeChange(%val) } %resolutionList = getScreenResolutionList(%newDeviceID, %newDeviceMode); - // If we're switching to borderless, default to monitor res if (%newDeviceMode == $Video::ModeBorderless) - %newRes = getWords(Canvas.getMonitorRect(%newDeviceID), 2); + { // If we're switching to borderless, default to monitor res on Windows OS, + // monitor usable area for other platforms. + if ($platform $= "windows") + %newRes = getWords(Canvas.getMonitorRect(%newDeviceID), 2); + else + %newRes = getWords(Canvas.getMonitorUsableRect(%newDeviceID), 2); + } else { // Otherwise, if our old resolution is still in the list, attempt to reset it. %oldRes = getWord(OptionsMenuSettingsList.getCurrentOption(3), 0) SPC getWord(OptionsMenuSettingsList.getCurrentOption(3), 2); From 9539a4a0555a3ae24d64cd2af9e5130d2dd7d00f Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Fri, 14 May 2021 17:30:23 -0400 Subject: [PATCH 5/5] Adds comment explaining window position change in GuiCanvas. --- Engine/source/gui/core/guiCanvas.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index abbf10561..7cbea6d64 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -1762,6 +1762,8 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) mode.antialiasLevel = 0; Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + // setVideoMode (above) will center the window on the display device. If the window had been positioned + // by the user or from script, put it back where it was before the light manager change. mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been disabled; it is not compatible with AdvancedLighting." ); @@ -1776,6 +1778,8 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) mode.parseFromString( pref ); Point2I winPos = mPlatformWindow->getPosition(); // Save position so we can put window back. mPlatformWindow->setVideoMode(mode); + // setVideoMode (above) will center the window on the display device. If the window had been positioned + // by the user or from script, put it back where it was before the light manager change. mPlatformWindow->setPosition(winPos); Con::printf( "AntiAliasing has been enabled while running BasicLighting." );