Exemple #1
0
 /// <summary>
 /// 获取圆角矩形路径
 /// </summary>
 /// <param name="g"></param>
 /// <param name="rectangle">原矩形坐标</param>
 /// <param name="radius">圆角半径</param>
 /// <param name="filter">圆角点筛选</param>
 /// <returns></returns>
 public static GraphicsPath generateRoundedRectangle(
     this Graphics g,
     RectangleF rectangle,
     float radius,
     RectangleCorner filter)
 {
     return(GraphicsUtil.generateRoundedRectangle(g, rectangle, radius, filter));
 }
Exemple #2
0
 /// <summary>
 /// 绘制圆角矩形
 /// </summary>
 /// <param name="g"></param>
 /// <param name="pen"></param>
 /// <param name="rectangle"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void drawRoundedRectangle(
     this Graphics g,
     Pen pen,
     RectangleF rectangle,
     int radius,
     RectangleCorner filter)
 {
     GraphicsUtil.drawRoundedRectangle(g, pen, rectangle, radius, filter);
 }
Exemple #3
0
 /// <summary>
 /// 填充圆角矩形
 /// </summary>
 /// <param name="g"></param>
 /// <param name="brush"></param>
 /// <param name="rectangle"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void fillRoundedRectangle(
     this Graphics g,
     Brush brush,
     RectangleF rectangle,
     int radius,
     RectangleCorner filter)
 {
     GraphicsUtil.fillRoundedRectangle(g, brush, rectangle, radius, filter);
 }
        /// <summary>
        /// Returns the Y co-ordinate of the requested <paramref name="corner"/> of this rectangle.
        /// </summary>
        /// <param name="corner">The corner whose position it is you wish to obtain.</param>
        /// <returns>The position on the Y-axis of the requested <paramref name="corner"/> of this rectangle.</returns>
        public float GetCornerY(RectangleCorner corner)
        {
            Assure.True(Enum.IsDefined(typeof(RectangleCorner), corner), "Invalid corner constant: " + corner + " is not a valid RectangleCorner value.");
            switch (corner)
            {
            case RectangleCorner.TopLeft:
            case RectangleCorner.TopRight:
                return(BottomLeft.Y + Height);

            default: return(BottomLeft.Y);
            }
        }
Exemple #5
0
 /// <summary>
 /// 绘制圆角矩形
 /// </summary>
 /// <param name="g"></param>
 /// <param name="pen"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void drawRoundedRectangle(
     this Graphics g,
     Pen pen,
     float x,
     float y,
     float width,
     float height,
     float radius,
     RectangleCorner filter)
 {
     GraphicsUtil.drawRoundedRectangle(g, pen, x, y, width, height, radius);
 }
Exemple #6
0
        /// <summary>
        /// Function to set an offset for a corner.
        /// </summary>
        /// <param name="corner">Corner of the sprite to set.</param>
        /// <param name="offset">Offset for the corner.</param>
        public void SetCornerOffset(RectangleCorner corner, Vector2 offset)
        {
            var index = (int)corner;

            if (_offsets[index] == offset)
            {
                return;
            }

            _offsets[index]         = offset;
            NeedsVertexOffsetUpdate = true;
        }
Exemple #7
0
 /// <summary>
 /// 填充圆角矩形
 /// </summary>
 /// <param name="g"></param>
 /// <param name="brush"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void fillRoundedRectangle(
     this Graphics g,
     Brush brush,
     float x,
     float y,
     float width,
     float height,
     float radius,
     RectangleCorner filter)
 {
     GraphicsUtil.fillRoundedRectangle(g, brush, x, y, width, height, radius);
 }
Exemple #8
0
        private void DrawHalfBox(Rectangle halfRectangle, int radius, RectangleCorner corners, string s)
        {
            using (var path = RoundedRectangle.Create(halfRectangle, radius, corners))
            {
                graphics.FillPath(backFillTop, path);
            }

            if (!String.IsNullOrEmpty(s))
            {
                DrawString(s, smallCityFont, halfRectangle);
            }
        }
