Esempio n. 1
0
        internal static Line Transform(this RotateTransform transform, Line line)
        {
            var p1 = transform.Transform(line.StartPoint);
            var p2 = transform.Transform(line.EndPoint);

            return(new Line(p1, p2));
        }
Esempio n. 2
0
        public void Rotate()
        {
            if (!IsDestroyed)
            {
                if (IsRotatingClockwise || IsRotatingCounterClockwise)
                {
                    int degrees = 0;
                    if (IsRotatingClockwise)
                    {
                        degrees = 5;
                    }
                    else if (IsRotatingCounterClockwise)
                    {
                        degrees = -5;
                    }
                    var rotation = new RotateTransform(degrees, Center.X, Center.Y);

                    PointCollection rotated = new PointCollection();
                    foreach (Point vert in Geometry.Points)
                    {
                        rotated.Add(rotation.Transform(vert));
                    }
                    Geometry.Points = rotated;
                    Trajectory      = rotation.Transform(Trajectory);
                    ThrustStart     = rotation.Transform(ThrustStart);
                    ThrustEnd       = rotation.Transform(ThrustEnd);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Draws an equilateral triangle from the given center point and rotation. Also applies the global rotation
        /// </summary>
        private void CreateTriangle(double x, double y, double rotation, int panelId, Transform globalRotationTransform)
        {
            //First assume that we draw the triangle facing up:
            //     A
            //    /\
            //   /  \
            //  /____\
            // B      C

            var A = new Point(x, y - ((Math.Sqrt(3) / 3) * _defaultTriangleSize));
            var B = new Point(x - (_defaultTriangleSize / 2), y + ((Math.Sqrt(3) / 6) * _defaultTriangleSize));
            var C = new Point(x + (_defaultTriangleSize / 2), y + ((Math.Sqrt(3) / 6) * _defaultTriangleSize));

            var rotateTransform = new RotateTransform(rotation, x, y);

            //Apply transformation and add points to polygon
            var triangle = new Polygon();

            triangle.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(A)));
            triangle.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(B)));
            triangle.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(C)));

            triangle.Stroke = _borderColor;
            triangle.HorizontalAlignment = HorizontalAlignment.Left;
            triangle.VerticalAlignment   = VerticalAlignment.Top;
            triangle.StrokeThickness     = 2;

            _unscaledTriangles.Add(new DrawablePanel
            {
                MidPoint = globalRotationTransform.Transform(new Point(x, y)),
                PanelId  = panelId,
                Polygon  = triangle
            });
        }
Esempio n. 4
0
 private void MouseAndTouchDown(Point downPoint)
 {
     oldX = ViewModel.Left;
     oldY = ViewModel.Top;
     //Transform MousePoint with the rotation to get the real x,y Point
     transformedDownLocation = rotateTransform.Transform(downPoint);
     //Signal we are moving this instance manually
     ViewModel.IsMoving = true;
 }
Esempio n. 5
0
        private PathFigure GetRotatedPathFigure(Size thermostatSize, Point start, Point end, double angle)
        {
            RotateTransform rotateTransform = GetRotateTransform(thermostatSize);

            rotateTransform.Angle = angle;
            Point rotatedStart = rotateTransform.Transform(start);
            Point rotatedEnd   = rotateTransform.Transform(end);

            return(GetPathFigure(rotatedStart, rotatedEnd));
        }
