-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdownMenu.pde
More file actions
113 lines (95 loc) · 2.36 KB
/
DropdownMenu.pde
File metadata and controls
113 lines (95 loc) · 2.36 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
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
class DropdownMenu{
float xpos;
float ypos;
float barWidth;
float barHeight;
boolean pressed;
String title;
color fillColor;
color defaultFillColor;
boolean clicked;
int textSize;
float offset;
boolean menuIsOpen;
ArrayList<String> options;
ArrayList<Button> listButtons = new ArrayList<Button>();
String name;
DropdownMenu(String name, float xpos, float ypos, float barWidth, float barHeight, String title, float offset, ArrayList<String> options){
this.name = name;
this.xpos = xpos;
this.ypos = ypos;
this.barWidth = barWidth;
this.barHeight = barHeight;
this.title = title;
clicked = false;
pressed = false;
defaultFillColor = color(100, 100);
textSize = 15;
this.offset = offset;
menuIsOpen = false;
this.options = options;
for(int i = 0; i < options.size(); i++){
listButtons.add(new Button(options.get(i), xpos, ypos + barHeight*(i+1), barWidth, barHeight, options.get(i), 12, 3));
}
}
void exist(){
display();
}
void display(){
noStroke();
if(contains(mouseX, mouseY) && !clicked){
stroke(255);
strokeWeight(1);
} else if(clicked){
fillColor = color(50, 100);
stroke(255);
strokeWeight(1);
} else {
fillColor = defaultFillColor;
}
fill(fillColor);
rect(xpos, ypos, barWidth, barHeight);
textSize(textSize);
fill(255);
textAlign(LEFT, CENTER);
text(name, xpos, ypos - barHeight/2 + offset);
text(title, xpos + 5, ypos + barHeight/2 - offset);
textAlign(LEFT, TOP);
if(menuIsOpen){
for(int i = 0; i < options.size(); i++){
//fill(defaultFillColor);
for(Button b : listButtons){
if(b.isPressed()){
b.done();
menuIsOpen = false;
title = b.name;
}
b.exist();
}
}
}
}
boolean contains(int x, int y) {
if (x >= xpos && x <= xpos + barWidth
&& y >= ypos && y <= ypos + barHeight) {
return true;
}
return false;
}
void wasClicked() {
clicked = !clicked;
if (clicked == false) {
pressed = !pressed;
menuIsOpen = !menuIsOpen;
}
}
boolean isPressed(){
return pressed;
}
void setX(float x){
xpos = x;
}
ArrayList<Button> getListButtons(){
return listButtons;
}
}