Skip to content

Commit 38d2d15

Browse files
committed
Add BooleanNode.
1 parent bce68d0 commit 38d2d15

19 files changed

+446
-108
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.6)
22

33
set (VSE_VERSION_1 0)
44
set (VSE_VERSION_2 0)
5-
set (VSE_VERSION_3 1)
5+
set (VSE_VERSION_3 2)
66
set (VSE_APP_NAME VisualScriptEngine)
77

88
function (SetCompilerOptions module maxWarningLevel)

Sources/BuiltInNodes/BI_InputUINodes.cpp

Lines changed: 124 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
namespace BI
1212
{
1313

14+
NE::DynamicSerializationInfo BooleanNode::serializationInfo (NE::ObjectId ("{72E14D86-E5DC-4AD6-A7E4-F60D47BFB114}"), NE::ObjectVersion (1), BooleanNode::CreateSerializableInstance);
15+
1416
NE::SerializationInfo NumericUpDownNode::serializationInfo (NE::ObjectVersion (1));
1517
NE::DynamicSerializationInfo IntegerUpDownNode::serializationInfo (NE::ObjectId ("{98ADBB4A-8E55-4FE5-B0F9-EC5DD776C000}"), NE::ObjectVersion (1), IntegerUpDownNode::CreateSerializableInstance);
1618
NE::DynamicSerializationInfo DoubleUpDownNode::serializationInfo (NE::ObjectId ("{F888C04D-FF22-4225-AC9A-90464D01ACF9}"), NE::ObjectVersion (1), DoubleUpDownNode::CreateSerializableInstance);
@@ -19,14 +21,131 @@ NE::SerializationInfo NumericRangeNode::serializationInfo (NE::ObjectVersion (
1921
NE::DynamicSerializationInfo IntegerRangeNode::serializationInfo (NE::ObjectId ("{74527771-58A4-42D4-850F-1C63FA9A4732}"), NE::ObjectVersion (1), IntegerRangeNode::CreateSerializableInstance);
2022
NE::DynamicSerializationInfo DoubleRangeNode::serializationInfo (NE::ObjectId ("{B697B7DE-7AB9-479D-8DBE-8D3CCB6E4F50}"), NE::ObjectVersion (1), DoubleRangeNode::CreateSerializableInstance);
2123

24+
BooleanNode::BooleanNode () :
25+
BooleanNode (L"", NUIE::Point (), false)
26+
{
27+
28+
}
29+
30+
BooleanNode::BooleanNode (const std::wstring& name, const NUIE::Point& position, bool val) :
31+
BasicUINode (name, position),
32+
val (val)
33+
{
34+
35+
}
36+
37+
BooleanNode::~BooleanNode ()
38+
{
39+
40+
}
41+
42+
void BooleanNode::Initialize ()
43+
{
44+
RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("out"), L"Output")));
45+
}
46+
47+
NUIE::EventHandlerResult BooleanNode::HandleMouseClick (NUIE::NodeUIEnvironment& env, const NUIE::ModifierKeys&, NUIE::MouseButton mouseButton, const NUIE::Point& position, NUIE::UINodeCommandInterface& commandInterface)
48+
{
49+
if (mouseButton != NUIE::MouseButton::Left) {
50+
return NUIE::EventHandlerResult::EventNotHandled;
51+
}
52+
53+
NUIE::Rect switchRect = GetSpecialRect (env, "switch");
54+
55+
if (switchRect.Contains (position)) {
56+
commandInterface.RunUndoableCommand ([&] () {
57+
SetValue (!val);
58+
});
59+
return NUIE::EventHandlerResult::EventHandled;
60+
}
61+
return NUIE::EventHandlerResult::EventNotHandled;
62+
}
63+
64+
NUIE::EventHandlerResult BooleanNode::HandleMouseDoubleClick (NUIE::NodeUIEnvironment& env, const NUIE::ModifierKeys& keys, NUIE::MouseButton mouseButton, const NUIE::Point& position, NUIE::UINodeCommandInterface& commandInterface)
65+
{
66+
return HandleMouseClick (env, keys, mouseButton, position, commandInterface);
67+
}
68+
69+
bool BooleanNode::IsForceCalculated () const
70+
{
71+
return true;
72+
}
73+
74+
NE::ValueConstPtr BooleanNode::Calculate (NE::EvaluationEnv&) const
75+
{
76+
return NE::ValueConstPtr (new NE::BooleanValue (val));
77+
}
78+
79+
void BooleanNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const
80+
{
81+
class ValueParameter : public NUIE::BooleanNodeParameter<BooleanNode>
82+
{
83+
public:
84+
ValueParameter () :
85+
NUIE::BooleanNodeParameter<BooleanNode> (L"Value")
86+
{
87+
88+
}
89+
90+
virtual NE::ValueConstPtr GetValueInternal (const NUIE::UINodeConstPtr& uiNode) const override
91+
{
92+
return NE::ValuePtr (new NE::BooleanValue (GetTypedNode (uiNode)->GetValue ()));
93+
}
94+
95+
virtual bool SetValueInternal (NUIE::NodeUIManager& uiManager, NE::EvaluationEnv&, NUIE::UINodePtr& uiNode, const NE::ValueConstPtr& value) override
96+
{
97+
GetTypedNode (uiNode)->SetValue (NE::BooleanValue::Get (value));
98+
uiManager.InvalidateNodeValue (uiNode);
99+
uiManager.InvalidateNodeDrawing (uiNode);
100+
return true;
101+
}
102+
};
103+
104+
BasicUINode::RegisterParameters (parameterList);
105+
parameterList.AddParameter (NUIE::NodeParameterPtr (new ValueParameter ()));
106+
}
107+
108+
NE::Stream::Status BooleanNode::Read (NE::InputStream& inputStream)
109+
{
110+
NE::ObjectHeader header (inputStream);
111+
BasicUINode::Read (inputStream);
112+
inputStream.Read (val);
113+
return inputStream.GetStatus ();
114+
}
115+
116+
NE::Stream::Status BooleanNode::Write (NE::OutputStream& outputStream) const
117+
{
118+
NE::ObjectHeader header (outputStream, serializationInfo);
119+
BasicUINode::Write (outputStream);
120+
outputStream.Write (val);
121+
return outputStream.GetStatus ();
122+
}
123+
124+
bool BooleanNode::GetValue () const
125+
{
126+
return val;
127+
}
128+
129+
void BooleanNode::SetValue (bool newVal)
130+
{
131+
val = newVal;
132+
InvalidateValue ();
133+
}
134+
135+
void BooleanNode::UpdateNodeDrawingImage (NUIE::NodeUIDrawingEnvironment& env, NUIE::NodeDrawingImage& drawingImage) const
136+
{
137+
short selectedIndex = val ? 0 : 1;
138+
DrawHeaderWithSlotsAndSwitchLayout (*this, "switch", L"true", L"false", selectedIndex, env, drawingImage);
139+
}
140+
22141
NumericUpDownNode::NumericUpDownNode () :
23142
NumericUpDownNode (L"", NUIE::Point ())
24143
{
25144

26145
}
27146

