Skip to content

Commit 213e8ea

Browse files
committed
Add NodeEditorNodeListHwndControl. This control contains a node list, and a node editor. Also added WindowsEmbeddingDemo2 for testing the new control.
1 parent a4ba56d commit 213e8ea

11 files changed

Lines changed: 671 additions & 65 deletions

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,29 @@ if (MSVC)
161161
target_link_libraries (WindowsEmbeddingDemo NodeEngine NodeUIEngine BuiltInNodes WindowsAppSupport)
162162
SetCompilerOptions (WindowsEmbeddingDemo)
163163

164+
# WindowsEmbeddingDemo2
165+
166+
set (WindowsEmbeddingDemo2SourcesFolder Sources/WindowsEmbeddingDemo2)
167+
file (GLOB WindowsEmbeddingDemo2HeaderFiles ${WindowsEmbeddingDemo2SourcesFolder}/*.hpp)
168+
file (GLOB WindowsEmbeddingDemo2SourceFiles ${WindowsEmbeddingDemo2SourcesFolder}/*.cpp)
169+
set (
170+
WindowsEmbeddingDemo2Files
171+
${WindowsEmbeddingDemo2HeaderFiles}
172+
${WindowsEmbeddingDemo2SourceFiles}
173+
)
174+
source_group ("Sources" FILES ${WindowsEmbeddingDemo2Files})
175+
add_executable (WindowsEmbeddingDemo2 WIN32 ${WindowsEmbeddingDemo2Files})
176+
target_include_directories (
177+
WindowsEmbeddingDemo2 PUBLIC
178+
${NodeEngineSourcesFolder}
179+
${NodeUIEngineSourcesFolder}
180+
${BuiltInNodesSourcesFolder}
181+
${TestFrameworkSourcesFolder}
182+
${WindowsAppSupportSourcesFolder}
183+
)
184+
target_link_libraries (WindowsEmbeddingDemo2 NodeEngine NodeUIEngine BuiltInNodes WindowsAppSupport)
185+
SetCompilerOptions (WindowsEmbeddingDemo2)
186+
164187
if (NOT ${WXWIDGETS_DIR} STREQUAL "")
165188
link_directories (${WXWIDGETS_DIR}/lib/vc_x64_lib)
166189

Sources/NodeUIEngine/NUIE_EventHandlers.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class EventHandlers
2323
virtual NUIE::MenuCommandPtr OnContextMenu (NodeUIManager& uiManager, NodeUIEnvironment& env, const Point& position, const UIOutputSlotPtr& inputSlot, const MenuCommandStructure& commands) = 0;
2424
virtual NUIE::MenuCommandPtr OnContextMenu (NodeUIManager& uiManager, NodeUIEnvironment& env, const Point& position, const UIInputSlotPtr& inputSlot, const MenuCommandStructure& commands) = 0;
2525
virtual NUIE::MenuCommandPtr OnContextMenu (NodeUIManager& uiManager, NodeUIEnvironment& env, const Point& position, const UINodeGroupPtr& group, const MenuCommandStructure& commands) = 0;
26-
27-
virtual bool OnParameterSettings (ParameterInterfacePtr paramAccessor) = 0;
26+
virtual bool OnParameterSettings (ParameterInterfacePtr paramAccessor) = 0;
2827
};
2928

3029
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "WAS_HwndEventHandlers.hpp"
2+
#include "WAS_ParameterDialog.hpp"
3+
#include "WAS_WindowsAppUtils.hpp"
4+
5+
namespace WAS
6+
{
7+
8+
HwndEventHandlers::HwndEventHandlers () :
9+
NUIE::EventHandlers (),
10+
hwnd (NULL)
11+
{
12+
13+
}
14+
15+
void HwndEventHandlers::Init (HWND newHwnd)
16+
{
17+
hwnd = newHwnd;
18+
}
19+
20+
NUIE::MenuCommandPtr HwndEventHandlers::OnContextMenu (NUIE::NodeUIManager&, NUIE::NodeUIEnvironment&, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands)
21+
{
22+
return WAS::SelectCommandFromContextMenu (hwnd, position, commands);
23+
}
24+
25+
NUIE::MenuCommandPtr HwndEventHandlers::OnContextMenu (NUIE::NodeUIManager&, NUIE::NodeUIEnvironment&, const NUIE::Point& position, const NUIE::UINodePtr&, const NUIE::MenuCommandStructure& commands)
26+
{
27+
return WAS::SelectCommandFromContextMenu (hwnd, position, commands);
28+
}
29+
30+
NUIE::MenuCommandPtr HwndEventHandlers::OnContextMenu (NUIE::NodeUIManager&, NUIE::NodeUIEnvironment&, const NUIE::Point& position, const NUIE::UIOutputSlotPtr&, const NUIE::MenuCommandStructure& commands)
31+
{
32+
return WAS::SelectCommandFromContextMenu (hwnd, position, commands);
33+
}
34+
35+
NUIE::MenuCommandPtr HwndEventHandlers::OnContextMenu (NUIE::NodeUIManager&, NUIE::NodeUIEnvironment&, const NUIE::Point& position, const NUIE::UIInputSlotPtr&, const NUIE::MenuCommandStructure& commands)
36+
{
37+
return WAS::SelectCommandFromContextMenu (hwnd, position, commands);
38+
}
39+
40+
NUIE::MenuCommandPtr HwndEventHandlers::OnContextMenu (NUIE::NodeUIManager&, NUIE::NodeUIEnvironment&, const NUIE::Point& position, const NUIE::UINodeGroupPtr&, const NUIE::MenuCommandStructure& commands)
41+
{
42+
return WAS::SelectCommandFromContextMenu (hwnd, position, commands);
43+
}
44+
45+
bool HwndEventHandlers::OnParameterSettings (NUIE::ParameterInterfacePtr paramAccessor)
46+
{
47+
WAS::ParameterDialog paramDialog (paramAccessor);
48+
return paramDialog.Show (hwnd, 50, 50);
49+
}
50+
51+
52+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef WAS_HWNDEVENTHANDLERS_HPP
2+
#define WAS_HWNDEVENTHANDLERS_HPP
3+
4+
#include "NUIE_EventHandlers.hpp"
5+
#include "WAS_IncludeWindowsHeaders.hpp"
6+
7+
namespace WAS
8+
{
9+
10+
class HwndEventHandlers : public NUIE::EventHandlers
11+
{
12+
public:
13+
HwndEventHandlers ();
14+
15+
void Init (HWND newHwnd);
16+
17+
virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::NodeUIManager& uiManager, NUIE::NodeUIEnvironment& env, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands) override;
18+
virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::NodeUIManager& uiManager, NUIE::NodeUIEnvironment& env, const NUIE::Point& position, const NUIE::UINodePtr& uiNode, const NUIE::MenuCommandStructure& commands) override;
19+
virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::NodeUIManager& uiManager, NUIE::NodeUIEnvironment& env, const NUIE::Point& position, const NUIE::UIOutputSlotPtr& inputSlot, const NUIE::MenuCommandStructure& commands) override;
20+
virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::NodeUIManager& uiManager, NUIE::NodeUIEnvironment& env, const NUIE::Point& position, const NUIE::UIInputSlotPtr& inputSlot, const NUIE::MenuCommandStructure& commands) override;
21+
virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::NodeUIManager& uiManager, NUIE::NodeUIEnvironment& env, const NUIE::Point& position, const NUIE::UINodeGroupPtr& group, const NUIE::MenuCommandStructure& commands) override;
22+
virtual bool OnParameterSettings (NUIE::ParameterInterfacePtr paramAccessor) override;
23+
24+
protected:
25+
HWND hwnd;
26+
};
27+
28+
}
29+
30+
#endif

Sources/WindowsAppSupport/WAS_IncludeWindowsHeaders.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <windows.h>
55
#include <windowsx.h>
66
#include <minmax.h>
7+
#include <CommCtrl.h>
78

89
#pragma warning (push)
910
#pragma warning (disable : 4244)

Sources/WindowsAppSupport/WAS_NodeEditorHwndControl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SetCaptureHandler
3535
int counter;
3636
};
3737

38-
static LRESULT CALLBACK StaticWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
38+
static LRESULT CALLBACK NodeEditorStaticWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3939
{
4040
static SetCaptureHandler setCaptureHandler;
4141

@@ -214,15 +214,12 @@ bool NodeEditorHwndControl::Init (NUIE::NodeEditor* nodeEditorPtr, HWND parentHa
214214
nodeEditor = nodeEditorPtr;
215215
DBGASSERT (nodeEditor != nullptr);
216216

217-
hwnd = CreateCustomControl (parentHandle, StaticWindowProc, L"NodeEditorHwndControl", this);
217+
hwnd = CreateCustomControl (parentHandle, NodeEditorStaticWindowProc, L"NodeEditorHwndControl", this);
218218
if (DBGERROR (hwnd == NULL)) {
219219
return false;
220220
}
221221

222222
bitmapContext.Init (hwnd);
223-
224-
ShowWindow (hwnd, SW_SHOW);
225-
UpdateWindow (hwnd);
226223
MoveWindow (hwnd, x, y, width, height, TRUE);
227224

228225
return true;
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#include "WAS_NodeEditorNodeListHwndControl.hpp"
2+
#include "WAS_WindowsAppUtils.hpp"
3+
#include "NE_Debug.hpp"
4+
5+
#include "BI_InputUINodes.hpp" // TODO: remove
6+
7+
namespace WAS
8+
{
9+
10+
static const short NodeListWidth = 200;
11+
12+
static LRESULT CALLBACK NodeEditorNodeListStaticWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
13+
{
14+
if (msg == WM_CREATE) {
15+
LPCREATESTRUCT createStruct = LPCREATESTRUCT (lParam);
16+
SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) createStruct->lpCreateParams);
17+
}
18+
19+
NodeEditorNodeListHwndControl* control = (NodeEditorNodeListHwndControl*) GetWindowLongPtr (hwnd, GWLP_USERDATA);
20+
if (control == nullptr) {
21+
return DefWindowProc (hwnd, msg, wParam, lParam);
22+
}
23+
24+
switch (msg) {
25+
case WM_NOTIFY:
26+
{
27+
LPNMHDR header = (LPNMHDR) lParam;
28+
switch (header->code) {
29+
case TVN_BEGINDRAG:
30+
control->TreeViewBeginDrag ((LPNMTREEVIEW) lParam);
31+
break;
32+
case TVN_SELCHANGED:
33+
control->TreeViewSelectionChanged ((LPNMTREEVIEW) lParam);
34+
break;
35+
case NM_DBLCLK:
36+
control->TreeViewDoubleClick (header);
37+
break;
38+
}
39+
}
40+
break;
41+
}
42+
43+
return DefWindowProc (hwnd, msg, wParam, lParam);
44+
}
45+
46+
NodeTreeView::NodeTreeView () :
47+
hwnd (NULL)
48+
{
49+
50+
}
51+
52+
NodeTreeView::~NodeTreeView ()
53+
{
54+
55+
}
56+
57+
bool NodeTreeView::Init (HWND parentHandle, int x, int y, int width, int height)
58+
{
59+
hwnd = CreateWindowEx (
60+
0, WC_TREEVIEW, NULL, WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS,
61+
x, y, width, height, parentHandle, NULL, NULL, NULL
62+
);
63+
if (DBGERROR (hwnd == NULL)) {
64+
return false;
65+
}
66+
return true;
67+
}
68+
69+
bool NodeTreeView::HasGroup (const std::wstring& group) const
70+
{
71+
return groups.find (group) != groups.end ();
72+
}
73+
74+
void NodeTreeView::AddGroup (const std::wstring& group)
75+
{
76+
auto found = groups.find (group);
77+
if (DBGERROR (found != groups.end ())) {
78+
return;
79+
}
80+
81+
TVINSERTSTRUCT tvInsertStruct;
82+
memset (&tvInsertStruct, 0, sizeof (TVINSERTSTRUCT));
83+
tvInsertStruct.hParent = NULL;
84+
tvInsertStruct.hInsertAfter = NULL;
85+
tvInsertStruct.item.mask = TVIF_TEXT | TVIF_PARAM;
86+
tvInsertStruct.item.pszText = (LPWSTR) group.c_str ();
87+
tvInsertStruct.item.cchTextMax = sizeof (tvInsertStruct.item.pszText) / sizeof (wchar_t);
88+
tvInsertStruct.item.lParam = (LPARAM) -1;
89+
90+
HTREEITEM groupItem = (HTREEITEM) SendMessage (hwnd, TVM_INSERTITEM, 0, (LPARAM) &tvInsertStruct);
91+
groups.insert ({ group, groupItem });
92+
}
93+
94+
void NodeTreeView::AddItem (const std::wstring& group, const std::wstring& text, LPARAM lParam)
95+
{
96+
auto found = groups.find (group);
97+
if (DBGERROR (found == groups.end ())) {
98+
return;
99+
}
100+
101+
TVINSERTSTRUCT tvInsertStruct;
102+
memset (&tvInsertStruct, 0, sizeof (TVINSERTSTRUCT));
103+
tvInsertStruct.hParent = found->second;
104+
tvInsertStruct.hInsertAfter = NULL;
105+
tvInsertStruct.item.mask = TVIF_TEXT | TVIF_PARAM;
106+
tvInsertStruct.item.pszText = (LPWSTR) text.c_str ();
107+
tvInsertStruct.item.cchTextMax = sizeof (tvInsertStruct.item.pszText) / sizeof (wchar_t);
108+
tvInsertStruct.item.lParam = lParam;
109+
SendMessage (hwnd, TVM_INSERTITEM, 0, (LPARAM) &tvInsertStruct);
110+
}
111+
112+
void NodeTreeView::ExpandAll ()
113+
{
114+
for (const auto& it : groups) {
115+
TreeView_Expand (hwnd, it.second, TVM_EXPAND);
116+
}
117+
}
118+
119+
HWND NodeTreeView::GetWindowHandle ()
120+
{
121+
return hwnd;
122+
}
123+
124+
NodeEditorNodeListHwndControl::NodeEditorNodeListHwndControl () :
125+
nodeTreeView (),
126+
nodeEditorControl (),
127+
mainHandle (NULL),
128+
selectedNode (-1),
129+
nextNodeId (0)
130+
{
131+
132+
}
133+
134+
NodeEditorNodeListHwndControl::~NodeEditorNodeListHwndControl ()
135+
{
136+
137+
}
138+
139+
bool NodeEditorNodeListHwndControl::Init (NUIE::NodeEditor* nodeEditorPtr, HWND parentHandle, int x, int y, int width, int height)
140+
{
141+
mainHandle = CreateCustomControl (parentHandle, NodeEditorNodeListStaticWindowProc, L"NodeEditorNodeListHwndControl", this);
142+
if (DBGERROR (mainHandle == NULL)) {
143+
return false;
144+
}
145+
146+
MoveWindow (mainHandle, x, y, width, height, TRUE);
147+
nodeTreeView.Init (mainHandle, 0, 0, NodeListWidth, height);
148+
nodeEditorControl.Init (nodeEditorPtr, mainHandle, NodeListWidth, 0, width - NodeListWidth, height);
149+
150+
return true;
151+
}
152+
153+
void NodeEditorNodeListHwndControl::Resize (int x, int y, int width, int height)
154+
{
155+
MoveWindow (mainHandle, x, y, width, height, TRUE);
156+
nodeEditorControl.Resize (x + NodeListWidth, y, width - NodeListWidth, height);
157+
}
158+
159+
HWND NodeEditorNodeListHwndControl::GetEditorHandle ()
160+
{
161+
return nodeEditorControl.GetWindowHandle ();
162+
}
163+
164+
NUIE::DrawingContext& NodeEditorNodeListHwndControl::GetEditorContext ()
165+
{
166+
return nodeEditorControl.GetDrawingContext ();
167+
}
168+
169+
void NodeEditorNodeListHwndControl::InvalidateEditor ()
170+
{
171+
nodeEditorControl.Invalidate ();
172+
}
173+
174+
void NodeEditorNodeListHwndControl::RegisterNode (const std::wstring& group, const std::wstring& text, const CreatorFunction& creator)
175+
{
176+
if (!nodeTreeView.HasGroup (group)) {
177+
nodeTreeView.AddGroup (group);
178+
}
179+
180+
nodeTreeView.AddItem (group, text, nextNodeId);
181+
nodeIdToCreator.insert ({ nextNodeId, creator });
182+
nextNodeId++;
183+
184+
nodeTreeView.ExpandAll ();
185+
}
186+
187+
void NodeEditorNodeListHwndControl::TreeViewSelectionChanged (LPNMTREEVIEW lpnmtv)
188+
{
189+
if (lpnmtv->hdr.hwndFrom != nodeTreeView.GetWindowHandle ()) {
190+
return;
191+
}
192+
193+
selectedNode = lpnmtv->itemNew.lParam;
194+
}
195+
196+
void NodeEditorNodeListHwndControl::TreeViewDoubleClick (LPNMHDR lpnmhdr)
197+
{
198+
if (lpnmhdr->hwndFrom != nodeTreeView.GetWindowHandle ()) {
199+
return;
200+
}
201+
202+
if (selectedNode == -1) {
203+
return;
204+
}
205+
206+
auto found = nodeIdToCreator.find (selectedNode);
207+
if (DBGERROR (found == nodeIdToCreator.end ())) {
208+
return;
209+
}
210+
211+
RECT clientRect;
212+
GetClientRect (nodeEditorControl.GetWindowHandle (), &clientRect);
213+
214+
NUIE::NodeEditor* nodeEditor = nodeEditorControl.GetNodeEditor ();
215+
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+
}
219+
220+
void NodeEditorNodeListHwndControl::TreeViewBeginDrag (LPNMTREEVIEW lpnmtv)
221+
{
222+
if (lpnmtv->hdr.hwndFrom != nodeTreeView.GetWindowHandle ()) {
223+
return;
224+
}
225+
226+
if (lpnmtv->itemNew.lParam == (LPARAM) -1) {
227+
return;
228+
}
229+
230+
HTREEITEM item = lpnmtv->itemOld.hItem;
231+
TreeView_SelectItem (lpnmtv->hdr.hwndFrom, item);
232+
(void) item;
233+
}
234+
235+
}

0 commit comments

Comments
 (0)