-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.pde
More file actions
executable file
·88 lines (73 loc) · 1.61 KB
/
Button.pde
File metadata and controls
executable file
·88 lines (73 loc) · 1.61 KB
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
class Button {
String name;
float xpos;
float ypos;
float buttonWidth;
float buttonHeight;
color fillColor;
String message;
int textSize;
int offset;
boolean clicked;
boolean pressed;
Button(String name, float xpos, float ypos, float buttonWidth, float buttonHeight, String message, int textSize, int offset) {
this.name = name;
this.xpos = xpos;
this.ypos = ypos;
this.buttonWidth = buttonWidth;
this.buttonHeight = buttonHeight;
this.message = message;
this.textSize = textSize;
this.offset = offset;
clicked = false;
pressed = false;
}
void exist() {
display();
}
void display() {
noStroke();
if (contains(mouseX, mouseY) && !clicked) {
//fillColor = color(200, 100);
stroke(255);
strokeWeight(1);
} else if (clicked) {
fillColor = color(50, 100);
stroke(255);
strokeWeight(1);
} else {
fillColor = color(100, 100);
}
fill(fillColor);
rect(xpos, ypos, buttonWidth, buttonHeight);
textSize(textSize);
fill(255);
textAlign(LEFT, TOP);
text(message, xpos + 15, ypos + buttonHeight/2 - textSize/2 - offset);
}
String name() {
return name;
}
boolean contains(int x, int y) {
if (x >= xpos && x <= xpos + buttonWidth
&& y >= ypos && y <= ypos + buttonHeight) {
return true;
}
return false;
}
void wasClicked() {
clicked = !clicked;
if (clicked == false) {
pressed = true;
}
}
boolean isPressed() {
return pressed;
}
void done(){
pressed = false;
}
void setX(float x) {
xpos = x;
}
}