28147
NumericUpDownNode::NumericUpDownNode (const std::wstring& name, const NUIE::Point& position) :
29-
NUIE::UINode (name, position)
148+
BasicUINode (name, position)
30149
{
31150

32151
}
@@ -77,14 +196,14 @@ bool NumericUpDownNode::IsForceCalculated () const
77196
NE::Stream::Status NumericUpDownNode::Read (NE::InputStream& inputStream)
78197
{
79198
NE::ObjectHeader header (inputStream);
80-
NUIE::UINode::Read (inputStream);
199+
BasicUINode::Read (inputStream);
81200
return inputStream.GetStatus ();
82201
}
83202

84203
NE::Stream::Status NumericUpDownNode::Write (NE::OutputStream& outputStream) const
85204
{
86205
NE::ObjectHeader header (outputStream, serializationInfo);
87-
NUIE::UINode::Write (outputStream);
206+
BasicUINode::Write (outputStream);
88207
return outputStream.GetStatus ();
89208
}
90209

@@ -163,7 +282,7 @@ void IntegerUpDownNode::RegisterParameters (NUIE::NodeParameterList& parameterLi
163282
}
164283
};
165284

166-
NUIE::UINode::RegisterParameters (parameterList);
285+
NumericUpDownNode::RegisterParameters (parameterList);
167286
parameterList.AddParameter (NUIE::NodeParameterPtr (new ValueParameter ()));
168287
parameterList.AddParameter (NUIE::NodeParameterPtr (new StepParameter ()));
169288
}
@@ -289,7 +408,7 @@ void DoubleUpDownNode::RegisterParameters (NUIE::NodeParameterList& parameterLis
289408
}
290409
};
291410

