fixed keyframe dragging
parent
2780ad2859
commit
a27551ff9a
34
script.js
34
script.js
|
|
@ -148,7 +148,7 @@ window.onload = () => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let f = currentFrame; f <= 399; f++) {
|
for (let f = currentFrame; f <= totalFrames; f++) {
|
||||||
if (keyframes[f] !== undefined) {
|
if (keyframes[f] !== undefined) {
|
||||||
nextFrame = f;
|
nextFrame = f;
|
||||||
break;
|
break;
|
||||||
|
|
@ -628,7 +628,7 @@ window.onload = () => {
|
||||||
|
|
||||||
if (selectedDial !== null) {
|
if (selectedDial !== null) {
|
||||||
for (let frame in dialKeyframes[selectedDial]) {
|
for (let frame in dialKeyframes[selectedDial]) {
|
||||||
const x = (frame / 400) * width;
|
const x = (frame / totalFrames) * width;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x, 0);
|
ctx.moveTo(x, 0);
|
||||||
ctx.lineTo(x, height);
|
ctx.lineTo(x, height);
|
||||||
|
|
@ -639,7 +639,7 @@ window.onload = () => {
|
||||||
} else {
|
} else {
|
||||||
for (let ch = 0; ch < 5; ch++) {
|
for (let ch = 0; ch < 5; ch++) {
|
||||||
for (let frame in dialKeyframes[ch]) {
|
for (let frame in dialKeyframes[ch]) {
|
||||||
const x = (frame / 400) * width;
|
const x = (frame / totalFrames) * width;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x, 0);
|
ctx.moveTo(x, 0);
|
||||||
ctx.lineTo(x, height);
|
ctx.lineTo(x, height);
|
||||||
|
|
@ -650,7 +650,7 @@ window.onload = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentX = (currentFrame / 400) * width;
|
const currentX = (currentFrame / totalFrames) * width;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(currentX, 0);
|
ctx.moveTo(currentX, 0);
|
||||||
ctx.lineTo(currentX, height);
|
ctx.lineTo(currentX, height);
|
||||||
|
|
@ -673,22 +673,23 @@ window.onload = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
canvas.addEventListener('mousedown', (e) => {
|
canvas.addEventListener('mousedown', (e) => {
|
||||||
const x = e.offsetX;
|
const x = e.offsetX;
|
||||||
const frame = Math.round((x / canvas.width) * totalFrames);
|
const dialIndices = selectedDial !== null ? [selectedDial] : [0, 1, 2, 3, 4];
|
||||||
|
|
||||||
const dialIndices = selectedDial !== null ? [selectedDial] : [0, 1, 2, 3, 4];
|
for (let ch of dialIndices) {
|
||||||
|
for (let f in dialKeyframes[ch]) {
|
||||||
|
const frameNum = parseInt(f);
|
||||||
|
const fx = (frameNum / totalFrames) * canvas.width;
|
||||||
|
|
||||||
for (let ch of dialIndices) {
|
if (Math.abs(fx - x) < 15) {
|
||||||
for (let f in dialKeyframes[ch]) {
|
draggingKeyframe = { dialIndex: ch, originalFrame: frameNum };
|
||||||
const fx = (f / totalFrames) * canvas.width;
|
isDragging = true;
|
||||||
if (Math.abs(fx - x) < 5) {
|
return;
|
||||||
draggingKeyframe = { dialIndex: ch, originalFrame: parseInt(f) };
|
|
||||||
isDragging = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
canvas.addEventListener('mousemove', (e) => {
|
canvas.addEventListener('mousemove', (e) => {
|
||||||
if (!isDragging || !draggingKeyframe) return;
|
if (!isDragging || !draggingKeyframe) return;
|
||||||
|
|
@ -711,6 +712,7 @@ window.onload = () => {
|
||||||
canvas.addEventListener('mouseup', () => {
|
canvas.addEventListener('mouseup', () => {
|
||||||
isDragging = false;
|
isDragging = false;
|
||||||
draggingKeyframe = null;
|
draggingKeyframe = null;
|
||||||
|
syncMotorsWithTimeline();
|
||||||
});
|
});
|
||||||
|
|
||||||
canvas.addEventListener('dblclick', (e) => {
|
canvas.addEventListener('dblclick', (e) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue