public Frame TryGetFrame(FrameRange frameRangeConstraints, EntryCountPreference ecp, System.Random random = null)
    {
        random = random ?? new System.Random();

        List <Frame> preferredFrames = PreferredFrames(random);

        preferredFrames.Shuffle(random);
        if (ecp == EntryCountPreference.Min)
        {
            preferredFrames.Sort((f, g) => f.EntryCount - g.EntryCount);
        }
        else if (ecp == EntryCountPreference.Max)
        {
            preferredFrames.Sort((f, g) => g.EntryCount - f.EntryCount);
        }

        //Debug.Log(preferredFrames[0].EntryCount);

        // Debug.Log(preferredFrames[0]);
        // Debug.Log(frameRangeConstraints);
        // Debug.Log("TryGetFrame: " + frameRangeConstraints.Contains(preferredFrames[0]));

        foreach (Frame preferredFrame in preferredFrames)
        {
            if (frameRangeConstraints.Contains(preferredFrame))
            {
                return(preferredFrame);
            }
        }
        return(null);
    }
Example #2
0
        protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            bool leftHandleVisible  = viewRange.Contains(Evt.Start);
            bool rightHandleVisible = viewRange.Contains(Evt.End);

            Rect leftHandleRect  = _eventRect; leftHandleRect.width = 4;
            Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4;

            if (leftHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, _leftHandleGuiId);
            }

            if (rightHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, _rightHandleGuiId);
            }

            switch (Event.current.type)
            {
            case EventType.Repaint:
                if (!viewRange.Overlaps(Evt.FrameRange))
                {
                    break;
                }

                GUIStyle evtStyle = GetEventStyle();

                GUI.backgroundColor = GetColor();

                evtStyle.Draw(_eventRect, _isSelected, _isSelected, false, false);

                string text = Evt.Text;
                if (text != null)
                {
                    var style = GetTextStyle();
                    //style.alignment = TextAnchor.MiddleCenter;
                    GUI.Label(_eventRect, text, style);
                }

                /*
                 * var leftRect = _eventRect;
                 * leftRect.xMax = leftRect.xMin + 16;
                 * GUI.Label(leftRect, Evt.Start.ToString(), GetTextStyle());
                 * var rightRect = _eventRect;
                 * rightRect.xMin = rightRect.xMax - 16;
                 * GUI.Label(rightRect, Evt.End.ToString(), GetTextStyle());
                 */
                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;

                    if (Event.current.button == 0)     // left click?
                    {
                        if (rightHandleVisible && rightHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _rightHandleGuiId;
                            //						keyframeOnSelect = evt.Start;
                            Event.current.Use();
                        }
                        else if (leftHandleVisible && leftHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _leftHandleGuiId;
                            //						keyframeOnSelect = evt.End;
                            Event.current.Use();
                        }
                        else if (_eventRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = GuiId;
                            _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start;

                            if (IsSelected)
                            {
                                if (Event.current.control)
                                {
                                    SequenceEditor.Deselect(this);
                                }
                            }
                            else
                            {
                                if (Event.current.shift)
                                {
                                    SequenceEditor.Select(this);
                                }
                                else if (!Event.current.control)
                                {
                                    SequenceEditor.SelectExclusive(this);
                                }
                            }
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.button == 1 && _eventRect.Contains(Event.current.mousePosition))     // right click?
                    {
                        CreateEventContextMenu().ShowAsContext();
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId ||
                        EditorGUIUtility.hotControl == _leftHandleGuiId ||
                        EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        EditorGUIUtility.hotControl = 0;
                        Event.current.Use();
                        SequenceEditor.Repaint();
                        FinishMovingEventEditors();
                    }
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId)
                    {
                        int t     = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;
                        int delta = t - Evt.Start;
                        SequenceEditor.MoveEvents(delta);
                        Event.current.Use();
                    }
                    else if (EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        int leftLimit  = 0;
                        int rightLimit = 0;

                        bool draggingStart = EditorGUIUtility.hotControl == _leftHandleGuiId;

                        if (draggingStart)
                        {
                            leftLimit  = validKeyframeRange.Start;
                            rightLimit = Evt.End - 1;
                        }
                        else
                        {
                            leftLimit  = Evt.Start + 1;
                            rightLimit = validKeyframeRange.End;
                        }


                        int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                        t = Mathf.Clamp(t, leftLimit, rightLimit);

                        int delta = t - (draggingStart ? Evt.Start : Evt.End);

                        if (draggingStart)
                        {
                            int newLength = Evt.Length - delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta += newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta += newLength - Evt.GetMaxLength();
                            }
                        }
                        else
                        {
                            int newLength = Evt.Length + delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta -= newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta -= newLength - Evt.GetMaxLength();
                            }
                        }

                        if (delta != 0)
                        {
                            if (draggingStart)
                            {
                                SequenceEditor.ResizeEventsLeft(delta);
                            }
                            else
                            {
                                SequenceEditor.ResizeEventsRight(delta);
                            }
                        }

                        Event.current.Use();
                    }
                }
                break;

            case EventType.Ignore:
                if (EditorGUIUtility.hotControl == GuiId ||
                    EditorGUIUtility.hotControl == _leftHandleGuiId ||
                    EditorGUIUtility.hotControl == _rightHandleGuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;
            }
        }
        protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            if (_animEvtSO == null)
            {
                _animEvtSO   = new SerializedObject(AnimEvt);
                _blendLength = _animEvtSO.FindProperty("_blendLength");
                _startOffset = _animEvtSO.FindProperty("_startOffset");
            }

            UpdateEventFromController();

            _animEvtSO.Update();

            FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor;

            Rect transitionOffsetRect = _eventRect;

            int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);
            int transitionHandleId  = EditorGUIUtility.GetControlID(FocusType.Passive);

            bool isBlending     = AnimEvt.IsBlending();
            bool isAnimEditable = Flux.FUtility.IsAnimationEditable(AnimEvt._animationClip);

            if (isBlending)
            {
                transitionOffsetRect.xMin  = Rect.xMin + SequenceEditor.GetXForFrame(AnimEvt.Start + AnimEvt._blendLength) - 3;
                transitionOffsetRect.width = 6;
                transitionOffsetRect.yMin  = transitionOffsetRect.yMax - 8;
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && Event.current.alt && !isAnimEditable)
                {
                    if (isBlending && transitionOffsetRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.hotControl = transitionHandleId;

                        AnimatorWindowProxy.OpenAnimatorWindowWithAnimatorController((AnimatorController)AnimTrack.AnimatorController);

                        if (Selection.activeObject != _transitionToState)
                        {
                            Selection.activeObject = _transitionToState;
                        }

                        Event.current.Use();
                    }
                    else if (_eventRect.Contains(Event.current.mousePosition))
                    {
                        _mouseDown = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - AnimEvt.Start;

                        EditorGUIUtility.hotControl = startOffsetHandleId;

                        Event.current.Use();
                    }
                }
                break;

            case EventType.Ignore:
            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == transitionHandleId ||
                    EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == transitionHandleId)
                {
                    int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length);

                    if (_blendLength.intValue != mouseDragPos)
                    {
                        _blendLength.intValue = mouseDragPos;

                        FPlayAnimationEvent prevAnimEvt = (FPlayAnimationEvent)animTrackEditor.Track.GetEvent(AnimEvt.GetId() - 1);

                        if (_transitionDuration != null)
                        {
                            _transitionDuration.floatValue = (_blendLength.intValue / prevAnimEvt._animationClip.frameRate) / prevAnimEvt._animationClip.length;
                        }

                        Undo.RecordObject(this, "Animation Blending");
                    }
                    Event.current.Use();
                }
                else if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length);

                    int delta = _mouseDown - mouseDragPos;

                    _mouseDown = mouseDragPos;

                    _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + delta, 0, AnimEvt._animationClip.isLooping ? AnimEvt.Length : Mathf.RoundToInt(AnimEvt._animationClip.length * AnimEvt._animationClip.frameRate) - AnimEvt.Length);

                    if (_transitionOffset != null)
                    {
                        _transitionOffset.floatValue = (_startOffset.intValue / AnimEvt._animationClip.frameRate) / AnimEvt._animationClip.length;
                    }

                    Undo.RecordObject(this, "Animation Offset");

                    Event.current.Use();
                }
                break;
            }

            _animEvtSO.ApplyModifiedProperties();
            if (_transitionSO != null)
            {
                _transitionSO.ApplyModifiedProperties();
            }


            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (_eventRect.Contains(Event.current.mousePosition))
                {
                    int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Evt.Sequence.FrameRate);
                    DragAndDrop.visualMode = numAnimationsDragged > 0 ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
                    Event.current.Use();
                }
                break;

            case EventType.DragPerform:
                if (_eventRect.Contains(Event.current.mousePosition))
                {
                    AnimationClip animationClipDragged = FAnimationEventInspector.GetAnimationClipDragAndDrop(Evt.Sequence.FrameRate);
                    if (animationClipDragged)
                    {
                        int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate);

                        FAnimationEventInspector.SetAnimationClip(AnimEvt, animationClipDragged);

                        FrameRange maxRange = AnimEvt.GetMaxFrameRange();

                        SequenceEditor.MoveEvent(AnimEvt, new FrameRange(AnimEvt.Start, Mathf.Min(AnimEvt.Start + animFrameLength, maxRange.End)));

                        DragAndDrop.AcceptDrag();
                        Event.current.Use();
                    }
                    else
                    {
                        Event.current.Use();
                    }
                }
                break;
            }

