diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 3a11ed449..7f2351426 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1550,9 +1550,9 @@ namespace FlaxEditor // Handle case when Game window is not selected in tab view var dockedTo = gameWin.ParentDockPanel; if (dockedTo != null && dockedTo.SelectedTab != gameWin && dockedTo.SelectedTab != null) - result = dockedTo.SelectedTab.Size * root.DpiScale; + result = dockedTo.SelectedTab.Size; else - result = gameWin.Viewport.Size * root.DpiScale; + result = gameWin.Viewport.Size; result = Float2.Round(result); } diff --git a/Source/Engine/Engine/Screen.h b/Source/Engine/Engine/Screen.h index 7322fa368..469d30847 100644 --- a/Source/Engine/Engine/Screen.h +++ b/Source/Engine/Engine/Screen.h @@ -30,7 +30,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen); API_PROPERTY() static void SetIsFullscreen(bool value); /// - /// Gets the window size. + /// Gets the window size (in screen-space, includes DPI scale). /// /// The value API_PROPERTY() static Float2 GetSize(); @@ -50,7 +50,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen); API_FUNCTION() static Float2 GameViewportToScreen(const Float2& viewportPos); /// - /// Sets the window size. + /// Sets the window size (in screen-space, includes DPI scale). /// /// /// Resizing may not happen immediately. It will be performed before next frame rendering. diff --git a/Source/Engine/Level/Actors/Camera.cpp b/Source/Engine/Level/Actors/Camera.cpp index f6aa00c78..f664537d2 100644 --- a/Source/Engine/Level/Actors/Camera.cpp +++ b/Source/Engine/Level/Actors/Camera.cpp @@ -246,11 +246,16 @@ Ray Camera::ConvertMouseToRay(const Float2& mousePosition, const Viewport& viewp Viewport Camera::GetViewport() const { Viewport result = Viewport(Float2::Zero); + float dpiScale = Platform::GetDpiScale(); #if USE_EDITOR // Editor if (Editor::Managed) + { result.Size = Editor::Managed->GetGameWindowSize(); + if (auto* window = Editor::Managed->GetGameWindow()) + dpiScale = window->GetDpiScale(); + } #else // Game auto mainWin = Engine::MainWindow; @@ -258,9 +263,13 @@ Viewport Camera::GetViewport() const { const auto size = mainWin->GetClientSize(); result.Size = size; + dpiScale = mainWin->GetDpiScale(); } #endif + // Remove DPI scale (game viewport coords are unscaled) + result.Size /= dpiScale; + // Fallback to the default value if (result.Size.MinValue() <= ZeroTolerance) result.Size = Float2(1280, 720);