-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.pde
62 lines (62 loc) · 1.79 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
class Button {
float x, y, w, h;
String s;
color fill;
color pressedFill;
color border;
boolean noStroke=false;
boolean pressed=false;
public Button(float x, float y, float w, float h, String s, color fill, color border) {
this.x=x;
this.y=y;
this.w=w;
this.h=h;
this.s=s;
this.fill=fill;
this.pressedFill=color(255-(red(fill)+green(fill)+blue(fill))/3);
this.border=border;
}
public Button(float x, float y, float w, float h, String s, color fill) {
this.x=x;
this.y=y;
this.w=w;
this.h=h;
this.s=s;
this.fill=fill;
this.pressedFill=color(255-(red(fill)+green(fill)+blue(fill))/3);
noStroke =true;
}
public Button(float x, float y, float w, float h, color fill) {
this.x=x;
this.y=y;
this.w=w;
this.h=h;
this.s="";
this.fill=fill;
this.pressedFill=color(255-(red(fill)+green(fill)+blue(fill))/3);
noStroke =true;
}
void show() {
if(pressed)fill(pressedFill);
else fill(fill);
if (noStroke)noStroke();
else stroke(border);
rect(x, y, w, h);
if(pressed)fill(fill);
else fill(255-(red(fill)+green(fill)+blue(fill))/3);
textSize(h-10);
text(s, x+5, y+h-h/5);
}
void printInfo() {
println("buttonDim: ", x, " ", y, " ", x+w, " ", y+h);
}
boolean isPressed() {
if (mouseX>x &&mouseX<x+w && mouseY >y &&mouseY<y+h) {
pressed=!pressed;
String ss=pressed==true?"on":"off";
println(s," was clicked and is now: "+ss);
return true;
}
else return false;
}
}