public IEnumerator <object> Task()
        {
            var input = timeline.Overview.RootWidget.Input;

            while (true)
            {
                if (input.WasMouseReleased(1) || input.WasKeyPressed(Key.Mouse0DoubleClick))
                {
                    var pos          = timeline.Overview.ContentWidget.LocalMousePosition();
                    var offset       = pos - timeline.Grid.Size / 2;
                    var maxScrollPos = Vector2.Max(Vector2.Zero, timeline.Grid.ContentSize - timeline.Grid.Size);
                    timeline.Offset = Vector2.Clamp(offset, Vector2.Zero, maxScrollPos);
                    Document.Current.History.DoTransaction(() => {
                        var col = (input.MousePosition.X / (TimelineMetrics.ColWidth * timeline.Overview.ContentWidget.Scale.X)).Round();
                        SetCurrentColumn.Perform(col);
                    });
                }
                if (input.WasMousePressed())
                {
                    var originalMousePosition = input.MousePosition;
                    var scrollPos             = timeline.Offset;
                    while (input.IsMousePressed())
                    {
                        var mouseDelta   = input.MousePosition - originalMousePosition;
                        var scrollDelta  = Vector2.Round(mouseDelta / timeline.Overview.ContentWidget.Scale);
                        var maxScrollPos = Vector2.Max(Vector2.Zero, timeline.Grid.ContentSize - timeline.Grid.Size);
                        timeline.Offset = Vector2.Clamp(scrollPos + scrollDelta, Vector2.Zero, maxScrollPos);
                        yield return(null);
                    }
                }
                yield return(null);
            }
        }
        private IEnumerator <object> Drag(IntRectangle boundaries, DragSide side)
        {
            IntVector2?last = null;

            Save(boundaries);
            bool isStretchingMarkers = input.IsKeyPressed(Key.Control);

            using (Document.Current.History.BeginTransaction()) {
                while (input.IsMousePressed())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.SizeWE);
                    var current = grid.CellUnderMouse();
                    if (current == last)
                    {
                        yield return(null);

                        continue;
                    }
                    Document.Current.History.RollbackTransaction();
                    current.X = Math.Max(current.X, 0);
                    if (side == DragSide.Left)
                    {
                        current.X = Math.Min(current.X, boundaries.Right - 1);
                    }
                    else
                    {
                        current.X = Math.Max(current.X, boundaries.Left + 1);
                    }
                    Stretch(boundaries, side, current.X, stretchMarkers: isStretchingMarkers);
                    if (side == DragSide.Left)
                    {
                        boundaries.Left = current.X;
                    }
                    else
                    {
                        boundaries.Right = current.X;
                    }
                    ClearGridSelection.Perform();
                    for (int i = boundaries.Top; i <= boundaries.Bottom; ++i)
                    {
                        SelectGridSpan.Perform(i, boundaries.Left, boundaries.Right);
                    }
                    SetCurrentColumn.Perform(boundaries.Right);
                    last = current;
                    yield return(null);
                }
                Document.Current.History.CommitTransaction();
            }
            yield return(null);
        }