Esempio n. 6
0
        void DrawLineCap(DrawingContext dc, Point point, Vector vector,
                         PenLineCap startLineCap, PenLineCap endLineCap)
        {
            if (startLineCap == PenLineCap.Flat && endLineCap == PenLineCap.Flat)
            {
                return;
            }

            // Construct really tiny horizontal line
            vector.Normalize();
            double          angle  = Math.Atan2(vector.Y, vector.X);
            RotateTransform rotate = new RotateTransform(-180 * angle / Math.PI, point.X, point.Y);
            Point           point1 = rotate.Transform(point);
            Point           point2 = rotate.Transform(point + 0.25 * vector);

            // Construct pen for that line
            Pen pen = new Pen()
            {
                Thickness    = StrokeThickness,
                StartLineCap = startLineCap,
                EndLineCap   = endLineCap
            };

            pen.Freeze();

            // Why don't I just call dc.DrawLine at this point? Well, to avoid gaps between
            //  the tetragons, I had to draw them with an 'outlinePenWidth' pen based on the
            //  same brush as the fill. If I just called dc.DrawLine here, the caps would
            //  look a little smaller than the line, so....

            LineGeometry lineGeo = new LineGeometry(point1, point2);
            PathGeometry pathGeo = lineGeo.GetWidenedPathGeometry(pen);
            Brush        brush   = null;

            if (GradientMode == GradientMode.Perpendicular)
            {
                brush = new LinearGradientBrush(GradientStops, new Point(0, 0), new Point(0, 1));
                (brush as LinearGradientBrush).ColorInterpolationMode = ColorInterpolationMode;
            }
            else
            {
                double offset = endLineCap == PenLineCap.Flat ? 0 : 1;
                brush = new SolidColorBrush(GetColorFromGradientStops(offset));
                brush.Freeze();
            }

            pen = new Pen(brush, outlinePenWidth);
            pen.Freeze();
            rotate.Angle = 180 * angle / Math.PI;
            dc.PushTransform(rotate);
            dc.DrawGeometry(brush, pen, pathGeo);
            dc.Pop();
        }
Esempio n. 7
0
        public void IsConstrainedFalse_ParentIsRotated_ElementIsPositionedCorrectly()
        {
            Rectangle rect = CreateRectangleInGrid();
            MouseDragElementBehavior behavior  = CreateAndAttachMouseDragElementBehavior(rect);
            RotateTransform          transform = new RotateTransform(30);

            ((Grid)rect.Parent).RenderTransform = transform;
            Point startPoint = transform.Transform(new Point(5, 5));
            Point dragPoint  = transform.Transform(new Point(50, 50));

            this.PerformSingleDrag(behavior, startPoint, dragPoint);
            this.VerifyOffset(rect.RenderTransform, 45.0d, 45.0d);
        }
Esempio n. 8
0
        /// <summary>
        /// Intersects a line with a geometry to return the point of intersection
        /// </summary>
        /// <param name="node"></param>
        /// <param name="p"></param>
        /// <param name="centerVector"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static Point FindOppositePoint(PathGeometry node, Point p, Vector centerVector, Transform t)
        {
            Vector          xaxis        = new Point(1, 0) - new Point(0, 0);
            double          angleBetween = Vector.AngleBetween(centerVector, xaxis);
            RotateTransform r            = new RotateTransform(angleBetween, p.X, p.Y);
            SortedList      pointList    = new SortedList();

            for (int i = 0; i < node.Figures.Count; i++)
            {
                PathFigure pf = node.Figures[i];
                Point      lastPathFigurePoint = r.Transform(pf.StartPoint);
                for (int j = 0; j < pf.Segments.Count; j++)
                {
                    if (pf.Segments[j] is PolyLineSegment)
                    {
                        PolyLineSegment pls = (PolyLineSegment)pf.Segments[j];
                        for (int k = 0; k < pls.Points.Count; k++)
                        {
                            Point point1 = r.Transform(pls.Points[k]);
                            CheckLineSegmentForIntersection(p, point1, lastPathFigurePoint, pointList);
                            lastPathFigurePoint = point1;
                        }
                    }
                    else if (pf.Segments[j] is LineSegment)
                    {
                        LineSegment ls = (LineSegment)pf.Segments[j];
                        Point       p1 = r.Transform(ls.Point);
                        Point       p2 = lastPathFigurePoint;
                        lastPathFigurePoint = p1;
                        CheckLineSegmentForIntersection(p, p1, p2, pointList);
                    }
                }
            }
            if (pointList.Count < 1)
            {
                return(centerVector + p);
            }
            Point returnPt = new Point((double)pointList.GetByIndex(0), p.Y);

            r.Angle  = -1 * angleBetween;
            returnPt = r.Transform(returnPt);
            Vector finalVector = returnPt - p;

            if (finalVector.Length > centerVector.Length)
            {
                return(centerVector + p);
            }
            return(returnPt);
        }
