Ejemplo n.º 1
0
        public void DrawBlock(XGraphics graphics)
        {
            var bounds = new Rect(Segment.Start, Vector.Zero);

            var compassPoint = CompassPointHelper.GetCompassPointFromDirectionVector(Segment.Delta);
            var pos          = bounds.GetCorner(compassPoint);
            var offsets      = new Size(0, 0);

            switch (compassPoint)
            {
            case CompassPoint.NorthWest:
                offsets.Height = -(Offset * 12);
                offsets.Width  = -(Offset * 10) - HORIZONTAL_LINE_OFFSET;
                break;

            case CompassPoint.NorthEast:
                offsets.Height = -(Offset * 12);
                offsets.Width  = Offset * 10 + HORIZONTAL_STEM_OFFSET;
                break;

            case CompassPoint.SouthEast:
                offsets.Height = Offset * 12;
                offsets.Width  = Offset * 10 + HORIZONTAL_LINE_OFFSET;
                break;

            case CompassPoint.SouthWest:
                offsets.Height = Offset * 12 + VERTICAL_LINE_OFFSET;
                offsets.Width  = -(Offset * 10);
                break;

            case CompassPoint.East:
                offsets.Height = VERTICAL_LINE_OFFSET;
                offsets.Width  = Offset * 16 + HORIZONTAL_STEM_OFFSET;
                break;

            case CompassPoint.West:
                offsets.Height = VERTICAL_LINE_OFFSET;
                offsets.Width  = -(Offset * 16) - HORIZONTAL_LINE_OFFSET;
                break;

            case CompassPoint.South:
                offsets.Height = Offset * 16 + VERTICAL_STEM_OFFSET;
                offsets.Width  = -HORIZONTAL_LINE_OFFSET;
                break;

            case CompassPoint.North:
                offsets.Height = -(Offset * 16) - VERTICAL_STEM_OFFSET;
                offsets.Width  = -HORIZONTAL_LINE_OFFSET;
                break;
            }

            //      int dist = 15;
//      if (compassPoint == CompassPoint.NorthWest)
//        bounds.Inflate(-dist, -dist + 9);
//
//      if (compassPoint == CompassPoint.NorthEast)
//        bounds.Inflate(-dist - 5, -dist);
//
//      if (compassPoint == CompassPoint.SouthEast)
//        bounds.Inflate(-dist, dist - 9);
//
//      if (compassPoint == CompassPoint.SouthWest)
//        bounds.Inflate(-dist, -dist);
//


            graphics.DrawImage(Image, pos.ToPointF() + offsets);
        }
