Home Reference Source

cables_dev/cables_ui/src/ui/gltimeline/tlvalueruler.js

  1. import GlRect from "../gldraw/glrect.js";
  2. import { GlTimeline } from "./gltimeline.js";
  3. import { TlAnimLine } from "./tlanimline.js";
  4. import { tlView } from "./tlview.js";
  5. export class TlValueRuler
  6. {
  7. #numMarker = 20;
  8. /** @type {GlRect} */
  9. #zeroRect = null;
  10. /** @type {GlTimeline} */
  11. #glTl;
  12. /** @type {tlView} */
  13. #view;
  14. /** @type {GlRect[]} */
  15. #marker = [];
  16. #parentRect;
  17. /** @type {TlAnimLine} */
  18. #animLine;
  19. /**
  20. * @param {GlTimeline} glTl
  21. * @param {TlAnimLine} animline
  22. * @param {GlRect} parentRect
  23. */
  24. constructor(glTl, animline, parentRect)
  25. {
  26. this.#glTl = glTl;
  27. this.#parentRect = parentRect;
  28. this.#view = glTl.view;
  29. this.#animLine = animline;
  30. this.init();
  31. }
  32. init()
  33. {
  34. this.dispose();
  35. this.#zeroRect = this.#glTl.rects.createRect({ "name": "zero rect", "draggable": true, "interactive": false });
  36. this.#zeroRect.setSize(99999, 1);
  37. this.#zeroRect.setColor(0, 0, 0, 1);
  38. this.#zeroRect.setParent(this.#parentRect);
  39. for (let i = 0; i < this.#numMarker; i++)
  40. {
  41. const r = this.#glTl.rects.createRect({ "name": "nummarker", "draggable": true, "interactive": false });
  42. r.setPosition(0, i);
  43. r.setSize(20, 1);
  44. r.setParent(this.#parentRect);
  45. this.#marker.push(r);
  46. }
  47. }
  48. update()
  49. {
  50. for (let i = 0; i < this.#marker.length; i++)
  51. {
  52. this.#marker[i].setPosition(this.#parentRect.w - 20, this.#animLine.valueToPixel(i - this.#numMarker / 2));
  53. }
  54. this.#zeroRect.setPosition(0, this.#animLine.valueToPixel(0));
  55. }
  56. dispose()
  57. {
  58. for (let i = 0; i < this.#marker.length; i++) this.#marker[i].dispose();
  59. if (this.#zeroRect)
  60. this.#zeroRect.dispose();
  61. return null;
  62. }
  63. }