Esempio n. 9
0
        private void DrawLineCap(
            DrawingContext dc,
            Line line,
            PenLineCap startLineCap,
            PenLineCap endLineCap)
        {
            if (startLineCap == PenLineCap.Flat && endLineCap == PenLineCap.Flat)
            {
                return;
            }
            var point = endLineCap == PenLineCap.Flat ? line.StartPoint : line.EndPoint;
            // Construct really tiny horizontal line
            var angle  = Math.Atan2(line.Direction.Y, line.Direction.X);
            var rotate = new RotateTransform(-180 * angle / Math.PI, point.X, point.Y);
            var point1 = rotate.Transform(point);
            var point2 = rotate.Transform(point + 0.25 * line.Direction);

            // Construct pen for that line
            var pen = new Pen()
            {
                Thickness = this.StrokeThickness, StartLineCap = startLineCap, EndLineCap = endLineCap
            };

            // Why don't I just call dc.DrawLine at this point? Well, to avoid gaps between
            //  the tetragons, I had to draw them with an 'outlinePenWidth' pen based on the
            //  same brush as the fill. If I just called dc.DrawLine here, the caps would
            //  look a little smaller than the line, so....

            var   lineGeo = new LineGeometry(point1, point2);
            var   pathGeo = lineGeo.GetWidenedPathGeometry(pen);
            Brush brush;

            if (this.GradientMode == GradientMode.Perpendicular)
            {
                brush = new LinearGradientBrush(this.GradientStops, new Point(0, 0), new Point(0, 1));
                ((LinearGradientBrush)brush).ColorInterpolationMode = this.ColorInterpolationMode;
            }
            else
            {
                double offset = endLineCap == PenLineCap.Flat ? 0 : 1;
                brush = new SolidColorBrush(this.GradientStops.GetColorAt(offset, this.ColorInterpolationMode));
            }

            pen          = new Pen(brush, 0);
            rotate.Angle = 180 * angle / Math.PI;
            dc.PushTransform(rotate);
            dc.DrawGeometry(brush, pen, pathGeo);
            dc.Pop();
        }