//            FrameRange currentRange = Evt.FrameRange;

            base.RenderEvent(viewRange, validKeyframeRange);

//            if( isAnimEditable && currentRange.Length != Evt.FrameRange.Length )
//            {
//                FAnimationEventInspector.ScaleAnimationClip( AnimEvt._animationClip, Evt.FrameRange );
//            }

            if (Event.current.type == EventType.Repaint)
            {
                if (isBlending && !isAnimEditable && viewRange.Contains(AnimEvt.Start + AnimEvt._blendLength))
                {
                    GUISkin skin = FUtility.GetFluxSkin();

                    GUIStyle transitionOffsetStyle = skin.GetStyle("BlendOffset");

                    Texture2D t = FUtility.GetFluxTexture("EventBlend.png");

                    Rect r = new Rect(_eventRect.xMin, _eventRect.yMin + 1, transitionOffsetRect.center.x - _eventRect.xMin, _eventRect.height - 2);

                    Color guiColor = GUI.color;

                    Color c = new Color(1f, 1f, 1f, 0.3f);
                    c.a      *= guiColor.a;
                    GUI.color = c;

                    GUI.DrawTexture(r, t);

                    if (Event.current.alt)
                    {
                        GUI.color = Color.white;
                    }

                    transitionOffsetStyle.Draw(transitionOffsetRect, false, false, false, false);

                    GUI.color = guiColor;

//					Debug.Log ( transitionOffsetRect );
                }

//				GUI.color = Color.red;

                if (EditorGUIUtility.hotControl == transitionHandleId)
                {
                    Rect transitionOffsetTextRect = transitionOffsetRect;
                    transitionOffsetTextRect.y     -= 16;
                    transitionOffsetTextRect.height = 20;
                    transitionOffsetTextRect.width += 50;
                    GUI.Label(transitionOffsetTextRect, AnimEvt._blendLength.ToString(), EditorStyles.label);
                }

                if (EditorGUIUtility.hotControl == startOffsetHandleId)
                {
                    Rect startOffsetTextRect = _eventRect;
                    GUI.Label(startOffsetTextRect, AnimEvt._startOffset.ToString(), EditorStyles.label);
                }
            }
        }
