Esempio n. 1
0
        // Methods
        public Vector2 Rotate(double angle)
        {
            RotateTransform xform = new RotateTransform {
                Angle = angle
            };
            Point pt = xform.TransformPoint(new Point(X, Y));

            return(new Vector2(pt.X, pt.Y));
        }
Esempio n. 2
0
        private void Rotate()
        {
            var t = new RotateTransform(RotationAngle, _rotationCenter.X, _rotationCenter.Y);

            foreach (var previewPixel in Pixels)
            {
                var point = t.TransformPoint(previewPixel.Location.X, previewPixel.Location.Y);
                previewPixel.Location = point;
            }
        }
Esempio n. 3
0
        private void RotateDragPoints()
        {
            RotateTransform t = new RotateTransform(RotationAngle, _rotationCenter.X, _rotationCenter.Y);

            for (int i = 0; i < _dragPoints.Count; i++)
            {
                var p = t.TransformPoint(_dragPoints[i].X, _dragPoints[i].Y);
                _dragPoints[i].X = p.X;
                _dragPoints[i].Y = p.Y;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the rotated rect.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <param name="rotate">The rotate.</param>
        /// <returns></returns>
        public Rect GetRotatedRect(Rect rect, RotateTransform rotate)
        {
#if !WINRT
            Point  leftTop     = rotate.Transform(new Point(rect.Left, rect.Top));
            Point  rightTop    = rotate.Transform(new Point(rect.Right, rect.Top));
            Point  leftBottom  = rotate.Transform(new Point(rect.Left, rect.Bottom));
            Point  rightBottom = rotate.Transform(new Point(rect.Right, rect.Bottom));
            double left        = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X));
            double top         = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y));
            double right       = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X));
            double bottom      = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y));
            return(new Rect(left, top, right - left, bottom - top));
#else
            Point  leftTop     = rotate.TransformPoint(new Point(rect.Left, rect.Top));
            Point  rightTop    = rotate.TransformPoint(new Point(rect.Right, rect.Top));
            Point  leftBottom  = rotate.TransformPoint(new Point(rect.Left, rect.Bottom));
            Point  rightBottom = rotate.TransformPoint(new Point(rect.Right, rect.Bottom));
            double left        = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X));
            double top         = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y));
            double right       = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X));
            double bottom      = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y));
            return(new Rect(left, top, right - left, bottom - top));
#endif
        }