292-
NUIE::UINode::RegisterParameters (parameterList);
411+
NumericUpDownNode::RegisterParameters (parameterList);
293412
parameterList.AddParameter (NUIE::NodeParameterPtr (new ValueParameter ()));
294413
parameterList.AddParameter (NUIE::NodeParameterPtr (new StepParameter ()));
295414
}

Sources/BuiltInNodes/BI_InputUINodes.hpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,38 @@
77
namespace BI
88
{
99

10-
class NumericUpDownNode : public NUIE::UINode
10+
class BooleanNode : public BasicUINode
11+
{
12+
DYNAMIC_SERIALIZABLE (BooleanNode);
13+
14+
public:
15+
BooleanNode ();
16+
BooleanNode (const std::wstring& name, const NUIE::Point& position, bool val);
17+
virtual ~BooleanNode ();
18+
19+
virtual void Initialize () override;
20+
21+
virtual NUIE::EventHandlerResult HandleMouseClick (NUIE::NodeUIEnvironment& env, const NUIE::ModifierKeys& modifierKeys, NUIE::MouseButton mouseButton, const NUIE::Point& position, NUIE::UINodeCommandInterface& commandInterface) override;
22+
virtual NUIE::EventHandlerResult HandleMouseDoubleClick (NUIE::NodeUIEnvironment& env, const NUIE::ModifierKeys& modifierKeys, NUIE::MouseButton mouseButton, const NUIE::Point& position, NUIE::UINodeCommandInterface& commandInterface) override;
23+
24+
virtual bool IsForceCalculated () const override;
25+
26+
virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override;
27+
virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const override;
28+
29+
virtual NE::Stream::Status Read (NE::InputStream& inputStream) override;
30+
virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override;
31+
32+
bool GetValue () const;
33+
void SetValue (bool newVal);
34+
35+
private:
36+
virtual void UpdateNodeDrawingImage (NUIE::NodeUIDrawingEnvironment& env, NUIE::NodeDrawingImage& drawingImage) const override;
37+
38+
bool val;
39+
};
40+
41+
class NumericUpDownNode : public BasicUINode
1142
{
1243
SERIALIZABLE;
1344

Sources/BuiltInNodes/BI_UINodeLayouts.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,19 @@ void DrawHeaderWithSlotsAndButtonsLayout ( const NUIE::UINode& uiNode,
4343
drawer.Draw (env, drawingImage);
4444
}
4545

46+
void DrawHeaderWithSlotsAndSwitchLayout ( const NUIE::UINode& uiNode,
47+
const std::string& switchButtonId,
48+
const std::wstring& leftSwitchText,
49+
const std::wstring& rightSwitchText,
50+
short selectedIndex,
51+
NUIE::NodeUIDrawingEnvironment& env,
52+
NUIE::NodeDrawingImage& drawingImage)
53+
{
54+
NUIE::NodePanelDrawer drawer;
55+
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUIHeaderPanel (uiNode.GetNodeName ())));
56+
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUISlotPanel (uiNode, env)));
57+
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUISwitchPanel (switchButtonId, leftSwitchText, rightSwitchText, selectedIndex, env)));
58+
drawer.Draw (env, drawingImage);
59+
}
60+
4661
}

Sources/BuiltInNodes/BI_UINodeLayouts.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ void DrawHeaderWithSlotsAndButtonsLayout ( const NUIE::UINode& uiNode,
2020
NUIE::NodeUIDrawingEnvironment& env,
2121
NUIE::NodeDrawingImage& drawingImage);
2222

23+
void DrawHeaderWithSlotsAndSwitchLayout ( const NUIE::UINode& uiNode,
24+
const std::string& switchButtonId,
25+
const std::wstring& leftSwitchText,
26+
const std::wstring& rightSwitchText,
27+
short selectedIndex,
28+
NUIE::NodeUIDrawingEnvironment& env,
29+
NUIE::NodeDrawingImage& drawingImage);
30+
2331
}
2432

2533
#endif