Esempio n. 10
0
        private void GetMoveOffset(DragDeltaEventArgs e, ref double xOffset, ref double yOffset)
        {
            System.Windows.Point dragDelta       = new System.Windows.Point(e.HorizontalChange, e.VerticalChange);
            RotateTransform      rotateTransform = designerItem.RenderTransform as RotateTransform;

            if (rotateTransform != null)
            {
                dragDelta = rotateTransform.Transform(dragDelta);
                //Rect rec = rotateTransform.TransformBounds(new Rect(designerItem.RenderSize));
                //rotateTransform.
            }


            xOffset = dragDelta.X;
            yOffset = dragDelta.Y;

            //If shift key down, move widget by straight line.
            if ((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.None)
            {
                if (Math.Abs(xOffset) > Math.Abs(yOffset))
                {
                    yOffset = 0;
                }
                else
                {
                    xOffset = 0;
                }
            }

            IPagePropertyData page = designerCanvas.DataContext as IPagePropertyData;

            Snap(page.BoundingRect, ref xOffset, ref yOffset);
        }
Esempio n. 11
0
        public MoveThumb()
        {
            DragStarted += (sender, args) =>
            {
                _contentControl = DataContext as ContentControl;
                if (_contentControl != null)
                {
                    _rotateTransform = _contentControl.RenderTransform as RotateTransform;
                }
            };
            DragDelta += (sender, args) =>
            {
                if (_contentControl != null)
                {
                    var point = new Point(args.HorizontalChange, args.VerticalChange);
                    if (_rotateTransform != null)
                    {
                        point = _rotateTransform.Transform(point);
                    }

                    Canvas.SetTop(_contentControl, Canvas.GetTop(_contentControl) + point.Y);
                    Canvas.SetLeft(_contentControl, Canvas.GetLeft(_contentControl) + point.X);
                }
            };
        }
Esempio n. 12
0
        public static void CalculateViewFromLocations(IEnumerable <Location> locations, Size viewportSize, double heading, Thickness margin, out Point centerNormalizedMercator, out double zoomLevel)
        {
            var point1          = new Point(double.MaxValue, double.MaxValue);
            var point2          = new Point(double.MinValue, double.MinValue);
            var rotateTransform = new RotateTransform(heading)
            {
                CenterX = 0.5,
                CenterY = 0.5
            };

            foreach (var location in locations)
            {
                var point3 = rotateTransform.Transform(MercatorCube.Instance.FromLocation(location).ToPoint());
                point1.X = Math.Min(point1.X, point3.X);
                point1.Y = Math.Min(point1.Y, point3.Y);
                point2.X = Math.Max(point2.X, point3.X);
                point2.Y = Math.Max(point2.Y, point3.Y);
            }
            if (point2.X > point1.X && point2.Y > point1.Y)
            {
                var a = Math.Min((viewportSize.Width - margin.Left - margin.Right) / (DefaultTileSize * (point2.X - point1.X)), (viewportSize.Height - margin.Top - margin.Bottom) / (DefaultTileSize * (point2.Y - point1.Y)));
                zoomLevel = Math.Log(a, 2.0);
                var num = 1.0 / (DefaultTileSize * Math.Pow(2.0, zoomLevel));
                centerNormalizedMercator = rotateTransform.Inverse.Transform(new Point((point2.X + num * margin.Right + point1.X - num * margin.Left) / 2.0, (point2.Y + num * margin.Bottom + point1.Y - num * margin.Top) / 2.0));
            }
            else
            {
                if (point1.X != point2.X)
                {
                    throw new InvalidOperationException("Must provide at least one location.");
                }
                zoomLevel = 1.0;
                centerNormalizedMercator = point1;
            }
        }
        private Point RotatePointByTransformation(Point p, double angle)
        {
            var rotation = new RotateTransform();

            rotation.Angle = angle;
            return(rotation.Transform(p));
        }
Esempio n. 14
0
        public override Rect GetEditingBounds()
        {
            Rect            bounds            = GetCustomBound();
            RotateTransform rotationTransform = new RotateTransform(shapeStyle.rotation, GetCenter().X, GetCenter().Y);
            Point           topLeft           = rotationTransform.Transform(bounds.TopLeft);
            Point           topRight          = rotationTransform.Transform(bounds.TopRight);
            Point           bottomLeft        = rotationTransform.Transform(bounds.BottomLeft);
            Point           bottomRight       = rotationTransform.Transform(bounds.BottomRight);
            double          minX = Math.Min(Math.Min(Math.Min(topLeft.X, topRight.X), bottomLeft.X), bottomRight.X);
            double          maxX = Math.Max(Math.Max(Math.Max(topLeft.X, topRight.X), bottomLeft.X), bottomRight.X);
            double          minY = Math.Min(Math.Min(Math.Min(topLeft.Y, topRight.Y), bottomLeft.Y), bottomRight.Y);
            double          maxY = Math.Max(Math.Max(Math.Max(topLeft.Y, topRight.Y), bottomLeft.Y), bottomRight.Y);

            bounds = new Rect(new Point(minX - 15, minY - 15), new Point(maxX + 15, maxY + 15));
            return(bounds);
        }
Esempio n. 15
0
        private Polygon CreateRotatedHexagon(double x, double y, RotateTransform rotateTransform, Transform globalRotationTransform)
        {
            var polygon = new Polygon();

            /*      ____
             *     /    \
             *    /      \
             *    |       |
             *    |       |
             *    \      /
             *     \____/
             *
             * A hexagon has 6 sides. Use a loop to draw a hexagon with the x,y midpoint
             * and its side length.
             */
            const int hexagonSideLength = 67;

            for (var currentPoint = 0; currentPoint < 6; currentPoint++)
            {
                var point = new Point(
                    x + hexagonSideLength * (float)Math.Cos(currentPoint * 60 * Math.PI / 180f),
                    y + hexagonSideLength * (float)Math.Sin(currentPoint * 60 * Math.PI / 180f)
                    );
                polygon.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(point)));
            }

            return(polygon);
        }
        public static void RotateGraphicVisual(GraphicVisual graphicVisual, double angle, Point center)
        {
            RotateTransform tr = new RotateTransform(angle, center.X, center.Y);

            graphicVisual.Origin = tr.Transform(graphicVisual.Origin);
            graphicVisual.Angle += angle;
        }
