コード例 #1
0
        /// <summary>
        /// Event raised when the mouse is pressed down on a keyframe.
        /// </summary>
        private void Keyframe_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }

            FrameworkElement  keyframe          = (FrameworkElement)sender;
            KeyframeViewModel keyframeViewmodel = (KeyframeViewModel)keyframe.DataContext;

            isLeftMouseDownOnKeyframe = true;

            if ((Keyboard.Modifiers & ModifierKeys.Control) != 0)
            {
                //
                // Control key was held down.
                // This means that the keyframe is being added to or removed
                // from the existing selection. Don't do anything yet,
                // we will act on this later in the MouseUp event handler.
                //
                isLeftMouseAndControlDownOnKeyframe = true;
            }
            else
            {
                //
                // Control key is not held down.
                //
                isLeftMouseAndControlDownOnKeyframe = false;

                if (this.listBox.SelectedItems.Count == 0)
                {
                    //
                    // Nothing already selected, select the item.
                    //
                    this.listBox.SelectedItems.Add(keyframeViewmodel);
                }
                else if (this.listBox.SelectedItems.Contains(keyframeViewmodel))
                {
                    //
                    // Item is already selected, do nothing.
                    // We will act on this in the MouseUp if there was no drag operation.
                    //
                }
                else
                {
                    //
                    // Item is not selected.
                    // Deselect all, and select the item.
                    //
                    this.listBox.SelectedItems.Clear();
                    this.listBox.SelectedItems.Add(keyframeViewmodel);
                }
            }

            keyframe.CaptureMouse();
            origMouseDownPoint = e.GetPosition(GridContainer);
            listBox.Focus();
            Keyboard.Focus(listBox);
            e.Handled = true;
        }
コード例 #2
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;
        }
コード例 #3
0
 private void RemoveKeyframes(KeyframeViewModel keyVM)
 {
 }
コード例 #4
0
 private void AddKeyframes(KeyframeViewModel keyVM)
 {
     keyItems.Add(keyVM);
 }