예제 #1
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);
            }
        }