-
Notifications
You must be signed in to change notification settings - Fork 0
/
ButtonNavigation.pde
70 lines (55 loc) · 1.38 KB
/
ButtonNavigation.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
class ButtonNavigation extends Button {
int paddingX;
String label;
boolean isActive;
int destinationScene;
ButtonNavigation(int x, int y, int paddingX, String label, int destinationScene) {
super(x, y, 32, 32);
this.x = x;
this.y = y;
this.paddingX = paddingX;
this.label = label;
this.destinationScene = destinationScene;
pushStyle();
this.setFontStyle(false);
this.w = int(textWidth(label)) + paddingX * 2;
this.h = int(g.textLeading);
popStyle();
this.isActive = false;
}
@Override
void onClick(boolean insideElement) {
if (insideElement) {
currentScene = this.destinationScene;
if (narrationSounds[currStep].isPlaying()) {
narrationSounds[currStep].stop();
}
}
}
@Override
void draw() {
// Update Active Bar
this.isActive = (currentScene == destinationScene);
// Display
if (this.isActive) {
pushStyle();
fill(colAccent);
rect(this.x + this.paddingX, this.y + this.h - 14, this.w - this.paddingX * 2, 4);
popStyle();
}
pushStyle();
setFontStyle(this.isHovered);
text(this.label, this.x + this.paddingX, this.y);
popStyle();
}
void setFontStyle(boolean useHoverStyle) {
if (useHoverStyle) {
fill(colPrimary);
}
else {
fill(colText);
}
textFont(fontNavigation);
textAlign(LEFT, TOP);
}
}