// get the start and end times of what an added recording clip at a given time would be
        internal static void GetAddedRecordingClipRange(TrackAsset track, WindowState state, double atTime, out double start, out double end)
        {
            // size to make the clip in pixels. Reasonably big so that both handles are easily manipulated,
            // and the full title is normally visible
            double defaultDuration = state.PixelDeltaToDeltaTime(100);

            start = atTime;
            end   = atTime + defaultDuration;

            double gapStart = 0;
            double gapEnd   = 0;

            // no gap, pick are reasonable amount
            if (!track.GetGapAtTime(atTime, out gapStart, out gapEnd))
            {
                start = atTime;
                return;
            }

            if (!double.IsInfinity(gapEnd))
            {
                end = gapEnd;
            }

            start = state.SnapToFrameIfRequired(start);
            end   = state.SnapToFrameIfRequired(end);
        }
Пример #2
0
        public static double GetCandidateTime(WindowState state, Vector2?mousePosition, params TrackAsset[] trackAssets)
        {
            // Right-Click
            if (mousePosition != null)
            {
                return(state.GetSnappedTimeAtMousePosition(mousePosition.Value));
            }

            // Playhead
            if (state != null && state.editSequence.director != null)
            {
                return(state.SnapToFrameIfRequired(state.editSequence.time));
            }

            // Specific tracks end
            if (trackAssets != null && trackAssets.Any())
            {
                var items = trackAssets.SelectMany(t => t.GetItems()).ToList();
                return(items.Any() ? items.Max(i => i.end) : 0);
            }

            // Timeline tracks end
            if (state != null && state.editSequence.asset != null)
            {
                return(state.editSequence.asset.flattenedTracks.Any() ? state.editSequence.asset.flattenedTracks.Max(t => t.end) : 0);
            }

            return(0.0);
        }
Пример #3
0
            public void OnDrag(double value, WindowState state)
            {
                if (m_MoveItemHandler == null)
                {
                    return;
                }

                var startValue = value;

                startValue = state.SnapToFrameIfRequired(startValue);
                m_MoveItemHandler.OnAttractedEdge(null, ManipulateEdges.Both, AttractedEdge.None, startValue);
            }
Пример #4
0
        public void Snap(Vector2 currentMousePosition, EventModifiers modifiers)
        {
            var d = m_State.PixelToTime(currentMousePosition.x) - m_GrabbedTime;

            m_CurrentTimes = m_GrabbedTimes.Translate(d);

            bool isLeft  = m_ManipulateEdges == ManipulateEdges.Left || m_ManipulateEdges == ManipulateEdges.Both;
            bool isRight = m_ManipulateEdges == ManipulateEdges.Right || m_ManipulateEdges == ManipulateEdges.Both;

            bool attracted = false;

            m_SnapEnabled = modifiers == ManipulatorsUtils.actionModifier ? !m_State.edgeSnaps : m_State.edgeSnaps;

            if (m_SnapEnabled)
            {
                SnapInfo leftActiveMagnet  = null;
                SnapInfo rightActiveMagnet = null;

                if (isLeft)
                {
                    leftActiveMagnet = ClosestMagnet(m_CurrentTimes.left);
                }

                if (isRight)
                {
                    rightActiveMagnet = ClosestMagnet(m_CurrentTimes.right);
                }

                if (leftActiveMagnet != null || rightActiveMagnet != null)
                {
                    attracted = true;

                    bool leftAttraction = false;

                    if (rightActiveMagnet == null)
                    {
                        // Attracted by a left magnet only.
                        leftAttraction = true;
                    }
                    else
                    {
                        if (leftActiveMagnet != null)
                        {
                            // Attracted by both magnets, choose the closest one.
                            var leftDistance  = Math.Abs(leftActiveMagnet.time - m_CurrentTimes.left);
                            var rightDistance = Math.Abs(rightActiveMagnet.time - m_CurrentTimes.right);

                            leftAttraction = leftDistance <= rightDistance;
                        }
                        // else, Attracted by right magnet only
                    }

                    if (leftAttraction)
                    {
                        m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.Left, leftActiveMagnet.time);
                    }
                    else
                    {
                        m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.Right, rightActiveMagnet.time);
                    }
                }
            }

            if (!attracted)
            {
                var time = isLeft ? m_CurrentTimes.left : m_CurrentTimes.right;

                time = m_State.SnapToFrameIfRequired(time);

                m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.None, time);
            }
        }