1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- void mousePressed() {
- interactive = true;
- startInteractionTime = millis();
- if (timeline.hovering()) {
- timeline.clicked = true;
- timelinectrl();
- } else {
- nextSlide(interactMode);
- }
- }
- void mouseReleased() {
- 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;
- }
- }
- }
- }
- }
- }
-
- class Timeline { //currently timeline has to be from left to right to work
- int x, y, l, cursorPos;
- boolean clicked;
- Timeline(int x_, int y_, int l_) {
- x = x_;
- y = y_;
- l = l_;
- }
- boolean hovering() {
- if (mouseX > x - 20 && mouseX < x + l + 20 && mouseY > y - 20 && mouseY < y + 20) {
- return true;
- } else {
- return false;
- }
- }
- void update() {
- cursorPos = (int)map(notebooks.get(currentNotebookNo).year, 1966, 2012, 50, width-50);
- }
- void display() {
- 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){
- 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);
- }
- }
- }
|