Sources/BuiltInNodes/BI_UINodePanels.cpp

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
namespace BI
66
{
77

8+
static const NUIE::Pen ButtonBorderPen = NUIE::Pen (NUIE::Color (50, 75, 100), 1.0);
9+
static const NUIE::Color ButtonBackgroundColor = NUIE::Color (150, 175, 200);
10+
static const NUIE::Color ButtonSelectedBackgroundColor = NUIE::Color (190, 215, 240);
11+
812
SlotRectCollection::SlotRectCollection ()
913
{
1014

@@ -254,9 +258,6 @@ void NodeUISlotPanel::Draw (NUIE::NodeUIDrawingEnvironment& env, const NUIE::Rec
254258
});
255259
}
256260

257-
const NUIE::Pen NodeUILeftRightButtonsPanel::DefaultButtonBorderPen = NUIE::Pen (NUIE::Color (50, 75, 100), 1.0);
258-
const NUIE::Color NodeUILeftRightButtonsPanel::DefaultButtonBackgroundColor = NUIE::Color (150, 175, 200);
259-
260261
NodeUILeftRightButtonsPanel::NodeUILeftRightButtonsPanel ( const std::string& leftButtonId,
261262
const std::wstring& leftButtonText,
262263
const std::string& rightButtonId,
@@ -293,9 +294,8 @@ void NodeUILeftRightButtonsPanel::Draw (NUIE::NodeUIDrawingEnvironment& env, con
293294
const NUIE::SkinParams& skinParams = env.GetSkinParams ();
294295
double nodePadding = skinParams.GetNodePadding ();
295296

296-
const NUIE::Color backgroundColor = GetBackgroundColor (env);
297-
const NUIE::Color buttonBackgroundColor = GetButtonBackgroundColor (env);
298-
const NUIE::Color textColor = GetTextColor (env);
297+
const NUIE::Color backgroundColor = skinParams.GetNodeContentBackgroundColor ();
298+
const NUIE::Color textColor = skinParams.GetNodeContentTextColor ();
299299

300300
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (rect, backgroundColor)));
301301

@@ -304,35 +304,72 @@ void NodeUILeftRightButtonsPanel::Draw (NUIE::NodeUIDrawingEnvironment& env, con
304304
NUIE::Rect textRect = NUIE::Rect::FromPositionAndSize (leftButtonRect.GetTopRight (), NUIE::Size (rightButtonRect.GetLeft () - leftButtonRect.GetRight (), panelTextSize.GetHeight ()));
305305
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingText (textRect, skinParams.GetNodeTextFont (), panelText, NUIE::HorizontalAnchor::Center, NUIE::VerticalAnchor::Center, textColor)));
306306

307-
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (leftButtonRect, buttonBackgroundColor)));
307+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (leftButtonRect, ButtonBackgroundColor)));
308308
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingText (leftButtonRect, skinParams.GetNodeTextFont (), leftButtonText, NUIE::HorizontalAnchor::Center, NUIE::VerticalAnchor::Center, textColor)));
309-
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingRect (leftButtonRect, GetButtonBorderPen (env))));
309+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingRect (leftButtonRect, ButtonBorderPen)));
310310
drawingImage.AddSpecialRect (leftButtonId, leftButtonRect);
311311

312-
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (rightButtonRect, buttonBackgroundColor)));
312+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (rightButtonRect, ButtonBackgroundColor)));
313313
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingText (rightButtonRect, skinParams.GetNodeTextFont (), rightButtonText, NUIE::HorizontalAnchor::Center, NUIE::VerticalAnchor::Center, textColor)));
314-
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingRect (rightButtonRect, GetButtonBorderPen (env))));
314+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingRect (rightButtonRect, ButtonBorderPen)));
315315
drawingImage.AddSpecialRect (rightButtonId, rightButtonRect);
316316
}
317317

