17 #include "ofxDatGui.h" 28 const string& description,
29 std::function<
void(
int)> cb)
30 : value_ptr_(value), ui_ptr_(NULL),
31 type_(
INT_RANGE), title_(title), description_(description),
33 int_cb_(cb), double_cb_(nullptr), bool_cb_(nullptr) {
37 Tuneable(
double* value,
double min,
double max,
38 const string& title,
const string& description,
39 std::function<
void(
double)> cb)
40 : value_ptr_(value), ui_ptr_(NULL),
41 type_(
DOUBLE_RANGE), title_(title), description_(description),
43 int_cb_(nullptr), double_cb_(cb), bool_cb_(nullptr) {
47 Tuneable(
bool* value,
const string& title,
const string& description,
48 std::function<
void(
bool)> cb)
49 : value_ptr_(value), ui_ptr_(NULL),
50 type_(BOOL), title_(title), description_(description),
51 int_cb_(nullptr), double_cb_(nullptr), bool_cb_(cb) {
57 int* value =
static_cast<int*
>(value_ptr_);
58 ofxDatGuiSlider *slider = gui.addSlider(title_, min_, max_);
59 slider->setValue(*value);
60 ui_ptr_ =
static_cast<void*
>(slider);
61 gui.onSliderEvent(
this, &Tuneable::onSliderEvent);
62 gui.addTextBlock(description_);
67 double* value =
static_cast<double*
>(value_ptr_);
68 ofxDatGuiSlider *slider = gui.addSlider(title_, min_, max_);
69 slider->setValue(*value);
70 ui_ptr_ =
static_cast<void*
>(slider);
71 gui.onSliderEvent(
this, &Tuneable::onSliderEvent);
72 gui.addTextBlock(description_);
77 bool* value =
static_cast<bool*
>(value_ptr_);
78 ofxDatGuiToggle *toggle = gui.addToggle(title_, *value);
79 ui_ptr_ =
static_cast<void*
>(toggle);
80 gui.onButtonEvent(
this, &Tuneable::onToggleEvent);
81 gui.addTextBlock(description_);
92 int* value =
static_cast<int*
>(value_ptr_);
93 return "INT " + std::to_string(*value);
96 double* value =
static_cast<double*
>(value_ptr_);
97 return "DOUBLE " + std::to_string(*value);
100 bool* value =
static_cast<bool*
>(value_ptr_);
101 return std::string(
"BOOL ") + (*value ?
"true" :
"false");
104 ofLog(OF_LOG_ERROR) <<
"Unknown type";
113 std::istringstream iss(str);
118 int* p =
static_cast<int*
>(value_ptr_);
120 ofxDatGuiSlider *slider =
static_cast<ofxDatGuiSlider*
>(ui_ptr_);
121 slider->setValue(*p);
122 }
else if (word ==
"DOUBLE") {
123 double* p =
static_cast<double*
>(value_ptr_);
125 ofxDatGuiSlider *slider =
static_cast<ofxDatGuiSlider*
>(ui_ptr_);
126 slider->setValue(*p);
127 }
else if (word ==
"BOOL") {
128 bool* p =
static_cast<bool*
>(value_ptr_);
130 *p = (word ==
"true") ?
true :
false;
131 ofxDatGuiToggle *toggle =
static_cast<ofxDatGuiToggle*
>(ui_ptr_);
132 toggle->setEnabled(*p);
151 void onSliderEvent(ofxDatGuiSliderEvent e);
152 void onToggleEvent(ofxDatGuiButtonEvent e);
163 std::function<void(int)> int_cb_;
164 std::function<void(double)> double_cb_;
165 std::function<void(bool)> bool_cb_;
188 const string& name,
const string& description,
189 std::function<
void(
int)> cb =
nullptr);
211 const string& name,
const string& description,
212 std::function<
void(
double)> cb =
nullptr);
231 void registerTuneable(
bool& value,
const string& name,
const string& description,
232 std::function<
void(
bool)> cb =
nullptr);
Definition: tuneable.h:24
void title(const std::string &titlestr)
Definition: matplotlibcpp.h:292
Tuneable(double *value, double min, double max, const string &title, const string &description, std::function< void(double)> cb)
Definition: tuneable.h:37
Tuneable(int *value, int min, int max, const string &title, const string &description, std::function< void(int)> cb)
Definition: tuneable.h:27
Definition: tuneable.h:24
Definition: tuneable.h:21
Type getType() const
Definition: tuneable.h:146
void addToGUI(ofxDatGui &gui)
Definition: tuneable.h:54
void registerTuneable(int &value, int min, int max, const string &name, const string &description, std::function< void(int)> cb=nullptr)
Definition: tuneable.cpp:63
Tuneable(bool *value, const string &title, const string &description, std::function< void(bool)> cb)
Definition: tuneable.h:47
Definition: tuneable.h:24
Type
Definition: tuneable.h:24
void * getDataAddress() const
Definition: tuneable.h:142
void * getUIAddress() const
Definition: tuneable.h:138
bool fromString(std::string str)
Definition: tuneable.h:112
Definition: tuneable.h:24
std::string toString()
Definition: tuneable.h:89