-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathofxGuiGroup.h
147 lines (119 loc) · 4.77 KB
/
ofxGuiGroup.h
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
#pragma once
#include "ofxBaseGui.h"
#include "ofParameter.h"
#include "ofxButton.h"
#include "ofxLabel.h"
#include "ofxSlider.h"
#include "ofPath.h"
class ofxGuiGroup : public ofxBaseGui {
public:
ofxGuiGroup();
ofxGuiGroup(const ofParameterGroup & parameters, const of::filesystem::path & filename = "settings.xml", float x = 10, float y = 10);
virtual ~ofxGuiGroup() {
}
ofxGuiGroup * setup(const std::string & collectionName = "", const of::filesystem::path & filename = "settings.xml", float x = 10, float y = 10);
ofxGuiGroup * setup(const ofParameterGroup & parameters, const of::filesystem::path & filename = "settings.xml", float x = 10, float y = 10);
void add(ofxBaseGui * element);
void add(const ofParameterGroup & parameters);
template <typename T>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type add(ofParameter<T> & p) {
add(createGuiElement<ofxSlider<T>>(p));
}
void add(ofParameter<void> & parameter);
void add(ofParameter<bool> & parameter);
void add(ofParameter<std::string> & parameter);
template <typename F>
void add(ofReadOnlyParameter<std::string, F> & parameter) {
ownedCollection.emplace_back(std::make_unique<ofxLabel>(parameter));
add(ownedCollection.back().get());
}
void add(ofParameter<ofVec2f> & parameter);
void add(ofParameter<ofVec3f> & parameter);
void add(ofParameter<ofVec4f> & parameter);
void add(ofParameter<glm::vec2> & parameter);
void add(ofParameter<glm::vec3> & parameter);
void add(ofParameter<glm::vec4> & parameter);
void add(ofParameter<ofColor> & parameter);
void add(ofParameter<ofShortColor> & parameter);
void add(ofParameter<ofFloatColor> & parameter);
void add(ofParameter<ofRectangle> & parameter);
void minimize();
void maximize();
void minimizeAll();
void maximizeAll();
bool isMinimized() const;
void setWidthElements(float w);
void clear();
virtual void sizeChangedCB();
virtual bool mouseMoved(ofMouseEventArgs & args);
virtual bool mousePressed(ofMouseEventArgs & args);
virtual bool mouseDragged(ofMouseEventArgs & args);
virtual bool mouseReleased(ofMouseEventArgs & args);
virtual bool mouseScrolled(ofMouseEventArgs & args);
std::vector<std::string> getControlNames() const;
std::size_t getNumControls() const;
ofxIntSlider & getIntSlider(const std::string & name);
ofxFloatSlider & getFloatSlider(const std::string & name);
ofxToggle & getToggle(const std::string & name);
ofxButton & getButton(const std::string & name);
ofxGuiGroup & getGroup(const std::string & name);
ofxBaseGui * getControl(const std::string & name);
ofxBaseGui * getControl(std::size_t num);
virtual ofAbstractParameter & getParameter();
virtual void setPosition(const glm::vec3 & p);
virtual void setPosition(float x, float y);
void enableHeader();
void disableHeader();
bool isHeaderEnabled();
static float elementSpacing;
static float groupSpacing;
static float childrenLeftIndent;
static float childrenRightIndent;
protected:
void updateChildrenPositions(bool bUpdateWidth = false);
void updateChild(ofxBaseGui * child, const float & x, const float & y, const float & width, bool bUpdateWidth = false);
bool bHeaderEnabled = true;
virtual void render();
virtual bool setValue(float mx, float my, bool bCheck);
virtual void onMinimize();
virtual void onMaximize();
ofRectangle headerRect;
ofRectangle minimizeRect;
template <class ControlType>
ControlType & getControlType(const std::string & name);
virtual void generateDraw();
std::vector<ofxBaseGui *> collection;
ofParameterGroup parameters;
of::filesystem::path filename;
bool minimized;
bool bGuiActive;
ofPath border, headerBg;
ofVboMesh textMesh;
template <typename T, typename P>
ofxBaseGui * createGuiElement(ofParameter<P> & param, float width = 0, float height = defaultHeight) {
ownedCollection.emplace_back(std::make_unique<T>(param, (ofIsFloatEqual(width, 0.f) ? b.width : width), height));
return ownedCollection.back().get();
}
ofxBaseGui * createGuiGroup(const ofParameterGroup & parameters) {
ownedCollection.emplace_back(std::make_unique<ofxGuiGroup>(parameters));
return ownedCollection.back().get();
}
private:
// This array stores the unique pointers for the elements that this gui group creates, thus owns.
// This allowes for correct memory management and no leaks
std::vector<std::unique_ptr<ofxBaseGui>> ownedCollection;
};
template <class ControlType>
ControlType & ofxGuiGroup::getControlType(const std::string & name) {
ControlType * control = dynamic_cast<ControlType *>(getControl(name));
if (control) {
return *control;
} else {
ofLogWarning() << "getControlType " << name << " not found, creating new";
ownedCollection.emplace_back(std::make_unique<ControlType>());
control = static_cast<ControlType *>(ownedCollection.back().get());
control->setName(name);
add(control);
return *control;
}
}