-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderLayer.pde
More file actions
114 lines (92 loc) · 2.71 KB
/
RenderLayer.pde
File metadata and controls
114 lines (92 loc) · 2.71 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
114
// The idea of the class "Renderlayer" is that
// it is a wrapper around PGraphics, for better organization
// of what is going to be rendered in the program.
//
// The derived classes of the RenderLayer abstract class
// could be used as singletons to draw layers with specific
// functions such as UI, payload, people, etc.
abstract class RenderLayer {
PGraphics pg;
public RenderLayer(int w, int h, String renderer) {
this.pg = createGraphics(w, h, renderer);
}
public RenderLayer(int w, int h) {
this.pg = createGraphics(w, h, P2D);
}
public RenderLayer() {
this.pg = createGraphics(width, height, P2D);
}
public void render() {
this.pg.beginDraw();
renderGraphics();
this.pg.endDraw();
}
protected void renderGraphics() {
this.pg.clear();
}
}
class RenderUILayer extends RenderLayer {
// Layer states
long timestamp;
// Reference to the timeline object
Timeline timeline;
SpeedControl speedControl;
StatCardHover statCardHover;
public RenderUILayer() {
super();
this.timestamp = 0;
}
@Override
protected void renderGraphics() {
this.pg.clear();
this.renderTimestamp();
this.renderTimeline();
this.renderSpeedControl();
this.renderStatCardHover();
}
private void renderTimestamp() {
this.pg.textFont(monospaceFont);
this.pg.textAlign(CENTER, CENTER);
String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm").format(new java.util.Date(this.timestamp));
this.pg.textSize(20);
this.pg.fill(255);
this.pg.text(date, width/2, 20);
}
private void renderTimeline() {
this.pg.noFill();
// Set opacity of the timeline to 70 if not hovered or 255 if hovered
this.pg.stroke(255, this.timeline.hovered ? 255 : 70);
this.pg.strokeWeight(1);
this.pg.rect(this.timeline.x, this.timeline.y, this.timeline.w, this.timeline.h);
// Draw a cursor of where in the timeline we're currently are at
final float percentX = map(this.timeline.percentage, 0, 1, this.timeline.x, this.timeline.x + this.timeline.w);
this.pg.strokeWeight(3);
this.pg.line(percentX, this.timeline.y, percentX, this.timeline.y + this.timeline.h);
}
private void renderSpeedControl() {
if (this.speedControl == null) return;
this.pg.image(this.speedControl.getSpeedIcon(), 10, 10);
}
private void renderStatCardHover() {
this.pg.textFont(font);
if (this.statCardHover == null) return;
this.statCardHover.draw(this.pg);
}
}
class RenderPeopleLayer extends RenderLayer {
ArrayList<PersonNode> persons;
public RenderPeopleLayer() {
super();
}
@Override
protected void renderGraphics() {
this.pg.clear();
if (this.persons == null) {
println("Error: reference to persons arraylist is null");
return;
}
for (PersonNode person : persons) {
person.draw(this.pg);
}
}
}