Skip to content

Commit

Permalink
Draw the arc we are creating
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Jan 9, 2024
1 parent 0a96701 commit 6e966fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Editor/DearImGui/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ static void drawArrow(ImDrawList* draw_list, ImVec2 const& A, ImVec2 const& B,
draw_list->AddConvexPolyFilled(points.data(), points.size(), color);
}

//------------------------------------------------------------------------------
void drawArc(ImDrawList* draw_list, Node* from, Node* to, ImVec2* click_position, ImVec2 const& origin, ImVec2 const& cursor)
{
if (from != nullptr)
{
drawArrow(draw_list,
origin + ImVec2(from->x, from->y),
origin + ImVec2(cursor.x, cursor.y),
OUTLINE_COLOR);
}
else if (to != nullptr)
{
drawArrow(draw_list,
origin + ImVec2(cursor.x, cursor.y),
origin + ImVec2(to->x, to->y),
OUTLINE_COLOR);
}
else if (click_position != nullptr)
{
drawArrow(draw_list,
origin + ImVec2(click_position->x, click_position->y),
origin + ImVec2(cursor.x, cursor.y),
OUTLINE_COLOR);
}
}

//------------------------------------------------------------------------------
void drawArc(ImDrawList* draw_list, Arc const& arc, TypeOfNet const type, ImVec2 const& origin, float const alpha)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Editor/DearImGui/Drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static const float TRANS_HEIGHT = TRANS_WIDTH / 3.0f; // Rectangle height for r
static const float PLACE_RADIUS = TRANS_WIDTH / 2.0f; // Circle radius for rendering Places
static const float TOKEN_RADIUS = 2.0f; // Circle radius for rendering tokens


void drawArc(ImDrawList* draw_list, Node* from, Node* to, ImVec2* click_position, ImVec2 const& origin, ImVec2 const& cursor);
void drawArc(ImDrawList* draw_list, Arc const& arc, TypeOfNet const type, ImVec2 const& origin, float const alpha);
void drawToken(ImDrawList* draw_list, float const x, float const y);
void drawTimedToken(ImDrawList* draw_list, size_t tokens, float const x, float const y);
Expand Down
5 changes: 5 additions & 0 deletions src/Editor/PetriEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,11 @@ void Editor::PetriView::drawPetriNet(Net& net, Simulation& simulation)
it->y = m_mouse.position.y;
}

// Show the arc we are creating
drawArc(m_canvas.draw_list, m_mouse.from, m_mouse.to,
m_mouse.arc_from_unknown_node ? &m_mouse.click_position : nullptr,
origin, m_mouse.position);

// Draw critical cycle
//for (auto& a: m_marked_arcs)
// draw(*a, 255);
Expand Down

0 comments on commit 6e966fc

Please sign in to comment.