Example #4
0
        public static int TimeScrubber(Rect rect, int t, int frameRate, FrameRange range)
        {
            //		Rect actualRect = rect;
            //		actualRect.xMax -= 20; // buffer on the right

            Rect clickRect = rect;

            clickRect.yMin = clickRect.yMax - TIMELINE_SCRUBBER_HEIGHT;

            int length = range.Length;

            int controlId = EditorGUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.type)
            {
            case EventType.Repaint:
                int frames = range.Start;

                float width = rect.width;

                int maxFramesBetweenSteps = Mathf.Max(1, Mathf.FloorToInt(width / MIN_PIXELS_BETWEEN_FRAMES));

                int numFramesPerStep = Mathf.Max(1, length / maxFramesBetweenSteps);

                // multiple of 60 fps?
                if (numFramesPerStep < 30)
                {
                    if (numFramesPerStep <= 12)
                    {
                        if (numFramesPerStep != 5)
                        {
                            if (12 % numFramesPerStep != 0)
                            {
                                numFramesPerStep = 12;
                            }
                        }
                    }
                    else
                    {
                        numFramesPerStep = 30;
                    }
                }
                else if (numFramesPerStep < 60)
                {
                    numFramesPerStep = 60;
                }
                else
                {
                    int multiplesOf60 = numFramesPerStep / 60;
                    numFramesPerStep = (multiplesOf60 + 1) * 60;
                }

                int numFramesIter = numFramesPerStep < 30 ? 1 : numFramesPerStep / 10;

                Vector3 pt = new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0);

                Rect backgroundRect = clickRect;
                backgroundRect.xMin  = 0;
                backgroundRect.xMax += FSequenceEditor.RIGHT_BORDER;

