forked from ranenbg/Arduino-FFB-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBtn_info.pde
More file actions
76 lines (74 loc) · 2.11 KB
/
Btn_info.pde
File metadata and controls
76 lines (74 loc) · 2.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
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
class InfoButton {
int ns, as, dp;
float x, y, sx, sy;
String[] n = new String[ns];
String d;
Boolean enabled, hiden, showDescription;
InfoButton(float posx, float posy, float sizex, float sizey, int nSegments, String[] name, String description, int descriptionPos) {
x = posx;
y = posy;
sx = sizex;
sy = sizey;
ns = nSegments;
n = name;
as = -1; // no segment is active
d = description;
dp = descriptionPos;
enabled = false;
hiden = true;
showDescription = false;
}
void update(boolean resize) {
if (resize) {
if (d != " ") {
sx = textWidth(d)+font_size;
} else {
sx = 1.4*font_size;
}
sy = 1.4*font_size;
x = 0.123*widthprev + (wScaleX*axisHeight_init*0.8)/2;
y = 0.223*heightprev - (wScaleY*axisHeight_init*0.8)/2 - sy;
}
if (mouseX >= x && mouseX <= x+sx && mouseY >= y && mouseY <= y+sy) {
showDescription = true; // if howered with mouse
} else {
showDescription = false; // if not howered
}
}
void show() {
color ce = color (0, 200, 150); // red
color cd = color (0, 0, 100); // gray
thue = 255; // white
if (!hiden) {
for (int i=0; i<ns; i++) {
fill(cd);
if (i == as) fill(ce);
strokeWeight(1);
stroke(255);
pushMatrix();
translate(x, y);
rect(i*(sx/ns), 0, sx/ns, sy);
textSize(font_size);
fill(thue);
text(n[i], i*(sx/ns)+0.5*(sx/ns - textWidth(n[i])), font_size);
popMatrix();
}
if (showDescription) {
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
}
noFill();
rect(0, 0, textWidth(d)+font_size, sy);
text(d, 0.5*font_size, font_size);
popMatrix();
}
}
}
}