MCPcopy Create free account
hub / github.com/bwasti/mebm / scrubStart

Method scrubStart

script.js:888–950  ·  view source on GitHub ↗
(ev)

Source from the content-addressed store, hash-verified

886 }
887
888 scrubStart(ev) {
889 this.scrubbing = true;
890 let rect = this.time_canvas.getBoundingClientRect();
891 this.time = ev.offsetX / rect.width * this.total_time;
892
893 window.addEventListener('pointerup', this.scrubEnd.bind(this), {
894 once: true
895 });
896
897 let y_inc = this.time_canvas.clientHeight / (this.layers.length + 1);
898 let y_coord = this.time_canvas.clientHeight;
899 let mouseover = false;
900 for (let layer of this.layers) {
901 y_coord -= y_inc;
902 if (layer.start_time > (1.01 * this.time)) {
903 continue;
904 }
905 if (layer.start_time + layer.total_time < (0.99 * this.time)) {
906 continue;
907 }
908 if (Math.abs(ev.offsetY - y_coord) < (0.05 * this.time_canvas.clientHeight)) {
909 this.select(layer);
910 mouseover = true;
911 }
912 }
913
914 // can't drag unselected
915 if (!this.selected_layer || !mouseover) {
916 return;
917 }
918
919 // dragging something
920 let l = this.selected_layer;
921
922 if (this.intersectsTime(l.start_time)) {
923 this.time = l.start_time;
924 let base_t = this.time;
925 this.dragging = function(t) {
926 let diff = t - base_t;
927 base_t = t;
928 l.start_time += diff;
929 }
930 } else if (this.intersectsTime(l.start_time + l.total_time)) {
931 this.time = l.start_time + l.total_time;
932 let base_t = this.time;
933 this.dragging = function(t) {
934 let diff = t - base_t;
935 base_t = t;
936 if (l instanceof MoveableLayer) {
937 l.adjustTotalTime(diff);
938 } else {
939 l.start_time += diff;
940 }
941 }
942 } else if (this.time < l.start_time + l.total_time && this.time > l.start_time) {
943 let base_t = this.time;
944 this.dragging = function(t) {
945 let diff = t - base_t;

Callers

nothing calls this directly

Calls 3

selectMethod · 0.95
intersectsTimeMethod · 0.95
adjustTotalTimeMethod · 0.80

Tested by

no test coverage detected