-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.pde
More file actions
47 lines (44 loc) · 1.04 KB
/
Copy pathbutton.pde
File metadata and controls
47 lines (44 loc) · 1.04 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
class Button {
//position and size
int x;
int y;
int width;
int height;
//for displaying text on buttons
String s;
int textSize;
int pushBack;
//button color
color c;
Button(int tempx, int tempy, int tempwidth, int tempheight, String text, int textS, int tpushBack, color tc) {
//initialize button based on params
x = tempx;
y = tempy;
width = tempwidth;
height = tempheight;
s = text;
textSize = textS;
pushBack = tpushBack;
c = tc;
}
boolean within(float tempx, float tempy) {
//for checking if mouse is clicking button
if (tempx > x + width / 2 || tempx < x - width / 2) return false;
else if (tempy > y + height / 2 || tempy < y - height / 2) return false;
else return true;
}
void display() {
//transform to position and draw rect and text
rectMode(CENTER);
stroke(0);
pushMatrix();
translate(x, y);
fill(c);
rect(0, 0, width, height);
textAlign(CENTER, CENTER);
textSize(textSize);
fill(0);
text(s, 0, 0);
popMatrix();
}
}