-
Notifications
You must be signed in to change notification settings - Fork 1
/
toggle.pde
83 lines (69 loc) · 1.53 KB
/
toggle.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Toggle {
private String label;
private char hotkey;
private String description;
private int x, y, r;
public boolean on;
public boolean enabled;
public static final int radius = 10;
Toggle(String label, char hotkey, String description, int x, int y) {
this.label = label;
this.hotkey = hotkey;
this.description = description;
this.x = x;
this.y = y;
this.r = radius;
this.on = false;
this.enabled = true;
}
Toggle(String label, char hotkey, String description, int x, int y, boolean startOn) {
this(label, hotkey, description, x, y);
this.on = startOn;
}
String label() {
return label;
}
String description() {
return description;
}
void enableThisFrame(boolean isEnabled) {
enabled = isEnabled;
}
boolean wasClicked(int mx, int my) {
return enabled && (x-r) < mx && mx < (x+r) && (y-r) < my && my < (y+r);
}
boolean wasPressed(char key) {
return enabled && key == hotkey;
}
boolean on() {
return on && enabled;
}
// void turnOn() {
// on = true;
// }
// void turnOff() {
// on = false;
// }
void click() {
on = !on;
}
void draw(PApplet canvas) {
int bg, fg;
if (!enabled) {
bg = 128;
fg = 0;
} else if (on) {
bg = 255;
fg = 0;
} else {
bg = 0;
fg = 255;
}
canvas.fill(bg);
canvas.stroke(fg);
canvas.rect(x, y, (float) r, (float) r);
canvas.fill(fg);
if (uiFont != null) { canvas.textFont(uiFont); }
canvas.text(label, x, y);
}
}