Exemple #1
0
        private void InputElement_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            if (!IsManipulating && ManageCursor)
            {
                if (e.OriginalSource is UIElement sourceElement)
                {
                    var testArgs = HandleElementTest(sourceElement);
                    if (!testArgs.CanMove && !testArgs.CanResize)
                    {
                        SetCursorIfNeed(sourceElement, MoveUtility.GetCursor(RectManipulations.None));
                        return;
                    }

                    var inputRect     = new Rect(sourceElement.RenderSize);
                    var inputPoint    = e.GetPosition(sourceElement);
                    var manipulations = MoveUtility.GetRectManipulations(inputRect, inputPoint, testArgs.ResizeBorderPadding, testArgs.CanMove, testArgs.CanResize);

                    SetCursorIfNeed(sourceElement, MoveUtility.GetCursor(manipulations));
                }
            }
            else if (IsManipulating && e.LeftButton == MouseButtonState.Pressed)
            {
                var mousePos = MouseInfo.GetCursorPosition();
                MoveUtility.GetManipulationsVectors(CurrentInfo.Manipulations, mousePos, CurrentInfo.PrevMousePos, out var positionVector, out var sizeVector);
                CurrentInfo.PrevMousePos = mousePos;

                if (positionVector.Length != 0 || sizeVector.Length != 0)
                {
                    if (!HandlePerformManipulation(CurrentInfo.SourceElement, CurrentInfo.Manipulations, sizeVector, positionVector))
                    {
                        ReleaseCurrentManipulation();
                    }
                }

                e.Handled = true;
            }
        }
Exemple #2
0
        private void InputElement_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            if (!IsManipulating && e.LeftButton == MouseButtonState.Pressed)
            {
                if (e.OriginalSource is UIElement sourceElement)
                {
                    var testArgs = HandleElementTest(sourceElement);
                    if (!testArgs.CanMove && !testArgs.CanResize)
                    {
                        return;
                    }

                    var inputRect     = new Rect(sourceElement.RenderSize);
                    var inputPoint    = e.GetPosition(sourceElement);
                    var manipulations = MoveUtility.GetRectManipulations(inputRect, inputPoint, testArgs.ResizeBorderPadding, testArgs.CanMove, testArgs.CanResize);

                    if (manipulations != RectManipulations.None)
                    {
                        if (!HandleBeginManipulation(sourceElement, manipulations))
                        {
                            return;
                        }

                        if (!sourceElement.CaptureMouse())
                        {
                            HandleReleaseManipulation(sourceElement, manipulations);
                            return;
                        }

                        CurrentInfo = new MoverManipulationInfo(sourceElement, manipulations, MouseInfo.GetCursorPosition());
                        SetCursorIfNeed(sourceElement, MoveUtility.GetCursor(manipulations));

                        e.Handled = true;
                    }
                }
            }
        }