Esempio n. 5
0
        async void ManipulateMe_ManipulationStarted(object sender, Windows.UI.Xaml.Input.ManipulationStartedRoutedEventArgs e)
        {
            try
            {
                Point point = new Point(
                    e.Position.X,
                    e.Position.Y);

                TransformGroup     group = new TransformGroup();
                TranslateTransform tempTranslateTransform = new TranslateTransform();
                tempTranslateTransform.X = _transform.CenterX;
                tempTranslateTransform.Y = _transform.CenterY;

                RotateTransform tempRotateTransform = new RotateTransform();
                tempRotateTransform.CenterX = _transform.CenterX;
                tempRotateTransform.CenterY = _transform.CenterY;
                tempRotateTransform.Angle   = _transform.Rotation;

                group.Children.Add(tempTranslateTransform);
                group.Children.Add(tempRotateTransform);

                Point center     = tempRotateTransform.TransformPoint(e.Position);
                Point localPoint = group.Inverse.TransformPoint(center);

                localPoint.X *= _transform.ScaleX;
                localPoint.Y *= _transform.ScaleY;

                Point worldPoint = group.TransformPoint(localPoint);

                Point distance = new Point(
                    worldPoint.X - point.X,
                    worldPoint.Y - point.Y);

                _transform.TranslateX += distance.X;
                _transform.TranslateY += distance.Y;

                _transform.CenterX = point.X;
                _transform.CenterY = point.Y;
            }
            catch (Exception ex)
            {
            }
        }
        void OnCompositionTargetRendering(object sender, object args)
        {
            // Get elapsed seconds since app began
            TimeSpan timeSpan = (args as RenderingEventArgs).RenderingTime;
            double   seconds  = timeSpan.TotalSeconds;

            // Calculate rotation angle
            rotate.Angle = (360 * seconds / 5) % 360;

            // Calculate color and brush
            Color  clr;
            double fraction = 6 * (seconds % 10) / 10;

            if (fraction < 1)
            {
                clr = Color.FromArgb(255, 255, (byte)(fraction * 255), 0);
            }
            else if (fraction < 2)
            {
                clr = Color.FromArgb(255, (byte)(255 - (fraction - 1) * 255), 255, 0);
            }
            else if (fraction < 3)
            {
                clr = Color.FromArgb(255, 0, 255, (byte)((fraction - 2) * 255));
            }
            else if (fraction < 4)
            {
                clr = Color.FromArgb(255, 0, (byte)(255 - (fraction - 3) * 255), 255);
            }
            else if (fraction < 5)
            {
                clr = Color.FromArgb(255, (byte)((fraction - 4) * 255), 0, 255);
            }
            else
            {
                clr = Color.FromArgb(255, 255, 0, (byte)(255 - (fraction - 5) * 255));
            }

            (pageTitle.Foreground as SolidColorBrush).Color = clr;

            // All done if nobody's touching
            if (fingerTouches.Count == 0)
            {
                return;
            }

            bool bitmapNeedsUpdate = false;

            foreach (FingerInfo fingerInfo in fingerTouches.Values)
            {
                // Find point relative to rotated bitmap
                inverseRotate.Angle = -rotate.Angle;
                Point point1 = inverseRotate.TransformPoint(fingerInfo.ThisPosition);

                if (!Double.IsPositiveInfinity(fingerInfo.LastPosition.X))
                {
                    Point point2    = fingerInfo.LastPosition;
                    float thickness = 12;

                    // Draw the lines
                    surfaceImageSourceRenderer.DrawLine(point1, point2, clr, thickness);
                    surfaceImageSourceRenderer.DrawLine(new Point(dimension - point1.X, point1.Y),
                                                        new Point(dimension - point2.X, point2.Y),
                                                        clr, thickness);
                    surfaceImageSourceRenderer.DrawLine(new Point(point1.X, dimension - point1.Y),
                                                        new Point(point2.X, dimension - point2.Y),
                                                        clr, thickness);
                    surfaceImageSourceRenderer.DrawLine(new Point(dimension - point1.X,
                                                                  dimension - point1.Y),
                                                        new Point(dimension - point2.X,
                                                                  dimension - point2.Y),
                                                        clr, thickness);
                    bitmapNeedsUpdate = true;
                }
                fingerInfo.LastPosition = point1;
            }

            // Update bitmap
            if (bitmapNeedsUpdate)
            {
                surfaceImageSourceRenderer.Update();
            }
        }
Esempio n. 7
0
        /// <inheritdoc />
        public override void MouseMove(int x, int y, int changeX, int changeY)
        {
            var rt    = new RotateTransform(-RotationAngle, _rotationCenter.X, _rotationCenter.Y);
            var point = rt.TransformPoint(x, y);

            //See if we're resizing
            if (_selectionPoint != null && (_selectionPoint.PointType == PreviewPoint.PointTypes.Size || _selectionPoint.PointType == PreviewPoint.PointTypes.Rotate))
            {
                //We are resizing, so figure our change and scale the points.
                if (_selectionPoint == _dragPoints[0])
                {
                    //Top Left
                    var newHeight = Bounds.Height + (Bounds.TopLeft.Y - point.Y);
                    var newWidth  = Bounds.Width + (Bounds.TopLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }
                    Layout();

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[2].X), ZoomCoordToOriginal(_dragPoints[2].Y));

                    _selectionPoint = _dragPoints[0];
                }
                else if (_selectionPoint == _dragPoints[1])
                {
                    //Top Right
                    var newHeight = Bounds.Height + (Bounds.TopRight.Y - point.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.TopRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[3].X), ZoomCoordToOriginal(_dragPoints[3].Y));
                    Layout();

                    _selectionPoint = _dragPoints[1];
                }
                else if (_selectionPoint == _dragPoints[2])
                {
                    //Bottom Right
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomRight.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.BottomRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height:1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width:1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[0].X), ZoomCoordToOriginal(_dragPoints[0].Y));
                    Layout();

                    _selectionPoint = _dragPoints[2];
                }
                else if (_selectionPoint == _dragPoints[3])
                {
                    //Bottom Left
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomLeft.Y);
                    var newWidth  = Bounds.Width + (Bounds.BottomLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[1].X), ZoomCoordToOriginal(_dragPoints[1].Y));
                    Layout();

                    _selectionPoint = _dragPoints[3];
                }
                else if (_selectionPoint == _dragPoints[4])
                {
                    //We are rotating!
                    double angle = GetAngle(_rotationCenter, new Point(x, y));
                    RotationAngle   = (int)Math.Round(angle, MidpointRounding.AwayFromZero);
                    _selectionPoint = _dragPoints[4];
                }
            }
            else
            {
                var newX = _p1Start.X + changeX;
                var newY = _p1Start.Y + changeY;
                MoveTo(newX, newY);
            }
        }
