WPF Multitouch DeltaManipulation Mouse events equivalent?

I have a small demo application with a grid. This grid contains an image. I use the following code to scale and translate the image with touch.

        private void manipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {

        Matrix matrix = imagematrix.Matrix;

        matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
        matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y,
            e.ManipulationOrigin.X, e.ManipulationOrigin.Y);

        imagematrix.Matrix = matrix;

        e.Handled = true;

    }

The matrix is ​​placed in the rendertransformation property on the image.

I would like to have the same functionality in another demo application without touch, but with mouse event handlers.

I tried something like this to translate to mouse movement, but its not the same :(

        protected override void OnMouseMove(MouseEventArgs e)
    {

        if (e.LeftButton == MouseButtonState.Pressed)
        {


            Vector delta = lastPoint - e.GetPosition(canvascontrol);

            Matrix matrix = PART_MATRIX.Matrix;

            if(delta.X > 0)
                matrix.OffsetX += 1;
            else
                matrix.OffsetX -= 1;

            if (delta.Y > 0)
                matrix.OffsetY += 1;
            else
                matrix.OffsetY -= 1;

            imagematrix.Matrix = matrix;

        }

        base.OnMouseMove(e);

    }

lastPoint is the first onmouseleftbuttondown point.

Thank.

+3
source share
1 answer

, , , Thumb DragDelta, Thumb , Thumb.

0

Source: https://habr.com/ru/post/1781042/


All Articles