-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.pde
123 lines (95 loc) · 2.33 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// File to contain the base button class definition
abstract class Button {
// === BASE COMPONENTS ===
protected color colorPressed;
protected color colorNeutral;
protected int strokeAmount;
protected String text;
protected color textColor;
protected int textSize;
public Button () {
colorPressed = color(0);
colorNeutral = color(0);
strokeAmount = 0;
text = "";
textSize = 0;
}
public Button setColorPressed (color c) {
colorPressed = c;
return this;
}
public Button setColorNeutral (color c) {
colorNeutral = c;
return this;
}
public Button setStrokeAmount (int s) {
strokeAmount = s;
return this;
}
public Button setText (String t) {
text = t;
return this;
}
public Button setTextColor (color c) {
textColor = c;
return this;
}
public Button setTextSize (int ts) {
textSize = ts;
return this;
}
// === ABSTRACT COMPONENTS ===
// Indicate if mouse is over this button or not
abstract Boolean mouseIsOver();
// Draw the button
abstract void draw();
}
class RectButton extends Button {
protected int x1, y1; // Top left rectangle x and y coordinates
protected int w, h; // Width and height of the rectangle
public RectButton(int x_in, int y_in, int w_in, int h_in) {
super();
x1 = x_in;
y1 = y_in;
w = w_in;
h = h_in;
strokeAmount = 50;
}
// Get bottom right corner x coord
private int getX2 () {
return x1 + w;
}
// Get bottom right corner y coord
private int getY2 () {
return y1 + h;
}
private int getCenterX () {
return x1 + w/2;
}
private int getCenterY () {
return y1 + h/2;
}
// === ABSTRACT IMPLEMENTATIONS ===
final Boolean mouseIsOver () {
return (mouseX > x1 && mouseX < getX2() && mouseY > y1 && mouseY < getY2());
}
final void draw () {
if (!mouseIsOver()) {
fill(colorNeutral);
} else {
fill(colorPressed);
}
stroke(strokeAmount);
rect(x1, y1, w, h);
fill(0);
textSize(this.textSize);
textAlign(CENTER, CENTER);
text(this.text, getCenterX(), getCenterY()-2);
// Reset stroke
stroke(255); // TODO: Investigate removal
}
}
// NOTE: Since play button refactor, may not need this.
// However, may be wanted in the future. Keeping here as reminder
//class CircleButton extends Button {
//}