aboutsummaryrefslogtreecommitdiff
path: root/pages/editor.tsx
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-06-13 18:44:59 +0200
committerlonkaars <loek@pipeframe.xyz>2021-06-13 18:44:59 +0200
commitfce479419c4f6b61f181257d69e5ac43f63ef7fe (patch)
treede39ac77e757becbc5f678de98c0ffd14a181746 /pages/editor.tsx
parent1b4a0b417c6f346016c09a665fab5b554c6c1618 (diff)
this is the sauce selection
Diffstat (limited to 'pages/editor.tsx')
-rw-r--r--pages/editor.tsx16
1 files changed, 15 insertions, 1 deletions
diff --git a/pages/editor.tsx b/pages/editor.tsx
index f9828a1..e08d6ae 100644
--- a/pages/editor.tsx
+++ b/pages/editor.tsx
@@ -335,6 +335,8 @@ function TimelineEditor(props: {
});
}, []);
+ var [selectionActive, setSelectionActive] = useState(false);
+ var [selectionHidden, setSelectionHidden] = useState(true);
var [selectionPos, selectionPosAPI] = useSpring(() => ({
x1: 0,
y1: 0,
@@ -343,9 +345,13 @@ function TimelineEditor(props: {
config: { mass: 0.5, tension: 500, friction: 20 },
}));
var selectionRef = useRef(null);
- useDrag(({ xy: [x, y], initial: [bx, by] }) => {
+ useDrag(({ xy: [x, y], initial: [bx, by], 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);
+
var timelineInner = document.querySelector('.timeline .timelineInner');
var timelineRects = timelineInner.getBoundingClientRect();
var tx = x - timelineRects.x + timelineInner.scrollLeft;
@@ -360,6 +366,13 @@ function TimelineEditor(props: {
var y1 = iy + Math.min(0, sy);
var x2 = x1 + Math.abs(sx);
var y2 = y1 + Math.abs(sy);
+
+ if (!selectionActive) setSelectionActive(true);
+ if (last) {
+ setSelectionActive(false);
+ if (distanceTraveled <= minDistance) setSelectionHidden(true);
+ }
+
selectionPosAPI.start({ x1, y1, x2, y2 });
}, { domTarget: selectionRef, eventOptions: { passive: false } });
@@ -413,6 +426,7 @@ function TimelineEditor(props: {
className='posabs dispinbl'
style={{ left: selectionPos.x1.toJSON() - 6, top: selectionPos.y1.toJSON() - 6 }}
children={<Selection
+ className={'' + (selectionActive ? 'active ' : '') + (selectionHidden ? 'hidden ' : '')}
width={selectionPos.x2.toJSON() - selectionPos.x1.toJSON() + 12}
height={selectionPos.y2.toJSON() - selectionPos.y1.toJSON() + 12}
/>}