-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawable.pde
52 lines (44 loc) · 940 Bytes
/
Drawable.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
interface Drawable {
void setup();
void tick();
void draw();
void place(Point p);
float getWidth();
float getHeight();
}
class Point {
public float x, y;
Point(float x, float y) {
this.x = x;
this.y = y;
}
}
class Layout {
float cursorX, cursorY;
float left, top, w, h;
float lastHeight = 10f;
Layout(float left, float top, float w, float h) {
this.cursorX = left;
this.cursorY = top;
this.left = left;
this.top = top;
this.w= w;
this.h = h;
}
// really stupid thing that assumes the next drawable will be of the same size
// and we wrap to the next line if it wont fit
Point place(Drawable d) {
Point placement = new Point(cursorX, cursorY);
d.place(new Point(cursorX, cursorY));
cursorX += d.getWidth();
if(cursorX + d.getWidth() > w+8) {
lastHeight = d.getHeight();
newline();
}
return placement;
}
public void newline() {
cursorX = left;
cursorY += lastHeight + 20;
}
}