Esempio n. 17
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (GetValues(this) != null)
            {
                double total = 0.0;
                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    total += (double)(GetValues(this)[i]);
                }
                double offsetAngle = 0.0;

                double radius = finalSize.Width < finalSize.Height ? finalSize.Width / 2 : finalSize.Height / 2;
                //radius -= 2;
                Point beginFigure           = new Point(finalSize.Width / 2, finalSize.Height / 2);
                Point lineToBeforeTransform = new Point(beginFigure.X + radius, beginFigure.Y);
                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    ContentControl  container  = InternalChildren[i] as ContentControl;
                    double          wedgeAngle = (double)(GetValues(this)[i]) * 360 / total;
                    RotateTransform rt         = new RotateTransform(offsetAngle, beginFigure.X, beginFigure.Y);
                    container.SetValue(PiePanel.BeginFigurePointProperty, beginFigure);
                    container.SetValue(PiePanel.LineToPointProperty, rt.Transform(lineToBeforeTransform));
                    container.SetValue(PiePanel.WedgeAngleProperty, wedgeAngle);
                    offsetAngle += wedgeAngle;
                    Rect r = new Rect(finalSize);
                    container.Arrange(r);
                }
            }
            return(finalSize);
        }
Esempio n. 18
0
        private void RotateGroup()
        {
            if (selectedNodes.Count <= 0)
            {
                return;
            }

            Point gc = new Point();

            foreach (Node n in selectedNodes)
            {
                gc.X += n.X;
                gc.Y += n.Y;
            }

            gc.X /= selectedNodes.Count;
            gc.Y /= selectedNodes.Count;
            RotateTransform rt = new RotateTransform(angleDelta, gc.X, gc.Y);
            Point           p1 = new Point();

            foreach (Node n in selectedNodes)
            {
                p1.X = n.X;
                p1.Y = n.Y;
                Point p2 = rt.Transform(p1);
                n.X = p2.X;
                n.Y = p2.Y;
            }

            Redraw();
        }
Esempio n. 19
0
        private void DrawCar(Map map)
        {
            if (lastCar != null)
            {
                Canvas_trackPlanner.Children.Remove(lastCar);
            }

            const double CAR_WIDTH          = 55;
            const double CAR_HEIGHT         = 25;
            const double FRONT_SHOWER_LENTH = 10;

            System.Windows.Shapes.Polyline car = new Polyline();
            car.StrokeThickness = 7;
            car.Stroke          = new SolidColorBrush(Colors.Red);
            car.Points          = new PointCollection()
            {
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2),
                new Point(map.car.x - CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2),
                new Point(map.car.x - CAR_WIDTH / 2, map.car.y - CAR_HEIGHT / 2),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y - CAR_HEIGHT / 2),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH + FRONT_SHOWER_LENTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2)
            };

            RotateTransform rt = new RotateTransform(map.car.angle, map.car.x, map.car.y);

            car.Points = new PointCollection(car.Points.Select(x => rt.Transform(x)));
            Canvas_trackPlanner.Children.Add(car);

            lastCar = car;
        }
