-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDoubleEndedSlider.pde
More file actions
69 lines (60 loc) · 2.28 KB
/
DoubleEndedSlider.pde
File metadata and controls
69 lines (60 loc) · 2.28 KB
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
public class DoubleEndedSlider extends CircularSlider {
private float fValue2, fSlider2, fOffset;
public DoubleEndedSlider(float x, float y, float size, float begin, float end, float val, float min, float max, int id, Controllable target) {
this(x, y, size, SLIDER_BAR_WIDTH, begin, end, val, val, min, max, id, target);
}
public DoubleEndedSlider(float x, float y, float size, float thickness, float begin, float end, float val, float val2, float min, float max, int id, Controllable target) {
super(x, y, size, thickness, begin, end, val, min, max, id, target);
fOffset = DBLSIDED_HANDLE_WIDTH;
setValue2(val2);
}
public float getValue2() {
return fValue2;
}
public void setValue2(float val) {
fValue2 = constrain(val, fMin, fMax);
fSlider2 = constrain(map(val, fMin, fMax, fBegin, fEnd), fBegin, fEnd);
}
public void drawForeground() {
pushStyle();
fill((fHover) ? HIGHLIGHT_COLOR : SLIDER_BAR_COLOR);
arcWithThickness(fSize, fLoc.x, fLoc.y, fSlider, fSlider2, fThickness);
fill((fHover && (fState == BEGIN))
? 0xFFFFFFFF
: HIGHLIGHT_COLOR);
arcWithThickness(fSize, fLoc.x, fLoc.y, fSlider - fOffset, fSlider, fThickness);
fill((fHover && (fState == END))
? 0xFFFFFFFF
: HIGHLIGHT_COLOR);
arcWithThickness(fSize, fLoc.x, fLoc.y, fSlider2, fSlider2 + fOffset, fThickness);
popStyle();
}
public boolean selectState(float x, float y) {
float angle = Util.getAngleNorm(fLoc.x, fLoc.y, x, y);
if (angle >= fSlider2 && angle <= fSlider2 + fOffset)
fState = END;
else if (angle >= fSlider - fOffset && angle <= fSlider)
fState = BEGIN;
else if (angle < fEnd && angle > fBegin)
fState = SLIDER;
else
return false;
return true;
}
public void updateSlider(float x, float y) {
float angle = Util.getAngleNorm(fLoc.x, fLoc.y, x, y);
switch (fState) {
case BEGIN:
// TODO: bug in Util.constrain
fSlider = constrain(angle, fBegin, fSlider2);
fValue = map(fSlider, fBegin, fEnd, fMin, fMax);
fTarget.onEvent(fID, fValue);
break;
case END:
fSlider2 = Util.constrain(angle, fSlider, fEnd);
fValue2 = map(fSlider2, fBegin, fEnd, fMin, fMax);
fTarget.onEvent(fID, fValue2);
break;
}
}
}