mirror of
https://github.com/pkdawson/imgui-godot.git
synced 2026-09-18 12:44:18 +00:00
use better viewport id
This commit is contained in:
@@ -8,7 +8,7 @@ After installing the plugin, usage is as simple as this:
|
||||
```csharp
|
||||
public partial class MyNode : Node
|
||||
{
|
||||
public override void _Process()
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
ImGui.Begin("ImGui on Godot 4");
|
||||
ImGui.Text("hello world");
|
||||
|
||||
@@ -18,19 +18,19 @@ internal static class ImGuiGDInternal
|
||||
private static GCHandle _backendName = GCHandle.Alloc(Encoding.ASCII.GetBytes("imgui_impl_godot4"), GCHandleType.Pinned);
|
||||
|
||||
// necessary because we can't construct arbitrary RIDs without using reflection
|
||||
private static Dictionary<IntPtr, RID> _rids = new();
|
||||
private static Dictionary<IntPtr, RID> _texrids = new();
|
||||
|
||||
public static IntPtr BindTexture(Texture2D tex)
|
||||
{
|
||||
RID rid = tex.GetRid();
|
||||
IntPtr texid = (IntPtr)rid.Id;
|
||||
_rids.TryAdd(texid, rid);
|
||||
_texrids.TryAdd(texid, rid);
|
||||
return texid;
|
||||
}
|
||||
|
||||
public static void UnbindTexture(IntPtr texid)
|
||||
{
|
||||
_rids.Remove(texid);
|
||||
_texrids.Remove(texid);
|
||||
}
|
||||
|
||||
public static unsafe ImFontPtr AddFont(FontFile fontData, float fontSize, bool merge)
|
||||
@@ -176,8 +176,6 @@ internal static class ImGuiGDInternal
|
||||
{
|
||||
// TODO: correct mouse pos
|
||||
CurrentSubViewport.PushInput(evt, true);
|
||||
if (evt is not InputEventMouseMotion)
|
||||
return true;
|
||||
}
|
||||
|
||||
var io = ImGui.GetIO();
|
||||
@@ -391,8 +389,7 @@ internal static class ImGuiGDInternal
|
||||
|
||||
RID child = _children[nodeN++];
|
||||
|
||||
IntPtr texid = drawCmd.GetTexID();
|
||||
RID texrid = _rids[texid];
|
||||
RID texrid = _texrids[drawCmd.GetTexID()];
|
||||
RenderingServer.CanvasItemClear(child);
|
||||
RenderingServer.CanvasItemSetClip(child, true);
|
||||
RenderingServer.CanvasItemSetCustomRect(child, true, new Rect2(
|
||||
|
||||
@@ -18,7 +18,10 @@ public static class ImGuiGodot
|
||||
var pos_max = new Vector2(pos.X + vpSize.X, pos.Y + vpSize.Y);
|
||||
ImGui.GetWindowDrawList().AddImage(ImGuiGD.BindTexture(vp.GetTexture()), pos, pos_max);
|
||||
|
||||
ImGui.InvisibleButton(string.Format("{0}##{1}", vp.Name, vp.GetViewportRid().Id), vpSize);
|
||||
ImGui.PushID(vp.NativeInstance);
|
||||
ImGui.InvisibleButton("godot_subviewport", vpSize);
|
||||
ImGui.PopID();
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGuiGDInternal.CurrentSubViewport = vp;
|
||||
|
||||
@@ -19,6 +19,7 @@ color = Color(0.0784314, 0, 0.117647, 1)
|
||||
script = ExtResource("2_gnjei")
|
||||
|
||||
[node name="ShowHideButton" type="Button" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
@@ -31,7 +32,9 @@ offset_right = -7.0
|
||||
offset_bottom = -8.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
text = "show/hide"
|
||||
focus_mode = 0
|
||||
toggle_mode = true
|
||||
text = "hide"
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -3,17 +3,6 @@ using ImGuiNET;
|
||||
|
||||
public partial class MyNode : Node
|
||||
{
|
||||
public override void _EnterTree()
|
||||
{
|
||||
if (ImGuiLayer.Instance is null)
|
||||
{
|
||||
// if the plugin is disabled, we can do some basic setup to avoid crashes
|
||||
ImGuiGD.Init();
|
||||
ImGuiGD.RebuildFontAtlas();
|
||||
ImGui.NewFrame();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
ImGui.ShowDemoWindow();
|
||||
|
||||
@@ -82,5 +82,14 @@ public partial class MySecondNode : Node
|
||||
private void _on_show_hide()
|
||||
{
|
||||
ImGuiLayer.Instance.Visible = !ImGuiLayer.Instance.Visible;
|
||||
if (ImGuiLayer.Instance.Visible)
|
||||
{
|
||||
GetNode<Button>("%ShowHideButton").Text = "hide";
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNode<Button>("%ShowHideButton").Text = "show";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user