コード例 #1
0
        void DragMarker(Marker marker, int destColumn)
        {
            var markerToRemove = Document.Current.Animation.Markers.FirstOrDefault(m => m.Frame == destColumn);

            if (marker.Frame != destColumn && markerToRemove != null)
            {
                DeleteMarker.Perform(markerToRemove, false);
            }
            // Delete and add marker again, because we want to maintain the markers order.
            DeleteMarker.Perform(marker, false);
            SetProperty.Perform(marker, "Frame", destColumn);
            SetMarker.Perform(marker, true);
        }
コード例 #2
0
        void ShiftTimeline(int destColumn)
        {
            var delta = destColumn - timeline.CurrentColumn;

            if (delta > 0)
            {
                TimelineHorizontalShift.Perform(timeline.CurrentColumn, delta);
            }
            else if (delta < 0)
            {
                foreach (var node in Document.Current.Container.Nodes)
                {
                    foreach (var animator in node.Animators.Where(i => i.AnimationId == Document.Current.AnimationId).ToList())
                    {
                        RemoveKeyframeRange.Perform(animator, destColumn, timeline.CurrentColumn - 1);
                    }
                }
                foreach (var marker in Document.Current.Animation.Markers.Where(m => m.Frame >= destColumn && m.Frame < timeline.CurrentColumn).ToList())
                {
                    DeleteMarker.Perform(marker, removeDependencies: false);
                }
                TimelineHorizontalShift.Perform(destColumn, delta);
            }
        }
コード例 #3
0
        private void Stretch(IntRectangle boundaries, DragSide side, int newPos, bool stretchMarkers)
        {
            int length;

            if (side == DragSide.Left)
            {
                length = boundaries.Right - newPos - 1;
            }
            else
            {
                length = newPos - boundaries.Left - 1;
            }
            int oldLength = boundaries.Right - boundaries.Left - 1;
            var processed = new HashSet <IAnimator>();

            foreach (var animable in GridSelection.EnumerateAnimators(boundaries))
            {
                foreach (var animator in animable.Animators)
                {
                    if (animator.AnimationId != Document.Current.AnimationId || processed.Contains(animator) || !savedKeyframes.ContainsKey(animator))
                    {
                        continue;
                    }
                    processed.Add(animator);
                    IEnumerable <IKeyframe> saved = savedKeyframes[animator];
                    if (
                        side == DragSide.Left && length < oldLength ||
                        side == DragSide.Right && length > oldLength
                        )
                    {
                        saved = saved.Reverse();
                    }
                    foreach (var key in saved)
                    {
                        RemoveKeyframe.Perform(animator, key.Frame);
                    }
                    foreach (var key in saved)
                    {
                        double relpos = savedPositions[key];
                        int    newFrame;
                        if (side == DragSide.Left)
                        {
                            newFrame = (int)Math.Round(newPos + relpos * length);
                        }
                        else
                        {
                            newFrame = (int)Math.Round(boundaries.Left + relpos * length);
                        }
                        var newKey = key.Clone();
                        newKey.Frame = newFrame;
                        SetAnimableProperty.Perform(
                            animable.Host, animator.TargetPropertyPath, newKey.Value,
                            createAnimatorIfNeeded: true,
                            createInitialKeyframeForNewAnimator: false,
                            newKey.Frame
                            );
                        SetKeyframe.Perform(animable.Host, animator.TargetPropertyPath, Document.Current.AnimationId, newKey);
                    }
                }
            }
            if (stretchMarkers)
            {
                foreach (var marker in savedMarkers)
                {
                    DeleteMarker.Perform(marker, removeDependencies: false);
                }
                foreach (var marker in savedMarkers)
                {
                    double relpos = savedMarkerPositions[marker];
                    int    newFrame;
                    if (side == DragSide.Left)
                    {
                        newFrame = (int)Math.Round(newPos + relpos * length);
                    }
                    else
                    {
                        newFrame = (int)Math.Round(boundaries.Left + relpos * length);
                    }
                    var newMarker = marker.Clone();
                    newMarker.Frame = newFrame;
                    SetMarker.Perform(newMarker, removeDependencies: false);
                }
            }
        }
コード例 #4
0
        private void Stretch(Boundaries boundaries, DragSide side, int newPos, bool stretchMarkers)
        {
            int length;

            if (side == DragSide.Left)
            {
                length = boundaries.Right - newPos - 1;
            }
            else
            {
                length = newPos - boundaries.Left - 1;
            }
            int oldLength = boundaries.Right - boundaries.Left - 1;

            for (int i = boundaries.Top; i <= boundaries.Bottom; ++i)
            {
                if (!(Document.Current.Rows[i].Components.Get <NodeRow>()?.Node is IAnimationHost animable))
                {
                    continue;
                }
                foreach (var animator in animable.Animators.ToList())
                {
                    IEnumerable <IKeyframe> saved = savedKeyframes[animator];
                    if (
                        side == DragSide.Left && length < oldLength ||
                        side == DragSide.Right && length > oldLength
                        )
                    {
                        saved = saved.Reverse();
                    }
                    foreach (var key in saved)
                    {
                        RemoveKeyframe.Perform(animator, key.Frame);
                    }
                    foreach (var key in saved)
                    {
                        double relpos = savedPositions[key];
                        int    newFrame;
                        if (side == DragSide.Left)
                        {
                            newFrame = (int)Math.Round(newPos + relpos * length);
                        }
                        else
                        {
                            newFrame = (int)Math.Round(boundaries.Left + relpos * length);
                        }
                        var newKey = key.Clone();
                        newKey.Frame = newFrame;
                        SetAnimableProperty.Perform(
                            animable, animator.TargetPropertyPath, newKey.Value,
                            createAnimatorIfNeeded: true,
                            createInitialKeyframeForNewAnimator: false,
                            newKey.Frame
                            );
                        SetKeyframe.Perform(animable, animator.TargetPropertyPath, Document.Current.AnimationId, newKey);
                    }
                }
            }
            if (stretchMarkers)
            {
                foreach (var marker in savedMarkers)
                {
                    DeleteMarker.Perform(Document.Current.Container, marker, removeDependencies: false);
                }
                foreach (var marker in savedMarkers)
                {
                    double relpos = savedMarkerPositions[marker];
                    int    newFrame;
                    if (side == DragSide.Left)
                    {
                        newFrame = (int)Math.Round(newPos + relpos * length);
                    }
                    else
                    {
                        newFrame = (int)Math.Round(boundaries.Left + relpos * length);
                    }
                    var newMarker = marker.Clone();
                    newMarker.Frame = newFrame;
                    SetMarker.Perform(Document.Current.Container, newMarker, removeDependencies: false);
                }
            }
        }