-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofxJFControlGroup.cpp
221 lines (129 loc) · 5.09 KB
/
ofxJFControlGroup.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
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
//
// ofxJFControlPanel.cpp
// jfGui
//
// Created by João Fonseca on 03/04/15.
//
//
#include "ofxJFControlGroup.h"
ofxJFControlGroup::ofxJFControlGroup(){
enableMouseEvents();
}
ofxJFControlGroup::ofxJFControlGroup(string _name, int _x, int _y, int _width, int _height){
name=_name;
location.set(_x,_y);
size.set(_width,_height);
setEventArea(location, size);
enableMouseEvents();
addLabel(name, ofPoint(location.x+10,location.y+(size.y/2)));
setLabelColor(GROUP_LABEL_COLOR);
backgroundColor = SLIDER_BACKGROUND_COLOR;
widgetHeight=48;
maximizedHeight=size.y;
totalHeight=size.y;
isMaximized=false;
widgetChangedSize=false;
initialLocation=location;
}
void ofxJFControlGroup::addSlider(string _name, float _min, float _max){
int yLoc=initialWigetYlocation();
controls.push_back(new ofxJFSlider(_name, _min, _max, location.x, yLoc,size.x,widgetHeight));
maximizedHeight+=controls[controls.size()-1]->size.y;
}
void ofxJFControlGroup::addSlider(string _name, float &_var, float _min, float _max){
int yLoc=initialWigetYlocation();
controls.push_back(new ofxJFSlider(_name, _var, _min, _max, location.x, yLoc,size.x,widgetHeight));
maximizedHeight+=controls[controls.size()-1]->size.y;
}
void ofxJFControlGroup::addMultiSlider(string _name, float _min, float _max){
int yLoc=initialWigetYlocation();
controls.push_back(new ofxJFMultiSlider(_name, _min, _max, location.x, yLoc,size.x,widgetHeight));
maximizedHeight+=controls[controls.size()-1]->size.y;
}
void ofxJFControlGroup::addMultiSlider(string _name, ofPoint &_var, float _min, float _max){
int yLoc=initialWigetYlocation();
controls.push_back(new ofxJFMultiSlider(_name, _var, _min, _max, location.x, yLoc,size.x,widgetHeight));
maximizedHeight+=controls[controls.size()-1]->size.y;
}
void ofxJFControlGroup::update(){
widgetChangedSize=false;
for (int i=0; i< controls.size(); i++){
if(controls[i]->widgetChangedSize)relocateControls(i);
controls[i]->update();
}
}
void ofxJFControlGroup::drawController(){
ofPushStyle();
ofSetColor(backgroundColor);
ofRectRounded(location.x, location.y, size.x, size.y,3);
if(isMaximized){
for (int i=0; i< controls.size(); i++) {
controls[i]->drawController();
}
ofSetColor(GROUP_LABEL_COLOR);
ofLine((location.x+size.x)-20, location.y+(size.y/2), (location.x+size.x)-10, location.y+(size.y/2));
}else{
ofSetColor(GROUP_LABEL_COLOR);
ofLine((location.x+size.x)-20, location.y+(size.y/2), (location.x+size.x)-10, location.y+(size.y/2));
ofLine((location.x+size.x)-15, location.y+(size.y/2)-5, (location.x+size.x)-15, location.y+(size.y/2)+5);
}
drawLabel();
ofPopStyle();
//ofSetColor(255, 0, 0);
//ofLine(20, location.y+totalHeight, size.x+20, location.y+totalHeight);
}
int ofxJFControlGroup::initialWigetYlocation(){
int yLoc=location.y+size.y;
for (int i=0; i< controls.size(); i++) {
yLoc+=controls[i]->size.y;
}
return yLoc;
}
void ofxJFControlGroup::relocateControls(int _pos){
//cout<<controls[_pos]->name<<endl;
for (int i = _pos+1; i<controls.size(); i++) {
int relocation=0;
for(int p = 0; p < i; p++){
relocation+=controls[p]->totalHeight;
}
relocation+=controls[_pos]->size.y;
maximizedHeight=size.y+relocation+17; /// 17 WHY CHECK THIS, WHY THIS VALUE??????? MISSING SOMETHING
controls[i]->setLocation(ofPoint(controls[i]->location.x,relocation+location.y));
}
if(isMaximized){
// maximize=true;
totalHeight=maximizedHeight;
}
else {
// minimize=true;
totalHeight=size.y;
}
widgetChangedSize=true;
}
void ofxJFControlGroup::setLocation(ofPoint _location){ //here
int add=0;
for(int i = 0; i< controls.size();i++){
if(i>0)if(controls[i-1]->isMaximized)add+=controls[i-1]->totalHeight-controls[i-1]->size.y;
controls[i]->setLocation(ofPoint(controls[i]->location.x,controls[i]->initialLocation.y+_location.y+add));
}
location.y=initialLocation.y+_location.y;
setLPosition(ofPoint(location.x+10,location.y+(size.y/2)));
setEventArea(location, size);
//location=_location;
}
void ofxJFControlGroup::mousePressed(int x, int y, int button){
if(hitTest(x, y, size.x, size.y)){
isMaximized=!isMaximized;
widgetChangedSize=true;
if(isMaximized){
// maximize=true;
totalHeight=maximizedHeight;
// cout<<"maximized"<<totalHeight<<endl;
}
else {
// minimize=true;
totalHeight=size.y;
//cout<<"minimized"<<totalHeight<<endl;
}
}
}