Skip to content

Commit

Permalink
move some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Dec 2, 2022
1 parent 2895322 commit ee24f10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
9 changes: 8 additions & 1 deletion addons/imgui-godot/ImGuiGodot/ImGuiGD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ public static void RebuildFontAtlas()

public static void Update(double delta, Viewport vp)
{
Internal.State.Update(delta, vp);
var io = ImGui.GetIO();
var vpSize = vp.GetVisibleRect().Size;
io.DisplaySize = new(vpSize.x, vpSize.y);
io.DeltaTime = (float)delta;

Internal.Input.Update(io);

ImGui.NewFrame();
}

public static void Render(Viewport vp)
Expand Down
2 changes: 1 addition & 1 deletion addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public override void _Process(double delta)

public override void _Notification(long what)
{
Internal.State.ProcessNotification(what);
Internal.Input.ProcessNotification(what);
}

public override void _Input(InputEvent e)
Expand Down
13 changes: 13 additions & 0 deletions addons/imgui-godot/ImGuiGodot/Internal/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ public static bool ProcessInput(InputEvent evt, Window window)
return consumed;
}

public static void ProcessNotification(long what)
{
switch (what)
{
case MainLoop.NotificationApplicationFocusIn:
ImGui.GetIO().AddFocusEvent(true);
break;
case MainLoop.NotificationApplicationFocusOut:
ImGui.GetIO().AddFocusEvent(false);
break;
};
}

private static void UpdateKeyMods(ImGuiIOPtr io)
{
io.AddKeyEvent(ImGuiKey.ModCtrl, Godot.Input.IsKeyPressed(Key.Ctrl));
Expand Down
25 changes: 0 additions & 25 deletions addons/imgui-godot/ImGuiGodot/Internal/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,6 @@ public static unsafe void SetIniFilename(ImGuiIOPtr io, string fileName)
}
}

public static void Update(double delta, Viewport vp)
{
var io = ImGui.GetIO();
var vpSize = vp.GetVisibleRect().Size;
io.DisplaySize = new(vpSize.x, vpSize.y);
io.DeltaTime = (float)delta;

Input.Update(io);

ImGui.NewFrame();
}

public static void ProcessNotification(long what)
{
switch (what)
{
case MainLoop.NotificationApplicationFocusIn:
ImGui.GetIO().AddFocusEvent(true);
break;
case MainLoop.NotificationApplicationFocusOut:
ImGui.GetIO().AddFocusEvent(false);
break;
};
}

public static void AddLayerSubViewport(Node parent, out SubViewportContainer subViewportContainer, out SubViewport subViewport)
{
subViewportContainer = new SubViewportContainer
Expand Down

0 comments on commit ee24f10

Please sign in to comment.