Esempio n. 20
0
        public override void Move()
        {
            if (!IsDestroyed)
            {
                RotateTransform rotated = new RotateTransform(Rotation, Center.X, Center.Y);
                PointCollection p       = new PointCollection();
                foreach (Point vert in Geometry.Points)
                {
                    p.Add(rotated.Transform(vert));
                }
                Geometry.Points = p;

                TranslateTransform translated = new TranslateTransform(OffsetX, OffsetY);
                p = new PointCollection();
                foreach (Point vert in Geometry.Points)
                {
                    p.Add(translated.Transform(vert));
                }
                Geometry.Points = p;
                Center          = translated.Transform(Center);
            }

            Effects.RemoveAll(effect => { return(!effect.Display() ? RemoveFromDisplay(effect) : false); });
            DestroyedTimeoutCooldown();
        }
Esempio n. 21
0
        public static Point[] Sample(IList <Point> points, EllipseParams ellipse, int count = 20)
        {
            Contract.Requires(points != null);
            Contract.Requires(points.Count > 6);
            Contract.Requires(count > 0);
            Contract.Ensures(Contract.Result <Point[]>() != null);
            Contract.Ensures(Contract.Result <Point[]>().Length == count);

            /*using (StreamWriter writer = File.CreateText("Points.txt"))
             * {
             *  foreach (Point pnt in points)
             *  {
             *      writer.Write(pnt.X + " " + pnt.Y);
             *      writer.Write(writer.NewLine);
             *  }
             * }
             * MessageBox.Show("Done Writing Points");*/
            /*EllipseParams ellipse = new EllipseParams
             * {
             *  Center = new Point(0.9566, 0.8023),
             *  XRadius = 0.1149,
             *  YRadius = 0.0894,
             *  Degrees = -1.2418 * 180 / Math.PI
             * };*/
            var result    = new Point[count];
            var rotMatrix = new RotateTransform(ellipse.Degrees).Value;

            for (int i = 0; i < count; ++i)
            {
                var t   = 2 * Math.PI * i / (double)(count - 1);
                var vec = new Vector(ellipse.XRadius * Math.Cos(t), ellipse.YRadius * Math.Sin(t));
                result[i] = ellipse.Center + rotMatrix.Transform(vec);
            }
            return(result);
        }
Esempio n. 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="finalSize"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (GetValues(this) != null)
            {
                double total      = 0.0;
                int    leftCount  = 0;  //饼的左侧拥有的扇形数
                int    rightCount = 0;  //饼的右侧拥有的扇形数

                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    total += GetValues(this)[i];
                }
                double offsetAngle = 0.0;

                double radius = finalSize.Width < finalSize.Height ? finalSize.Width / 2 : finalSize.Height / 2;
                radius -= 2;
                Point beginFigure           = new Point(finalSize.Width / 2, finalSize.Height / 2);
                Point lineToBeforeTransform = new Point(beginFigure.X + radius, beginFigure.Y);
                Point centerBeforeTransform = new Point(beginFigure.X + radius / 2, beginFigure.Y);
                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    ContentControl container = InternalChildren[i] as ContentControl;
                    if (container == null)
                    {
                        throw new NoNullAllowedException(string.Format("Child control is null."));
                    }
                    double          proportion = GetValues(this)[i] / total * 1.0;
                    double          wedgeAngle = proportion * 360;
                    RotateTransform rt         = new RotateTransform(offsetAngle, beginFigure.X, beginFigure.Y);
                    container.SetValue(BeginFigurePointProperty, beginFigure);
                    container.SetValue(LineToPointProperty, rt.Transform(lineToBeforeTransform));
                    container.SetValue(WedgeAngleProperty, wedgeAngle);
                    container.SetValue(ProportionProperty, proportion);

                    double          wedgeAngle2 = wedgeAngle / 2 + offsetAngle;
                    RotateTransform rt2         = new RotateTransform(wedgeAngle2, beginFigure.X, beginFigure.Y);
                    Point           centerPoint = rt2.Transform(centerBeforeTransform);
                    container.SetValue(CenterPointProperty, centerPoint);
                    container.SetValue(TranslateXProperty, centerPoint.X - beginFigure.X);
                    container.SetValue(TranslateYProperty, centerPoint.Y - beginFigure.Y);

                    if (centerPoint.X < 0)
                    {
                        leftCount++;
                    }
                    if (centerPoint.X >= 0)
                    {
                        rightCount++;
                    }
                    container.SetValue(LeftCountProperty, leftCount);
                    container.SetValue(RightCountProperty, rightCount);

                    offsetAngle += wedgeAngle;
                    Rect r = new Rect(finalSize);
                    container.Arrange(r);
                }
            }
            return(finalSize);
        }
