public static double GetCandidateTime(Vector2?mousePosition, params TrackAsset[] trackAssets)
        {
            // Right-Click
            if (mousePosition != null)
            {
                return(TimeReferenceUtility.GetSnappedTimeAtMousePosition(mousePosition.Value));
            }

            // Playhead
            if (TimelineEditor.inspectedDirector != null)
            {
                return(TimeReferenceUtility.SnapToFrameIfRequired(TimelineEditor.inspectedSequenceTime));
            }

            // 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 (TimelineEditor.inspectedAsset != null)
            {
                return(TimelineEditor.inspectedAsset.flattenedTracks.Any() ? TimelineEditor.inspectedAsset.flattenedTracks.Max(t => t.end) : 0);
            }

            return(0.0);
        }
Exemplo n.º 2
0
        public static void FrameItems(IEnumerable <ITimelineItem> items)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            // if this is called before a repaint, the timeArea can be null
            if (TimelineEditor.window.timeArea == null)
            {
                return;
            }

            var start     = (float)items.Min(x => x.start);
            var end       = (float)items.Max(x => x.end);
            var timeRange = TimelineEditor.visibleTimeRange;

            // nothing to do
            if (timeRange.x <= start && timeRange.y >= end)
            {
                return;
            }

            timeRange.x = Mathf.Max(0, timeRange.x);
            timeRange.y = Mathf.Max(0, timeRange.y);

            var ds = start - timeRange.x;
            var de = end - timeRange.y;

            var padding = TimeReferenceUtility.PixelToTime(15) - TimeReferenceUtility.PixelToTime(0);
            var d       = Math.Abs(ds) < Math.Abs(de) ? ds - padding : de + padding;

            TimelineEditor.visibleTimeRange = new Vector2(timeRange.x + d, timeRange.y + d);
        }
        // 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 = TimeReferenceUtility.SnapToFrameIfRequired(start);
            end   = TimeReferenceUtility.SnapToFrameIfRequired(end);
        }
Exemplo n.º 4
0
        public static void Draw(WindowState state, double time)
        {
            var bounds = state.timeAreaRect;

            bounds.xMin = Mathf.Max(bounds.xMin, state.TimeToTimeAreaPixel(time));

            using (new GUIViewportScope(state.timeAreaRect))
            {
                s_Tooltip.text = TimeReferenceUtility.ToTimeString(time);

                var tooltipBounds = s_Tooltip.bounds;
                tooltipBounds.xMin = bounds.xMin - (tooltipBounds.width / 2.0f);
                tooltipBounds.y    = bounds.y;
                s_Tooltip.bounds   = tooltipBounds;

                if (time >= 0)
                {
                    s_Tooltip.Draw();
                }
            }

            if (time >= 0)
            {
                Graphics.DrawLineAtTime(state, time, Color.black, true);
            }
        }
Exemplo n.º 5
0
        public static double TimeGapBetweenItems(ITimelineItem leftItem, ITimelineItem rightItem)
        {
            if (leftItem is MarkerItem && rightItem is MarkerItem)
            {
                var markerType = ((MarkerItem)leftItem).marker.GetType();
                var gap        = TimeReferenceUtility.PixelToTime(StyleManager.UssStyleForType(markerType).fixedWidth) - TimeReferenceUtility.PixelToTime(0);
                return(gap);
            }

            return(0.0);
        }
            public void OnDrag(double value, WindowState state)
            {
                if (m_MoveItemHandler == null)
                {
                    return;
                }

                var startValue = value;

                startValue = TimeReferenceUtility.SnapToFrameIfRequired(startValue);
                m_MoveItemHandler.OnAttractedEdge(null, ManipulateEdges.Both, AttractedEdge.None, startValue);
            }
            public void OnDrag(double endValue, WindowState state)
            {
                var trimValue = endValue;

                trimValue = TimeReferenceUtility.SnapToFrameIfRequired(trimValue);

                foreach (var item in grabbedItems)
                {
                    EditMode.TrimEnd(item, trimValue, stretch);
                }
                state.UpdateRootPlayableDuration(state.editSequence.duration);
            }
        // Draws the box to enter the time field
        void TimeCodeGUI()
        {
            EditorGUI.BeginChangeCheck();

            var currentTime = state.editSequence.asset != null?TimeReferenceUtility.ToTimeString(state.editSequence.time, "F1") : "0";

            var r              = EditorGUILayout.GetControlRect(false, EditorGUI.kSingleLineHeight, EditorStyles.toolbarTextField, GUILayout.MinWidth(WindowConstants.minTimeCodeWidth));
            var id             = GUIUtility.GetControlID("RenameFieldTextField".GetHashCode(), FocusType.Passive, r);
            var newCurrentTime = EditorGUI.DelayedTextFieldInternal(r, id, GUIContent.none, currentTime, null, EditorStyles.toolbarTextField);

            if (EditorGUI.EndChangeCheck())
            {
                state.editSequence.time = TimeReferenceUtility.FromTimeString(newCurrentTime);
            }
        }
