timeline behaves more responsively, performance increase
This commit is contained in:
@@ -9,25 +9,34 @@ void mousePressed() {
|
||||
}
|
||||
}
|
||||
void mouseReleased() {
|
||||
timeline.clicked = false;
|
||||
}
|
||||
int currentYear;
|
||||
void mouseDragged() {
|
||||
if (timeline.clicked) {
|
||||
timeline.clicked = false;
|
||||
timelinectrl();
|
||||
}
|
||||
}
|
||||
int currentYear;
|
||||
void timelinectrl() {
|
||||
if (interactiveTimeline && displayTimeline) {
|
||||
int toYear = (int)constrain(map(mouseX, timeline.x, timeline.x + timeline.l, 1966, 2012), 1966, 2012);
|
||||
if (toYear != currentYear) {
|
||||
timeline.cursorPos = constrain(mouseX, timeline.x, timeline.x +timeline.l);
|
||||
boolean succ = false;
|
||||
for (int i = 0; i < notebooks.size(); i ++) {
|
||||
if (notebooks.get(i).year == toYear) {
|
||||
nextSlide(i, 0);
|
||||
succ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!succ) {
|
||||
for (int i = 0; i < notebooks.size(); i ++) {
|
||||
if (notebooks.get(i).year == toYear-1 || notebooks.get(i).year == toYear+1) {
|
||||
nextSlide(i, 0);
|
||||
succ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +63,15 @@ class Timeline { //currently timeline has to be from left to right to work
|
||||
stroke(255, 127);
|
||||
strokeWeight(4);
|
||||
line(x, y, l+x, y);
|
||||
if (clicked) {
|
||||
cursorPos = (int)constrain(mouseX, x, x+l);
|
||||
}
|
||||
ellipse(cursorPos, height-30, 20, 20);
|
||||
if (displayText) text(notebooks.get(currentNotebookNo).year, cursorPos, y-20);
|
||||
if (displayText){
|
||||
String labelText;
|
||||
if(!clicked) labelText = str(notebooks.get(currentNotebookNo).year);
|
||||
else labelText = str((int)constrain(map(mouseX, timeline.x, timeline.x + timeline.l, 1966, 2012), 1966, 2012));
|
||||
text(labelText, cursorPos, y-20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
95
|
||||
0
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user