Esempio n. 23
0
        /// <summary>
        /// 旋转操作。
        /// Rotation transform operation.
        /// </summary>
        /// <param name="angle">
        /// 旋转角度,单位度。
        /// Rotation angle which is in degrees.
        /// </param>
        /// <param name="center">
        /// 旋转中心点。
        /// Rotation transform center point.
        /// </param>
        /// <param name="IsLocalCenter">
        /// 旋转中心点位置是否为局部坐标,默认值为 false。
        /// Whether the rotation center point is in local coordinate, and default value is false.
        /// </param>
        public virtual void Rotate(double angle, Point center, bool IsLocalCenter = false)
        {
            Point     cpot  = IsLocalCenter ? Transform.Transform(center) : center;
            Transform trans = new RotateTransform(angle, cpot.X, cpot.Y);

            Origin = trans.Transform(Origin);
            Angle += angle;
        }
Esempio n. 24
0
        /// <summary>
        /// transforming mouse position invers to transformation of image object
        /// </summary>
        /// <param name="mousePos">initial position to be transformed</param>
        /// <returns>transformed position</returns>
        private Point transformMouse(Point mousePos)
        {
            var rt = new RotateTransform(-90, image.ActualWidth / 2.0, image.ActualHeight / 2.0);
            var st = new ScaleTransform(-1, 1, image.ActualWidth / 2.0, image.ActualHeight / 2.0);

            mousePos = st.Transform(mousePos);
            mousePos = rt.Transform(mousePos);
            return(mousePos);
        }
Esempio n. 25
0
        void Move(DesignerItem item, double x, double y)
        {
            RotateTransform rotateTransform = item.RenderTransform as RotateTransform;

            if (rotateTransform != null)
            {
                Point p = rotateTransform.Transform(new Point(x, y));
            }
        }
Esempio n. 26
0
        public bool RotatedRectContains(Rectangle rect, System.Windows.Point location)
        {
            var rectCorner   = new System.Windows.Point(Canvas.GetLeft(rect), Canvas.GetTop(rect));
            var rectRotation = (RotateTransform)rect.RenderTransform;
            var transform    = new RotateTransform(-rectRotation.Angle, rectCorner.X + rectRotation.CenterX, rectCorner.Y + rectRotation.CenterY);
            var rotated      = transform.Transform(location);

            return(rotated.X > rectCorner.X && rotated.X < rectCorner.X + rect.Width && rotated.Y > rectCorner.Y &&
                   rotated.Y < rectCorner.Y + rect.Height);
        }
		public bool RotatedRectContains(Rectangle rect, Point location)
		{
			var rectCorner = new Point(Canvas.GetLeft(rect), Canvas.GetTop(rect));
			var rectRotation = rect.RenderTransform as RotateTransform;
			if(rectRotation == null)
				return false;
			var transform = new RotateTransform(-rectRotation.Angle, rectCorner.X + rectRotation.CenterX, rectCorner.Y + rectRotation.CenterY);
			var rotated = transform.Transform(location);
			return rotated.X > rectCorner.X && rotated.X < rectCorner.X + rect.Width && rotated.Y > rectCorner.Y
				   && rotated.Y < rectCorner.Y + rect.Height;
		}
