forked from yangsu/Synaptic-Wall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slider.pde
59 lines (48 loc) · 1.38 KB
/
Slider.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
public abstract class Slider extends Control {
protected float fSize, fThickness, fMin, fMax, fValue, fBegin, fEnd, fSlider;
protected String fLabel;
public Slider(float x, float y, float size, float thickness, float begin, float end, float val, float min, float max, int id, Controllable target) {
super(x, y, id, target);
fSize = size;
fThickness = thickness;
setSliderBounds(begin, end);
setValueRange(min, max);
setValue(val);
fLabel = "";
fVisible = true;
}
public float getValue() {
return fValue;
}
public float getSliderPosition() {
return fSlider;
}
public void setLabel(String label) {
fLabel = label;
}
public void setValue(float val) {
fValue = constrain(val, fMin, fMax);
fSlider = constrain(map(val, fMin, fMax, fBegin, fEnd), fBegin, fEnd);
}
public void setSliderBounds(float begin, float end) {
fBegin = begin;
fEnd = end;
fSlider = constrain(fSlider, fBegin, fEnd);
}
public void setValueRange(float min, float max) {
fMin = min;
fMax = max;
}
public abstract void updateSlider(float x, float y);
public boolean onMouseDown(float x, float y) {
fSelected = isInBounds(x, y);
if (fSelected)
updateSlider(x, y);
return fSelected;
}
public boolean onMouseDragged(float x, float y) {
if (fSelected)
updateSlider(x, y);
return fSelected;
}
}