-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeline.pde
53 lines (42 loc) · 1.48 KB
/
Timeline.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
class Timeline {
float x;
float y;
float w;
float h;
float percentage;
boolean hovered;
public Timeline(float x, float y, float w, float h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.percentage = 0;
this.hovered = false;
}
public void setPercentage(float percentage) {
this.percentage = constrain(percentage, 0, 1);
}
public void handleMouseInput() {
// Check if mouse is inside the box
final float x2 = this.x + this.w;
this.hovered = mouseX > this.x && mouseX < x2 && mouseY > this.y && mouseY < this.y + this.h;
if (this.hovered) {
if (mousePressed) {
final float new_percentage = map(mouseX, this.x, x2, 0, 1);
this.setPercentage(new_percentage);
final int new_gi = (int) map(new_percentage, 0, 1, 0, man.organizedMessagesList.size());
if (gi < new_gi) {
while (gi < new_gi) {
int di = gi % man.organizedMessagesList.size();
MessageData current = man.organizedMessagesList.get(di);
processCurrentmessageData(current);
gi++;
}
} else {
gi = new_gi;
currentTimestamp = man.organizedMessagesList.get(gi).timestamp;
}
}
}
}
}