CedricGuillemet / ImGuizmo

Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui
MIT License
3.22k stars 907 forks source link

Fixed ImGuizmo::IsOver ignores ImGuizmo::SetID state #289

Closed adamkewley closed 1 year ago

adamkewley commented 1 year ago

Thank you for this amazing library - it has been extremely useful in my software!

This PR is a casual suggestion for making ImGuizmo::IsUsing respect ImGuizmo::SetID(). The idea being that calling IsUsing when an ID is set should only return true if the gizmo with that ID is the one currently being manipulated.

I'm not married to this implementation/fix and I'd welcome any alternate approaches (maybe I missed something). The reason I ultimately need it is because I'm using IsUsing to implement something similar to ImGui::IsItemDeactivatedAfterEdit (longer explanation below).

Context (if it's handy)

Just for some context, I develop opensim-creator, which uses ImGuizmo internally. Here's a screenshot of it in use:

imguizmo_screenshot

The UI supports multiple viewports, and the ImGuizmo-to-application interaction I need is similar to ImGui's IsItemDeactivatedAfterEdit function, which is that I need a flow like:

And the way I'm doing that is to keep track of state using bool usingThisFrame = ImGuizmo::IsUsing(); if (usingThisFrame && !m_WasUsingLastFrame) { saveToUndoRedo(); } m_WasUsingLastFrame = usingThisFrame;. The exact code I'm using to do that is here, but it fails (by saving multiple times) when multiple gizmos are shown, because IsUsing will return true for all viewports - even if only one viewport is actually using a gizmo.