-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticRenderer.pde
More file actions
90 lines (78 loc) · 1.88 KB
/
StaticRenderer.pde
File metadata and controls
90 lines (78 loc) · 1.88 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
class StaticRenderer implements Drawable {
SortingMachine m;
float labelHeight = 20f;
float lineMargin = 10f;
float lineHeight;
float cursorX, cursorY;
PFont labelFont = createFont("Georgia", 16);
private final List<Drawable> drawables;
StaticRenderer(SortingMachine m) {
this.m = m;
drawables = new ArrayList<Drawable>();
}
public void place(Point p) { }
public float getWidth() {
return width;
}
public float getHeight() {
return height;
}
public void setup() {
System.out.println("configuring standard view");
m.setup();
size(
m.getWindow().getWidth(),
m.getWindow().getHeight());
background(255);
noLoop();
beginRecord(PDF, "out.pdf");
float noteHeight = m.getNoteHeight();
float noteWidth = m.getStepWidth();
cursorX = m.getWindow().getLeftMargin();
cursorY = m.getWindow().getTopMargin();
for(SortJob job : m.getSortJobs()) {
LabelDrawable lbl =
new LabelDrawable(
job.getLabel(), LEFT, CENTER,
labelFont
);
lbl.place(new Point(cursorX, cursorY));
drawables.add(lbl);
cursorY += labelHeight;
DataSet data = job.getData();
int[] a = data.getValues();
lineHeight = a.length * m.getNoteHeight() + lineMargin;
for(Instruction instruction : job.getInstructions()) {
InstructionDrawable d =
new InstructionDrawable(
instruction,
noteHeight, noteWidth,
a
);
d.place(new Point(cursorX, cursorY));
drawables.add(d);
incrementCursorPosition(noteWidth);
}
newline();
cursorY += 10f;
}
}
void incrementCursorPosition(float amt) {
cursorX += amt;
if(cursorX >= (width-amt-m.getWindow().getRightMargin())) {
newline();
}
}
void newline() {
cursorX = m.getWindow().getLeftMargin();
cursorY += lineHeight;
}
public void tick() { }
public void draw() {
background(255, 255, 255);
for(Drawable d : drawables) {
d.draw();
}
endRecord();
}
}