diff --git a/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs b/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs index 6f99712..4640a10 100644 --- a/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs +++ b/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs @@ -153,13 +153,22 @@ private void OnChangeVisibility() if (Visible) { ProcessMode = ProcessModeEnum.Always; - // TODO: show all windows + // TODO: fix position with multiple monitors + //foreach (Node child in GetChildren()) + //{ + // if (child is Window w) + // w.Show(); + //} } else { ProcessMode = ProcessModeEnum.Disabled; Internal.Renderer.OnHide(); - // TODO: hide all windows + //foreach (Node child in GetChildren()) + //{ + // if (child is Window w) + // w.Hide(); + //} } } diff --git a/addons/imgui-godot/ImGuiGodot/Internal.cs b/addons/imgui-godot/ImGuiGodot/Internal.cs index 3112d5a..baf8466 100644 --- a/addons/imgui-godot/ImGuiGodot/Internal.cs +++ b/addons/imgui-godot/ImGuiGodot/Internal.cs @@ -261,9 +261,22 @@ public static void Update(double delta, Viewport vp) if (io.WantSetMousePos) { - Input.WarpMouse(new(io.MousePos.X, io.MousePos.Y)); + // TODO: get current focused window + // Input.WarpMouse(new(io.MousePos.X, io.MousePos.Y)); + } + else + { + var mousePos = DisplayServer.MouseGetPosition(); + io.AddMousePosEvent(mousePos.x, mousePos.y); } + MouseButton mbs = DisplayServer.MouseGetButtonState(); + io.AddMouseButtonEvent((int)ImGuiMouseButton.Left, mbs.HasFlag(MouseButton.Left)); + io.AddMouseButtonEvent((int)ImGuiMouseButton.Right, mbs.HasFlag(MouseButton.Right)); + io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle, mbs.HasFlag(MouseButton.Middle)); + io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle + 1, mbs.HasFlag(MouseButton.Xbutton1)); + io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle + 2, mbs.HasFlag(MouseButton.Xbutton2)); + // scrolling works better if we allow no more than one event per frame if (_mouseWheel != Vector2.Zero) { @@ -326,31 +339,14 @@ public static bool ProcessInput(InputEvent evt, Window window) bool consumed = false; - if (evt is InputEventMouseMotion mm) + if (evt is InputEventMouseMotion) { - GD.Print($"{windowPos.x + mm.GlobalPosition.x}, {windowPos.y + mm.GlobalPosition.y}"); - io.AddMousePosEvent(windowPos.x + mm.GlobalPosition.x, windowPos.y + mm.GlobalPosition.y); consumed = io.WantCaptureMouse; } else if (evt is InputEventMouseButton mb) { switch (mb.ButtonIndex) { - case MouseButton.Left: - io.AddMouseButtonEvent((int)ImGuiMouseButton.Left, mb.Pressed); - break; - case MouseButton.Right: - io.AddMouseButtonEvent((int)ImGuiMouseButton.Right, mb.Pressed); - break; - case MouseButton.Middle: - io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle, mb.Pressed); - break; - case MouseButton.Xbutton1: - io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle + 1, mb.Pressed); - break; - case MouseButton.Xbutton2: - io.AddMouseButtonEvent((int)ImGuiMouseButton.Middle + 2, mb.Pressed); - break; case MouseButton.WheelUp: _mouseWheel.y = mb.Factor; break;