Esempio n. 28
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="arrangeBounds"></param>
 /// <returns></returns>
 public StreamGeometry GetClipGeometry(Size arrangeBounds)
 {
     StreamGeometry clip = new StreamGeometry();
     StreamGeometryContext clipGC = clip.Open();
     clipGC.BeginFigure(BeginFigurePoint, true, true);
     clipGC.LineTo(LineToPoint, false, true);
     Vector v = LineToPoint - BeginFigurePoint;
     RotateTransform rt = new RotateTransform(WedgeAngle, BeginFigurePoint.X, BeginFigurePoint.Y);
     bool isLargeArc = WedgeAngle > 180.0;
     clipGC.ArcTo(rt.Transform(LineToPoint), new Size(v.Length, v.Length), WedgeAngle, isLargeArc, SweepDirection.Clockwise, false, true);
     clipGC.Close();
     return clip;
 }
Esempio n. 29
0
        private Polygon CreateRotatedSquare(double x, double y, RotateTransform rotateTransform, Transform globalRotationTransform)
        {
            var polygon = new Polygon();

            /*
             * a------------d
             * |            |
             * |            |
             * |     xy     |
             * |            |
             * |            |
             * b------------c
             *
             * The X and Y positions are given as if they are in the
             * middle of the square that should be created.
             * For that reason we always need to edit the X and Y position
             * to create a correct square.
             *
             * The Nanoleaf API returns the SideLength as the full length
             * of the sides of the square. Because the x and y are in the middle
             * Only half of the side length should be either add or removed
             * from the X and Y
             */

            // This is the distance from one of the corners to the center.
            const int squareSideLength = 100;
            var       distanceToCenter = squareSideLength / (double)2;
            var       a = new Point(x - distanceToCenter, y + distanceToCenter);
            var       b = new Point(x - distanceToCenter, y - distanceToCenter);
            var       c = new Point(x + distanceToCenter, y - distanceToCenter);
            var       d = new Point(x + distanceToCenter, y + distanceToCenter);

            polygon.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(a)));
            polygon.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(b)));
            polygon.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(c)));
            polygon.Points.Add(globalRotationTransform.Transform(rotateTransform.Transform(d)));

            return(polygon);
        }
Esempio n. 30
0
        private void MoveThumb_DragDelta1111(object sender, DragDeltaEventArgs e)
        {
            //Initialize
            if (bIsMousePressMove == false)
            {
                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designerCanvas);
                if (adornerLayer != null)
                {
                    adorner = new PreveiwMoveAdorner(designerCanvas);
                    if (adorner != null)
                    {
                        adornerLayer.Add(adorner);
                    }
                }

                foreach (ContentControl item in this.designerCanvas.SelectedItemandGroups)
                {
                    ContentPresenter wrapper = VisualTreeHelper.GetParent(item) as ContentPresenter;
                    if (wrapper == null)
                    {
                        continue;
                    }
                    minLeft = Math.Min(Canvas.GetLeft(wrapper), minLeft);
                    minTop  = Math.Min(Canvas.GetTop(wrapper), minTop);
                }
            }
            bIsMousePressMove = true;
            if (this.designerItem == null || this.designerCanvas == null)
            {
                return;
            }

            //Get x/y offset
            Point           dragDelta       = new Point(e.HorizontalChange, e.VerticalChange);
            RotateTransform rotateTransform = designerItem.RenderTransform as RotateTransform;

            if (rotateTransform != null)
            {
                dragDelta = rotateTransform.Transform(dragDelta);
            }

            double deltaHorizontal = Math.Max(-minLeft, dragDelta.X);
            double deltaVertical   = Math.Max(-minTop, dragDelta.Y);

            if (adorner != null)
            {
                adorner.PreviewMove(deltaHorizontal, deltaVertical);
            }

            e.Handled = true;
        }
Esempio n. 31
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
 }