/
Variable.cpp
56 lines (47 loc) · 1.23 KB
/
Variable.cpp
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
#include "Variable.h"
#include "igui.h"
#include "GuiExpression.h"
#include "string/case_conv.h"
namespace gui
{
WindowDefVariable::WindowDefVariable(IGuiWindowDef& windowDef,
const std::string& name) :
_windowDef(windowDef),
_name(string::to_lower_copy(name))
{}
// Assign a value to this Variable (returns TRUE on success)
bool WindowDefVariable::assignValueFromString(const std::string& val)
{
if (_name.empty()) return false;
if (_name == "text")
{
_windowDef.text.setValue(ConstantExpression<std::string>::Create(val));
return true;
}
else if (_name == "background")
{
if (_windowDef.background.getValue() != val)
{
// Reset the material reference when changing background
_windowDef.background.setValue(ConstantExpression<std::string>::Create(val));
_windowDef.backgroundShader.reset();
}
return true;
}
else
{
// TODO
return false;
}
}
GuiStateVariable::GuiStateVariable(IGui& gui, const std::string& key) :
_gui(gui),
_key(key)
{}
// Assign a value to this Variable (returns TRUE on success)
bool GuiStateVariable::assignValueFromString(const std::string& val)
{
_gui.setStateString(_key, val);
return true; // always succeeds
}
} // namespace