-
Notifications
You must be signed in to change notification settings - Fork 6
/
Button_class.pde
85 lines (82 loc) · 2.09 KB
/
Button_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Button {
int dp;
float x;
float y;
float sx, sy;
String t, d;
boolean showInfo;
boolean active;
Button(float posx, float posy, float sizex, float sizey, String text, String description, int descriptionPos) {
x = posx;
y = posy;
sx = sizex;
sy = sizey;
t = text;
d = description;
dp = descriptionPos; // 0-up, 1-down, 2-left, 3-right
showInfo = false;
active = true;
}
void update(int i) {
if (active) {
if (mouseX >= x && mouseX <= x+sx && mouseY >= y && mouseY <= y+sy) {
controlb[i] = true;
} else {
controlb[i] = false;
}
if (controlb[i] && mousePressed || buttonpressed[i] ) { // green with black text (activated)
col[0] = 96;
col[1] = 200;
col[2] = 150;
thue = 0;
showInfo = false;
} else if (controlb[i] && !mousePressed) { // yellow with white text (howered)
col[0] = 40;
col[1] = 200;
col[2] = 180;
thue = 255;
showInfo = true;
} else if (!controlb[i]) { // red with white text (deactivated)
col[0] = 0;
col[1] = 200;
col[2] = 150;
thue = 255;
showInfo = false;
}
} else {
col[0] = 0;
col[1] = 0;
col[2] = 100;
thue = 255;
showInfo = false;
}
}
void show() {
fill(col[0], col[1], col[2]);
strokeWeight(1);
stroke(255);
rect(x, y, sx, sy);
pushMatrix();
textSize(font_size);
fill(thue);
text(t, x+font_size*0.5, y+font_size);
popMatrix();
if (showInfo) {
pushMatrix();
if (dp == 0) {
translate(x, y-1.15*sy); // put description above
} else if (dp == 1) {
translate(x, y+1.15*sy); // put description bellow
} else if (dp == 2) {
translate(x-textWidth(d)-font_size, y); // put description to the left side
} else if (dp == 3) {
translate(x+sx, y); // put description to the right side
} else {
}
noFill();
rect(0, 0, textWidth(d)+font_size, sy);
text(d, font_size*0.5, font_size);
popMatrix();
}
}
}