示例#1
0
文件: SnapEngine.cs 项目: 0geova0/Jam
            public bool IsInInfluenceZone(double currentTime, WindowState state)
            {
                var pos       = state.TimeToPixel(currentTime);
                var magnetPos = state.TimeToPixel(time);

                return(Math.Abs(pos - magnetPos) < k_MagnetInfluenceInPixels);
            }
示例#2
0
        public TimeAreaAutoPanner(WindowState state)
        {
            m_State  = state;
            m_Window = m_State.GetWindow();

            var shownRange      = m_State.timeAreaShownRange;
            var trackViewBounds = m_Window.sequenceRect;

            m_ViewRect = Rect.MinMaxRect(m_State.TimeToPixel(shownRange.x), trackViewBounds.yMin,
                                         m_State.TimeToPixel(shownRange.y), trackViewBounds.yMax);
        }
示例#3
0
        void DrawCurveEditorForTrack(Rect headerRect, Rect trackRect, WindowState state)
        {
            if (m_TrackGUI.clipCurveEditor == null)
            {
                return;
            }

            var activeRange = new Vector2(state.TimeToPixel(0.0d), state.TimeToPixel(state.editSequence.duration));

            DrawCurveEditor(m_TrackGUI, state, headerRect, trackRect, activeRange, m_TrackGUI.locked);
            m_LastSelectionWasClip = false;
        }
示例#4
0
        static void DrawBorderOfAddedRecordingClip(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, WindowState state)
        {
            if (!state.IsArmedForRecord(trackAsset))
            {
                return;
            }

            AnimationTrack animTrack = trackAsset as AnimationTrack;

            if (animTrack == null || !animTrack.inClipMode)
            {
                return;
            }

            // make sure there is no clip but we can add one
            TimelineClip clip = null;

            if (trackAsset.FindRecordingClipAtTime(state.editSequence.time, out clip) || clip != null)
            {
                return;
            }

            float yMax = trackRect.yMax;
            float yMin = trackRect.yMin;

            double startGap = 0;
            double endGap   = 0;

            trackAsset.GetGapAtTime(state.editSequence.time, out startGap, out endGap);
            if (double.IsInfinity(endGap))
            {
                endGap = visibleTime.y;
            }

            if (startGap > visibleTime.y || endGap < visibleTime.x)
            {
                return;
            }


            startGap = Math.Max(startGap, visibleTime.x);
            endGap   = Math.Min(endGap, visibleTime.y);

            float xMin = state.TimeToPixel(startGap);
            float xMax = state.TimeToPixel(endGap);

            Rect r = Rect.MinMaxRect(xMin, yMin, xMax, yMax);

            ClipDrawer.DrawBorder(r, ClipBorder.kRecording, ClipBlends.kNone);
        }
        void DrawKeyFrame(float key, WindowState state)
        {
            var x      = state.TimeToPixel(key);
            var bounds = new Rect(x, m_TrackRect.yMin + 3.0f, 1.0f, m_TrackRect.height - 6.0f);

            if (!m_TrackRect.Overlaps(bounds))
            {
                return;
            }

            var iconWidth  = DirectorStyles.Instance.keyframe.fixedWidth;
            var iconHeight = DirectorStyles.Instance.keyframe.fixedHeight;

            var keyframeRect = bounds;

            keyframeRect.width  = iconWidth;
            keyframeRect.height = iconHeight;
            keyframeRect.xMin  -= iconWidth / 2.0f;
            keyframeRect.yMin   = m_TrackRect.yMin + ((m_TrackRect.height - iconHeight) / 2.0f);

            // case 890650 : Make sure to use GUI.Label and not GUI.Box since the number of key frames can vary while dragging keys in the inline curves causing hotControls to be desynchronized
            GUI.Label(keyframeRect, GUIContent.none, DirectorStyles.Instance.keyframe);

            EditorGUI.DrawRect(bounds, DirectorStyles.Instance.customSkin.colorInfiniteClipLine);
        }
