-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoogleButton.pde
More file actions
35 lines (32 loc) · 815 Bytes
/
toogleButton.pde
File metadata and controls
35 lines (32 loc) · 815 Bytes
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
class toggleButton {
int myXPos = 0;
int myYPos = 0;
int myWidth = 60;
int myHeight = 20;
color backgroundColor = color(30, 30, 30);
color forgroundColor = color(200, 200, 200);
boolean myStateActive = false;
toggleButton(int xPos, int yPos) {
myXPos = xPos;
myYPos = yPos;
}
void draw() {
pushMatrix();
translate(myXPos, myYPos);
noStroke();
fill(backgroundColor);
rect(0, 0, myWidth, myHeight, 8);
fill(forgroundColor);
if (!myStateActive) {
rect(0+2, 0+2, myWidth*0.6-4, myHeight-4, 5);
} else {
rect(0+myWidth-myWidth*0.6+2, 0+2, myWidth*0.6-4, myHeight-4, 5);
}
popMatrix();
}
void mousePressed() {
if (insideRect(mouseX, mouseY, myXPos, myYPos, myWidth, myHeight)) {
myStateActive = !myStateActive;
}
}
}