Exemple #9
0
 /// <summary>
 /// 绘制圆角矩形
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="pen"></param>
 /// <param name="rectangle"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void drawRoundedRectangle(
     Graphics graphics,
     Pen pen,
     RectangleF rectangle,
     int radius,
     RectangleCorner filter)
 {
     drawRoundedRectangle(graphics,
                          pen,
                          rectangle.X,
                          rectangle.Y,
                          rectangle.Width,
                          rectangle.Height,
                          radius,
                          filter);
 }
Exemple #10
0
 /// <summary>
 /// 填充圆角矩形
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="brush"></param>
 /// <param name="rectangle"></param>
 /// <param name="radius"></param>
 /// <param name="filter"></param>
 public static void fillRoundedRectangle(
     Graphics graphics,
     Brush brush,
     RectangleF rectangle,
     int radius,
     RectangleCorner filter)
 {
     fillRoundedRectangle(graphics,
                          brush,
                          rectangle.X,
                          rectangle.Y,
                          rectangle.Width,
                          rectangle.Height,
                          radius,
                          filter);
 }
Exemple #11
0
        /// <summary>
        /// 填充圆角矩形
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="brush"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="radius"></param>
        /// <param name="filter"></param>
        public static void fillRoundedRectangle(
            Graphics graphics,
            Brush brush,
            float x,
            float y,
            float width,
            float height,
            float radius,
            RectangleCorner filter)
        {
            RectangleF    rectangle = new RectangleF(x, y, width, height);
            GraphicsPath  path      = generateRoundedRectangle(graphics, rectangle, radius, filter);
            SmoothingMode old       = graphics.SmoothingMode;

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.FillPath(brush, path);
            graphics.SmoothingMode = old;
        }
Exemple #12
0
 /// <summary>
 /// Function to set a color for a specific corner of the rectangle.
 /// </summary>
 /// <param name="corner">Corner to set the color on.</param>
 /// <param name="color">Color to set.</param>
 public void SetCornerColor(RectangleCorner corner, GorgonColor color)
 {
     _colors[(int)corner] = color;
 }
Exemple #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpriteVertex"/> struct.
 /// </summary>
 /// <param name="sprite">The sprite content to use.</param>
 /// <param name="corner">Corner for the sprite rectangle.</param>
 public SpriteVertex(GorgonSpriteContent sprite, RectangleCorner corner)
 {
     _sprite = sprite;
     _corner = corner;
 }
Exemple #14
0
 /// <summary>
 /// Function to retrieve the color for a specific corner on the sprite.
 /// </summary>
 /// <param name="corner">Corner of the sprite to retrieve the color from.</param>
 /// <returns>The color on the specified corner of the sprite.</returns>
 public GorgonColor GetCornerColor(RectangleCorner corner)
 {
     return(Vertices[(int)corner].Color);
 }
Exemple #15
0
 /// <summary>
 /// Function to set the color for a specific corner on the sprite.
 /// </summary>
 /// <param name="corner">Corner of the sprite to set.</param>
 /// <param name="color">Color to set.</param>
 public void SetCornerColor(RectangleCorner corner, GorgonColor color)
 {
     Vertices[(int)corner].Color = color;
 }
Exemple #16
0
 /// <summary>
 /// Function to retrieve an offset for a corner.
 /// </summary>
 /// <param name="corner">Corner of the sprite to retrieve the offset from.</param>
 /// <returns>The offset of the corner.</returns>
 public Vector2 GetCornerOffset(RectangleCorner corner)
 {
     return(_offsets[(int)corner]);
 }
 /// <summary>
 /// Returns the X and Y co-ordinate of the requested <paramref name="corner"/> of this rectangle.
 /// </summary>
 /// <param name="corner">The corner whose position it is you wish to obtain.</param>
 /// <returns>A <see cref="Vector2"/> whose <see cref="Vector2.X"/> and <see cref="Vector2.Y"/> components
 /// are set to the X and Y position of the requested <paramref name="corner"/> on this rectangle.</returns>
 public Vector2 GetCorner(RectangleCorner corner)
 {
     return(new Vector2(GetCornerX(corner), GetCornerY(corner)));
 }
Exemple #18
0
 public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorner c)
 {
     return(Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c));
 }
