This repository has been archived by the owner on Jul 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.pde
96 lines (86 loc) · 1.96 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
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
88
89
90
91
92
93
94
95
96
class SwitchButton {
int px, py, sizeX, sizeY, buttonPx, buttonPy;
boolean IO;
String label;
color BLUE = #0000ff;
color RED = #ff0000;
color WHITE = #ffffff;
color BLACK = #000000;
SwitchButton(int px, int py, int sizeX, int sizeY, boolean IO, String label) {
this.px = px;
this.py = py;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.IO = IO;
this.label = label;
this.buttonPx = px-sizeX/2+sizeY/2;
this.buttonPy = py;
}
void putButton() {
if (overCircle(px, py, sizeX)) IO = !IO;
}
boolean overCircle(int x, int y, int diameter) {
return dist(buttonPx, buttonPy, mouseX, mouseY) <= sizeY/2;
}
void showUp() {
noStroke();
textSize(15);
if (IO) fill(BLUE);
else fill(RED);
rectMode(CENTER);
rect(px,py,sizeX,sizeY);
textAlign(CENTER);
if (IO) fill(WHITE);
else fill(BLACK);
text(label, px, py, sizeX, sizeY);
if (IO) fill(RED);
else fill(BLUE);
ellipseMode(CENTER);
ellipse(buttonPx, buttonPy, sizeY, sizeY);
}
}
class ClickButton {
int px, py, sizeX, sizeY;
color bgCol, textCol;
String label;
ClickButton(int px, int py, int sizeX, int sizeY, color bgCol, color textCol, String label) {
this.px = px;
this.py = py;
this.bgCol = bgCol;
this.textCol = textCol;
this.label = label;
this.sizeY = sizeY;
this.sizeX = sizeX;
}
void showUp() {
fill(bgCol);
noStroke();
rectMode(CENTER);
textSize(15);
rect(px, py, sizeX, sizeY);
fill(0);
fill(textCol);
text(label, px, py, sizeX, sizeY);
noFill();
}
boolean overButton() {
return abs(px - mouseX) <= sizeX/2 && abs(py - mouseY) <= sizeY/2;
}
void putButton() {
if(overButton()) {
switch(label) {
case "UNDO":
log.UNDO();
break;
case "REDO":
log.REDO();
break;
case "RESET":
reset();
break;
default:
break;
}
}
}
}