Keyframe drag snapping

This commit is contained in:
Aria Minaei 2021-08-03 12:17:10 +02:00
parent ae66ea90c6
commit e6bfd999a2

View file

@ -118,6 +118,7 @@ function useDragKeyframe(node: HTMLDivElement | null, props: IProps) {
let toUnitSpace: SequenceEditorPanelLayout['scaledSpace']['toUnitSpace'] let toUnitSpace: SequenceEditorPanelLayout['scaledSpace']['toUnitSpace']
let tempTransaction: CommitOrDiscard | undefined let tempTransaction: CommitOrDiscard | undefined
let propsAtStartOfDrag: IProps let propsAtStartOfDrag: IProps
let startingLayout: SequenceEditorPanelLayout
let selectionDragHandlers: let selectionDragHandlers:
| ReturnType<DopeSheetSelection['getDragHandlers']> | ReturnType<DopeSheetSelection['getDragHandlers']>
@ -148,21 +149,21 @@ function useDragKeyframe(node: HTMLDivElement | null, props: IProps) {
selectionDragHandlers.onDrag(dx, dy, event) selectionDragHandlers.onDrag(dx, dy, event)
return return
} }
const delta = toUnitSpace(dx) const original =
propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index]
const deltaPos = toUnitSpace(dx)
const newPosBeforeSnapping = Math.max(original.position + deltaPos, 0)
if (tempTransaction) { if (tempTransaction) {
tempTransaction.discard() tempTransaction.discard()
tempTransaction = undefined tempTransaction = undefined
} }
tempTransaction = getStudio()!.tempTransaction(({stateEditors}) => { tempTransaction = getStudio()!.tempTransaction(({stateEditors}) => {
stateEditors.coreByProject.historic.sheetsById.sequence.transformKeyframes( stateEditors.coreByProject.historic.sheetsById.sequence.replaceKeyframes(
{ {
...propsAtStartOfDrag.leaf.sheetObject.address, ...propsAtStartOfDrag.leaf.sheetObject.address,
trackId: propsAtStartOfDrag.leaf.trackId, trackId: propsAtStartOfDrag.leaf.trackId,
keyframeIds: [propsAtStartOfDrag.keyframe.id], keyframes: [{...original, position: newPosBeforeSnapping}],
translate: delta,
scale: 1,
origin: 0,
}, },
) )
}) })