-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckMark.pde
87 lines (76 loc) · 1.61 KB
/
CheckMark.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
84
85
86
87
class CheckMark
{
// has on or off state, x, y, texts for each button ig but not neccessary just on or off really
int x, y, x1;
int state;
int size = 50;
int count = 1;
float alpha0, alpha1;
String text;
CheckMark(int x, int y, int state, String text)
{
this.x = x;
this.y = y;
this.x1 = x + int((size*1.5));
this.state = state;
this.text = text;
}
int getState() {
return state;
}
void setState(int state)
{
this.state = state;
}
void update()
{
display();
listenForChanges();
}
void display()
{
// For the mouse glow effect
float distance = dist(mouseX, mouseY, x+buttonWidth/2, y+buttonHeight/2);
stroke(255, distance, distance);
//fill(#5F5B5B, 50+distance);
if (state == 1)
{
alpha0 = 20;
alpha1 = 255;
} else if (state == 0)
{
alpha0 = 255;
alpha1 = 20;
}
textSize(40);
text(text, x-120, y+37);
textSize(20);
// true
fill(#5F5B5B, alpha1);
rect(x, y, size, size);
fill(255);
text("On", x+size/2, y+size/2);
// false
fill(#5F5B5B, alpha0);
rect(x1, y, size, size);
fill(255);
text("Off", x1+size/2, y+size/2);
}
void listenForChanges()
{
// Guard clauses !?
if (!mousePressed) return;
if (mouseX >= x && mouseX <= x+size && mouseY>=y && mouseY <= y+size) {
state = 1;
stateChanged();
}
else if (mouseX >= x1 && mouseX <= x1+size && mouseY>=y && mouseY <= y+size) {
state = 0;
stateChanged();
}
}
// I guess this is a listener ?
boolean stateChanged() {
return true;
}
}