forked from bferdinandus/SwitchBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.pde
58 lines (47 loc) · 1.22 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
public class Button
{
private String _text;
private Integer _x, _y, _margin = 2, _textSize = 15, _textWidth;
private Boolean _mouseOver = false, _mousePressed = false;
private Constants.buttons _id;
Button() {
}
Button(Constants.buttons id, String text, Integer x, Integer y) {
_id = id;
_text = text;
_x = x;
_y = y;
}
public Boolean MouseOverCheck(Integer x, Integer y) {
Integer x1 = _x - _margin, x2 = _x - _margin + _textWidth + (2 * _margin);
Integer y1 = _y, y2 = _y + _textSize + (2 * _margin);
_mouseOver = (x >= x1 && x <= x2
&& y >= y1 && y <= y2);
return _mouseOver;
}
public Constants.buttons Id() {
return _id;
}
public void MousePressed() {
_mousePressed = true;
}
public void MouseReleased() {
_mousePressed = false;
}
public void Display() {
textAlign(LEFT, TOP);
textSize(_textSize);
_textWidth = round(textWidth(_text));
stroke(0);
strokeWeight(1);
fill(128);
if (_mouseOver && !_mousePressed) {
fill(255);
} else if (_mouseOver && _mousePressed) {
fill(64);
}
rect(_x - _margin, _y, _textWidth + (2 * _margin), _textSize + (2 * _margin));
fill(0);
text(_text, _x, _y );
}
}