diff --git a/Examples/Blueprints/Blueprints.cpp b/Examples/Blueprints/Blueprints.cpp index 90216f440..8d3dcf3c2 100644 --- a/Examples/Blueprints/Blueprints.cpp +++ b/Examples/Blueprints/Blueprints.cpp @@ -1429,6 +1429,8 @@ void Application_Frame() ImGui::EndPopup(); } + bool isNewNodePopuped = false; + if (ImGui::BeginPopup("Create New Node")) { auto newNodePostion = openPopupPosition; @@ -1437,6 +1439,8 @@ void Application_Frame() //auto drawList = ImGui::GetWindowDrawList(); //drawList->AddCircleFilled(ImGui::GetMousePosOnOpeningCurrentPopup(), 10.0f, 0xFFFF00FF); + isNewNodePopuped = true; + Node* node = nullptr; if (ImGui::MenuItem("Input Action")) node = SpawnInputActionNode(); @@ -1528,6 +1532,11 @@ void Application_Frame() cubic_bezier_subdivide(acceptPoint, c); */ + if (isNewNodePopuped && newNodeLinkPin != nullptr) + { + ed::DrawLastLine(); + } + ed::End(); diff --git a/NodeEditor/Include/imgui_node_editor.h b/NodeEditor/Include/imgui_node_editor.h index 98a83c695..d0a4a725b 100644 --- a/NodeEditor/Include/imgui_node_editor.h +++ b/NodeEditor/Include/imgui_node_editor.h @@ -340,7 +340,7 @@ ImVec2 GetScreenSize(); ImVec2 ScreenToCanvas(const ImVec2& pos); ImVec2 CanvasToScreen(const ImVec2& pos); - +void DrawLastLine(); diff --git a/NodeEditor/Source/imgui_node_editor.cpp b/NodeEditor/Source/imgui_node_editor.cpp index 0186e053f..1ab57612b 100644 --- a/NodeEditor/Source/imgui_node_editor.cpp +++ b/NodeEditor/Source/imgui_node_editor.cpp @@ -196,34 +196,34 @@ static void ImDrawListSplitter_Grow(ImDrawList* draw_list, ImDrawListSplitter* s static void ImDrawList_ChannelsGrow(ImDrawList* draw_list, int channels_count) { - ImDrawListSplitter_Grow(draw_list, &draw_list->_Splitter, channels_count); + ImDrawListSplitter_Grow(draw_list, &draw_list->_Splitter, channels_count); } static void ImDrawListSplitter_SwapChannels(ImDrawListSplitter* splitter, int left, int right) { - IM_ASSERT(left < splitter->_Count && right < splitter->_Count); - if (left == right) - return; + IM_ASSERT(left < splitter->_Count && right < splitter->_Count); + if (left == right) + return; - auto currentChannel = splitter->_Current; + auto currentChannel = splitter->_Current; - auto* leftCmdBuffer = &splitter->_Channels[left]._CmdBuffer; - auto* leftIdxBuffer = &splitter->_Channels[left]._IdxBuffer; - auto* rightCmdBuffer = &splitter->_Channels[right]._CmdBuffer; - auto* rightIdxBuffer = &splitter->_Channels[right]._IdxBuffer; + auto* leftCmdBuffer = &splitter->_Channels[left]._CmdBuffer; + auto* leftIdxBuffer = &splitter->_Channels[left]._IdxBuffer; + auto* rightCmdBuffer = &splitter->_Channels[right]._CmdBuffer; + auto* rightIdxBuffer = &splitter->_Channels[right]._IdxBuffer; - leftCmdBuffer->swap(*rightCmdBuffer); - leftIdxBuffer->swap(*rightIdxBuffer); + leftCmdBuffer->swap(*rightCmdBuffer); + leftIdxBuffer->swap(*rightIdxBuffer); - if (currentChannel == left) - splitter->_Current = right; - else if (currentChannel == right) - splitter->_Current = left; + if (currentChannel == left) + splitter->_Current = right; + else if (currentChannel == right) + splitter->_Current = left; } static void ImDrawList_SwapChannels(ImDrawList* drawList, int left, int right) { - ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right); + ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right); } //static void ImDrawList_TransformChannel_Inner(ImVector& vtxBuffer, const ImVector& idxBuffer, const ImVector& cmdBuffer, const ImVec2& preOffset, const ImVec2& scale, const ImVec2& postOffset) @@ -1081,7 +1081,7 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size) m_IsWindowActive = ImGui::IsWindowFocused(); // - m_NavigateAction.SetWindow(m_Canvas.ViewRect().Min, m_Canvas.ViewRect().GetSize()); + m_NavigateAction.SetWindow(m_Canvas.ViewRect().Min, m_Canvas.ViewRect().GetSize()); if (m_CurrentAction && m_CurrentAction->IsDragging() && m_NavigateAction.MoveOverEdge()) { @@ -1668,7 +1668,7 @@ void ed::EditorContext::Resume() bool ed::EditorContext::IsSuspended() { - return m_Canvas.IsSuspended(); + return m_Canvas.IsSuspended(); } bool ed::EditorContext::IsActive() @@ -1955,6 +1955,11 @@ bool ed::EditorContext::AreShortcutsEnabled() return m_ShortcutsEnabled; } +void ed::EditorContext::DrawLastLine() +{ + m_CreateItemAction.DrawLastLine(); +} + ed::Control ed::EditorContext::BuildControl(bool allowOffscreen) { if (!allowOffscreen && !ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) @@ -4129,6 +4134,18 @@ bool ed::CreateItemAction::Process(const Control& control) candidate.UpdateEndpoints(); candidate.Draw(drawList, m_LinkColor, m_LinkThickness); + + m_lastStartPinKind = candidate.m_StartPin->m_Kind; + m_lastStartPivot = candidate.m_StartPin->m_Pivot; + m_lastStartDir = candidate.m_StartPin->m_Dir; + m_lastStartPinCorners = candidate.m_StartPin->m_Corners; + m_lastStartPinStrength = candidate.m_StartPin->m_Strength; + + m_lastEndPinKind = candidate.m_EndPin->m_Kind; + m_lastEndPivot = candidate.m_EndPin->m_Pivot; + m_lastEndDir = candidate.m_EndPin->m_Dir; + m_lastEndPinCorners = candidate.m_EndPin->m_Corners; + m_lastEndPinStrength = candidate.m_EndPin->m_Strength; } else if (m_CurrentStage == Possible || !control.ActivePin) { @@ -4364,8 +4381,31 @@ ed::CreateItemAction::Result ed::CreateItemAction::QueryNode(PinId* pinId) return True; } +void ed::CreateItemAction::DrawLastLine() +{ + ed::Pin startPin(Editor, 0, m_lastStartPinKind); + startPin.m_Pivot = m_lastStartPivot; + startPin.m_Dir = m_lastStartDir; + startPin.m_Corners = m_lastStartPinCorners; + startPin.m_Strength = m_lastStartPinStrength; + + ed::Pin endPin(Editor, 0, m_lastEndPinKind); + endPin.m_Pivot = m_lastEndPivot; + endPin.m_Dir = m_lastEndDir; + endPin.m_Corners = m_lastEndPinCorners; + endPin.m_Strength = m_lastEndPinStrength; + ed::Link candidate(Editor, 0); + candidate.m_Color = m_LinkColor; + candidate.m_StartPin = &startPin; + candidate.m_EndPin = &endPin; + auto drawList = ImGui::GetWindowDrawList(); + drawList->ChannelsSetCurrent(c_LinkChannel_NewLink); + + candidate.UpdateEndpoints(); + candidate.Draw(drawList, m_LinkColor, m_LinkThickness); +} //------------------------------------------------------------------------------ // diff --git a/NodeEditor/Source/imgui_node_editor_api.cpp b/NodeEditor/Source/imgui_node_editor_api.cpp index d468b4e8e..2b270002b 100644 --- a/NodeEditor/Source/imgui_node_editor_api.cpp +++ b/NodeEditor/Source/imgui_node_editor_api.cpp @@ -635,3 +635,8 @@ ImVec2 ax::NodeEditor::CanvasToScreen(const ImVec2& pos) { return s_Editor->ToScreen(pos); } + +void ax::NodeEditor::DrawLastLine() +{ + return s_Editor->DrawLastLine(); +} \ No newline at end of file diff --git a/NodeEditor/Source/imgui_node_editor_internal.h b/NodeEditor/Source/imgui_node_editor_internal.h index 3bbe8048f..d21f9d784 100644 --- a/NodeEditor/Source/imgui_node_editor_internal.h +++ b/NodeEditor/Source/imgui_node_editor_internal.h @@ -1046,6 +1046,17 @@ struct CreateItemAction final : EditorAction int m_LastChannel = -1; + PinKind m_lastStartPinKind; + ImRect m_lastStartPivot; + ImVec2 m_lastStartDir; + float m_lastStartPinCorners; + float m_lastStartPinStrength; + + PinKind m_lastEndPinKind; + ImRect m_lastEndPivot; + ImVec2 m_lastEndDir; + float m_lastEndPinCorners; + float m_lastEndPinStrength; CreateItemAction(EditorContext* editor); @@ -1073,6 +1084,8 @@ struct CreateItemAction final : EditorAction Result QueryLink(PinId* startId, PinId* endId); Result QueryNode(PinId* pinId); + void DrawLastLine(); + private: bool m_IsInGlobalSpace; @@ -1374,6 +1387,8 @@ struct EditorContext return ImVec2(AlignPointToGrid(p.x), AlignPointToGrid(p.y)); } + void DrawLastLine(); + private: void LoadSettings(); void SaveSettings();