-
Notifications
You must be signed in to change notification settings - Fork 0
/
verticalToggleButton.pde
60 lines (57 loc) · 1.22 KB
/
verticalToggleButton.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
class verticalToggleButton{
private String label, onText, offText;
private int x,y,w,h,txtSize;
private boolean value;
private color backgroundColor, Color, txtColor;
verticalToggleButton(int _x, int _y, int _w, int _h, color _Color,color _txtColor, String _offText, String _onText){
x=_x;
y=_y;
w=_w;
h=_h;
Color=_Color;
backgroundColor=color(_Color,90);
txtColor=_txtColor;
offText=_offText;
onText=_onText;
label=_offText;
}
boolean getValue(){
return value;
}
void setColors(color _Color, color _txtColor){
Color=_Color;
txtColor=_txtColor;
backgroundColor =color(_Color,50);
}
void setPosition(int _x, int _y) {
x=_x;
y=_y;
}
void setSize(int _w, int _h) {
w=_w;
h=_h;
}
void setText(String _offText, String _onText) {
offText=_offText;
onText=_onText;
}
void show(){
if (mouseX>x && mouseX<x+w && mouseY>y && mouseY<y+h/2) {
if (mousePressed){
value=false;
}
}
else if(mouseX>x && mouseX<x+w && mouseY>y+h/2 && mouseY<y+h){
if (mousePressed){
value=true;
}
}
fill(backgroundColor);
rect(x,y,w,h,30);
fill(Color);
if(value){label=onText;rect(x,y,w,h/2,30);}else {label=offText;rect(x,y+h/2,w,h/2,30);}
fill(txtColor);
textAlign(CENTER);
text(label,x+w/2,y+h/2);
}
}