mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: integrate snapping functionality into timeline track component
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
|||||||
TIMELINE_CONSTANTS,
|
TIMELINE_CONSTANTS,
|
||||||
} from "@/constants/timeline-constants";
|
} from "@/constants/timeline-constants";
|
||||||
import { useProjectStore } from "@/stores/project-store";
|
import { useProjectStore } from "@/stores/project-store";
|
||||||
|
import { useTimelineSnapping } from "@/hooks/use-timeline-snapping";
|
||||||
|
|
||||||
export function TimelineTrackContent({
|
export function TimelineTrackContent({
|
||||||
track,
|
track,
|
||||||
@@ -45,8 +46,25 @@ export function TimelineTrackContent({
|
|||||||
endDrag: endDragAction,
|
endDrag: endDragAction,
|
||||||
clearSelectedElements,
|
clearSelectedElements,
|
||||||
insertTrackAt,
|
insertTrackAt,
|
||||||
|
snappingEnabled,
|
||||||
|
gridSnappingEnabled,
|
||||||
|
elementSnappingEnabled,
|
||||||
|
playheadSnappingEnabled,
|
||||||
|
snapThreshold,
|
||||||
|
gridInterval,
|
||||||
} = useTimelineStore();
|
} = useTimelineStore();
|
||||||
|
|
||||||
|
const { currentTime } = usePlaybackStore();
|
||||||
|
|
||||||
|
// Initialize snapping hook
|
||||||
|
const { snapElementPosition } = useTimelineSnapping({
|
||||||
|
snapThreshold,
|
||||||
|
gridInterval,
|
||||||
|
enableGridSnapping: snappingEnabled && gridSnappingEnabled,
|
||||||
|
enableElementSnapping: snappingEnabled && elementSnappingEnabled,
|
||||||
|
enablePlayheadSnapping: snappingEnabled && playheadSnappingEnabled,
|
||||||
|
});
|
||||||
|
|
||||||
const timelineRef = useRef<HTMLDivElement>(null);
|
const timelineRef = useRef<HTMLDivElement>(null);
|
||||||
const [isDropping, setIsDropping] = useState(false);
|
const [isDropping, setIsDropping] = useState(false);
|
||||||
const [dropPosition, setDropPosition] = useState<number | null>(null);
|
const [dropPosition, setDropPosition] = useState<number | null>(null);
|
||||||
@@ -85,12 +103,26 @@ export function TimelineTrackContent({
|
|||||||
mouseX / (TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel)
|
mouseX / (TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel)
|
||||||
);
|
);
|
||||||
const adjustedTime = Math.max(0, mouseTime - dragState.clickOffsetTime);
|
const adjustedTime = Math.max(0, mouseTime - dragState.clickOffsetTime);
|
||||||
// Use frame snapping if project has FPS, otherwise use decimal snapping
|
|
||||||
const projectStore = useProjectStore.getState();
|
|
||||||
const projectFps = projectStore.activeProject?.fps || 30;
|
|
||||||
const snappedTime = snapTimeToFrame(adjustedTime, projectFps);
|
|
||||||
|
|
||||||
updateDragTime(snappedTime);
|
// Apply snapping if enabled
|
||||||
|
let finalTime = adjustedTime;
|
||||||
|
if (snappingEnabled) {
|
||||||
|
const snapResult = snapElementPosition(
|
||||||
|
adjustedTime,
|
||||||
|
tracks,
|
||||||
|
currentTime,
|
||||||
|
zoomLevel,
|
||||||
|
dragState.elementId || undefined
|
||||||
|
);
|
||||||
|
finalTime = snapResult.snappedTime;
|
||||||
|
} else {
|
||||||
|
// Use frame snapping if project has FPS, otherwise use decimal snapping
|
||||||
|
const projectStore = useProjectStore.getState();
|
||||||
|
const projectFps = projectStore.activeProject?.fps || 30;
|
||||||
|
finalTime = snapTimeToFrame(adjustedTime, projectFps);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDragTime(finalTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseUp = (e: MouseEvent) => {
|
const handleMouseUp = (e: MouseEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user