-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider_class.pde
executable file
·67 lines (58 loc) · 1.97 KB
/
slider_class.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
color idle = color(255,102,0);
//class
class myVertSlider{
//class vars
int sliderPosX, sliderPosY;
int sliderHeight;
int sliderWidth = 16;
int sliderRaw;
int sliderVal;
int sliderMin, sliderMax;
int sliderGrabbed;
//initialize
myVertSlider(int posX, int posY, int tall, int min, int max, int input){
sliderPosX = posX;
sliderPosY = posY;
sliderHeight = tall;
sliderVal = input;
sliderMin = min;
sliderMax = max;
}
int update(){
sliderRaw = int(map(sliderVal, sliderMin, sliderMax, sliderHeight, 0));
if(mousePressed){
if(mouseX >= sliderPosX && mouseX <= sliderPosX + sliderWidth && mouseY >= sliderPosY && mouseY <= sliderPosY + sliderHeight){
sliderRaw = mouseY - sliderPosY;
sliderVal = int(map(sliderHeight - sliderRaw, 0 , sliderHeight, sliderMin, sliderMax));
}
}
return sliderVal;
}
void display(boolean showMenu){
if (showMenu == true){
//stroke(idle);
//strokeWeight(1);
//main line
line(sliderPosX + sliderWidth/2, sliderPosY, sliderPosX + sliderWidth/2, sliderPosY + sliderHeight);
//horizontal indicators
line(sliderPosX + sliderWidth/2, sliderPosY, sliderPosX, sliderPosY); //top
line(sliderPosX + sliderWidth/2, sliderPosY + sliderHeight, sliderPosX, sliderPosY + sliderHeight);
line(sliderPosX + sliderWidth/2, sliderPosY + sliderHeight/2, sliderPosX, sliderPosY + sliderHeight/2);
drawTriangle(int(sliderPosX + sliderWidth/2), sliderRaw + sliderPosY, 10);
// text indicator
fill(idle);
text(sliderVal, sliderPosX-2, sliderPosY-2);
text("Press 'm' to toggle\nPress 'r' to randomize",30, 250);
}
}
public void setSliderVal(int sliderVal){
this.sliderVal = sliderVal;
}
}
void drawTriangle(int triX, int triY, int triSize){
int triangleSize = triSize;
//stroke(idle);
//strokeWeight(1);
noFill();
triangle(triX, triY, triX + triangleSize, triY - triangleSize/2, triX + triangleSize, triY + triangleSize/2);
}