Esempio n. 8
0
        /// <inheritdoc />
        public override void MouseMove(int x, int y, int changeX, int changeY)
        {
            var rt    = new RotateTransform(-RotationAngle, _rotationCenter.X, _rotationCenter.Y);
            var point = rt.TransformPoint(x, y);

            //See if we're resizing
            if (_selectionPoint != null && (_selectionPoint.PointType == PreviewPoint.PointTypes.Size || _selectionPoint.PointType == PreviewPoint.PointTypes.Rotate))
            {
                //We are resizing, so figure our change and scale the points.
                if (_selectionPoint == _dragPoints[0])
                {
                    //Top Left
                    var newHeight = Bounds.Height + (Bounds.TopLeft.Y - point.Y);
                    var newWidth  = Bounds.Width + (Bounds.TopLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }
                    Layout();

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[2].X), ZoomCoordToOriginal(_dragPoints[2].Y));

                    _selectionPoint = _dragPoints[0];
                }
                else if (_selectionPoint == _dragPoints[1])
                {
                    //Top Right
                    var newHeight = Bounds.Height + (Bounds.TopRight.Y - point.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.TopRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[3].X), ZoomCoordToOriginal(_dragPoints[3].Y));
                    Layout();

                    _selectionPoint = _dragPoints[1];
                }
                else if (_selectionPoint == _dragPoints[2])
                {
                    //Bottom Right
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomRight.Y);
                    var newWidth  = Bounds.Width + (point.X - Bounds.BottomRight.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height:1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width:1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[0].X), ZoomCoordToOriginal(_dragPoints[0].Y));
                    Layout();

                    _selectionPoint = _dragPoints[2];
                }
                else if (_selectionPoint == _dragPoints[3])
                {
                    //Bottom Left
                    var newHeight = Bounds.Height + (point.Y - Bounds.BottomLeft.Y);
                    var newWidth  = Bounds.Width + (Bounds.BottomLeft.X - point.X);

                    var minSize = ClampSize();
                    var scaleY  = newHeight > minSize ? newHeight / Bounds.Height : 1;
                    var scaleX  = newWidth > minSize ? newWidth / Bounds.Width : 1;

                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        scaleX = scaleY = MaxValue(scaleX, scaleY);
                    }

                    Scale(scaleX, scaleY, ZoomCoordToOriginal(_dragPoints[1].X), ZoomCoordToOriginal(_dragPoints[1].Y));
                    Layout();

                    _selectionPoint = _dragPoints[3];
                }
                else if (_selectionPoint == _dragPoints[4])
                {
                    //We are rotating!
                    double angle = GetAngle(_rotationCenter, new Point(x, y));

                    // Use Detents of 0, 45, 90, 135, 180, 225, 270 and 315 when holding the Shift modifier key down.
                    if (Control.ModifierKeys == Keys.Control)
                    {
                        if (angle >= 22.5 && angle < 67.5)
                        {
                            angle = 45;
                        }
                        else if (angle >= 67.5 && angle < 112.5)
                        {
                            angle = 90;
                        }
                        else if (angle >= 112.5 && angle < 157.5)
                        {
                            angle = 135;
                        }
                        else if (angle >= 157.5 && angle < 202.5)
                        {
                            angle = 180;
                        }
                        else if (angle >= 202.5 && angle < 247.5)
                        {
                            angle = 225;
                        }
                        else if (angle >= 247.5 && angle < 292.5)
                        {
                            angle = 270;
                        }
                        else if (angle >= 292.5 && angle < 337.5)
                        {
                            angle = 315;
                        }
                        else if (angle >= 337.5 || angle < 22.5)
                        {
                            angle = 0;
                        }
                    }

                    RotationAngle   = (int)Math.Round(angle, MidpointRounding.AwayFromZero);
                    _selectionPoint = _dragPoints[4];
                }
            }
            else
            {
                var newX = _p1Start.X + changeX;
                var newY = _p1Start.Y + changeY;
                MoveTo(newX, newY);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Gets the rotated rect.
 /// </summary>
 /// <param name="rect">The rect.</param>
 /// <param name="rotate">The rotate.</param>
 /// <returns></returns>
 public Rect GetRotatedRect(Rect rect, RotateTransform rotate)
 {
     #if !WINRT
     Point leftTop = rotate.Transform(new Point(rect.Left, rect.Top));
     Point rightTop = rotate.Transform(new Point(rect.Right, rect.Top));
     Point leftBottom = rotate.Transform(new Point(rect.Left, rect.Bottom));
     Point rightBottom = rotate.Transform(new Point(rect.Right, rect.Bottom));
     double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X));
     double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y));
     double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X));
     double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y));
     return new Rect(left, top, right - left, bottom - top);
     #else
     Point leftTop = rotate.TransformPoint(new Point(rect.Left, rect.Top));
     Point rightTop = rotate.TransformPoint(new Point(rect.Right, rect.Top));
     Point leftBottom = rotate.TransformPoint(new Point(rect.Left, rect.Bottom));
     Point rightBottom = rotate.TransformPoint(new Point(rect.Right, rect.Bottom));
     double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X));
     double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y));
     double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X));
     double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y));
     return new Rect(left, top, right - left, bottom - top);
     #endif
 }
