Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make a line shown while popup menu #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Examples/Blueprints/Blueprints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,8 @@ void Application_Frame()
ImGui::EndPopup();
}

bool isNewNodePopuped = false;

if (ImGui::BeginPopup("Create New Node"))
{
auto newNodePostion = openPopupPosition;
Expand All @@ -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();
Expand Down Expand Up @@ -1528,6 +1532,11 @@ void Application_Frame()
cubic_bezier_subdivide(acceptPoint, c);
*/

if (isNewNodePopuped && newNodeLinkPin != nullptr)
{
ed::DrawLastLine();
}

ed::End();


Expand Down
2 changes: 1 addition & 1 deletion NodeEditor/Include/imgui_node_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ ImVec2 GetScreenSize();
ImVec2 ScreenToCanvas(const ImVec2& pos);
ImVec2 CanvasToScreen(const ImVec2& pos);


void DrawLastLine();



Expand Down
76 changes: 58 additions & 18 deletions NodeEditor/Source/imgui_node_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImDrawVert>& vtxBuffer, const ImVector<ImDrawIdx>& idxBuffer, const ImVector<ImDrawCmd>& cmdBuffer, const ImVec2& preOffset, const ImVec2& scale, const ImVec2& postOffset)
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -1668,7 +1668,7 @@ void ed::EditorContext::Resume()

bool ed::EditorContext::IsSuspended()
{
return m_Canvas.IsSuspended();
return m_Canvas.IsSuspended();
}

bool ed::EditorContext::IsActive()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

//------------------------------------------------------------------------------
//
Expand Down
5 changes: 5 additions & 0 deletions NodeEditor/Source/imgui_node_editor_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,8 @@ ImVec2 ax::NodeEditor::CanvasToScreen(const ImVec2& pos)
{
return s_Editor->ToScreen(pos);
}

void ax::NodeEditor::DrawLastLine()
{
return s_Editor->DrawLastLine();
}
15 changes: 15 additions & 0 deletions NodeEditor/Source/imgui_node_editor_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -1073,6 +1084,8 @@ struct CreateItemAction final : EditorAction
Result QueryLink(PinId* startId, PinId* endId);
Result QueryNode(PinId* pinId);

void DrawLastLine();

private:
bool m_IsInGlobalSpace;

Expand Down Expand Up @@ -1374,6 +1387,8 @@ struct EditorContext
return ImVec2(AlignPointToGrid(p.x), AlignPointToGrid(p.y));
}

void DrawLastLine();

private:
void LoadSettings();
void SaveSettings();
Expand Down