318-
NUIE::Color NodeUILeftRightButtonsPanel::GetTextColor (NUIE::NodeUIDrawingEnvironment& env) const
318+
NodeUISwitchPanel::NodeUISwitchPanel ( const std::string& switchRectId,
319+
const std::wstring& leftSwitchText,
320+
const std::wstring& rightSwitchText,
321+
short selectedIndex,
322+
NUIE::NodeUIDrawingEnvironment& env) :
323+
switchRectId (switchRectId),
324+
leftSwitchText (leftSwitchText),
325+
rightSwitchText (rightSwitchText),
326+
selectedIndex (selectedIndex)
319327
{
320-
return env.GetSkinParams ().GetNodeContentTextColor ();
328+
const NUIE::SkinParams& skinParams = env.GetSkinParams ();
329+
double nodePadding = skinParams.GetNodePadding ();
330+
leftSwitchSize = env.GetDrawingContext ().MeasureText (skinParams.GetNodeTextFont (), leftSwitchText).Grow (2.0 * nodePadding, nodePadding);
331+
rightSwitchSize = env.GetDrawingContext ().MeasureText (skinParams.GetNodeTextFont (), rightSwitchText).Grow (2.0 * nodePadding, nodePadding);
321332
}
322333

323-
NUIE::Color NodeUILeftRightButtonsPanel::GetBackgroundColor (NUIE::NodeUIDrawingEnvironment& env) const
334+
NUIE::Size NodeUISwitchPanel::GetMinSize (NUIE::NodeUIDrawingEnvironment& env) const
324335
{
325-
return env.GetSkinParams ().GetNodeContentBackgroundColor ();
336+
const NUIE::SkinParams& skinParams = env.GetSkinParams ();
337+
double nodePadding = skinParams.GetNodePadding ();
338+
NUIE::Size minSize;
339+
minSize.SetWidth (leftSwitchSize.GetWidth () + rightSwitchSize.GetWidth ());
340+
minSize.SetHeight (std::max (leftSwitchSize.GetHeight (), rightSwitchSize.GetHeight ()));
341+
minSize = minSize.Grow (2.0 * nodePadding, 2.0 * nodePadding);
342+
return minSize;
326343
}
327344

328-
NUIE::Pen NodeUILeftRightButtonsPanel::GetButtonBorderPen (NUIE::NodeUIDrawingEnvironment&) const
345+
void NodeUISwitchPanel::Draw (NUIE::NodeUIDrawingEnvironment& env, const NUIE::Rect& rect, NUIE::NodeDrawingImage& drawingImage) const
329346
{
330-
return DefaultButtonBorderPen;
331-
}
347+
const NUIE::SkinParams& skinParams = env.GetSkinParams ();
348+
const NUIE::Color backgroundColor = skinParams.GetNodeContentBackgroundColor ();
349+
const NUIE::Color textColor = skinParams.GetNodeContentTextColor ();
332350

333-
NUIE::Color NodeUILeftRightButtonsPanel::GetButtonBackgroundColor (NUIE::NodeUIDrawingEnvironment&) const
334-
{
335-
return DefaultButtonBackgroundColor;
351+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (rect, backgroundColor)));
352+
353+
NUIE::Size switchSize (
354+
leftSwitchSize.GetWidth () + rightSwitchSize.GetWidth (),
355+
std::max (leftSwitchSize.GetHeight (), rightSwitchSize.GetHeight ())
356+
);
357+
NUIE::Rect switchRect = NUIE::Rect::FromCenterAndSize (rect.GetCenter (), switchSize);
358+
NUIE::Rect leftSwitchRect = NUIE::Rect::FromPositionAndSize (switchRect.GetTopLeft (), leftSwitchSize);
359+
NUIE::Rect rightSwitchRect = NUIE::Rect::FromPositionAndSize (leftSwitchRect.GetTopRight (), rightSwitchSize);
360+
361+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (switchRect, ButtonBackgroundColor)));
362+
if (selectedIndex == 0) {
363+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (leftSwitchRect, ButtonSelectedBackgroundColor)));
364+
} else if (selectedIndex == 1) {
365+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingFillRect (rightSwitchRect, ButtonSelectedBackgroundColor)));
366+
}
367+
368+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingText (leftSwitchRect, skinParams.GetNodeTextFont (), leftSwitchText, NUIE::HorizontalAnchor::Center, NUIE::VerticalAnchor::Center, textColor)));
369+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingText (rightSwitchRect, skinParams.GetNodeTextFont (), rightSwitchText, NUIE::HorizontalAnchor::Center, NUIE::VerticalAnchor::Center, textColor)));
370+
371+
drawingImage.AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingRect (switchRect, ButtonBorderPen)));
372+
drawingImage.AddSpecialRect (switchRectId, switchRect);
336373
}
337374

338375
}

0 commit comments

Comments
 (0)