Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State: explicitly use internal state #82

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions addons/imgui-godot/ImGuiGodot/ImGuiController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if GODOT_PC
#nullable enable
using Godot;
using ImGuiGodot.Internal;
using ImGuiNET;

namespace ImGuiGodot;
Expand All @@ -24,8 +23,9 @@ public override void _Ready()

public override void _Process(double delta)
{
State.Instance.InProcessFrame = true;
State.Instance.Update(delta, State.Instance.Layer.UpdateViewport().ToImVec2());
Internal.State.Instance.InProcessFrame = true;
var vpSize = Internal.State.Instance.Layer.UpdateViewport();
Internal.State.Instance.Update(delta, new(vpSize.X, vpSize.Y));
}
}

Expand Down Expand Up @@ -55,7 +55,7 @@ public override void _EnterTree()
GD.PushError($"imgui-godot: config does not exist: {cfgPath}");
}

State.Init(cfg ?? (Resource)((GDScript)GD.Load(
Internal.State.Init(cfg ?? (Resource)((GDScript)GD.Load(
"res://addons/imgui-godot/scripts/ImGuiConfig.gd")).New());

_helper = new ImGuiControllerHelper();
Expand All @@ -73,14 +73,14 @@ public override void _Ready()

public override void _ExitTree()
{
State.Instance.Dispose();
Internal.State.Instance.Dispose();
}

public override void _Process(double delta)
{
Signaler.EmitSignal("imgui_layout");
State.Instance.Render();
State.Instance.InProcessFrame = false;
Internal.State.Instance.Render();
Internal.State.Instance.InProcessFrame = false;
}

public override void _Notification(int what)
Expand All @@ -91,7 +91,7 @@ public override void _Notification(int what)
public void OnLayerExiting()
{
// an ImGuiLayer is being destroyed without calling SetMainViewport
if (State.Instance.Layer.GetViewport() != _window)
if (Internal.State.Instance.Layer.GetViewport() != _window)
{
// revert to main window
SetMainViewport(_window);
Expand All @@ -100,7 +100,7 @@ public void OnLayerExiting()

public void SetMainViewport(Viewport vp)
{
ImGuiLayer? oldLayer = State.Instance.Layer;
ImGuiLayer? oldLayer = Internal.State.Instance.Layer;
if (oldLayer != null)
{
oldLayer.TreeExiting -= OnLayerExiting;
Expand All @@ -112,7 +112,7 @@ public void SetMainViewport(Viewport vp)

if (vp is Window window)
{
State.Instance.Input = new Internal.Input();
Internal.State.Instance.Input = new Internal.Input();
if (window == _window)
AddChild(newLayer);
else
Expand All @@ -122,7 +122,7 @@ public void SetMainViewport(Viewport vp)
}
else if (vp is SubViewport svp)
{
State.Instance.Input = new InputLocal();
Internal.State.Instance.Input = new Internal.InputLocal();
svp.AddChild(newLayer);
ImGui.GetIO().BackendFlags &= ~ImGuiBackendFlags.PlatformHasViewports;
ImGui.GetIO().BackendFlags &= ~ImGuiBackendFlags.HasMouseHoveredViewport;
Expand All @@ -131,7 +131,7 @@ public void SetMainViewport(Viewport vp)
{
throw new System.ArgumentException("secret third kind of viewport??", nameof(vp));
}
State.Instance.Layer = newLayer;
Internal.State.Instance.Layer = newLayer;
}

private void CheckContentScale()
Expand All @@ -144,7 +144,7 @@ private void CheckContentScale()

public static void WindowInputCallback(InputEvent evt)
{
State.Instance.Input.ProcessInput(evt);
Internal.State.Instance.Input.ProcessInput(evt);
}
}
#endif
11 changes: 5 additions & 6 deletions addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Godot;
using ImGuiGodot.Internal;
#if GODOT_PC
#nullable enable

Expand All @@ -17,15 +16,15 @@ public partial class ImGuiLayer : CanvasLayer
public override void _EnterTree()
{
Name = "ImGuiLayer";
Layer = State.Instance.LayerNum;
Layer = Internal.State.Instance.LayerNum;

_parentViewport = GetViewport();
_subViewportRid = AddLayerSubViewport(this);
_canvasItem = RenderingServer.CanvasItemCreate();
RenderingServer.CanvasItemSetParent(_canvasItem, GetCanvas());

State.Instance.Renderer.InitViewport(_subViewportRid);
State.Instance.Viewports.SetMainWindow(GetWindow(), _subViewportRid);
Internal.State.Instance.Renderer.InitViewport(_subViewportRid);
Internal.State.Instance.Viewports.SetMainWindow(GetWindow(), _subViewportRid);
}

public override void _Ready()
Expand All @@ -50,15 +49,15 @@ private void OnChangeVisibility()
else
{
SetProcessInput(false);
State.Instance.Renderer.OnHide();
Internal.State.Instance.Renderer.OnHide();
_subViewportSize = Vector2I.Zero;
RenderingServer.CanvasItemClear(_canvasItem);
}
}

public override void _Input(InputEvent @event)
{
if (State.Instance.Input.ProcessInput(@event))
if (Internal.State.Instance.Input.ProcessInput(@event))
{
_parentViewport.SetInputAsHandled();
}
Expand Down