-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathButton.pde
53 lines (46 loc) · 1.08 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
class Button {
int sizeX = 100;
int sizeY = 100;
float posX, posY;
int fontSize = 38;
String label;
final color BRIGHT = color(255),
MID = color(150),
DARK = color(100);
color bgColor, textColor;
float bgBrightness;
Button(float _posX, float _posY, String _label) {
posX = _posX;
posY = _posY;
label = _label;
textColor = BRIGHT;
bgColor = DARK;
bgBrightness = 0.0;
}
void display() {
updateColors();
// Draw rectangle.
fill(bgColor);
stroke(MID);
rect(posX, posY, sizeX, sizeY);
// Draw text.
textSize(fontSize);
textAlign(CENTER, CENTER);
fill(textColor);
stroke(textColor);
text(label, posX + sizeX / 2, posY + sizeY / 2);
}
// Returns true if mouse is pressed and mouse is inside button.
boolean clicked() {
return (mouseX > posX && mouseX < posX + sizeX) &&
(mouseY > posY && mouseY < posY + sizeY) &&
mousePressed;
}
void updateColors() {
bgBrightness /= 1.5;
bgColor = lerpColor(DARK, BRIGHT, bgBrightness);
}
void flash() {
bgBrightness = 1.0;
}
}