From 2f5cffe67969a4cc2902ac49c9d278ab4153f93b Mon Sep 17 00:00:00 2001 From: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com> Date: Tue, 15 Jun 2021 13:46:53 -0400 Subject: [PATCH] Added r_ViewportPos cvar for set the position of a viewport of a game/server launchers --- Code/LauncherUnified/Launcher.cpp | 5 +++++ .../Platform/Android/Launcher_Android.cpp | 2 ++ .../LauncherUnified/Platform/Linux/Launcher_Linux.cpp | 2 ++ Code/LauncherUnified/Platform/Mac/Launcher_Mac.mm | 2 ++ .../Platform/Windows/Launcher_Windows.cpp | 11 +++++++++++ Code/LauncherUnified/Platform/iOS/Launcher_iOS.mm | 2 ++ 6 files changed, 24 insertions(+) diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index c73cdd1981..48747b50a7 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -46,6 +46,8 @@ extern "C" void CreateStaticModules(AZStd::vector& modulesOut); # define REMOTE_ASSET_PROCESSOR #endif +void CVar_OnViewportPosition(const AZ::Vector2& value); + namespace { void OnViewportResize(const AZ::Vector2& value); @@ -60,6 +62,9 @@ namespace AzFramework::WindowSize newSize = AzFramework::WindowSize(aznumeric_cast(value.GetX()), aznumeric_cast(value.GetY())); AzFramework::WindowRequestBus::Broadcast(&AzFramework::WindowRequestBus::Events::ResizeClientArea, newSize); } + + AZ_CVAR(AZ::Vector2, r_viewportPos, AZ::Vector2::CreateZero(), CVar_OnViewportPosition, AZ::ConsoleFunctorFlags::DontReplicate, + "The default position for the launcher viewport, 0 0 means top left corner of your main desktop"); void ExecuteConsoleCommandFile(AzFramework::Application& application) { diff --git a/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp b/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp index 6455373e58..fa26b9d204 100644 --- a/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp +++ b/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp @@ -433,3 +433,5 @@ void android_main(android_app* appState) MAIN_EXIT_FAILURE(appState, GetReturnCodeString(status)); } } + +void CVar_OnViewportPosition([[maybe_unused]] const AZ::Vector2& value) {} diff --git a/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp b/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp index 0c422877b1..3d283ce77f 100644 --- a/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp +++ b/Code/LauncherUnified/Platform/Linux/Launcher_Linux.cpp @@ -113,3 +113,5 @@ int main(int argc, char** argv) return static_cast(status); } + +void CVar_OnViewportPosition([[maybe_unused]] const AZ::Vector2& value) {} diff --git a/Code/LauncherUnified/Platform/Mac/Launcher_Mac.mm b/Code/LauncherUnified/Platform/Mac/Launcher_Mac.mm index 1a491d66ad..2886bb16b1 100644 --- a/Code/LauncherUnified/Platform/Mac/Launcher_Mac.mm +++ b/Code/LauncherUnified/Platform/Mac/Launcher_Mac.mm @@ -63,3 +63,5 @@ int main(int argc, char* argv[]) } #endif // AZ_TESTS_ENABLED + +void CVar_OnViewportPosition([[maybe_unused]] const AZ::Vector2& value) {} diff --git a/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp b/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp index 8f8d310475..494779dcf8 100644 --- a/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp +++ b/Code/LauncherUnified/Platform/Windows/Launcher_Windows.cpp @@ -69,3 +69,14 @@ int APIENTRY WinMain([[maybe_unused]] HINSTANCE hInstance, [[maybe_unused]] HINS return static_cast(status); } + +void CVar_OnViewportPosition(const AZ::Vector2& value) +{ + if (HWND windowHandle = GetActiveWindow()) + { + SetWindowPos(windowHandle, nullptr, + value.GetX(), + value.GetY(), + 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE); + } +} diff --git a/Code/LauncherUnified/Platform/iOS/Launcher_iOS.mm b/Code/LauncherUnified/Platform/iOS/Launcher_iOS.mm index 52c616fe64..05857842a7 100644 --- a/Code/LauncherUnified/Platform/iOS/Launcher_iOS.mm +++ b/Code/LauncherUnified/Platform/iOS/Launcher_iOS.mm @@ -23,3 +23,5 @@ int main(int argc, char* argv[]) [pool release]; return 0; } + +void CVar_OnViewportPosition([[maybe_unused]] const AZ::Vector2& value) {}