示例#3
0
        public IEnumerator <object> Task()
        {
            var rulerWidget = timeline.Ruler.RootWidget;
            var input       = rulerWidget.Input;

            while (true)
            {
                if (input.WasMousePressed())
                {
                    yield return(null);

                    using (Document.Current.History.BeginTransaction()) {
                        int initialCurrentColumn = CalcColumn(rulerWidget.LocalMousePosition().X);
                        Document.Current.AnimationFrame = initialCurrentColumn;
                        var saved = CoreUserPreferences.Instance.StopAnimationOnCurrentFrame;
                        // Dirty hack: prevent creating RestoreAnimationsTimesComponent
                        // in order to stop running animation on clicked frame (RBT-2887)
                        CoreUserPreferences.Instance.StopAnimationOnCurrentFrame = true;
                        SetCurrentColumn.Perform(initialCurrentColumn);
                        CoreUserPreferences.Instance.StopAnimationOnCurrentFrame = saved;
                        int  previousColumn = -1;
                        var  marker         = Document.Current.Animation.Markers.GetByFrame(initialCurrentColumn);
                        bool isShifting     = false;
                        while (input.IsMousePressed())
                        {
                            bool isEditing     = input.IsKeyPressed(Key.Control);
                            bool startShifting = isEditing && input.IsKeyPressed(Key.Shift);
                            isShifting = isShifting && startShifting;

                            var cw = TimelineMetrics.ColWidth;
                            var mp = rulerWidget.LocalMousePosition().X;
                            if (mp > rulerWidget.Width - cw / 2)
                            {
                                timeline.OffsetX += cw;
                            }
                            else if (mp < cw / 2)
                            {
                                timeline.OffsetX = Math.Max(0, timeline.OffsetX - cw);
                            }
                            int newColumn = CalcColumn(mp);
                            if (newColumn == previousColumn)
                            {
                                yield return(null);

                                continue;
                            }
                            // Evgenii Polikutin: don't Undo to avoid animation cache invalidation when just scrolling
                            // Evgenii Polikutin: yet we have to sacrifice performance when editing document
                            SetCurrentColumn.IsFrozen = !isEditing;
                            SetCurrentColumn.RollbackHistoryWithoutScrolling();
                            SetCurrentColumn.IsFrozen = false;

                            if (isEditing && !input.WasMousePressed())
                            {
                                if (isShifting)
                                {
                                    ShiftTimeline(CalcColumn(mp));
                                }
                                else if (startShifting && CalcColumn(mp) == initialCurrentColumn)
                                {
                                    isShifting = true;
                                }
                                else if (!startShifting && marker != null)
                                {
                                    DragMarker(marker, CalcColumn(mp));
                                }
                            }
                            // Evgenii Polikutin: we need operation to backup the value we need, not the previous one
                            Document.Current.AnimationFrame = initialCurrentColumn;
                            SetCurrentColumn.Perform(newColumn);
                            timeline.Ruler.MeasuredFrameDistance = timeline.CurrentColumn - initialCurrentColumn;
                            previousColumn = newColumn;
                            DockHierarchy.Instance.InvalidateWindows();
                            yield return(null);
                        }
                        Document.Current.History.CommitTransaction();
                        timeline.Ruler.MeasuredFrameDistance = 0;
                    }
                }
                yield return(null);
            }
        }
        public IEnumerator <object> Task()
        {
            var rulerWidget = timeline.Ruler.RootWidget;
            var input       = rulerWidget.Input;

            while (true)
            {
                if (input.WasMousePressed())
                {
                    Operations.SetCurrentColumn.Processor.CacheAnimationsStates = true;
                    using (Document.Current.History.BeginTransaction()) {
                        int initialColumnUnderMouse = CalcColumn(rulerWidget.LocalMousePosition().X);
                        int initialCurrentColumn    = timeline.CurrentColumn;
                        int previousColumn          = -1;
                        var marker = Document.Current.Container.Markers.GetByFrame(initialColumnUnderMouse);
                        while (input.IsMousePressed())
                        {
                            bool isEditing  = input.IsKeyPressed(Key.Control);
                            bool isShifting = isEditing && input.IsKeyPressed(Key.Shift);

                            var cw = TimelineMetrics.ColWidth;
                            var mp = rulerWidget.LocalMousePosition().X;
                            if (mp > rulerWidget.Width - cw / 2)
                            {
                                timeline.OffsetX += cw;
                            }
                            else if (mp < cw / 2)
                            {
                                timeline.OffsetX = Math.Max(0, timeline.OffsetX - cw);
                            }
                            int newColumn = CalcColumn(mp);
                            if (newColumn == previousColumn)
                            {
                                yield return(null);

                                continue;
                            }
                            // Evgenii Polikutin: don't Undo to avoid animation cache invalidation when just scrolling
                            // Evgenii Polikutin: yet we have to sacrifice performance when editing document
                            SetCurrentColumn.IsFrozen = !isEditing;
                            SetCurrentColumn.RollbackHistoryWithoutScrolling();
                            SetCurrentColumn.IsFrozen = false;

                            if (isEditing && !input.WasMousePressed())
                            {
                                if (isShifting)
                                {
                                    ShiftTimeline(CalcColumn(mp));
                                }
                                else if (marker != null)
                                {
                                    DragMarker(marker, CalcColumn(mp));
                                }
                            }
                            // Evgenii Polikutin: we need operation to backup the value we need, not the previous one
                            Document.Current.AnimationFrame = initialCurrentColumn;
                            Operations.SetCurrentColumn.Perform(CalcColumn(mp));
                            timeline.Ruler.MeasuredFrameDistance = timeline.CurrentColumn - initialColumnUnderMouse;
                            if (newColumn == initialCurrentColumn && previousColumn != initialCurrentColumn)
                            {
                                Document.ForceAnimationUpdate();
                            }
                            previousColumn = newColumn;
                            Window.Current.Invalidate();
                            yield return(null);
                        }
                        timeline.Ruler.MeasuredFrameDistance = 0;
                        Operations.SetCurrentColumn.Processor.CacheAnimationsStates = false;
                        Document.Current.History.CommitTransaction();
                    }
                }
                yield return(null);
            }
        }