From 4562c60cf284a97ae1fa861480b0916f5fb7c453 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 25 May 2021 16:11:54 +0200 Subject: ghost for adding keyframes :tada: --- pages/editor.tsx | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'pages') diff --git a/pages/editor.tsx b/pages/editor.tsx index 95b6005..2058485 100644 --- a/pages/editor.tsx +++ b/pages/editor.tsx @@ -2,7 +2,7 @@ import { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react'; import { animated, useSpring } from 'react-spring'; import { useDrag } from 'react-use-gesture'; import create from 'zustand'; -import { anySlide, loopSlide, slide } from '../timeline'; +import { anySlide, loopSlide, slide, slideTypes } from '../timeline'; import { TimedVideoPlayer } from './present'; import AppBar from '@material-ui/core/AppBar'; @@ -128,7 +128,6 @@ function TimelineKeyframe(props: { } var mouseUpListener = useRef(null); - useDrag(({ last }) => { if (!last) return; player.timeline.slides = Array(...workingTimeline); @@ -168,7 +167,10 @@ function TimelineKeyframe(props: { ; } -function TimelineEditor(props: { player: TimedVideoPlayer; }) { +function TimelineEditor(props: { + player: TimedVideoPlayer; + selectedTool: string; +}) { var timelineZoom = getTimelineZoom((st: any) => st.zoom); var timelineLabels = useTimelineLabels((st: any) => st.labels); @@ -295,6 +297,21 @@ function TimelineEditor(props: { player: TimedVideoPlayer; }) { } }, { domTarget: scrubberDragRef, eventOptions: { passive: false } }); + var [ghost, ghostApi] = useSpring(() => ({ + x: 0, + y: 0, + config: { mass: 0.5, tension: 500, friction: 20 }, + })); + useEffect(() => { + document.querySelector('.timeline').addEventListener('mousemove', (e: MouseEvent) => { + var rect = document.querySelector('.timeline').getBoundingClientRect(); + var offset = 16; + var x = e.clientX - rect.left - offset; + var y = e.clientY - rect.top - offset; + ghostApi.start({ x, y }); + }); + }, []); + return <>
@@ -324,6 +341,17 @@ function TimelineEditor(props: { player: TimedVideoPlayer; }) { children={workingTimeline.map((slide: anySlide) => )} />
+
+ } + /> +
; } @@ -343,7 +371,6 @@ export default function Index() { var [playing, setPlaying] = useState(false); var mouseX = 0; - // var mouseY = 0; useEffect(() => { var videoEL = document.getElementById('player') as HTMLVideoElement; @@ -375,7 +402,6 @@ export default function Index() { window.addEventListener('mousemove', e => { var rect = canvas.getBoundingClientRect(); mouseX = e.clientX - rect.x; - // mouseY = e.clientY - rect.y; }); }, []); @@ -554,6 +580,7 @@ export default function Index() { > -- cgit v1.2.3