-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputSlider.pde
52 lines (41 loc) · 1.07 KB
/
InputSlider.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
class InputSlider extends Element {
float value;
float minValue;
float maxValue;
InputSliderCallback callback;
InputSlider(int x, int y, int w, int h, float minValue, float maxValue, float initialValue, InputSliderCallback callback) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.value = initialValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.callback = callback;
}
@Override
void onClick(boolean insideElement) {
if (insideElement) {
value = map(mouseX, x, x + w, minValue, maxValue);
callback.onChange(value);
}
}
@Override
void onMouseDragged(boolean insideElement) {
if (insideElement) {
value = map(mouseX, x, x + w, minValue, maxValue);
callback.onChange(value);
}
}
void draw() {
pushStyle();
rectMode(CENTER);
fill(colBright);
rect(x + w / 2, y + h / 2, w, defaultStrokeWeight);
rect(map(value, minValue, maxValue, x, x + w), y + h / 2, 8, h - 8);
popStyle();
}
}
interface InputSliderCallback {
void onChange(float value);
}