Ejemplo n.º 2
0
        public Vector GetCorner(CompassPoint point, RoomShape myRmShape = RoomShape.SquareCorners, CornerRadii corners = null)
        {
            var    isOctagonal = myRmShape == RoomShape.Octagonal;
            var    isRounded   = myRmShape == RoomShape.RoundedCorners;
            var    isEllipse   = myRmShape == RoomShape.Ellipse;
            double angleInRadians;

            if (myRmShape == RoomShape.Ellipse)
            {
                angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this);
                return(new Vector(Center.X + (float)(Width / 2.0 * Math.Cos(angleInRadians)), Center.Y + (float)(Height / 2.0 * Math.Sin(angleInRadians))));
            }

            if (myRmShape == RoomShape.Ellipse)
            {
                if (point == CompassPoint.NorthEast || point == CompassPoint.NorthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthEast)
                {
                    angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this);

                    if (point == CompassPoint.NorthEast)
                    {
                        var rect = new Rect(X + Width, Y, (float)corners.TopRight, (float)corners.TopRight);
                        return(new Vector(rect.Center.X - (float)(corners.TopRight / 2.0) - (float)(corners.TopRight / 2.0 * Math.Cos(angleInRadians)), rect.Center.Y + (float)(corners.TopLeft / 4.0) + (float)(corners.TopRight / 2.0 * Math.Sin(angleInRadians))));
                    }

                    if (point == CompassPoint.NorthWest)
                    {
                        var rect = new Rect(X, Y, (float)corners.TopLeft, (float)corners.TopLeft);
                        return(new Vector(rect.Center.X - (float)(corners.TopLeft / 2.0) - (float)(corners.TopLeft / 2.0 * Math.Cos(angleInRadians)), rect.Center.Y + (float)(corners.TopLeft / 4.0) + (float)(corners.TopLeft / 2.0 * Math.Sin(angleInRadians))));
                    }

                    if (point == CompassPoint.SouthWest)
                    {
                        var rect = new Rect(X, Y + Height, (float)corners.BottomLeft, (float)corners.BottomLeft);
                        return(new Vector(rect.Center.X - (float)(corners.BottomLeft / 2.0) - (float)(corners.BottomLeft / 2.0 * Math.Cos(angleInRadians)), rect.Center.Y - (float)(corners.BottomLeft / 2.0) - (float)(corners.BottomLeft / 2.0 * Math.Sin(angleInRadians))));
                    }

                    if (point == CompassPoint.SouthEast)
                    {
                        var rect = new Rect(X + Width, Y + Height, (float)corners.BottomRight, (float)corners.BottomRight);
                        return(new Vector(rect.Center.X - (float)(corners.BottomRight / 2.0) - (float)(corners.BottomRight / 2.0 * Math.Cos(angleInRadians)), rect.Center.Y - (float)(corners.BottomRight / 2.0) - (float)(corners.BottomRight / 2.0 * Math.Sin(angleInRadians))));
                    }
                }
            }

            switch (point)
            {
            case CompassPoint.North:
                return(new Vector(X + Width / 2, Y));

            case CompassPoint.NorthNorthEast:
                return(new Vector(X + Width * 3 / 4, Y));

            case CompassPoint.NorthEast:
                if (isOctagonal)
                {
                    return(new Vector(X + Width * 7 / 8, Y + Height * 1 / 8));
                }
                if (isRounded)
                {
                    return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + 0.25 * corners.TopLeft)));
                }
                return(new Vector(X + Width, Y));

            case CompassPoint.EastNorthEast:
                return(new Vector(X + Width, Y + Height / 4));

            case CompassPoint.East:
                return(new Vector(X + Width, Y + Height / 2));

            case CompassPoint.EastSouthEast:
                return(new Vector(X + Width, Y + Height * 3 / 4));

            case CompassPoint.SouthEast:
                if (isOctagonal)
                {
                    return(new Vector(X + Width * 7 / 8, Y + Height * 7 / 8));
                }
                if (isRounded)
                {
                    return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + Height - 0.25 * corners.TopLeft)));
                }
                return(new Vector(X + Width, Y + Height));

            case CompassPoint.SouthSouthEast:
                return(new Vector(X + Width * 3 / 4, Y + Height));

            case CompassPoint.South:
                return(new Vector(X + Width / 2, Y + Height));

            case CompassPoint.SouthSouthWest:
                return(new Vector(X + Width / 4, Y + Height));

            case CompassPoint.SouthWest:
                if (isOctagonal)
                {
                    return(new Vector(X + Width * 1 / 8, Y + Height * 7 / 8));
                }
                if (isRounded)
                {
                    return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + Height - 0.3 * corners.TopLeft)));
                }
                return(new Vector(X, Y + Height));

            case CompassPoint.WestSouthWest:
                return(new Vector(X, Y + Height * 3 / 4));

            case CompassPoint.West:
                return(new Vector(X, Y + Height / 2));

            case CompassPoint.WestNorthWest:
                return(new Vector(X, Y + Height / 4));

            case CompassPoint.NorthWest:
                if (isOctagonal)
                {
                    return(new Vector(X + Width * 1 / 8, Y + Height * 1 / 8));
                }
                if (isRounded)
                {
                    return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + 0.3 * corners.TopLeft)));
                }
                return(new Vector(X, Y));

            case CompassPoint.NorthNorthWest:
                return(new Vector(X + Width / 4, Y));

            default:
                throw new InvalidOperationException();
            }
        }