-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButton.pde
73 lines (65 loc) · 1.46 KB
/
Button.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
68
69
70
71
72
73
public class Button{
String label;
float left, top, right, bottom, w, h, radius, fontScale;
color background_color, text_color;
boolean disabled;
boolean active;
public Button(String s, float l, float t, float r, float b, float rad, int bg, int tc){
this.label = s;
this.left = l;
this.top = t;
this.right = r;
this.bottom = b;
this.radius = rad;
this.w = r - l;
this.h = b - t;
this.background_color = bg;
this.text_color = tc;
this.disabled = false;
this.fontScale = 1;
}
public void move(float l, float t, float r, float b){
this.left = l;
this.top = t;
this.right = r;
this.bottom = b;
this.w = r - l;
this.h = b - t;
}
public void bigFont(){
this.fontScale = 3.2;
}
public boolean touched(float xPos, float yPos){
if(disabled == false){
if(xPos >= left && xPos <= right && yPos >= top && yPos <= bottom){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
public void drawIt(){
rectMode(CORNERS);
if(disabled == false){
fill(background_color);
}
else{
fill(150);
}
rect(left, top, right, bottom, radius);
fill(text_color);
textAlign(CENTER);
textSize(fontScale*h/4);
text(label, left + w / 2, top + h*(.5 + .1*fontScale));
}
public void enable(){
this.disabled = false;
}
public void disable(){
this.disabled = true;
}
}