private Keyframe GetLastKeyframe(long tick)
 => tick > StartTick && Keyframes.Any(x => x.Tick < tick)
         ? Keyframes
 .Where(x => x.Tick < tick)
 .OrderBy(x => Math.Abs(x.Tick - tick))
 .FirstOrDefault()
         : Keyframe.GetDefault(StartTick);
Beispiel #2
0
        public Matrix GetAbsoluteTransformAtTime(float time)
        {
            Matrix parentTransform = Matrix.Identity;

            if (Parent != null)
            {
                parentTransform = Parent.GetAbsoluteTransformAtTime(time);
            }

            Matrix transform = Transform;

            if (Keyframes.Any())
            {
                var framesBefore = Keyframes.Where(x => x.Time < time);
                var framesAfter  = Keyframes.Where(x => x.Time > time);
                var frame1       = framesBefore.Any() ? framesBefore.Last() : Keyframes.First();
                var frame2       = framesAfter.Any() ? framesAfter.First() : Keyframes.Last();

                transform = Matrix.Lerp(frame1.Transform, frame2.Transform, Math.Min((time - frame1.Time) / (float)(frame2.Time - frame1.Time), 1f)) * Transform;
            }

            return(transform * parentTransform);
        }
Beispiel #3
0
        /// <summary>
        /// Event raised when the mouse is released on a keyframe.
        /// </summary>
        private void Keyframe_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (isLeftMouseDownOnKeyframe)
            {
                FrameworkElement  keyframe          = (FrameworkElement)sender;
                KeyframeViewModel keyframeViewModel = (KeyframeViewModel)keyframe.DataContext;

                if (!isDraggingKeyframe)
                {
                    //
                    // Execute mouse up selection logic only if there was no drag operation.
                    //
                    if (isLeftMouseAndControlDownOnKeyframe)
                    {
                        //
                        // Control key was held down.
                        // Toggle the selection.
                        //
                        if (this.listBox.SelectedItems.Contains(keyframeViewModel))
                        {
                            //
                            // Item was already selected, control-click removes it from the selection.
                            //
                            this.listBox.SelectedItems.Remove(keyframeViewModel);
                        }
                        else
                        {
                            //
                            // Item was not already selected, control-click adds it to the selection.
                            //
                            this.listBox.SelectedItems.Add(keyframeViewModel);
                        }
                    }
                    else
                    {
                        //
                        // Control key was not held down.
                        //
                        if (this.listBox.SelectedItems.Count == 1 &&
                            this.listBox.SelectedItem == keyframeViewModel)
                        {
                            //
                            // The item that was clicked is already the only selected item.
                            // Don't need to do anything.
                            //
                        }
                        else
                        {
                            //
                            // Clear the selection and select the clicked item as the only selected item.
                            //
                            this.listBox.SelectedItems.Clear();
                            this.listBox.SelectedItems.Add(keyframeViewModel);
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("Frames Moved " + currentOperationFramesDragged);
                    bool hasKeyConflict = false;

                    foreach (KeyframeViewModel key in this.listBox.SelectedItems)
                    {
                        int newTime = key.Time + currentOperationFramesDragged;
                        if (Keyframes.Any(x => x.Time == newTime))
                        {
                            hasKeyConflict = true;
                        }
                        key.IsDragging = false;
                    }

                    //Check if we can just move the keys or if we need to prompt the user
                    if (!hasKeyConflict)
                    {
                    }
                    else
                    {
                        MessageBoxResult confirmBox = MessageBox.Show("One or more of the dragged keyframes will overwrite an existing keyframe", "Overwrite keyframes", MessageBoxButton.OKCancel);

                        if (confirmBox == MessageBoxResult.Yes)
                        {
                            Debug.WriteLine("Overwriting");
                        }
                        else
                        {
                            Debug.WriteLine("Dont overwrite");
                            double stepSize = (ActualWidth - keyFrameTicksPadding * 2) / (TimeRangeEnd - TimeRangeStart);
                            //TODO Fix with Time instead of explicit offset
                            //foreach (KeyframeViewModel key in this.listBox.SelectedItems)
                            //{

                            //    key.TimelinePositionX = stepSize * currentOperationFramesDragged;
                            //}
                        }
                    }
                }

                keyframe.ReleaseMouseCapture();
                isLeftMouseDownOnKeyframe           = false;
                isLeftMouseAndControlDownOnKeyframe = false;

                e.Handled = true;
            }

            isDraggingKeyframe            = false;
            currentDeltaStepDistance      = 0;
            currentOperationFramesDragged = 0;
        }