Added function to get viewport size of the game window when in editor. This allows for certain functions to behave correctly.

This commit is contained in:
Chandler Cox
2023-02-03 13:27:53 -06:00
parent d8a9b699ad
commit f4da984399
4 changed files with 42 additions and 1 deletions

View File

@@ -1408,6 +1408,23 @@ namespace FlaxEditor
}
}
internal void Internal_GetGameWindowViewportSize(out Float2 result)
{
result = new Float2(1280, 720);
var gameWin = Windows.GameWin;
if (gameWin?.Root?.RootWindow is WindowRootControl root)
{
// 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;
else
result = gameWin.Viewport.Size * root.DpiScale;
result = Float2.Round(result);
}
}
internal bool Internal_OnAppExit()
{
// In editor play mode (when main window is not closed) just skip engine exit and leave the play mode

View File

@@ -457,6 +457,24 @@ Float2 ManagedEditor::GetGameWindowSize()
return Float2::Zero;
}
Float2 ManagedEditor::GetGameWindowViewportSize()
{
if (HasManagedInstance())
{
if (Internal_GetGameWindowSize == nullptr)
{
Internal_GetGameWindowSize = GetClass()->GetMethod("Internal_GetGameWindowViewportSize", 1);
ASSERT(Internal_GetGameWindowSize);
}
Float2 size;
void* params[1];
params[0] = &size;
Internal_GetGameWindowSize->Invoke(GetManagedInstance(), params, nullptr);
return size;
}
return Float2::Zero;
}
bool ManagedEditor::OnAppExit()
{
if (!HasManagedInstance())

View File

@@ -133,6 +133,12 @@ public:
/// <returns>The size.</returns>
Float2 GetGameWindowSize();
/// <summary>
/// Gets the size of the game window viewport output.
/// </summary>
/// <returns>The size.</returns>
Float2 GetGameWindowViewportSize();
/// <summary>
/// Called when application code calls exit. Editor may end play mode or exit normally.
/// </summary>

View File

@@ -189,7 +189,7 @@ Viewport Camera::GetViewport() const
#if USE_EDITOR
// Editor
if (Editor::Managed)
result.Size = Editor::Managed->GetGameWindowSize();
result.Size = Editor::Managed->GetGameWindowViewportSize();
#else
// game
auto mainWin = Engine::MainWindow;