-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControll.pde
186 lines (160 loc) · 4.48 KB
/
Controll.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
class Controll {
private int w; // width
private int h; // height
private int x; // x position
private int y; // y position
private int ow; // outline width
private int type; // 0 - label, 1 - button, 2 - big label
private color oC = 0; // outline color
private color bC = 255; // body color
private color tC = 0; // text color
private color hOC = 0; // hovered outline color
private color hBC = 220; // hovered body color
private color hTC = 0; // hovered text color
private color aOC = 0; // active outline color
private color aBC = 0; // active body color
private color aTC = 255; // active text color
private color dOC; // draw outline color for current state
private color dBC; // draw body color for current state
private color dTC; // draw text color for current state
private String t; // controll text
private float tS = 50; // text size
public Controll setWidth(int width) {
this.w = width;
return this;
}
public Controll setHeigth(int heigth) {
this.h = heigth;
return this;
}
public Controll setX(int posX) {
this.x = posX;
return this;
}
public Controll setY(int posY) {
this.y = posY;
return this;
}
public Controll setOutlineWidth(int outlineWidth) {
this.ow = outlineWidth;
return this;
}
// not in use hovered block
public Controll setHoveredOutlineColor(color hoveredOutlineColor) {
this.hOC = hoveredOutlineColor;
return this;
}
public Controll setHoveredBodyColor(color hoveredBodyColor) {
this.hBC = hoveredBodyColor;
return this;
}
public Controll setHoveredTextColor(color hoveredTextColor) {
this.hTC = hoveredTextColor;
return this;
}
// ---------------------
// not in use normal state block
public Controll setOutlineColor(color outlineColor) {
this.oC = outlineColor;
return this;
}
public Controll setBodyColor(color bodyColor) {
this.bC = bodyColor;
return this;
}
// ---------------------
public Controll setTextColor(color textColor) {
this.tC = textColor;
return this;
}
// not in use active block
public Controll setActiveOutlineColor(color activeOutlineColor) {
this.aOC = activeOutlineColor;
return this;
}
public Controll setActiveBodyColor(color activeBodyColor) {
this.aBC = activeBodyColor;
return this;
}
public Controll setActiveTextColor(color activeTextColor) {
this.aTC = activeTextColor;
return this;
}
// ---------------------
public Controll setText(String text) {
this.t = text;
return this;
}
public Controll setTextSize(float textSize) {
this.tS = textSize;
return this;
}
Controll(int type) {
this.type = type;
}
public void show(boolean click) {
if (this.type == 0) { // label
pushStyle();
noStroke();
fill(oC); // outline color
rect(x, y+h-ow, w, ow);
fill(bC); // body color
rect(x, y, w, h-ow); // x + outline width...
textAlign(CENTER, CENTER);
textSize(tS);
fill(tC); // text color
text(t, x+w/2, y+(h+ow)/2);
popStyle();
} else if (this.type == 1) { // button
// not hovered
dOC = oC;
dBC = bC;
dTC = tC;
if (isHovered()) { // hovered
dOC = hOC;
dBC = hBC;
dTC = hTC;
}
if (isClicked(click)) { // clicked
dOC = aOC;
dBC = aBC;
dTC = aTC;
}
pushStyle();
noStroke();
fill(dOC); // outline color
rect(x, y, w, h);
fill(dBC); // body color
rect(x+ow, y+ow, w-ow*2, h-ow*2); // x + outline width...
textAlign(CENTER, CENTER);
textSize(tS);
fill(dTC); // text color
text(t, x+w/2, y+h/2);
popStyle();
} else { // big label
pushStyle();
noStroke();
fill(bC); // body color
rect(x, y, w, h); // x + outline width...
textAlign(CENTER, CENTER);
textSize(tS);
fill(tC); // text color
text(t, x+w/2, y+h/2);
popStyle();
}
}
public boolean isHovered() {
if ((mouseX >= x && mouseX <= x+w) && (mouseY >= y && mouseY <= y+h)) {
return true;
} else {
return false;
}
}
public boolean isClicked(boolean click) {
if (isHovered() && click) {
return true;
} else {
return false;
}
}
}