forked from adamhrv/HaarcascadeVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.pde
49 lines (40 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
// Daniel Shiffman's button
class Button {
Rectangle r; //button's rectangle
String txt; //button's text
boolean clicked; //did i click on it?
boolean rollover; //did i rollover it?
Button(int x, int y, int w, int h, String s) {
r = new Rectangle(x,y,w,h);
txt = s;
}
void render() {
//draw rectangle and text based on whether rollover or clicked
rectMode(CORNER);
stroke(0); noFill();
if (rollover) fill(0.5);
if (clicked) fill(0);
rect(r.x,r.y,r.width,r.height);
float b = 0.0;
if (clicked) b = 1;
else if (rollover) b = 0.2;
else b = 0;
fill(b);
textAlign(LEFT);
text(txt,r.x+10,r.y+14);
}
//methods to check rollover, clicked, or released (must be called from appropriate
//places in draw, mousePressed, mouseReleased
boolean rollover(int mx, int my) {
if (r.contains(mx,my)) rollover = true;
else rollover = false;
return rollover;
}
boolean clicked(int mx, int my) {
if (r.contains(mx,my)) clicked = true;
return clicked;
}
void released() {
clicked = false;
}
}