Skip to content

Commit a102f45

Browse files
committed
Refactor connection interaction class hierarchy.
1 parent 56cac15 commit a102f45

3 files changed

Lines changed: 174 additions & 84 deletions

File tree

Sources/NodeUIEngine/NUIE_ConnectionInteractions.cpp

Lines changed: 100 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@
77
namespace NUIE
88
{
99

10-
NodeOutputToInputConnectionHandler::NodeOutputToInputConnectionHandler (NodeUIManager& uiManager, const UIOutputSlotConstPtr& startSlot, const Point& startSlotPosition) :
11-
NodeConnectionHandler<UIOutputSlotConstPtr, UIInputSlotConstPtr> (uiManager, startSlot, startSlotPosition)
10+
ConnectionStartOutputSlot::ConnectionStartOutputSlot (const UIOutputSlotConstPtr& slot, const Point& position) :
11+
slot (slot),
12+
position (position)
1213
{
13-
14+
1415
}
1516

16-
void NodeOutputToInputConnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
17+
ConnectionStartInputSlot::ConnectionStartInputSlot (const UIInputSlotConstPtr& slot, const Point& position) :
18+
slot (slot),
19+
position (position)
1720
{
18-
const ViewBox& viewBox = uiManager.GetViewBox ();
19-
Point position = viewBox.ViewToModel (currentPosition);
20-
processor (startSlotPosition, position, Direction::Forward);
21+
22+
}
23+
24+
NodeOutputToInputConnectionHandlerBase::NodeOutputToInputConnectionHandlerBase (NodeUIManager& uiManager) :
25+
MouseMoveHandler (),
26+
uiManager (uiManager),
27+
endSlot (nullptr)
28+
{
29+
2130
}
2231

23-
void NodeOutputToInputConnectionHandler::HandleMouseMove (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point& position)
32+
void NodeOutputToInputConnectionHandlerBase::HandleMouseMove (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point& position)
2433
{
2534
const ViewBox& viewBox = uiManager.GetViewBox ();
2635
currentPosition = position;
2736
endSlot = FindInputSlotUnderPosition (uiManager, uiEnvironment, currentPosition);
2837
if (endSlot != nullptr) {
29-
if (CanConnectToInputSlot (startSlot, endSlot)) {
38+
if (CanConnectToInputSlot (endSlot)) {
3039
UINodePtr uiNode = uiManager.GetNode (endSlot->GetOwnerNodeId ());
3140
currentPosition = viewBox.ModelToView (uiNode->GetInputSlotConnPosition (uiEnvironment, endSlot->GetId ()));
3241
} else {
@@ -36,34 +45,60 @@ void NodeOutputToInputConnectionHandler::HandleMouseMove (NodeUIEnvironment& uiE
3645
uiManager.RequestRedraw ();
3746
}
3847

48+
void NodeOutputToInputConnectionHandlerBase::HandleAbort ()
49+
{
50+
uiManager.RequestRedraw ();
51+
}
52+
53+
NodeOutputToInputConnectionHandler::NodeOutputToInputConnectionHandler (NodeUIManager& uiManager, const ConnectionStartOutputSlot& startSlot) :
54+
NodeOutputToInputConnectionHandlerBase (uiManager),
55+
startSlot (startSlot)
56+
{
57+
58+
}
59+
60+
void NodeOutputToInputConnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
61+
{
62+
const ViewBox& viewBox = uiManager.GetViewBox ();
63+
Point position = viewBox.ViewToModel (currentPosition);
64+
processor (startSlot.position, position, Direction::Forward);
65+
}
66+
3967
void NodeOutputToInputConnectionHandler::HandleMouseUp (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point&)
4068
{
4169
if (endSlot != nullptr) {
42-
ConnectSlotsCommand command (startSlot, endSlot);
70+
ConnectSlotsCommand command (startSlot.slot, endSlot);
4371
uiManager.ExecuteCommand (command, uiEnvironment);
4472
} else {
4573
uiManager.RequestRedraw ();
4674
}
4775
}
4876

49-
bool NodeOutputToInputConnectionHandler::CanConnectToInputSlot (const UIOutputSlotConstPtr& outputSlot, const UIInputSlotConstPtr& inputSlot) const
77+
bool NodeOutputToInputConnectionHandler::CanConnectToInputSlot (const UIInputSlotConstPtr& inputSlot) const
5078
{
51-
return uiManager.CanConnectOutputSlotToInputSlot (outputSlot, inputSlot);
79+
return uiManager.CanConnectOutputSlotToInputSlot (startSlot.slot, inputSlot);
5280
}
5381

54-
55-
NodeOutputToInputReconnectionHandler::NodeOutputToInputReconnectionHandler (NodeUIManager& uiManager, const UIOutputSlotConstPtr& startSlot, const UIInputSlotConstPtr& originalEndSlot, const Point& startSlotPosition) :
56-
NodeOutputToInputConnectionHandler (uiManager, startSlot, startSlotPosition),
82+
NodeOutputToInputReconnectionHandler::NodeOutputToInputReconnectionHandler (NodeUIManager& uiManager, const ConnectionStartOutputSlot& startSlot, const UIInputSlotConstPtr& originalEndSlot) :
83+
NodeOutputToInputConnectionHandlerBase (uiManager),
84+
startSlot (startSlot),
5785
originalEndSlot (originalEndSlot)
5886
{
5987

6088
}
6189

90+
void NodeOutputToInputReconnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
91+
{
92+
const ViewBox& viewBox = uiManager.GetViewBox ();
93+
Point position = viewBox.ViewToModel (currentPosition);
94+
processor (startSlot.position, position, Direction::Forward);
95+
}
96+
6297
bool NodeOutputToInputReconnectionHandler::NeedToDrawConnection (const NE::NodeId& outputNodeId, const NE::SlotId& outputSlotId, const NE::NodeId& inputNodeId, const NE::SlotId& inputSlotId) const
6398
{
64-
if (outputNodeId == startSlot->GetOwnerNodeId () &&
99+
if (outputNodeId == startSlot.slot->GetOwnerNodeId () &&
65100
inputNodeId == originalEndSlot->GetOwnerNodeId () &&
66-
outputSlotId == startSlot->GetId () &&
101+
outputSlotId == startSlot.slot->GetId () &&
67102
inputSlotId == originalEndSlot->GetId ())
68103
{
69104
return false;
@@ -74,47 +109,42 @@ bool NodeOutputToInputReconnectionHandler::NeedToDrawConnection (const NE::NodeI
74109
void NodeOutputToInputReconnectionHandler::HandleMouseUp (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point&)
75110
{
76111
if (endSlot != nullptr && endSlot != originalEndSlot) {
77-
ReconnectInputSlotCommand command (startSlot, originalEndSlot, endSlot);
112+
ReconnectInputSlotCommand command (startSlot.slot, originalEndSlot, endSlot);
78113
uiManager.ExecuteCommand (command, uiEnvironment);
79114
} else if (endSlot == nullptr) {
80-
DisconnectSlotsCommand disconnectCommand (startSlot, originalEndSlot);
115+
DisconnectSlotsCommand disconnectCommand (startSlot.slot, originalEndSlot);
81116
uiManager.ExecuteCommand (disconnectCommand, uiEnvironment);
82117
} else {
83118
uiManager.RequestRedraw ();
84119
}
85120
}
86121

87-
bool NodeOutputToInputReconnectionHandler::CanConnectToInputSlot (const UIOutputSlotConstPtr& outputSlot, const UIInputSlotConstPtr& inputSlot) const
122+
bool NodeOutputToInputReconnectionHandler::CanConnectToInputSlot (const UIInputSlotConstPtr& inputSlot) const
88123
{
89124
if (inputSlot == originalEndSlot) {
90125
return true;
91126
}
92-
if (uiManager.CanConnectOutputSlotToInputSlot (outputSlot, inputSlot)) {
127+
if (uiManager.CanConnectOutputSlotToInputSlot (startSlot.slot, inputSlot)) {
93128
return true;
94129
}
95130
return false;
96131
}
97132

98-
NodeInputToOutputConnectionHandler::NodeInputToOutputConnectionHandler (NodeUIManager& uiManager, const UIInputSlotConstPtr& startSlot, const Point& startSlotPosition) :
99-
NodeConnectionHandler<UIInputSlotConstPtr, UIOutputSlotConstPtr> (uiManager, startSlot, startSlotPosition)
133+
NodeInputToOutputConnectionHandlerBase::NodeInputToOutputConnectionHandlerBase (NodeUIManager& uiManager) :
134+
MouseMoveHandler (),
135+
uiManager (uiManager),
136+
endSlot (nullptr)
100137
{
101138

102139
}
103140

104-
void NodeInputToOutputConnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
105-
{
106-
const ViewBox& viewBox = uiManager.GetViewBox ();
107-
Point position = viewBox.ViewToModel (currentPosition);
108-
processor (position, startSlotPosition, Direction::Backward);
109-
}
110-
111-
void NodeInputToOutputConnectionHandler::HandleMouseMove (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point& position)
141+
void NodeInputToOutputConnectionHandlerBase::HandleMouseMove (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point& position)
112142
{
113143
const ViewBox& viewBox = uiManager.GetViewBox ();
114144
currentPosition = position;
115145
endSlot = FindOutputSlotUnderPosition (uiManager, uiEnvironment, currentPosition);
116146
if (endSlot != nullptr) {
117-
if (CanConnectToOutputSlot (endSlot, startSlot)) {
147+
if (CanConnectToOutputSlot (endSlot)) {
118148
UINodePtr uiNode = uiManager.GetNode (endSlot->GetOwnerNodeId ());
119149
currentPosition = viewBox.ModelToView (uiNode->GetOutputSlotConnPosition (uiEnvironment, endSlot->GetId ()));
120150
} else {
@@ -124,34 +154,61 @@ void NodeInputToOutputConnectionHandler::HandleMouseMove (NodeUIEnvironment& uiE
124154
uiManager.RequestRedraw ();
125155
}
126156

157+
void NodeInputToOutputConnectionHandlerBase::HandleAbort ()
158+
{
159+
uiManager.RequestRedraw ();
160+
}
161+
162+
NodeInputToOutputConnectionHandler::NodeInputToOutputConnectionHandler (NodeUIManager& uiManager, const ConnectionStartInputSlot& startSlot) :
163+
NodeInputToOutputConnectionHandlerBase (uiManager),
164+
startSlot (startSlot)
165+
{
166+
167+
}
168+
169+
void NodeInputToOutputConnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
170+
{
171+
const ViewBox& viewBox = uiManager.GetViewBox ();
172+
Point position = viewBox.ViewToModel (currentPosition);
173+
processor (position, startSlot.position, Direction::Backward);
174+
}
175+
127176
void NodeInputToOutputConnectionHandler::HandleMouseUp (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point&)
128177
{
129178
if (endSlot != nullptr) {
130-
ConnectSlotsCommand command (endSlot, startSlot);
179+
ConnectSlotsCommand command (endSlot, startSlot.slot);
131180
uiManager.ExecuteCommand (command, uiEnvironment);
132181
} else {
133182
uiManager.RequestRedraw ();
134183
}
135184
}
136185

137-
bool NodeInputToOutputConnectionHandler::CanConnectToOutputSlot (const UIOutputSlotConstPtr& outputSlot, const UIInputSlotConstPtr& inputSlot) const
186+
bool NodeInputToOutputConnectionHandler::CanConnectToOutputSlot (const UIOutputSlotConstPtr& outputSlot) const
138187
{
139-
return uiManager.CanConnectOutputSlotToInputSlot (outputSlot, inputSlot);
188+
return uiManager.CanConnectOutputSlotToInputSlot (outputSlot, startSlot.slot);
140189
}
141190

142-
NodeInputToOutputReconnectionHandler::NodeInputToOutputReconnectionHandler (NodeUIManager& uiManager, const UIInputSlotConstPtr& startSlot, const UIOutputSlotConstPtr& originalEndSlot, const Point& startSlotPosition) :
143-
NodeInputToOutputConnectionHandler (uiManager, startSlot, startSlotPosition),
191+
NodeInputToOutputReconnectionHandler::NodeInputToOutputReconnectionHandler (NodeUIManager& uiManager, const ConnectionStartInputSlot& startSlot, const UIOutputSlotConstPtr& originalEndSlot) :
192+
NodeInputToOutputConnectionHandlerBase (uiManager),
193+
startSlot (startSlot),
144194
originalEndSlot (originalEndSlot)
145195
{
146196

147197
}
148198

199+
void NodeInputToOutputReconnectionHandler::EnumerateTemporaryConnections (const std::function<void (const Point& beg, const Point& end, Direction dir)>& processor) const
200+
{
201+
const ViewBox& viewBox = uiManager.GetViewBox ();
202+
Point position = viewBox.ViewToModel (currentPosition);
203+
processor (position, startSlot.position, Direction::Backward);
204+
}
205+
149206
bool NodeInputToOutputReconnectionHandler::NeedToDrawConnection (const NE::NodeId& outputNodeId, const NE::SlotId& outputSlotId, const NE::NodeId& inputNodeId, const NE::SlotId& inputSlotId) const
150207
{
151208
if (outputNodeId == originalEndSlot->GetOwnerNodeId () &&
152-
inputNodeId == startSlot->GetOwnerNodeId () &&
209+
inputNodeId == startSlot.slot->GetOwnerNodeId () &&
153210
outputSlotId == originalEndSlot->GetId () &&
154-
inputSlotId == startSlot->GetId ()) {
211+
inputSlotId == startSlot.slot->GetId ()) {
155212
return false;
156213
}
157214
return true;
@@ -160,22 +217,22 @@ bool NodeInputToOutputReconnectionHandler::NeedToDrawConnection (const NE::NodeI
160217
void NodeInputToOutputReconnectionHandler::HandleMouseUp (NodeUIEnvironment& uiEnvironment, const ModifierKeys&, const Point&)
161218
{
162219
if (endSlot != nullptr && endSlot != originalEndSlot) {
163-
ReconnectOutputSlotCommand command (originalEndSlot, endSlot, startSlot);
220+
ReconnectOutputSlotCommand command (originalEndSlot, endSlot, startSlot.slot);
164221
uiManager.ExecuteCommand (command, uiEnvironment);
165222
} else if (endSlot == nullptr) {
166-
DisconnectSlotsCommand disconnectCommand (originalEndSlot, startSlot);
223+
DisconnectSlotsCommand disconnectCommand (originalEndSlot, startSlot.slot);
167224
uiManager.ExecuteCommand (disconnectCommand, uiEnvironment);
168225
} else {
169226
uiManager.RequestRedraw ();
170227
}
171228
}
172229

173-
bool NodeInputToOutputReconnectionHandler::CanConnectToOutputSlot (const UIOutputSlotConstPtr& outputSlot, const UIInputSlotConstPtr& inputSlot) const
230+
bool NodeInputToOutputReconnectionHandler::CanConnectToOutputSlot (const UIOutputSlotConstPtr& outputSlot) const
174231
{
175232
if (outputSlot == originalEndSlot) {
176233
return true;
177234
}
178-
if (uiManager.CanConnectOutputSlotToInputSlot (outputSlot, inputSlot)) {
235+
if (uiManager.CanConnectOutputSlotToInputSlot (outputSlot, startSlot.slot)) {
179236
return true;
180237
}
181238
return false;

0 commit comments

Comments
 (0)