-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.pde
239 lines (214 loc) · 5.82 KB
/
UI.pde
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
color colBackgroud = color(16);
color colHeader = color(32);
color colBorder = color(128);
color colText = #0084CB;
// =======================================================================
public class RButton {
float x, y, w, h;
boolean enabled = true;
boolean selected = false;
boolean down = false;
PImage icon;
String label;
String ID;
String help;
int durOn = 0;
// ---------------------------------------------------------------------
// Constructor
RButton(float _x, float _y, float _w, float _h, String _label, String _ID) {
x = _x;
y = _y;
w = _w;
h = _h;
ID=_ID;
icon = loadImage("btn_"+_ID+".png");
while (icon.width == 0) delay(10);
label = _label;
help = _ID;
enabled = false;
selected = false;
}
RButton(float _x, float _y, float _w, float _h, String _label, String _ID, String _help) {
x = _x;
y = _y;
w = _w;
h = _h;
ID=_ID;
icon = loadImage("btn_"+_ID+".png");
while (icon.width == 0) delay(10);
label = _label;
help = _help;
enabled = false;
selected = false;
}
// ---------------------------------------------------------------------
// Toggle enabled state
public void set() {
enabled = !enabled;
}
// ---------------------------------------------------------------------
// Show the button
public void show() {
pushStyle();
if (down) { // light Gray when pressed
fill(64);
durOn++;
println("duron", durOn);
} else {
durOn=0;
fill(colHeader);
}
rect(x, y, w, h);
if (selected) { // blue accent and blue icon
tint(colText);
image(icon, x, y, h, h);
fill(colText);
rect(x, y, h/16.0, h);
} else {
tint(192);
image(icon, x, y, h, h);
}
if ((durOn > 10) && (durOn < 20)) {
fill(#2bcb65);
rect(x, y, h/16.0, h*(durOn-10)/10);
}
popStyle();
// reset value
if (durOn == 20) {
vibrate(20);
if (parameters[mode] != null) {
parameters[mode].reset();
sld.val = parameters[mode].valueX;
if (mode == iSpike) {
spikes.clear();
}
fft.fftChanged = true;
}
}
}
// ---------------------------------------------------------------------
// Check if mouse is over button
public boolean hit() {
boolean inside = false;
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
inside = true;
} else {
inside = false;
}
return inside;
}
}
// =======================================================================
public class RLabel {
float x, y, w, h;
String text = "0 %";
String unit = "%";
int val;
// ---------------------------------------------------------------------
// Constructor
RLabel(float _x, float _y, float _w, float _h) {
x = _x;
y = _y;
w = _w;
h = _h;
}
// ---------------------------------------------------------------------
// Set value
public void set(int _value, String _unit) {
val = _value;
text = str(int(_value)) + " " + _unit;
}
// ---------------------------------------------------------------------
// Show label
public void show() {
text = str(int(val)) + " " + unit;
pushStyle();
fill(colHeader);
rect(x, y, w, h);
fill(colText);
myText(text, x, y + tS/10);
popStyle();
}
}
// =======================================================================
public class RSlider {
int min = 0;
int max = 100;
int val = 100;
float x, y, w, h;
float p1, p2, t;
int prevVal = -1;
// ---------------------------------------------------------------------
// Constructor
RSlider(float _x, float _y, float _w, float _h) {
x = _x;
y = _y;
w = _w;
h = _h;
p1 = h / 2.06; // padding
p2 = h / 2.03; // padding
t = h / 2; //thickness
}
// ---------------------------------------------------------------------
// Set value of slider, check boundaries, return true if val was changed
public boolean setValMouse(float _mouseX) {
val = constrain(round(map(_mouseX, x+t, x+w-t, min, max)), min, max);
if (val != prevVal) {
prevVal = val;
if ((val == min) || (val == max)) vibrate(15);
lbl.set(val, "%");
return true;
} else {
return false;
}
}
// ---------------------------------------------------------------------
// Set value of slider, check boundaries
public void setVal(int _val) {
val = constrain(_val, min, max);
lbl.set(val, "%");
}
// ---------------------------------------------------------------------
// Show slider
public void show() {
pushStyle();
fill(colHeader);
rect(x, y, w, h);
fill(128);
rect(x+p2, y+p2, w-p2-p2, h-p2-p2, p2, p2, p2, p2);
fill(colText);
rect(x+p1, y+p1, map(val, min, max, 0, w-p1-p1), h-p1-p1, p1, p1, p1, p1);
ellipse(map(val, min, max, x+t, x+w-t), y+t, t*.7, t*0.7);
popStyle();
}
// ---------------------------------------------------------------------
// Test if mouse is over slider
public boolean hit() {
boolean inside = false;
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
inside = true;
} else {
inside = false;
}
return inside;
}
}
// =======================================================================
// Draw text with shadow
void imageText(String _text, float _x, float _y) {
final float blur = 1;
pushStyle();
fill(0);
text(_text, _x-blur, _y-blur);
text(_text, _x-blur, _y+blur);
text(_text, _x+blur, _y-blur);
text(_text, _x+blur, _y+blur);
popStyle();
text(_text, _x, _y);
}
// =======================================================================
// Draw text on with offset at location
void myText(String _text, float _x, float _y) {
//text(_text, _x + tS/5, _y + tS/4);
text(_text, _x, _y + tS/8);
}