Esempio n. 10
0
        async void ManipulateMe_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            try
            {
                Point point = new Point(
                    e.Position.X,
                    e.Position.Y);

                TransformGroup     group = new TransformGroup();
                TranslateTransform tempTranslateTransform = new TranslateTransform();
                tempTranslateTransform.X = _transform.CenterX;
                tempTranslateTransform.Y = _transform.CenterY;

                RotateTransform tempRotateTransform = new RotateTransform();
                tempRotateTransform.CenterX = _transform.CenterX;
                tempRotateTransform.CenterY = _transform.CenterY;
                tempRotateTransform.Angle   = _transform.Rotation;

                group.Children.Add(tempTranslateTransform);
                group.Children.Add(tempRotateTransform);

                Point center     = tempRotateTransform.TransformPoint(e.Position);
                Point localPoint = group.Inverse.TransformPoint(center);

                localPoint.X *= _transform.ScaleX;
                localPoint.Y *= _transform.ScaleY;

                Point worldPoint = group.TransformPoint(localPoint);

                Point distance = new Point(
                    worldPoint.X - point.X,
                    worldPoint.Y - point.Y);


                _transform.TranslateX += distance.X;
                _transform.TranslateY += distance.Y;

                CurrentZoomScale = _transform.ScaleY = _transform.ScaleX *= e.Delta.Scale;


                if (_transform.Rotation > 360)
                {
                    _transform.Rotation -= 360;
                }
                else if (_transform.Rotation < -360)
                {
                    _transform.Rotation += 360;
                }
                RotationOffset = _transform.Rotation += e.Delta.Rotation;


                _transform.CenterX = point.X;
                _transform.CenterY = point.Y;

                DebugDot.RenderTransform = new TranslateTransform()
                {
                    X = point.X,
                    Y = point.Y
                };



                Rect desktopBounds = BoundsRelativeTo(Outer, LayoutRoot);

                double zoomRatio       = Outer.ActualWidth / desktopBounds.Width;
                double zoomRatioInvert = desktopBounds.Width / Outer.ActualWidth;

                double edgeBufferYPadding = 0;



                if (desktopBounds.X < LayoutRoot.ActualWidth / 2 && desktopBounds.Right > LayoutRoot.ActualWidth / 2)
                {
                    _transform.TranslateX += e.Delta.Translation.X;
                }
                if (desktopBounds.X > LayoutRoot.ActualWidth / 2)
                {
                    _transform.TranslateX += e.Delta.Translation.X - (desktopBounds.X - (LayoutRoot.ActualWidth / 2) - 1);
                }
                if (desktopBounds.Right < LayoutRoot.ActualWidth / 2)
                {
                    _transform.TranslateX += e.Delta.Translation.X - (desktopBounds.Right - (LayoutRoot.ActualWidth / 2) - 1);
                }

                if (desktopBounds.Y + edgeBufferYPadding < LayoutRoot.ActualHeight / 2 && desktopBounds.Bottom - edgeBufferYPadding * zoomRatio > LayoutRoot.ActualHeight / 2)
                {
                    _transform.TranslateY += e.Delta.Translation.Y;
                }
                if (desktopBounds.Y + edgeBufferYPadding * zoomRatio > LayoutRoot.ActualHeight / 2)
                {
                    _transform.TranslateY += e.Delta.Translation.Y - (desktopBounds.Y + edgeBufferYPadding - (LayoutRoot.ActualHeight / 2) - 1);
                }
                if (desktopBounds.Bottom - edgeBufferYPadding < LayoutRoot.ActualHeight / 2)
                {
                    _transform.TranslateY += e.Delta.Translation.Y - (desktopBounds.Bottom - edgeBufferYPadding - (LayoutRoot.ActualHeight / 2) - 1);
                }
            }
            catch (Exception ex)
            {
            }
        }