feat: add MainViewport to ImGuiHelpers instead

This commit is contained in:
goat 2021-04-05 23:33:34 +02:00
parent c21e7efab7
commit 303ddf8d27
2 changed files with 7 additions and 17 deletions

View file

@ -9,7 +9,10 @@ namespace Dalamud.Interface
/// </summary> /// </summary>
public static class ImGuiHelpers public static class ImGuiHelpers
{ {
private static uint mainViewportId; /// <summary>
/// Gets the main viewport.
/// </summary>
public static ImGuiViewportPtr MainViewport { get; internal set; }
/// <summary> /// <summary>
/// Gets the global Dalamud scale. /// Gets the global Dalamud scale.
@ -19,21 +22,7 @@ namespace Dalamud.Interface
/// <summary> /// <summary>
/// Force this ImGui window to stay inside the main game window. /// Force this ImGui window to stay inside the main game window.
/// </summary> /// </summary>
public static void ForceMainWindow() => ImGui.SetNextWindowViewport(GetMainViewportId()); public static void ForceMainWindow() => ImGui.SetNextWindowViewport(MainViewport.ID);
/// <summary>
/// Get the ID of the main game window viewport.
/// </summary>
/// <returns>The ID of the main game window viewport.</returns>
public static uint GetMainViewportId()
{
if (mainViewportId == 0)
mainViewportId = ImGui.GetMainViewport().ID;
return mainViewportId;
}
public static Vector2 MainWindowPos { get; set; }
/// <summary> /// <summary>
/// Create a dummy scaled by the global Dalamud scale. /// Create a dummy scaled by the global Dalamud scale.
@ -55,7 +44,6 @@ namespace Dalamud.Interface
internal static void NewFrame() internal static void NewFrame()
{ {
GlobalScale = ImGui.GetIO().FontGlobalScale; GlobalScale = ImGui.GetIO().FontGlobalScale;
MainWindowPos = ImGui.GetMainViewport().Pos;
} }
} }
} }

View file

@ -267,6 +267,8 @@ namespace Dalamud.Interface
ImGui.GetIO().FontGlobalScale = this.dalamud.Configuration.GlobalUiScale; ImGui.GetIO().FontGlobalScale = this.dalamud.Configuration.GlobalUiScale;
ImGui.GetIO().ConfigFlags &= ~ImGuiConfigFlags.DockingEnable; ImGui.GetIO().ConfigFlags &= ~ImGuiConfigFlags.DockingEnable;
ImGuiHelpers.MainViewport = ImGui.GetMainViewport();
} }
// Process information needed by ImGuiHelpers each frame. // Process information needed by ImGuiHelpers each frame.