@@ -22,6 +22,14 @@ static LRESULT CALLBACK NodeEditorNodeListStaticWindowProc (HWND hwnd, UINT msg,
22
22
}
23
23
24
24
switch (msg) {
25
+ case WM_LBUTTONUP:
26
+ {
27
+ ReleaseCapture ();
28
+ int x = GET_X_LPARAM (lParam);
29
+ int y = GET_Y_LPARAM (lParam);
30
+ control->TreeViewEndDrag (x, y);
31
+ }
32
+ break ;
25
33
case WM_NOTIFY:
26
34
{
27
35
LPNMHDR header = (LPNMHDR) lParam;
@@ -126,6 +134,7 @@ NodeEditorNodeListHwndControl::NodeEditorNodeListHwndControl () :
126
134
nodeEditorControl (),
127
135
mainHandle (NULL ),
128
136
selectedNode (-1 ),
137
+ draggedNode (-1 ),
129
138
nextNodeId (0 )
130
139
{
131
140
@@ -199,22 +208,15 @@ void NodeEditorNodeListHwndControl::TreeViewDoubleClick (LPNMHDR lpnmhdr)
199
208
return ;
200
209
}
201
210
202
- if (selectedNode == -1 ) {
203
- return ;
204
- }
205
-
206
- auto found = nodeIdToCreator.find (selectedNode);
207
- if (DBGERROR (found == nodeIdToCreator.end ())) {
211
+ if (selectedNode == (LPARAM) -1 ) {
208
212
return ;
209
213
}
210
214
211
215
RECT clientRect;
212
216
GetClientRect (nodeEditorControl.GetWindowHandle (), &clientRect);
213
-
214
- NUIE::NodeEditor* nodeEditor = nodeEditorControl.GetNodeEditor ();
215
217
NUIE::Rect viewRect = NUIE::Rect::FromPositionAndSize (NUIE::Point (0.0 , 0.0 ), NUIE::Size (clientRect.right - clientRect.left , clientRect.bottom - clientRect.top ));
216
- NUIE::Point modelPosition = nodeEditor-> ViewToModel ( viewRect.GetCenter () );
217
- nodeEditor-> AddNode (found-> second (modelPosition ));
218
+ NUIE::Point center = viewRect.GetCenter ();
219
+ CreateNode (selectedNode, ( int ) center. GetX (), ( int ) center. GetY ( ));
218
220
}
219
221
220
222
void NodeEditorNodeListHwndControl::TreeViewBeginDrag (LPNMTREEVIEW lpnmtv)
@@ -227,9 +229,43 @@ void NodeEditorNodeListHwndControl::TreeViewBeginDrag (LPNMTREEVIEW lpnmtv)
227
229
return ;
228
230
}
229
231
230
- HTREEITEM item = lpnmtv->itemOld .hItem ;
232
+ HTREEITEM item = lpnmtv->itemNew .hItem ;
231
233
TreeView_SelectItem (lpnmtv->hdr .hwndFrom , item);
232
- (void ) item;
234
+ SetCapture (mainHandle);
235
+ SetCursor (LoadCursor (NULL , IDC_CROSS));
236
+
237
+ draggedNode = lpnmtv->itemNew .lParam ;
238
+ }
239
+
240
+ void NodeEditorNodeListHwndControl::TreeViewEndDrag (int x, int y)
241
+ {
242
+ if (DBGERROR (draggedNode == (LPARAM) -1 )) {
243
+ return ;
244
+ }
245
+
246
+ RECT editorRect;
247
+ GetClientRect (nodeEditorControl.GetWindowHandle (), &editorRect);
248
+ MapWindowPoints (nodeEditorControl.GetWindowHandle (), mainHandle, (LPPOINT) &editorRect, 2 );
249
+
250
+ if (x < editorRect.left || x > editorRect.right || y < editorRect.top || y > editorRect.bottom ) {
251
+ draggedNode = (LPARAM) -1 ;
252
+ return ;
253
+ }
254
+
255
+ CreateNode (draggedNode, x - editorRect.left , y - editorRect.top );
256
+ draggedNode = (LPARAM) -1 ;
257
+ }
258
+
259
+ void NodeEditorNodeListHwndControl::CreateNode (LPARAM nodeId, int screenX, int screenY)
260
+ {
261
+ auto found = nodeIdToCreator.find (nodeId);
262
+ if (DBGERROR (found == nodeIdToCreator.end ())) {
263
+ return ;
264
+ }
265
+
266
+ NUIE::NodeEditor* nodeEditor = nodeEditorControl.GetNodeEditor ();
267
+ NUIE::Point modelPosition = nodeEditor->ViewToModel (NUIE::Point (screenX, screenY));
268
+ nodeEditor->AddNode (found->second (modelPosition));
233
269
}
234
270
235
271
}
0 commit comments