//				GUI.color = new Color( 0.15f, 0.15f, 0.15f, 1f );//FGUI.GetTimelineColor();
//				GUI.DrawTexture( backgroundRect, EditorGUIUtility.whiteTexture );
//				GUI.color = Color.white;
                GUI.color = GetTextColor();                 // a little darker than it is originally to stand out
                GUI.Label(backgroundRect, GUIContent.none, FGUI.GetTimeScrubberStyle());

                Handles.color = GetLineColor();

                //			int framesBetweenSteps = maxFramesBetweenSteps / (maxFramesBetweenSteps * 10 / MIN_PIXELS_BETWEEN_FRAMES);
                //			float pixelsBetweenSteps = minPixelsBetweenSteps / framesBetweenSteps;
                //
                //			Debug.Log ( maxFramesBetweenSteps + " " + minPixelsBetweenSteps + " vs " + framesBetweenSteps + " " + pixelsBetweenSteps );

                GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel);
                labelStyle.normal.textColor = Color.white;
                labelStyle.alignment        = TextAnchor.UpperCenter;

                GUI.contentColor = FGUI.GetLineColor();

                frames = (frames / numFramesIter) * numFramesIter;
                while (frames <= range.End)
                {
                    pt.x = rect.x + (width * ((float)(frames - range.Start) / length));

                    if (pt.x >= rect.x)
                    {
                        if (frames % numFramesPerStep == 0)
                        {
                            Handles.DrawLine(pt, pt - new Vector3(0, rect.height - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0));

                            GUI.Label(new Rect(pt.x - 30, pt.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(frames, frameRate), labelStyle);
                        }
                        else
                        {
                            Vector3 smallTickPt = pt;
                            smallTickPt.y -= TIMELINE_SCRUBBER_TICK_HEIGHT;
                            Handles.DrawLine(smallTickPt, smallTickPt - new Vector3(0, TIMELINE_SCRUBBER_TICK_HEIGHT, 0));
                        }
                    }

                    frames += numFramesIter;
                }

                if (t >= 0 && range.Contains(t))
                {
                    Vector3 tStart = new Vector3(rect.x + (width * ((float)(t - range.Start) / length)), rect.yMin, 0);
                    Vector3 tEnd   = tStart;
                    tEnd.y = rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT;

                    Handles.color = Color.red;
                    Handles.DrawLine(tStart, tEnd);

                    GUI.contentColor = Color.red;
                    GUI.Label(new Rect(tEnd.x - 30, tEnd.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(t, frameRate), labelStyle);
                    GUI.contentColor = FGUI.GetTextColor();
                }

                GUI.color        = Color.white;
                GUI.contentColor = Color.white;

                Handles.color = GetLineColor();

                Handles.DrawLine(new Vector3(rect.x, rect.yMin, 0), new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_HEIGHT, 0));

                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && clickRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.hotControl = controlId;
                }
                goto case EventType.MouseDrag;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    Rect touchRect = rect;
                    touchRect.yMin = touchRect.yMax - TIMELINE_SCRUBBER_HEIGHT;
                    //			if( touchRect.Contains( Event.current.mousePosition ) )
                    {
                        //				Debug.Log( (Event.current.mousePosition.x - touchRect.xMin /
                        t = Mathf.Clamp(range.Start + Mathf.RoundToInt(((Event.current.mousePosition.x - touchRect.xMin) / touchRect.width) * range.Length), range.Start, range.End);
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }
            rect.height = TIMELINE_SCRUBBER_HEIGHT;

            return(t);
        }
