-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_mgr.pde
319 lines (252 loc) · 9.02 KB
/
window_mgr.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Simple popup window system to contain UI elements
// implemented in P4 by vvixi
// more bug-fixes, and new params added, additional notes and cleanup
// needs additional work to make multiple windows play nicely
windowManager windowmgr;
Window window, topbar;
void setup() {
size(900, 900);
windowmgr = new windowManager();
}
void draw() {
background(0);
windowmgr.render();
}
public class windowManager {
Window window, topbar;
windowManager() {
//window = new Window("bottomHalf");
//window = new Window("bottomBar");
//window = new Window("topHalf");
//topbar = new Window("topBar");
//window = new Window("rightHalf");
//window = new Window("leftHalf");
//window = new Window("listFull");
//window = new Window("gridFull");
window = new Window("gridFull");
topbar = new Window("topBar");
}
void render() {
window.display();
window.checkMouseOver();
topbar.display();
topbar.checkMouseOver();
}
}
public class Window {
// creates windows based on string passed in
// params: "topHalf", "topBar","leftHalf", "rightHalf", "bottomHalf", "bottomBar", "twoColumn", "listFull", "gridFull"
private PVector[][] gridPositions;
private Boolean displayed = true;
private Boolean showClose = true;
private String position;
private PVector size;
private float vOffset;
private int closeStartX;
private int closeStartY;
private int topRight;
private PVector gridSize;
private int divH;
private int divV;
private int bufferX=0, bufferY=50;
private PVector block;
Boolean hasFocus = false;
Window(String _position) {
position = _position;
}
private void drawClose(int _startX, int _startY) {
// draws the click-to-close box on each window
int startX = _startX;
int endX = startX + 50;
int startY = _startY;
int endY = _startY + 50;
fill(200, 0, 0);
rect(startX, startY, 50, 50);
stroke(0);
line(startX, startY, endX, endY);
line(startX, endY, endX, startY);
}
void display() {
// displays the window based on the string: "position"
if (displayed) {
rectMode(CORNER);
fill(50);
if (position == "rightHalf") {
size = new PVector(width / 2, height);
topRight = width;
bufferX = width / 2;
closeStartX = width - 50;
closeStartY = 0;
rect(bufferX, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 5, 5);
} else if (position == "leftHalf") {
size = new PVector(width / 2, height);
topRight = width / 2;
bufferX = 0;
closeStartX = width/2 - 50;
closeStartY = 0;
rect(bufferX, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 4, 4);
} else if (position == "topBar") {
size = new PVector(width, height / 2 - height / 4);
topRight = width;
bufferY = 0;
closeStartX = width - 50;
closeStartY = 0;
rect(0, 0, size.x, size.y);
drawGrid(new PVector(size.x-50, size.y), 6, 1);
} else if (position == "topHalf") {
size = new PVector(width, height/2);
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = 0;
rect(0, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 2, 3);
} else if (position == "bottomBar") {
size = new PVector(width, height / 2 + height / 4);
vOffset = size.y;
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = height / 2 + height / 4 + bufferY;
rect(0, size.y + bufferY, size.x, size.y);
drawGrid(new PVector(size.x-50, height /2 + size.y), 6, 1);
} else if (position == "bottomHalf") {
size = new PVector(width, height/2);
vOffset = height / 2;
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = height / 2;
rect(0, height / 2, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 3, 3);
} else if (position == "twoColumn") {
size = new PVector(width, height);
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = 0;
rect(0, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 2, 3);
} else if (position == "listFull") {
size = new PVector(width, height);
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = 0;
rect(0, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 1, 8);
} else if (position == "gridFull") {
size = new PVector(width, height);
topRight = width;
bufferY = 50;
closeStartX = width - 50;
closeStartY = 0;
rect(0, 0, size.x, size.y);
drawGrid(new PVector(size.x, size.y), 4, 8);
}
if(showClose) { drawClose(closeStartX, closeStartY); }
if(showClose) { drawClose(closeStartX, closeStartY); }
}
}
void drawGrid(PVector _gSize, int _divH, int _divV) {
// draws the UI grid within the displayed window
//GridCell gridCell;
gridSize = _gSize;
divH = _divH;
divV = _divV;
// determines block size for the below loop
block = new PVector(gridSize.x / divH, gridSize.y / divV - (bufferY / divV));
fill(200);
gridPositions = new PVector[divH][divV];
for (int i = 0; i < divH; i++) {
for (int j = 0; j < divV; j++) {
gridPositions[i][j] = new PVector(bufferX + i * block.x, bufferY + j * block.y + vOffset);
rect(bufferX + i * block.x, bufferY + j * block.y + vOffset, gridSize.x / divH, gridSize.y / divV - (bufferY / divV));
//gridCells.add(new GridCell(bufferX + i * block.x, bufferY + j * block.y + vOffset, gridSize.x / divH, gridSize.y / divV - (bufferY / divV)));
}
}
}
void checkClose() {
// test for user closing a window
if (mouseX > topRight - 50 && mouseX < topRight &&
mouseY > closeStartY && mouseY < closeStartY+50) {
displayed = false;
}
}
void checkMouseOver() {
// test for mouse over a cell, highlight cell to show user
if (displayed) {
float cellXsize = gridSize.x / divH;
float cellYsize = gridSize.y / divV - (bufferY / divV);
for (int i = 0; i < gridPositions.length; i++) {
for (int j = 0; j < gridPositions[0].length; j++) {
if(mouseX > gridPositions[i][j].x && mouseX < gridPositions[i][j].x + cellXsize &&
mouseY > gridPositions[i][j].y && mouseY < gridPositions[i][j].y + cellYsize) {
hasFocus = true;
fill(0, 180, 220);
rect(gridPositions[i][j].x, gridPositions[i][j].y, cellXsize, cellYsize);
} else {
hasFocus = false;
}
}
}
}
}
PVector translateMouse() {
// helper function to translate the mouse into the UI grid
// this needs to account for bufferY which is throwing the input off
PVector cell = new PVector(0, 0);
cell.x = floor(mouseX / windowmgr.window.block.x);
cell.y = floor((mouseY / windowmgr.window.block.y)-(windowmgr.window.bufferY/windowmgr.window.block.y));
//println(window.divV/window.block.y);
fill(0, 100, 200);
//rect(cell.x * window.block.x, (cell.y * window.block.y), window.block.x, window.block.y);
if (windowmgr.window.position == "rightHalf") {
// here we are accounting for the grid starting on the right half
// of the screen, adjusting x to be 0 instead of 5 in the 0,0 spot
// the right window and bottom require this distinction
cell.x -= divH;
} else if (windowmgr.window.position == "bottomHalf") {
// the obvious cell.y - this.divV didn't work so this is an ugly work around
cell.y = floor((mouseY / block.y)-(bufferY/block.y) - divV - bufferY/block.y);
}
return new PVector(cell.x, cell.y);
}
PVector receiveGridInput() {
PVector pos = translateMouse();
// this captures user input from the grid
// cell select
if (hasFocus) {
if (pos.x == 0 && pos.y == 0) {
window = new Window("leftHalf");
println("0 - 0");
} else if (pos.x == 1 && pos.y == 0) {
window = new Window("rightHalf");
println("1 - 0");
} else if (pos.x == 2 && pos.y == 0) {
window = new Window("topHalf");
println("2 - 0");
} else if (pos.x == 3 && pos.y == 0) {
window = new Window("bottomHalf");
println("2 - 1");
}
}
//// col select
//if (translateMouse().x == 0) {
// println("col zero");
//}
//// row select
//if (pos.y == 0) {
// println("row zero");
//}
return pos;
}
}
void mousePressed() {
windowmgr.window.checkClose();
windowmgr.window.receiveGridInput();
windowmgr.topbar.checkClose();
windowmgr.topbar.receiveGridInput();
}