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: --- components/icons.tsx | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- pages/editor.tsx | 37 ++++++++++++++++++++++++++++++----- styles/editor.css | 13 +++++++++++++ styles/keyframes.css | 5 ++++- 4 files changed, 103 insertions(+), 7 deletions(-) diff --git a/components/icons.tsx b/components/icons.tsx index f8d6668..ea73b26 100644 --- a/components/icons.tsx +++ b/components/icons.tsx @@ -116,11 +116,22 @@ export function PressureIcon() { } export function SlideKeyframe(props: { + type: slideTypes; + ghost?: boolean; + loopEnd?: boolean; +}) { + return
+ {props.ghost && } + +
; +} + +export function SlideKeyframeBackground(props: { type: slideTypes; loopEnd?: boolean; }) { return ; } + +export function SlideKeyframeOutline(props: { + type: slideTypes; + loopEnd?: boolean; +}) { + return + {{ + 'default': , + 'delay': , + 'speedChange': , + 'loop': !props.loopEnd + ? + : , + }[props.type]} + ; +} 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() { > diff --git a/styles/editor.css b/styles/editor.css index 1a1a91f..7eda309 100644 --- a/styles/editor.css +++ b/styles/editor.css @@ -169,6 +169,19 @@ width: calc(var(--zoom) * var(--total-frames) * 1px); } +.appGrid .timeline .ghostArea { + pointer-events: none; + line-height: 0; + transition-property: opacity; + transition-duration: 150ms; + opacity: 0; + color: var(--gruble); +} + +.appGrid .timeline:hover .ghostArea.active { + opacity: 1; +} + .appGrid .timeline .keyframes .frame { background-color: transparent; height: 100%; diff --git a/styles/keyframes.css b/styles/keyframes.css index 49c8e4e..8a4f06f 100644 --- a/styles/keyframes.css +++ b/styles/keyframes.css @@ -39,7 +39,10 @@ z-index: 1; } -.keyframe > * { +.keyframe { + line-height: 0; fill: currentColor; } +.keyframe.ghost .background { opacity: .2; } +.keyframe.ghost .outline { opacity: .7; } -- cgit v1.2.3