-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.pde
50 lines (36 loc) · 1.39 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
class Button {
public PVector corner1, corner2;
public Button (PVector origin, PVector dimensions) throws Exception{
this.corner1 = origin;
this.corner2 = new PVector(origin.x + dimensions.x, origin.y + dimensions.y);
if(dimensions.x < 1 || dimensions.y < 1) {
throw new Exception("Width and height of a button must be positive");
}
}
public Button (PVector origin, int wide, int high) throws Exception {
this.corner1 = origin;
this.corner2 = new PVector(origin.x + wide, origin.y + high);
if(wide <1 || high < 1) {
throw new Exception("Width and height of a button must be positive");
}
}
public Button (int x, int y, int wide, int high) throws Exception {
this.corner1 = new PVector(x, y);
this.corner2 = new PVector(x + wide, y + high);
if(wide <1 || high < 1) {
throw new Exception("Width and height of a button must be positive");
}
}
public String toString(){
return "C1: " + corner1.x + ", " + corner1.y + "\n"
+"C2: " + corner2.y + ", " + corner2.y + "\n";
}
public boolean isClicked(){
if(mouseX > corner1.x && mouseX < corner2.x
&& mouseY >corner1.y && mouseY < corner2.y ){
return true;
} else {
return false;
}
}
}