-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlider.pde
More file actions
38 lines (33 loc) · 1.11 KB
/
Copy pathSlider.pde
File metadata and controls
38 lines (33 loc) · 1.11 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
class Slider extends Widget {
int minValue, maxValue, currentValue;
float sliderPosition;
boolean isDragging = false;
Slider(int x, int y, int width, int height, int minValue, int maxValue, int startValue, color widgetColor, color hoverColor, PFont widgetFont, int event) {
super(x, y, width, height, "", widgetColor, hoverColor, widgetFont, event);
this.minValue = minValue;
this.maxValue = maxValue;
this.currentValue = startValue;
this.sliderPosition = map(startValue, minValue, maxValue, y-10, y + width - 10);
}
void draw() {
super.draw();
fill(0);
rect(x, sliderPosition, width, 10);
text(getValue(), x + 11, y + height + 20);
}
int getEvent(int mX, int mY) {
if (mousePressed) {
if (mY > sliderPosition && mY < sliderPosition + 10 && mX > x && mX < x + width) {
isDragging = true;
return event;
}
} else {
isDragging = false;
}
return event;
}
int getValue() {
float sliderValue = map(sliderPosition, y, y + height - 10, minValue, maxValue);
return round(sliderValue);
}
}