-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
220 lines (198 loc) · 7.86 KB
/
main.cpp
File metadata and controls
220 lines (198 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "Application.hpp"
#include "NE_MemoryStream.hpp"
#include "BI_BuiltInNodes.hpp"
#include <locale>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
static const NUIE::BasicSkinParams& GetAppSkinParams ()
{
static const NUIE::BasicSkinParams skinParams (
/*backgroundColor*/ NUIE::Color (255, 255, 255),
/*connectionLinePen*/ NUIE::Pen (NUIE::Color (38, 50, 56), 1.0),
/*connectionMarker */ NUIE::SkinParams::ConnectionMarker::None,
/*connectionMarkerSize*/ NUIE::Size (8.0, 8.0),
/*nodePadding*/ 5.0,
/*nodeBorderPen*/ NUIE::Pen (NUIE::Color (38, 50, 56), 1.0),
/*nodeHeaderTextFont*/ NUIE::Font (L"Arial", 14.0),
/*nodeHeaderTextColor*/ NUIE::Color (250, 250, 250),
/*nodeHeaderErrorTextColor*/ NUIE::Color (250, 250, 250),
/*nodeHeaderBackgroundColor*/ NUIE::Color (41, 127, 255),
/*nodeHeaderErrorBackgroundColor*/ NUIE::Color (199, 80, 80),
/*nodeContentTextFont*/ NUIE::Font (L"Arial", 12.0),
/*nodeContentTextColor*/ NUIE::Color (0, 0, 0),
/*nodeContentBackgroundColor*/ NUIE::Color (236, 236, 236),
/*slotTextColor*/ NUIE::Color (0, 0, 0),
/*slotTextBackgroundColor*/ NUIE::Color (246, 246, 246),
/*slotMarker*/ NUIE::SkinParams::SlotMarker::None,
/*hiddenSlotMarker*/ NUIE::SkinParams::HiddenSlotMarker::Arrow,
/*slotMarkerSize*/ NUIE::Size (8.0, 8.0),
/*selectionBlendColor*/ NUIE::BlendColor (NUIE::Color (41, 127, 255), 0.25),
/*disabledBlendColor*/ NUIE::BlendColor (NUIE::Color (0, 138, 184), 0.2),
/*selectionRectPen*/ NUIE::Pen (NUIE::Color (41, 127, 255), 1.0),
/*nodeSelectionRectPen*/ NUIE::Pen (NUIE::Color (41, 127, 255), 3.0),
/*buttonBorderPen*/ NUIE::Pen (NUIE::Color (146, 152, 155), 1.0),
/*buttonBackgroundColor*/ NUIE::Color (217, 217, 217),
/*textPanelTextColor*/ NUIE::Color (0, 0, 0),
/*textPanelBackgroundColor*/ NUIE::Color (236, 236, 236),
/*groupNameFont*/ NUIE::Font (L"Arial", 14.0),
/*groupNameColor*/ NUIE::Color (0, 0, 0),
/*groupBackgroundColors*/ NUIE::NamedColorSet ({
{ NE::LocalizeString (L"Blue"), NUIE::Color (160, 200, 240) },
{ NE::LocalizeString (L"Green"), NUIE::Color (160, 239, 160) },
{ NE::LocalizeString (L"Red"), NUIE::Color (239, 189, 160) }
}),
/*groupPadding*/ 12.0
);
return skinParams;
}
class MyAppInterface : public CustomAppInterface
{
public:
MyAppInterface () :
evaluationEnv (nullptr)
{
}
virtual void BuildNodeTree (AppNodeTree& nodeTree) const override
{
size_t inputs = nodeTree.AddGroup (L"Inputs");
nodeTree.AddItem (inputs, L"Boolean", L"Boolean.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::BooleanNode (NE::LocString (L"Boolean"), position, true));
});
nodeTree.AddItem (inputs, L"Integer", L"Integer.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::IntegerUpDownNode (NE::LocString (L"Integer"), position, 0, 1));
});
nodeTree.AddItem (inputs, L"Number", L"Double.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::DoubleUpDownNode (NE::LocString (L"Number"), position, 0.0, 1.0));
});
nodeTree.AddItem (inputs, L"Integer Increment", L"IntegerIncremented.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::IntegerIncrementedNode (NE::LocString (L"Integer Increment"), position));
});
nodeTree.AddItem (inputs, L"Number Increment", L"DoubleIncremented.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::DoubleIncrementedNode (NE::LocString (L"Number Increment"), position));
});
nodeTree.AddItem (inputs, L"Number Distribution", L"DoubleDistributed.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::DoubleDistributedNode (NE::LocString (L"Number Distribution"), position));
});
size_t arithmetics = nodeTree.AddGroup (L"Arithmetics");
nodeTree.AddItem (arithmetics, L"Addition", L"Addition.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::AdditionNode (NE::LocString (L"Addition"), position));
});
nodeTree.AddItem (arithmetics, L"Subtraction", L"Subtraction.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::SubtractionNode (NE::LocString (L"Subtraction"), position));
});
nodeTree.AddItem (arithmetics, L"Multiplication", L"Multiplication.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::MultiplicationNode (NE::LocString (L"Multiplication"), position));
});
nodeTree.AddItem (arithmetics, L"Division", L"Division.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::DivisionNode (NE::LocString (L"Division"), position));
});
nodeTree.AddItem (arithmetics, L"Floor", L"Floor.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::FloorNode (NE::LocString (L"Floor"), position));
});
nodeTree.AddItem (arithmetics, L"Ceil", L"Ceil.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::CeilNode (NE::LocString (L"Ceil"), position));
});
nodeTree.AddItem (arithmetics, L"Abs", L"Abs.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::AbsNode (NE::LocString (L"Abs"), position));
});
nodeTree.AddItem (arithmetics, L"Negative", L"Negative.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::NegativeNode (NE::LocString (L"Negative"), position));
});
nodeTree.AddItem (arithmetics, L"Sqrt", L"Sqrt.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::SqrtNode (NE::LocString (L"Sqrt"), position));
});
size_t other = nodeTree.AddGroup (L"Other");
nodeTree.AddItem (other, L"List Builder", L"ListBuilder.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::ListBuilderNode (NE::LocString (L"List Builder"), position));
});
nodeTree.AddItem (other, L"Viewer", L"Viewer.png", [&] (const NUIE::Point& position) {
return NUIE::UINodePtr (new BI::MultiLineViewerNode (NE::LocString (L"Viewer"), position, 5));
});
}
virtual const NUIE::SkinParams& GetSkinParams () const override
{
return GetAppSkinParams ();
}
virtual NE::EvaluationEnv& GetEvaluationEnv () override
{
return evaluationEnv;
}
virtual void OnValuesRecalculated () override
{
#ifdef EMSCRIPTEN
std::string resultString = "Values Recalculated";
EM_ASM ({
OnValuesRecalculated ($0);
}, resultString.c_str ());
#endif
}
virtual void OnSelectionChanged (bool hasSelection) override
{
#ifdef EMSCRIPTEN
EM_ASM ({
OnSelectionChanged ($0);
}, hasSelection);
#else
(void) hasSelection;
#endif
}
virtual void OnUndoStateChanged (bool canUndo, bool canRedo) override
{
#ifdef EMSCRIPTEN
EM_ASM ({
OnUndoStateChanged ($0, $1);
}, canUndo, canRedo);
#else
(void) canUndo;
(void) canRedo;
#endif
}
virtual void OnClipboardStateChanged (bool hasContent) override
{
#ifdef EMSCRIPTEN
EM_ASM ({
OnClipboardStateChanged ($0);
}, hasContent);
#else
(void) hasContent;
#endif
}
virtual bool SaveFile (NUIE::NodeEditor& nodeEditor, std::vector<char>& buffer) const override
{
NE::MemoryOutputStream outputStream;
if (!nodeEditor.Save (outputStream)) {
return false;
}
buffer = outputStream.GetBuffer ();
return true;
}
virtual bool OpenFile (const std::vector<char>& buffer, NUIE::NodeEditor& nodeEditor) override
{
NE::MemoryInputStream inputStream (buffer);
return nodeEditor.Open (inputStream);
}
virtual bool ConvertParameterValueToJson (const NUIE::ParameterInterfacePtr&, size_t, rapidjson::Value&, rapidjson::Document::AllocatorType&) const override
{
return false;
}
virtual NE::ValuePtr ConvertParameterJsonToValue (const rapidjson::Value&, NUIE::ParameterInterfacePtr&, size_t) const override
{
return nullptr;
}
private:
NE::EvaluationEnv evaluationEnv;
};
int main (int, char**)
{
MyAppInterface appInterface;
Application app (appInterface);
app.Init ("VisualScriptEngineWeb");
#ifndef EMSCRIPTEN
app.CreateNode (0, 4, 100, 100);
app.CreateNode (2, 1, 400, 300);
#endif
app.Start ();
app.Shut ();
return EXIT_SUCCESS;
}