示例#6
0
文件: SnapEngine.cs 项目: 0geova0/Jam
        public void OnGUI(bool showLeft = true, bool showRight = true)
        {
            if (displayDebugLayout)
            {
                // Display Magnet influence zone
                foreach (var m in m_Magnets)
                {
                    var window = TimelineWindow.instance;
                    var rect   = new Rect(m_State.TimeToPixel(m.time) - k_MagnetInfluenceInPixels, window.state.timeAreaRect.yMax, 2f * k_MagnetInfluenceInPixels, m_State.windowHeight);
                    EditorGUI.DrawRect(rect, new Color(1f, 0f, 0f, 0.4f));
                }

                // Display Cursor position
                var mousePos = Event.current.mousePosition;
                var time     = m_State.PixelToTime(mousePos.x);
                var p        = new Vector2(m_State.TimeToPixel(time), TimelineWindow.instance.state.timeAreaRect.yMax);
                var s        = new Vector2(1f, m_State.windowHeight);
                EditorGUI.DrawRect(new Rect(p, s), Color.blue);

                p = new Vector2(m_State.TimeToPixel(m_GrabbedTime), TimelineWindow.instance.state.timeAreaRect.yMax);
                s = new Vector2(1f, m_State.windowHeight);
                EditorGUI.DrawRect(new Rect(p, s), Color.red);

                p = new Vector2(m_State.TimeToPixel(m_CurrentTimes.left), TimelineWindow.instance.state.timeAreaRect.yMax);
                s = new Vector2(1f, m_State.windowHeight);
                EditorGUI.DrawRect(new Rect(p, s), Color.yellow);

                p = new Vector2(m_State.TimeToPixel(m_CurrentTimes.right), TimelineWindow.instance.state.timeAreaRect.yMax);
                EditorGUI.DrawRect(new Rect(p, s), Color.yellow);
            }

            if (m_SnapEnabled)
            {
                if (showLeft)
                {
                    DrawMagnetLineAt(m_Attractable.start);
                }

                if (showRight)
                {
                    DrawMagnetLineAt(m_Attractable.end);
                }
            }
        }
        public double AdjustStartTime(WindowState state, ItemsPerTrack itemsGroup, double time)
        {
            var track = itemsGroup.targetTrack;

            if (track == null)
            {
                return(time);
            }

            double start;
            double end;

            if (EditModeUtils.IsInfiniteTrack(track))
            {
                EditModeUtils.GetInfiniteClipBoundaries(track, out start, out end);
            }
            else
            {
                var siblings             = ItemsUtils.GetItemsExcept(track, itemsGroup.items);
                var firstIntersectedItem = EditModeUtils.GetFirstIntersectedItem(siblings, time);

                if (firstIntersectedItem == null)
                {
                    return(time);
                }

                start = firstIntersectedItem.start;
                end   = firstIntersectedItem.end;
            }

            var closestTime = Math.Abs(time - start) < Math.Abs(time - end) ? start : end;

            var pixelTime        = state.TimeToPixel(time);
            var pixelClosestTime = state.TimeToPixel(closestTime);

            if (Math.Abs(pixelTime - pixelClosestTime) < k_SnapToEdgeDistance)
            {
                return(closestTime);
            }

            return(time);
        }
示例#8
0
        public static void DrawLineAtTime(WindowState state, double time, Color color, bool dotted = false)
        {
            var t = state.TimeToPixel(time);

            var p0 = new Vector3(t, state.timeAreaRect.yMax);
            var p1 = new Vector3(t, state.timeAreaRect.yMax + state.windowHeight - WindowConstants.sliderWidth);

            if (dotted)
            {
                DrawDottedLine(p0, p1, 4.0f, color);
            }
            else
            {
                DrawLine(p0, p1, color);
            }
        }
示例#9
0
        void DrawCurveEditorsForClipsOnTrack(Rect headerRect, Rect trackRect, WindowState state)
        {
            if (m_TrackGUI.clips.Count == 0)
            {
                return;
            }

            if (Event.current.type == EventType.Layout)
            {
                var selectedClip = SelectionManager.SelectedClipGUI().FirstOrDefault(x => x.parent == m_TrackGUI);
                if (selectedClip != null)
                {
                    m_LastSelectedClipGUI = selectedClip;
                    SelectFromCurveOwner(m_LastSelectedClipGUI);
                }
                else if (state.recording && state.IsArmedForRecord(m_TrackGUI.track))
                {
                    if (m_LastSelectedClipGUI == null || !m_TrackGUI.track.IsRecordingToClip(m_LastSelectedClipGUI.clip))
                    {
                        var clip = m_TrackGUI.clips.FirstOrDefault(x => m_TrackGUI.track.IsRecordingToClip(x.clip));
                        if (clip != null)
                        {
                            m_LastSelectedClipGUI = clip;
                        }
                    }
                }

                if (m_LastSelectedClipGUI == null)
                {
                    m_LastSelectedClipGUI = m_TrackGUI.clips[0];
                }
            }

            if (m_LastSelectedClipGUI == null || m_LastSelectedClipGUI.clipCurveEditor == null || m_LastSelectedClipGUI.isInvalid)
            {
                return;
            }

            var activeRange = new Vector2(state.TimeToPixel(m_LastSelectedClipGUI.clip.start), state.TimeToPixel(m_LastSelectedClipGUI.clip.end));

            DrawCurveEditor(m_LastSelectedClipGUI, state, headerRect, trackRect, activeRange, m_TrackGUI.locked);
            m_LastSelectionWasClip = true;
        }
示例#10
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();
                }
            }
        }
示例#11
0
 public Vector2 ToPixel()
 {
     return(new Vector2(m_State.TimeToPixel(m_Time), m_YPos - (m_TreeViewGUI.scrollPosition.y - m_YScrollPos)));
 }