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: --- components/selection.tsx | 3 ++- pages/editor.tsx | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/selection.tsx b/components/selection.tsx index ad86f9f..a039f79 100644 --- a/components/selection.tsx +++ b/components/selection.tsx @@ -65,6 +65,7 @@ function Corner(props: { export default function Selection(props: { width: number; height: number; + frameWidth: number; left?: slideTypes; right?: slideTypes; className?: string; @@ -73,7 +74,7 @@ export default function Selection(props: { return
{ 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