Tool to display Walter Giers' notebooks in either chronological or in random order
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Interaction.pde 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. void mousePressed() {
  2. interactive = true;
  3. startInteractionTime = millis();
  4. if (timeline.hovering()) {
  5. timeline.clicked = true;
  6. timelinectrl();
  7. } else {
  8. nextSlide(interactMode);
  9. }
  10. }
  11. void mouseReleased() {
  12. if (timeline.clicked) {
  13. timeline.clicked = false;
  14. timelinectrl();
  15. }
  16. }
  17. int currentYear;
  18. void timelinectrl() {
  19. if (interactiveTimeline && displayTimeline) {
  20. int toYear = (int)constrain(map(mouseX, timeline.x, timeline.x + timeline.l, 1966, 2012), 1966, 2012);
  21. if (toYear != currentYear) {
  22. timeline.cursorPos = constrain(mouseX, timeline.x, timeline.x +timeline.l);
  23. boolean succ = false;
  24. for (int i = 0; i < notebooks.size(); i ++) {
  25. if (notebooks.get(i).year == toYear) {
  26. nextSlide(i, 0);
  27. succ = true;
  28. break;
  29. }
  30. }
  31. if (!succ) {
  32. for (int i = 0; i < notebooks.size(); i ++) {
  33. if (notebooks.get(i).year == toYear-1 || notebooks.get(i).year == toYear+1) {
  34. nextSlide(i, 0);
  35. succ = true;
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. class Timeline { //currently timeline has to be from left to right to work
  44. int x, y, l, cursorPos;
  45. boolean clicked;
  46. Timeline(int x_, int y_, int l_) {
  47. x = x_;
  48. y = y_;
  49. l = l_;
  50. }
  51. boolean hovering() {
  52. if (mouseX > x - 20 && mouseX < x + l + 20 && mouseY > y - 20 && mouseY < y + 20) {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. void update() {
  59. cursorPos = (int)map(notebooks.get(currentNotebookNo).year, 1966, 2012, 50, width-50);
  60. }
  61. void display() {
  62. stroke(255, 127);
  63. strokeWeight(4);
  64. line(x, y, l+x, y);
  65. if (clicked) {
  66. cursorPos = (int)constrain(mouseX, x, x+l);
  67. }
  68. ellipse(cursorPos, height-30, 20, 20);
  69. if (displayText){
  70. String labelText;
  71. if(!clicked) labelText = str(notebooks.get(currentNotebookNo).year);
  72. else labelText = str((int)constrain(map(mouseX, timeline.x, timeline.x + timeline.l, 1966, 2012), 1966, 2012));
  73. text(labelText, cursorPos, y-20);
  74. }
  75. }
  76. }