From c6a62404fa7a46e7eea1a832291ed3634ec68c90 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 14 Jun 2021 10:18:15 +0200 Subject: selection working (with offsets) :tada: --- components/selection.tsx | 5 +++-- pages/editor.tsx | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/components/selection.tsx b/components/selection.tsx index a039f79..bcc1656 100644 --- a/components/selection.tsx +++ b/components/selection.tsx @@ -69,12 +69,13 @@ export default function Selection(props: { left?: slideTypes; right?: slideTypes; className?: string; + widthOffset?: number; }) { - var small = props.width < 24 || props.height < 24 || !props.left || !props.right; + var small = (props.width + props.widthOffset) < 24 || props.height < 24 || !props.left || !props.right; return
({ setFrame: (newFrame: number) => set(() => ({ currentFrame: newFrame })), })); +function calculateSelectionOffsets(left: slideTypes, right: slideTypes) { + var offsets = { + default: { left: -6, right: 6 }, + loop: { left: -2, right: 1 }, + delay: { left: -6, right: 6 }, + speedChange: { left: -6, right: 6 }, + }; + + var offsetLeft = offsets[left].left; + var offsetWidth = offsets[right].right - offsetLeft; + + return [offsetLeft, offsetWidth]; +} + function TimelineKeyframe(props: { slide: slide; }) { @@ -344,8 +358,11 @@ function TimelineEditor(props: { y1: 0, x2: 0, y2: 0, + center: 0, startingFrame: 0, frameWidth: 0, + startOffset: 0, + widthOffset: 0, config: { mass: 0.5, tension: 500, friction: 20 }, })); var selectionRef = useRef(null); @@ -357,6 +374,11 @@ function TimelineEditor(props: { if (selectionHidden && distanceTraveled > minDistance) setSelectionHidden(false); if (selectionLeftType) setSelectionLeftType(null); if (selectionRightType) setSelectionRightType(null); + selectionPosAPI.start({ + center: 0, + startOffset: 0, + widthOffset: 0, + }); var timelineInner = document.querySelector('.timeline .timelineInner'); var timelineRects = timelineInner.getBoundingClientRect(); @@ -388,14 +410,24 @@ function TimelineEditor(props: { slide.frame >= Math.floor(startingFrame) && slide.frame <= Math.ceil(endingFrame) ); - if (keyframesInSelection.length < 1) return; + if (keyframesInSelection.length < 1) { + setSelectionHidden(true); + return; + } + var left = keyframesInSelection[0]; var right = keyframesInSelection[keyframesInSelection.length - 1]; + + var [startOffset, widthOffset] = calculateSelectionOffsets(left.type, right.type); + selectionPosAPI.start({ y1: 50, y2: 62, startingFrame: left.frame, frameWidth: right.frame - left.frame, + center: 0.5, + startOffset, + widthOffset, }); setSelectionLeftType(left.type); setSelectionRightType(right.type); @@ -452,7 +484,8 @@ function TimelineEditor(props: { id='selection' className='posabs dispinbl' style={{ - left: `calc(var(--zoom) * ${selectionPos.startingFrame.toJSON()} * 1px - 6px)`, + left: `calc(var(--zoom) * ${selectionPos.startingFrame.toJSON() + + selectionPos.center.toJSON()} * 1px - 6px + ${selectionPos.startOffset.toJSON()} * 1px)`, top: selectionPos.y1.toJSON() - 6, }} children={} />
-- cgit v1.2.3