Exemple #1
0
        private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point point = e.GetPosition(Center);

            X = point.X;
            Y = point.Y;

            if (sender is Path)
            {
                Path arrow = (Path)sender;
                if (arrow.Name == "XManipulator")
                {
                    DraggingX = true;
                }
                else
                {
                    DraggingY = true;
                }
                IsHitTestVisible = false;
                TransformationChanged?.Invoke(this, TransformationEvent.TranslationStarted);
            }
            else if (sender is Rectangle)
            {
                DraggingX        = true;
                DraggingY        = true;
                IsHitTestVisible = false;
                TransformationChanged?.Invoke(this, TransformationEvent.TranslationStarted);
            }
            else
            {
                e.MouseDevice.Capture((UIElement)sender);
                IsRotating = true;
                TransformationChanged?.Invoke(this, TransformationEvent.RotationStarted);
            }
        }
Exemple #2
0
 private void Ellipse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (DraggingX || DraggingY)
     {
         TransformationChanged?.Invoke(this, TransformationEvent.TranslationEnded);
     }
     else
     {
         TransformationChanged?.Invoke(this, TransformationEvent.RotationEnded);
     }
     IsRotating = false;
     DraggingX  = false;
     DraggingY  = false;
     e.MouseDevice.Capture(null);
 }
 private void OnTransformationChanged(object sender, EventArgs e) => TransformationChanged?.Invoke(this, EventArgs.Empty);
        private void CalculateMatrix()
        {
            PhysicalObject parent = null;

            Matrix     = Matrix.Identity;
            DrawMatrix = Matrix.Identity;
            Vector2 scaledSize = ScaledSize;

            // - Check if we have a parent
            if (Parent != null && Parent is PhysicalObject)
            {
                parent = Parent as PhysicalObject;
            }

            // - Apply rotation to the matrix
            {
                Vector2 rotationCenter = -ComputeAnchorPosition(scaledSize, RotationCustomCenter, RotationCenter);

                var matrix = Matrix.CreateTranslation(rotationCenter.X, rotationCenter.Y, 0);
                Matrix *= Matrix.CreateRotationZ(Rotation);
                Matrix *= Matrix.CreateTranslation(-rotationCenter.X, -rotationCenter.Y, 0);
            }

            // - Create translation to requests point
            {
                Vector2 finalPosition = Position;
                if (parent != null)
                {
                    // - Apply origin point
                    finalPosition *= ComputeVectorDir(Anchor, Origin);
                    finalPosition += ComputeAnchorPosition(parent.ScaledSize, CustomOrigin, Origin);
                }

                // - Apply anchor point
                finalPosition -= ComputeAnchorPosition(scaledSize, CustomAnchor, Anchor);

                // - Calculate matrix
                Matrix *= Matrix.CreateTranslation(finalPosition.X, finalPosition.Y, 0);
            }

            // - Scale with parent
            if (parent != null && ScaleWithParent)
            {
                Vector2 scaleReference   = parent.ScaleReference;
                Vector2 parentScaledSize = parent.ScaledSize;
                Vector2 scaleFactor      = parentScaledSize / scaleReference;
                Matrix *= Matrix.CreateScale(scaleFactor.X, scaleFactor.Y, 0);
            }

            // - If we have a parent do relative transformation
            if (parent != null)
            {
                Matrix *= parent.Matrix;
            }

            // - Set object size
            DrawMatrix *= Matrix.CreateScale(scaledSize.Width, scaledSize.Y, 0) * Matrix;
            DrawMatrix *= ToRelativeFloat;

            MatrixInverse = Matrix.Invert(Matrix);

            TransformationChanged?.Invoke(this, EventArgs.Empty);
        }