feat: add Namespace, BgAlpha, scaling to WindowSystem

This commit is contained in:
goat 2021-04-05 23:21:59 +02:00
parent ec8e320b6c
commit 65fb949c61

View file

@ -1,6 +1,7 @@
using System.Numerics; using System.Numerics;
using ImGuiNET; using ImGuiNET;
using Serilog;
namespace Dalamud.Interface.Windowing namespace Dalamud.Interface.Windowing
{ {
@ -11,6 +12,7 @@ namespace Dalamud.Interface.Windowing
{ {
private bool internalLastIsOpen = false; private bool internalLastIsOpen = false;
private bool internalIsOpen = false; private bool internalIsOpen = false;
private bool mainIsOpen = false;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Window"/> class. /// Initializes a new instance of the <see cref="Window"/> class.
@ -28,6 +30,8 @@ namespace Dalamud.Interface.Windowing
this.ForceMainWindow = forceMainWindow; this.ForceMainWindow = forceMainWindow;
} }
public string Namespace { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name of the window. /// Gets or sets the name of the window.
/// If you have multiple windows with the same name, you will need to /// If you have multiple windows with the same name, you will need to
@ -85,13 +89,24 @@ namespace Dalamud.Interface.Windowing
/// </summary> /// </summary>
public bool ForceMainWindow { get; set; } public bool ForceMainWindow { get; set; }
/// <summary>
/// Gets or sets this window's background alpha value.
/// </summary>
public float? BgAlpha { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether or not this window will stay open. /// Gets or sets a value indicating whether or not this window will stay open.
/// </summary> /// </summary>
public bool IsOpen public bool IsOpen
{ {
get => this.internalIsOpen; get => this.mainIsOpen;
set => this.internalIsOpen = value; set
{
if (!value)
this.internalIsOpen = true;
this.mainIsOpen = value;
}
} }
/// <summary> /// <summary>
@ -115,6 +130,14 @@ namespace Dalamud.Interface.Windowing
/// </summary> /// </summary>
internal void DrawInternal() internal void DrawInternal()
{ {
if (!this.IsOpen)
return;
var hasNamespace = !string.IsNullOrEmpty(this.Namespace);
if (hasNamespace)
ImGui.PushID(this.Namespace);
this.ApplyConditionals(); this.ApplyConditionals();
if (this.ForceMainWindow) if (this.ForceMainWindow)
@ -124,10 +147,13 @@ namespace Dalamud.Interface.Windowing
{ {
// Draw the actual window contents // Draw the actual window contents
this.Draw(); this.Draw();
ImGui.End();
} }
ImGui.End();
if (hasNamespace)
ImGui.PopID();
if (this.internalLastIsOpen != this.internalIsOpen) if (this.internalLastIsOpen != this.internalIsOpen)
{ {
if (this.internalIsOpen) if (this.internalIsOpen)
@ -141,18 +167,26 @@ namespace Dalamud.Interface.Windowing
} }
this.internalLastIsOpen = this.internalIsOpen; this.internalLastIsOpen = this.internalIsOpen;
if (this.internalIsOpen != true)
this.IsOpen = false;
} }
private void ApplyConditionals() private void ApplyConditionals()
{ {
if (this.Position.HasValue) if (this.Position.HasValue)
{ {
ImGui.SetNextWindowPos(this.Position.Value, this.PositionCondition); var pos = this.Position.Value;
if (this.ForceMainWindow)
pos += ImGuiHelpers.MainWindowPos;
ImGui.SetNextWindowPos(pos, this.PositionCondition);
} }
if (this.Size.HasValue) if (this.Size.HasValue)
{ {
ImGui.SetNextWindowPos(this.Size.Value * ImGuiHelpers.GlobalScale, this.SizeCondition); ImGui.SetNextWindowSize(this.Size.Value * ImGuiHelpers.GlobalScale, this.SizeCondition);
} }
if (this.Collapsed.HasValue) if (this.Collapsed.HasValue)
@ -164,6 +198,11 @@ namespace Dalamud.Interface.Windowing
{ {
ImGui.SetNextWindowSizeConstraints(this.SizeConstraintsMin.Value * ImGuiHelpers.GlobalScale, this.SizeConstraintsMax.Value * ImGuiHelpers.GlobalScale); ImGui.SetNextWindowSizeConstraints(this.SizeConstraintsMin.Value * ImGuiHelpers.GlobalScale, this.SizeConstraintsMax.Value * ImGuiHelpers.GlobalScale);
} }
if (this.BgAlpha.HasValue)
{
ImGui.SetNextWindowBgAlpha(this.BgAlpha.Value);
}
} }
} }
} }