Exemple #19
0
        public static GraphicsPath Create(int x, int y, int width, int height,
                                          int radius, RectangleCorner corners)
        {
            int xw   = x + width;
            int yh   = y + height;
            int xwr  = xw - radius;
            int yhr  = yh - radius;
            int xr   = x + radius;
            int yr   = y + radius;
            int r2   = radius * 2;
            int xwr2 = xw - r2;
            int yhr2 = yh - r2;

            GraphicsPath p = new GraphicsPath();

            p.StartFigure();

            //Top Left Corner
            if ((RectangleCorner.TopLeft & corners) == RectangleCorner.TopLeft)
            {
                p.AddArc(x, y, r2, r2, 180, 90);
            }
            else
            {
                p.AddLine(x, yr, x, y);
                p.AddLine(x, y, xr, y);
            }

            //Top Edge
            p.AddLine(xr, y, xwr, y);

            //Top Right Corner
            if ((RectangleCorner.TopRight & corners) == RectangleCorner.TopRight)
            {
                p.AddArc(xwr2, y, r2, r2, 270, 90);
            }
            else
            {
                p.AddLine(xwr, y, xw, y);
                p.AddLine(xw, y, xw, yr);
            }

            //Right Edge
            p.AddLine(xw, yr, xw, yhr);

            //Bottom Right Corner
            if ((RectangleCorner.BottomRight & corners) == RectangleCorner.BottomRight)
            {
                p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
            }
            else
            {
                p.AddLine(xw, yhr, xw, yh);
                p.AddLine(xw, yh, xwr, yh);
            }

            //Bottom Edge
            p.AddLine(xwr, yh, xr, yh);

            //Bottom Left Corner
            if ((RectangleCorner.BottomLeft & corners) == RectangleCorner.BottomLeft)
            {
                p.AddArc(x, yhr2, r2, r2, 90, 90);
            }
            else
            {
                p.AddLine(xr, yh, x, yh);
                p.AddLine(x, yh, x, yhr);
            }

            //Left Edge
            p.AddLine(x, yhr, x, yr);

            p.CloseFigure();
            return(p);
        }
Exemple #20
0
 /// <summary>
 /// Function to retrieve a color for a specific corner of the rectangle.
 /// </summary>
 /// <param name="corner">Corner to retrieve color from.</param>
 /// <returns>The color on the specified corner.</returns>
 public GorgonColor GetCornerColor(RectangleCorner corner)
 {
     return(_colors[(int)corner]);
 }
Exemple #21
0
        /// <summary>
        /// 获取圆角矩形路径
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="rectangle">原矩形坐标</param>
        /// <param name="radius">圆角半径</param>
        /// <param name="filter">圆角点筛选</param>
        /// <returns></returns>
        public static GraphicsPath generateRoundedRectangle(
            Graphics graphics,
            RectangleF rectangle,
            float radius,
            RectangleCorner filter)
        {
            float        diameter;
            GraphicsPath path = new GraphicsPath();

            if (radius <= 0.0F || filter == RectangleCorner.None)
            {
                path.AddRectangle(rectangle);
                path.CloseFigure();
                return(path);
            }
            else
            {
                if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)
                {
                    return(generateCapsule(graphics, rectangle));
                }
                diameter = radius * 2.0F;
                SizeF      sizeF = new SizeF(diameter, diameter);
                RectangleF arc   = new RectangleF(rectangle.Location, sizeF);
                if ((RectangleCorner.TopLeft & filter) == RectangleCorner.TopLeft)
                {
                    path.AddArc(arc, 180, 90);
                }
                else
                {
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
                    path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
                }
                arc.X = rectangle.Right - diameter;
                if ((RectangleCorner.TopRight & filter) == RectangleCorner.TopRight)
                {
                    path.AddArc(arc, 270, 90);
                }
                else
                {
                    path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
                    path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y);
                }
                arc.Y = rectangle.Bottom - diameter;
                if ((RectangleCorner.BottomRight & filter) == RectangleCorner.BottomRight)
                {
                    path.AddArc(arc, 0, 90);
                }
                else
                {
                    path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height);
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height);
                }
                arc.X = rectangle.Left;
                if ((RectangleCorner.BottomLeft & filter) == RectangleCorner.BottomLeft)
                {
                    path.AddArc(arc, 90, 90);
                }
                else
                {
                    path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height);
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
                }
                path.CloseFigure();
            }
            return(path);
        }