-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScrollMenu.pde
233 lines (190 loc) · 5.4 KB
/
ScrollMenu.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
class ScrollMenu extends View {
public PImage uparrow;
public PImage downarrow;
public int smallHeight;
public boolean expanded;
public int openedHeight;
Integrator head;
//Integrator leftMenu = new Integrator(20);
//Integrator leftCheckBoxes = new Integrator(100);
//Integrator leftText = new Integrator(130);
void draw()
{
rectMode(CORNERS);
pushMatrix();
translate(this.x, this.y);
// draw out content, then our subviews on top
// drawContent();
fill(0, 150);
rect(0, head.value, w, openedHeight);
if(expanded){
if(subviews.size()>0){
int divid = (openedHeight-50)/(subviews.size());
for (int i = 0; i < subviews.size(); i++) {
View v = (View)subviews.get(i);
v.y = ((divid*(i+1)))+head.value;
// System.out.println(v.y);
v.draw();
}
//roundrect(0, openedHeight, (int)w, smallHeight, 10);
}
}else{
for (int i = 0; i < subviews.size(); i++) {
View v = (View)subviews.get(i);
v.y = ((300*(i+1)))+head.value;
// System.out.println(v.y);
v.draw();
}
// roundrect(0, openedHeight, (int)w, smallHeight, 10);
}
fill(tabColor2);
roundrect(0, openedHeight, (int)w, smallHeight, 10);
roundrect(0, (int)head.value, (int)w, smallHeight, 10);
if (expanded)
image(downarrow, w/2-10, head.value-5);
else {
image(uparrow, w/2-10, head.value-5);
}
head.update();
popMatrix();
}
public ScrollMenu(float x_, float y_, float w_, float h_, boolean expanded, int openedHeight ) {
super(x_, y_, w_, openedHeight+30);
this.expanded = expanded;
uparrow = loadImage("br_up.png");
downarrow = loadImage("br_down.png");
uparrow.resize(0, 15);
downarrow.resize(0, 15);
this.openedHeight = openedHeight;
smallHeight = (int)h_;
this.head = new Integrator (openedHeight);
// Source of the Code: http://processing.org/discourse/yabb2/YaBB.pl?num=1213696787
if (expanded)
head.target(0);
//System.out.println(hi.value);
}
void roundrect(int x2, int y2, int w2, int h2, int r) {
noStroke();
rectMode(CORNER);
int ax, ay, hr;
ax=x2+w2-1;
ay=y2+h2-1;
hr = r/2;
rect(x2, y2, w2, h2);
arc(x2, y2, r, r, radians(180.0), radians(270.0));
arc(ax, y2, r, r, radians(270.0), radians(360.0));
arc(x2, ay, r, r, radians(90.0), radians(180.0));
arc(ax, ay, r, r, radians(0.0), radians(90.0));
rect(x2, y2-hr, w2, hr);
rect(x2-hr, y2, hr, h2);
rect(x2, y2+h2, w2, hr);
rect(x2+w2, y2, hr, h2);
rectMode(CORNERS);
}
/*
void drawContent() {
fill(0);
rect(0,0,w,h);
fill(0, 150);
rect(0, head.value, w, openedHeight);
fill(tabColor2);
roundrect(0, openedHeight, (int)w, smallHeight, 10);
roundrect(0, (int)head.value, (int)w, smallHeight, 10);
if (expanded)
image(downarrow, w/2-10, head.value-5);
else {
image(uparrow, w/2-10, head.value-5);
}
//head.update();
}
*/
boolean contentClicked(float lx, float ly) {
// System.out.println("Hey in here "+x+" BUT "+ lx);
if (expanded) {
if (lx >= 0 && lx <= w && ly >= -5 && ly <= smallHeight) {
expanded = !expanded;
head.target(openedHeight);
}
}
else {
if (lx >= 0 && lx <= w && ly >= openedHeight-5 && ly <= openedHeight+smallHeight) {
expanded = !expanded;
head.target(0);
}
}
return true;
}
}
/*
class ScrollMenu extends View {
public PImage uparrow;
public PImage downarrow;
public int smallHeight;
public boolean expanded;
public int openedHeight;
Integrator head;
//Integrator leftMenu = new Integrator(20);
//Integrator leftCheckBoxes = new Integrator(100);
//Integrator leftText = new Integrator(130);
public ScrollMenu(float x_, float y_, float w_, float h_, boolean expanded, int openedHeight ){
super(x_, y_, w_, openedHeight+30);
this.expanded = expanded;
uparrow = loadImage("br_up.png");
downarrow = loadImage("br_down.png");
uparrow.resize(0,15);
downarrow.resize(0,15);
this.openedHeight = openedHeight;
smallHeight = (int)h_;
head = new Integrator (openedHeight);
// Source of the Code: http://processing.org/discourse/yabb2/YaBB.pl?num=1213696787
if(expanded)
head.target(0);
}
void roundrect(int x2, int y2, int w2, int h2, int r) {
noStroke();
rectMode(CORNER);
int ax, ay, hr;
ax=x2+w2-1;
ay=y2+h2-1;
hr = r/2;
rect(x2, y2, w2, h2);
arc(x2, y2, r, r, radians(180.0), radians(270.0));
arc(ax, y2, r,r, radians(270.0), radians(360.0));
arc(x2, ay, r,r, radians(90.0), radians(180.0));
arc(ax, ay, r,r, radians(0.0), radians(90.0));
rect(x2, y2-hr, w2, hr);
rect(x2-hr, y2, hr, h2);
rect(x2, y2+h2, w2, hr);
rect(x2+w2,y2,hr, h2);
rectMode(CORNERS);
}
void drawContent(){
fill(0,150);
rect(0,head.value,w,openedHeight);
fill(tabColor2);
roundrect(0,openedHeight,(int)w,smallHeight,10);
roundrect(0,(int)head.value,(int)w,smallHeight,10);
if(expanded)
image(downarrow, w/2-10,head.value-5);
else{
image(uparrow,w/2-10,head.value-5);
}
head.update();
}
boolean mousePressed(float lx, float ly){
if(expanded){
if(lx >= x && lx <= x+w && ly >= y-5 && ly <= y+smallHeight){
expanded = !expanded;
head.target(openedHeight);
}
}
else{
if(lx >= x && lx <= x+w && ly >= y+openedHeight-5 && ly <= y+openedHeight+smallHeight){
expanded = !expanded;
head.target(0);
}
}
return true;
}
}
*/