Exemplo n.º 9
0
        public void Draw(Rect rect, WindowState state, double time)
        {
            var clipRect = new Rect(0.0f, 0.0f, TimelineWindow.instance.position.width, TimelineWindow.instance.position.height);

            clipRect.xMin += state.sequencerHeaderWidth;

            using (new GUIViewportScope(clipRect))
            {
                Vector2 windowCoordinate = rect.min;
                windowCoordinate.y += 4.0f;

                windowCoordinate.x = state.TimeToPixel(time);

                m_BoundingRect = new Rect((windowCoordinate.x - widgetWidth / 2.0f), windowCoordinate.y, widgetWidth, widgetHeight);

                // Do not paint if the time cursor goes outside the timeline bounds...
                if (Event.current.type == EventType.Repaint)
                {
                    if (m_BoundingRect.xMax < state.timeAreaRect.xMin)
                    {
                        return;
                    }
                    if (m_BoundingRect.xMin > state.timeAreaRect.xMax)
                    {
                        return;
                    }
                }

                var top    = new Vector3(windowCoordinate.x, rect.y - DirectorStyles.kDurationGuiThickness);
                var bottom = new Vector3(windowCoordinate.x, rect.yMax);

                if (drawLine)
                {
                    Rect lineRect = Rect.MinMaxRect(top.x - 0.5f, top.y, bottom.x + 0.5f, bottom.y);
                    EditorGUI.DrawRect(lineRect, lineColor);
                }

                if (drawHead)
                {
                    Color c = GUI.color;
                    GUI.color = headColor;
                    GUI.Box(bounds, m_HeaderContent, m_Style);
                    GUI.color = c;

                    if (canMoveHead)
                    {
                        EditorGUIUtility.AddCursorRect(bounds, MouseCursor.MoveArrow);
                    }
                }

                if (showTooltip)
                {
                    m_Tooltip.text = TimeReferenceUtility.ToTimeString(time);

                    Vector2 position = bounds.position;
                    position.y  = state.timeAreaRect.y;
                    position.y -= m_Tooltip.bounds.height;
                    position.x -= Mathf.Abs(m_Tooltip.bounds.width - bounds.width) / 2.0f;

                    Rect tooltipBounds = bounds;
                    tooltipBounds.position = position;
                    m_Tooltip.bounds       = tooltipBounds;

                    m_Tooltip.Draw();
                }
            }
        }
Exemplo n.º 10
0
 public double GetSnappedTimeAtMousePosition(Vector2 mousePos)
 {
     return(TimeReferenceUtility.SnapToFrameIfRequired(ScreenSpacePixelToTimeAreaTime(mousePos.x)));
 }
Exemplo n.º 11
0
 public double SnapToFrameIfRequired(double currentTime)
 {
     return(frameSnap ? TimeReferenceUtility.SnapToFrame(currentTime) : currentTime);
 }
Exemplo n.º 12
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 = TimeReferenceUtility.SnapToFrameIfRequired(time);

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