Example #5
0
        protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            int leftHandleId  = EditorGUIUtility.GetControlID(FocusType.Passive);
            int evtHandleId   = EditorGUIUtility.GetControlID(FocusType.Passive);
            int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            bool leftHandleVisible  = viewRange.Contains(_evt.Start);
            bool rightHandleVisible = viewRange.Contains(_evt.End);

            Rect leftHandleRect  = _eventRect; leftHandleRect.width = 4;
            Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4;

            if (leftHandleVisible && IsSelected())
            {
                EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, leftHandleId);
            }

            if (rightHandleVisible && IsSelected())
            {
                EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, rightHandleId);
            }

            switch (Event.current.type)
            {
            case EventType.Repaint:
                if (!viewRange.Overlaps(_evt.FrameRange))
                {
                    break;
                }

                GUISkin  skin       = FUtility.GetFluxSkin();
                GUIStyle eventStyle = skin.GetStyle("Event");

                GUI.color = GetColor();

                eventStyle.Draw(_eventRect, _isSelected, _isSelected, false, false);

                GUI.color = Color.white;

                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected() && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;

                    if (rightHandleVisible && rightHandleRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = rightHandleId;
//						keyframeOnSelect = evt.Start;
                        Event.current.Use();
                    }
                    else if (leftHandleVisible && leftHandleRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = leftHandleId;
//						keyframeOnSelect = evt.End;
                        Event.current.Use();
                    }
                    else if (_eventRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = evtHandleId;
                        _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - _evt.Start;

                        if (IsSelected())
                        {
                            if (Event.current.control)
                            {
                                SequenceEditor.Deselect(this);
                            }
                        }
                        else
                        {
                            if (Event.current.shift)
                            {
                                SequenceEditor.Select(this);
                            }
                            else if (!Event.current.control)
                            {
                                SequenceEditor.SelectExclusive(this);
                            }
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == evtHandleId ||
                        EditorGUIUtility.hotControl == leftHandleId ||
                        EditorGUIUtility.hotControl == rightHandleId)
                    {
                        EditorGUIUtility.hotControl = 0;
                        Event.current.Use();
                        SequenceEditor.Repaint();
                    }
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == evtHandleId)
                    {
                        int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;

                        int delta = t - _evt.Start;

                        SequenceEditor.MoveEvents(delta);

                        Event.current.Use();
                    }
                    else if (EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId)
                    {
                        int leftLimit  = 0;
                        int rightLimit = 0;

                        bool draggingStart = EditorGUIUtility.hotControl == leftHandleId;

                        if (draggingStart)
                        {
                            leftLimit  = validKeyframeRange.Start;
                            rightLimit = _evt.End - 1;
                        }
                        else
                        {
                            leftLimit  = _evt.Start + 1;
                            rightLimit = validKeyframeRange.End;
                        }


                        int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                        t = Mathf.Clamp(t, leftLimit, rightLimit);

                        int delta = t - (draggingStart ? _evt.Start : _evt.End);

                        if (draggingStart)
                        {
                            int newLength = _evt.Length - delta;
                            if (newLength < _evt.GetMinLength())
                            {
                                delta += newLength - _evt.GetMinLength();
                            }
                            if (newLength > _evt.GetMaxLength())
                            {
                                delta += newLength - _evt.GetMaxLength();
                            }
                        }
                        else
                        {
                            int newLength = _evt.Length + delta;
                            if (newLength < _evt.GetMinLength())
                            {
                                delta -= newLength - _evt.GetMinLength();
                            }
                            if (newLength > _evt.GetMaxLength())
                            {
                                delta -= newLength - _evt.GetMaxLength();
                            }
                        }

                        if (delta != 0)
                        {
                            if (draggingStart)
                            {
                                SequenceEditor.ResizeEventsLeft(delta);
                            }
                            else
                            {
                                SequenceEditor.ResizeEventsRight(delta);
                            }
                        }

                        Event.current.Use();
                    }
                }
                break;
            }
        }