aboutsummaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-06-14 09:05:38 +0200
committerlonkaars <loek@pipeframe.xyz>2021-06-14 09:05:38 +0200
commit1ade35210767854624e32f2d635662645e08e31c (patch)
tree68288c7d23398edb373a6070524ed0d4065a2bbb /pages
parentc5bf7ef263c58458103bc88a4964b84ffe450dc1 (diff)
zoom selection with timeline :tada:
Diffstat (limited to 'pages')
-rw-r--r--pages/editor.tsx15
1 files changed, 12 insertions, 3 deletions
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: {
<div
id='selection'
className='posabs dispinbl'
- style={{ left: selectionPos.x1.toJSON() - 6, top: selectionPos.y1.toJSON() - 6 }}
+ style={{
+ left: `calc(var(--zoom) * ${selectionPos.startingFrame.toJSON()} * 1px - 6px)`,
+ top: selectionPos.y1.toJSON() - 6,
+ }}
children={<Selection
className={'' + (selectionActive ? 'active ' : '') + (selectionHidden ? 'hidden ' : '')}
width={selectionPos.x2.toJSON() - selectionPos.x1.toJSON() + 12}
+ frameWidth={selectionPos.frameWidth.toJSON()}
height={selectionPos.y2.toJSON() - selectionPos.y1.toJSON() + 12}
/>}
/>