From 7c7a76545540eb3b444c4253dd7330a2e684130f Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Wed, 1 May 2024 11:59:30 +0200 Subject: [PATCH] New nodes now spawn at popup start location. --- src/AnimGraph/AnimGraphEditor.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AnimGraph/AnimGraphEditor.cc b/src/AnimGraph/AnimGraphEditor.cc index 480d40f..3242b71 100644 --- a/src/AnimGraph/AnimGraphEditor.cc +++ b/src/AnimGraph/AnimGraphEditor.cc @@ -20,6 +20,7 @@ struct EditorState { size_t hierarchyStackIndex = 0; bool isGraphLoadedThisFrame = false; + ImVec2 mousePopupStart = {}; }; static EditorState sEditorState; @@ -520,13 +521,12 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { { const bool open_popup = ImGui::IsMouseReleased(ImGuiMouseButton_Right); - ImVec2 popup_mouse_position = ImGui::GetMousePos(); - - ax::NodeEditor::Suspend(); - if (open_popup) { + if (open_popup && ImGui::IsWindowHovered()) { + ax::NodeEditor::Suspend(); ImGui::OpenPopup("add node"); + ax::NodeEditor::Resume(); + sEditorState.mousePopupStart = ImGui::GetMousePos(); } - ax::NodeEditor::Resume(); ax::NodeEditor::Suspend(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 8.f)); @@ -570,7 +570,7 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) { size_t node_id = sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex] ->m_blend_tree_resource.GetNumNodes(); - ax::NodeEditor::SetNodePosition(node_id, popup_mouse_position); + ax::NodeEditor::SetNodePosition(node_id, sEditorState.mousePopupStart); sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex] ->m_blend_tree_resource.AddNode(node_resource); }