Skip to content

Commit

Permalink
State: explicitly use internal state
Browse files Browse the repository at this point in the history
  • Loading branch information
Garteal committed Aug 26, 2024
1 parent 1f6b8fc commit 687b7be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
24 changes: 12 additions & 12 deletions addons/imgui-godot/ImGuiGodot/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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;

Check failure on line 27 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
Internal.State.Instance.Update(delta, Internal.State.Instance.Layer.UpdateViewport().ToImVec2());

Check failure on line 28 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified

Check failure on line 28 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified

Check warning on line 28 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

A line is too long (109 characters)
}
}

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(

Check failure on line 58 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
"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();

Check failure on line 76 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
}

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

Check failure on line 82 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
Internal.State.Instance.InProcessFrame = false;

Check failure on line 83 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
}

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)

Check failure on line 94 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
{
// 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;

Check failure on line 103 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
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);

Check failure on line 147 in addons/imgui-godot/ImGuiGodot/ImGuiController.cs

View workflow job for this annotation

GitHub Actions / .NET 8.0.x

Name can be simplified
}
}
#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

0 comments on commit 687b7be

Please sign in to comment.