From 1ade35210767854624e32f2d635662645e08e31c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 14 Jun 2021 09:05:38 +0200 Subject: zoom selection with timeline :tada: --- pages/editor.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pages') diff --git a/pages/editor.tsx b/pages/editor.tsx index dc74699..5b032c8 100644 --- a/pages/editor.tsx +++ b/pages/editor.tsx @@ -342,12 +342,13 @@ function TimelineEditor(props: { y1: 0, x2: 0, y2: 0, + startingFrame: 0, + frameWidth: 0, config: { mass: 0.5, tension: 500, friction: 20 }, })); var selectionRef = useRef(null); useDrag(({ xy: [x, y], initial: [bx, by], first, last, movement: [ox, oy] }) => { if (props.selectedTool != 'cursor') return; - // var frame = Math.max(0, Math.round(getFrameAtOffset(x - 240, timelineZoom)) - 1); var minDistance = 5; // minimal drag distance in pixels to register selection var distanceTraveled = Math.sqrt(ox ** 2 + oy ** 2); if (selectionHidden && distanceTraveled > minDistance) setSelectionHidden(false); @@ -367,13 +368,17 @@ function TimelineEditor(props: { var x2 = x1 + Math.abs(sx); var y2 = y1 + Math.abs(sy); + var zoom = zoomToPx(timelineZoom); + var frameWidth = Math.abs(sx) / zoom; + var startingFrame = x1 / zoom; + if (!selectionActive) setSelectionActive(true); if (last) { setSelectionActive(false); if (distanceTraveled <= minDistance) setSelectionHidden(true); } - selectionPosAPI[first && selectionHidden ? 'set' : 'start']({ x1, y1, x2, y2 }); + selectionPosAPI[first && selectionHidden ? 'set' : 'start']({ x1, y1, x2, y2, startingFrame, frameWidth }); }, { domTarget: selectionRef, eventOptions: { passive: false } }); return <> @@ -424,10 +429,14 @@ function TimelineEditor(props: {
} /> -- cgit v1.2.3