Skip to content

Commit

Permalink
WIP: Added draft support for reroute nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzinoth committed Aug 9, 2023
1 parent 4fa8edf commit 08303b6
Show file tree
Hide file tree
Showing 5 changed files with 664 additions and 229 deletions.
67 changes: 67 additions & 0 deletions SubSystems/VisualNodeArea/VisualNodeArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,71 @@ VisualNodeConnectionStyle* VisualNodeArea::GetConnectionStyle(const NodeSocket*
}

return nullptr;
}

std::vector<VisualNodeConnectionSegment> VisualNodeArea::GetConnectionSegments(const VisualNodeConnection* Connection) const
{
std::vector<VisualNodeConnectionSegment> Result;
VisualNodeConnectionSegment CurrentSegment;

ImVec2 BeginPosition;
ImVec2 EndPosition;

if (Connection->RerouteConnections.empty())
{
BeginPosition = SocketToPosition(Connection->Out);
EndPosition = SocketToPosition(Connection->In);

CurrentSegment.Begin = BeginPosition;
CurrentSegment.BeginSocket = Connection->Out;
CurrentSegment.End = EndPosition;
CurrentSegment.EndSocket = Connection->In;
Result.push_back(CurrentSegment);
}
else
{
for (size_t i = 0; i < Connection->RerouteConnections.size(); i++)
{
// First we will add segment from start to current reroute
if (Connection->RerouteConnections[i]->BeginSocket != nullptr)
{
BeginPosition = SocketToPosition(Connection->RerouteConnections[i]->BeginSocket);
CurrentSegment.BeginSocket = Connection->RerouteConnections[i]->BeginSocket;
}
else
{
BeginPosition = LocalToScreen(Connection->RerouteConnections[i]->BeginReroute->Position);
CurrentSegment.BeginReroute = Connection->RerouteConnections[i]->BeginReroute;
}

EndPosition = LocalToScreen(Connection->RerouteConnections[i]->Position);
CurrentSegment.EndReroute = Connection->RerouteConnections[i];

CurrentSegment.Begin = BeginPosition;
CurrentSegment.End = EndPosition;
Result.push_back(CurrentSegment);

// Than we will add segment from current reroute to end, only if it is last reroute
if (i == Connection->RerouteConnections.size() - 1)
{
CurrentSegment = VisualNodeConnectionSegment();
BeginPosition = LocalToScreen(Connection->RerouteConnections[i]->Position);
CurrentSegment.BeginReroute = Connection->RerouteConnections[i]/*->BeginReroute*/;

EndPosition = SocketToPosition(Connection->RerouteConnections[i]->EndSocket);
CurrentSegment.EndSocket = Connection->RerouteConnections[i]->EndSocket;

CurrentSegment.Begin = BeginPosition;
CurrentSegment.End = EndPosition;
Result.push_back(CurrentSegment);
}
}
}

return Result;
}

ImVec2 VisualNodeArea::LocalToScreen(ImVec2 LocalPosition) const
{
return ImGui::GetCurrentWindow()->Pos + LocalPosition * Zoom + RenderOffset;
}
49 changes: 41 additions & 8 deletions SubSystems/VisualNodeArea/VisualNodeArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class VisualNodeArea
float MAX_ZOOM_LEVEL = 5.0f; // Max zoom 500%
float MIN_ZOOM_LEVEL = 0.2f; // Min zoom 20%
float GetNodeSocketSize() const { return NODE_SOCKET_SIZE * Zoom; }
float GetRerouteNodeSize() const { return NODE_SOCKET_SIZE * Zoom * 1.5f; }
float GetNodeTitleHeight() const { return NODE_TITLE_HEIGHT * Zoom; }
ImVec2 GetMouseDragDelta() const { return ImGui::GetMouseDragDelta(0) * Zoom; }
ImVec2 GetMouseDelta() const { return ImGui::GetIO().MouseDelta / Zoom; }
Expand All @@ -117,6 +118,7 @@ class VisualNodeArea
bool bMouseHovered = false;
std::vector<VisualNode*> SelectedNodes;
std::vector<VisualNodeConnection*> SelectedConnections;
std::vector<VisualNodeRerouteNode*> SelectedRerouteNodes;

ImVec2 MouseCursorPosition;
ImVec2 MouseCursorSize = ImVec2(1, 1);
Expand All @@ -127,6 +129,7 @@ class VisualNodeArea
std::vector<VisualNodeConnection*> Connections;
NodeSocket* SocketLookingForConnection = nullptr;
NodeSocket* SocketHovered = nullptr;
VisualNodeRerouteNode* RerouteNodeHovered = nullptr;
ImVec2 AreaPosition;
ImVec2 AreaSize;
ImU32 GridBackgroundColor = IM_COL32(32, 32, 32, 255);
Expand All @@ -136,7 +139,6 @@ class VisualNodeArea
void(*MainContextMenuFunc)() = nullptr;
std::vector<void(*)(VisualNode*, VISUAL_NODE_EVENT)> NodeEventsCallbacks;
std::queue<SocketEvent> SocketEventQueue;


void PropagateNodeEventsCallbacks(VisualNode* Node, VISUAL_NODE_EVENT EventToPropagate) const;
void ProcessSocketEventQueue();
Expand All @@ -146,17 +148,45 @@ class VisualNodeArea

void InputUpdate();
void MouseInputUpdate();

void LeftMouseClick();
void LeftMouseClickNodesUpdate();
void LeftMouseClickConnectionsUpdate();
void LeftMouseClickRerouteUpdate();

void RightMouseClick();
void RightMouseClickNodesUpdate();
void RightMouseClickConnectionsUpdate();
void RightMouseClickRerouteUpdate();

void MouseDragging();
void MouseDraggingNodesUpdate();
void MouseDraggingConnectionsUpdate();
void MouseDraggingRerouteUpdate();

void KeyboardInputUpdate();
bool AddSelected(VisualNode* NewNode);
void InputUpdateNode(VisualNode* Node);
void InputUpdateSocket(NodeSocket* Socket);
void MouseInputUpdateConnections();
void InputUpdateReroute(VisualNodeRerouteNode* Reroute);

bool AddSelected(VisualNode* Node);
bool IsSelected(const VisualNode* Node) const;
bool AddSelected(VisualNodeConnection* NewConnection);
bool AddSelected(VisualNodeConnection* Connection);
bool IsSelected(const VisualNodeConnection* Connection) const;
bool UnSelected(const VisualNodeConnection* Connection);
bool IsMouseOverConnection(const ImVec2 mousePos, VisualNodeConnection* Connection, const int Steps, const float maxDistance, ImVec2& CollisionPoint = ImVec2());
bool IsPointInRegion(const ImVec2& point, const ImVec2& regionMin, const ImVec2& regionMax);
bool UnSelect(const VisualNodeConnection* Connection);
bool AddSelected(VisualNodeRerouteNode* RerouteNode);
bool IsSelected(const VisualNodeRerouteNode* RerouteNode) const;
bool UnSelect(const VisualNodeRerouteNode* RerouteNode);
void UnSelectAllRerouteNodes();

void ConnectionsDoubleMouseClick();
std::vector<VisualNodeConnectionSegment> GetConnectionSegments(const VisualNodeConnection* Connection) const;
bool IsMouseOverConnection(VisualNodeConnection* Connection, const int Steps, const float MaxDistance, ImVec2& CollisionPoint = ImVec2());
bool IsMouseOverSegment(ImVec2 Begin, ImVec2 End, const int Steps, const float MaxDistance, ImVec2& CollisionPoint = ImVec2());
bool IsPointInRegion(const ImVec2& Point, const ImVec2& RegionMin, const ImVec2& RegionMax);
bool IsSegmentInRegion(ImVec2 Begin, ImVec2 End, const int Steps);
bool IsConnectionInRegion(VisualNodeConnection* Connection, const int Steps);
void InputUpdateNode(VisualNode* Node);
void InputUpdateSocket(NodeSocket* Socket);

void Render();
void RenderGrid(ImVec2 CurrentPosition) const;
Expand All @@ -166,7 +196,10 @@ class VisualNodeArea
void DrawHermiteLine(ImVec2 P1, ImVec2 P2, int Steps, ImColor Color, const VisualNodeConnectionStyle* Style) const;
void DrawHermiteLine(const ImVec2 P1, const ImVec2 P2, const int Steps, const ImColor Color, const float Thickness) const;
void RenderConnection(const VisualNodeConnection* Connection) const;
void RenderReroute(const VisualNodeRerouteNode* RerouteNode) const;
VisualNodeConnectionStyle* GetConnectionStyle(const NodeSocket* ParticipantOfConnection) const;

bool IsMouseRegionSelectionActive() const;

ImVec2 LocalToScreen(ImVec2 LocalPosition) const;
};
Loading

0 comments on commit 08303b6

Please sign in to comment.