public void FillRectangle(Brush brush, float x, float y, float width, float height, float radius, RectangleCorners corners) { GraphicsPath p = GetRectangleWithRoundedCorners(x, y, width, height, radius, corners); gc.FillPath(brush, p); }
/// <summary> /// Fills the interior of a rectangle with rounded corners specified by a pair of coordinates, a width, and a height. /// </summary> /// <param name="brush">Brush that determines the characteristics of the fill.</param> /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="width">Width of the rectangle to fill.</param> /// <param name="height">Height of the rectangle to fill.</param> /// <param name="radius"></param> /// <param name="corners"></param> public void FillRectangle(Brush brush, float x, float y, float width, float height, float radius, RectangleCorners corners) { SetBrush(brush); template.RoundRectangle(x, y, width, height, radius); template.Fill(); }
/// <summary> /// Fills the interior of a rectangle with rounded corners specified by a pair of coordinates, a width, and a height. /// </summary> /// <param name="brush">Brush that determines the characteristics of the fill.</param> /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="width">Width of the rectangle to fill.</param> /// <param name="height">Height of the rectangle to fill.</param> /// <param name="radius"></param> /// <param name="corners"></param> public void FillRectangle(Brush brush, float x, float y, float width, float height, float radius, RectangleCorners corners) { rectList.Add(new Rect { X = x, Y = y, Width = width, Height = height, Fill = BrushColor(brush), Transform = Transform, Rx = radius, Ry = radius }); }
private void DrawHalfBox(Rectangle halfRectangle, int radius, RectangleCorners corners, string s) { var path = RoundedRectangle.Create(halfRectangle, radius, corners); Gfx.FillPath(backFillTop, path); if (!String.IsNullOrEmpty(s)) { DrawString(s, smallCityFont, halfRectangle); } }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, int radiusB = 0) { int num = x + width; int num2 = y + height; if (radiusB == 0) { radiusB = radius; } int x2 = num - radius; int x3 = x + radius; int num3 = y + radius; int num4 = radius * 2; int x4 = num - num4; int x5 = num - radiusB; int num5 = num2 - radiusB; int x6 = x + radiusB; int num6 = radiusB * 2; int x7 = num - num6; int y2 = num2 - num6; RectangleCorners rectangleCorners = RectangleCorners.All; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.StartFigure(); if ((RectangleCorners.TopLeft & rectangleCorners) == RectangleCorners.TopLeft) { graphicsPath.AddArc(x, y, num4, num4, 180f, 90f); } graphicsPath.AddLine(x3, y, x2, y); if ((RectangleCorners.TopRight & rectangleCorners) == RectangleCorners.TopRight) { graphicsPath.AddArc(x4, y, num4, num4, 270f, 90f); } graphicsPath.AddLine(num, num3, num, num5); if ((RectangleCorners.BottomRight & rectangleCorners) == RectangleCorners.BottomRight) { graphicsPath.AddArc(x7, y2, num6, num6, 0f, 90f); } graphicsPath.AddLine(x5, num2, x6, num2); if ((RectangleCorners.BottomLeft & rectangleCorners) == RectangleCorners.BottomLeft) { graphicsPath.AddArc(x, y2, num6, num6, 90f, 90f); } graphicsPath.AddLine(x, num5, x, num3); graphicsPath.CloseFigure(); return(graphicsPath); }
public static GraphicsPath GenerateRoundedRectPath(Rectangle bounds, int roundradius, RectangleCorners roundedcorners) { GraphicsPath path = new GraphicsPath(); int doubleround = roundradius * 2; path.AddLine(new Point(bounds.X + (((roundedcorners & RectangleCorners.TopLeft) > 0) ? roundradius : 0), bounds.Y), new Point(bounds.X + bounds.Width - (((roundedcorners & RectangleCorners.TopRight) > 0) ? roundradius : 0), bounds.Y)); if ((roundedcorners & RectangleCorners.TopRight) > 0) { path.AddArc(new Rectangle(bounds.X + bounds.Width - doubleround, bounds.Y, doubleround, doubleround), 270, 90); } path.AddLine(new Point(bounds.X + bounds.Width, bounds.Y + (((roundedcorners & RectangleCorners.TopRight) > 0) ? roundradius : 0)), new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height - (((roundedcorners & RectangleCorners.BottomRight) > 0) ? roundradius : 0))); if ((roundedcorners & RectangleCorners.BottomRight) > 0) { path.AddArc(new Rectangle(bounds.X + bounds.Width - doubleround, bounds.Y + bounds.Height - doubleround, doubleround, doubleround), 0, 90); } path.AddLine(new Point(bounds.X + bounds.Width - (((roundedcorners & RectangleCorners.BottomRight) > 0) ? roundradius : 0), bounds.Y + bounds.Height), new Point(bounds.X + (((roundedcorners & RectangleCorners.BottomLeft) > 0) ? roundradius : 0), bounds.Y + bounds.Height)); if ((roundedcorners & RectangleCorners.BottomLeft) > 0) { path.AddArc(new Rectangle(bounds.X, bounds.Y + bounds.Height - doubleround, doubleround, doubleround), 90, 90); } path.AddLine(new Point(bounds.X, bounds.Y + bounds.Height - (((roundedcorners & RectangleCorners.BottomLeft) > 0) ? roundradius : 0)), new Point(bounds.X, bounds.Y + (((roundedcorners & RectangleCorners.TopLeft) > 0) ? roundradius : 0))); if ((roundedcorners & RectangleCorners.TopLeft) > 0) { path.AddArc(new Rectangle(bounds.X, bounds.Y, doubleround, doubleround), 180, 90); } return path; }
public System.Drawing.Drawing2D.GraphicsPath CreateRoundRect(System.Drawing.Rectangle rect, int radius, RectangleCorners corners) { return(CreateRoundRect(rect.X, rect.Y, rect.Width, rect.Height, radius, corners)); }
/// <summary> /// Creates a GraphicsPath object for a rounded rectangle. /// </summary> /// <param name="rect">The rectangle to use as the basis of the rounded rectangle.</param> /// <param name="radius">The radius of the rounded corners.</param> /// <param name="corners">The corners to round.</param> /// <returns>Returns the graphics path representing the rounded rectangle.</returns> public static GraphicsPath Create(RectangleF rect, float radius, RectangleCorners corners) { return(Create(rect.X, rect.Y, rect.Width, rect.Height, radius, corners)); }
/// <summary> /// Fills the interior of a rectangle with rounded corners specified by a pair of coordinates, a width, and a height. /// </summary> /// <param name="brush">Brush that determines the characteristics of the fill.</param> /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to fill.</param> /// <param name="width">Width of the rectangle to fill.</param> /// <param name="height">Height of the rectangle to fill.</param> /// <param name="radius"></param> /// <param name="corners"></param> public void FillRectangle(Brush brush, float x, float y, float width, float height, float radius, RectangleCorners corners) { rectList.Add(new Rect{ X = x, Y = y, Width = width, Height = height, Fill = BrushColor(brush), Transform = Transform, Rx = radius, Ry = radius }); }
public static GraphicsPath CreateRoundRectangle(Rectangle r, int radius, RectangleCorners corners) { Rectangle tlc = new Rectangle(r.Left, r.Top, 2 * radius, 2 * radius); Rectangle trc = tlc; trc.X = r.Right - 2 * radius; Rectangle blc = tlc; blc.Y = r.Bottom - 2 * radius; Rectangle brc = blc; brc.X = r.Right - 2 * radius; Point[] n = new Point[] { new Point(tlc.Left, tlc.Bottom), tlc.Location, new Point(tlc.Right, tlc.Top), trc.Location, new Point(trc.Right, trc.Top), new Point(trc.Right, trc.Bottom), new Point(brc.Right, brc.Top), new Point(brc.Right, brc.Bottom), new Point(brc.Left, brc.Bottom), new Point(blc.Right, blc.Bottom), new Point(blc.Left, blc.Bottom), blc.Location }; GraphicsPath p = new GraphicsPath(); p.StartFigure(); //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft) { p.AddArc(tlc, 180, 90); } else { p.AddLines(new Point[] { n[0], n[1], n[2] }); } //Top Edge p.AddLine(n[2], n[3]); //Top Right Corner if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight) { p.AddArc(trc, 270, 90); } else { p.AddLines(new Point[] { n[3], n[4], n[5] }); } //Right Edge p.AddLine(n[5], n[6]); //Bottom Right Corner if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight) { p.AddArc(brc, 0, 90); } else { p.AddLines(new Point[] { n[6], n[7], n[8] }); } //Bottom Edge p.AddLine(n[8], n[9]); //Bottom Left Corner if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft) { p.AddArc(blc, 90, 90); } else { p.AddLines(new Point[] { n[9], n[10], n[11] }); } //Left Edge p.AddLine(n[11], n[0]); p.CloseFigure(); return(p); }
public void DrawRectangle(Pen pen, float x, float y, float width, float height, float radius, RectangleCorners corners) { GraphicsPath path = GetRectangleWithRoundedCorners(x, y, width, height, radius, corners); gc.DrawPath(pen, path); }
public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners c, WhichHalf which_half) { return(Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c, which_half)); }
/// <summary> /// I don't even know what I was doing. /// </summary> public static GraphicsPath CreateFill(int realX, int realY, int realWidth, int realHeight, int borderRadius, RectangleCorners corners) { GraphicsPath p = new GraphicsPath(); p.StartFigure(); for (int radius = 0; radius < borderRadius; ++radius) { int x = realX + radius; int y = realY + radius; int width = realWidth - radius * 2; int height = realHeight - radius * 2; int xw = x + width; int yh = y + height; int xwr = xw - borderRadius; int yhr = yh - borderRadius; int xr = x + borderRadius; int yr = y + borderRadius; int r2 = borderRadius * 2; int xwr2 = xw - r2; int yhr2 = yh - r2; //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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.FillMode = FillMode.Alternate; p.CloseFigure(); return(p); }
private static GraphicsPath GetRectangleWithRoundedCorners(float x, float y, float width, float height, float radius, RectangleCorners corners) { float xw = x + width; float yh = y + height; float xwr = xw - radius; float yhr = yh - radius; float xr = x + radius; float yr = y + radius; float r2 = radius; float xwr2 = xw - r2; float yhr2 = yh - r2; GraphicsPath p = new GraphicsPath(); //p.StartFigure(); //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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); }
public void DrawRectangle(Pen pen, float x, float y, float width, float height, float radius, RectangleCorners corners) { SetPen(pen); template.RoundRectangle(x, y, width, height, radius); template.Stroke(); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners) { return Create(new Rectangle(x, y, width, height), radius, corners); }
public static GraphicsPath Create(Rectangle r, int radius, RectangleCorners corners) { Rectangle tlc = new Rectangle(r.Left, r.Top, Math.Min(2 * radius, r.Width), Math.Min(2 * radius, r.Height)); Rectangle trc = tlc; trc.X = r.Right - 2 * radius; Rectangle blc = tlc; blc.Y = r.Bottom - 2 * radius; Rectangle brc = blc; brc.X = r.Right - 2 * radius; Point[] n = new Point[] { new Point(tlc.Left, tlc.Bottom), tlc.Location, new Point(tlc.Right, tlc.Top), trc.Location, new Point(trc.Right, trc.Top), new Point(trc.Right, trc.Bottom), new Point(brc.Right, brc.Top), new Point(brc.Right, brc.Bottom), new Point(brc.Left, brc.Bottom), new Point(blc.Right, blc.Bottom), new Point(blc.Left, blc.Bottom), blc.Location }; GraphicsPath p = new GraphicsPath(); p.StartFigure(); //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft) { p.AddArc(tlc, 180, 90); } else { p.AddLines(new Point[] { n[0], n[1], n[2] }); } //Top Edge p.AddLine(n[2], n[3]); //Top Right Corner if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight) { p.AddArc(trc, 270, 90); } else { p.AddLines(new Point[] { n[3], n[4], n[5] }); } //Right Edge p.AddLine(n[5], n[6]); //Bottom Right Corner if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight) { p.AddArc(brc, 0, 90); } else { p.AddLines(new Point[] { n[6], n[7], n[8] }); } //Bottom Edge p.AddLine(n[8], n[9]); //Bottom Left Corner if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft) { p.AddArc(blc, 90, 90); } else { p.AddLines(new Point[] { n[9], n[10], n[11] }); } //Left Edge p.AddLine(n[11], n[0]); p.CloseFigure(); return p; }
private static GraphicsPath GetRectangleWithRoundedCorners(float x, float y, float width, float height, float radius, RectangleCorners corners) { float xw = x + width; float yh = y + height; float xwr = xw - radius; float yhr = yh - radius; float xr = x + radius; float yr = y + radius; float r2 = radius; float xwr2 = xw - r2; float yhr2 = yh - r2; GraphicsPath p = new GraphicsPath(); //p.StartFigure(); //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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; }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners) { GraphicsPath p = new GraphicsPath(); p.StartFigure(); // Top left corner if ((corners & RectangleCorners.TopLeft) == RectangleCorners.TopLeft) { p.AddArc(x, y, 2*radius, 2*radius, 180, 90); } else { p.AddLine(x, y + radius, x, y); p.AddLine(x, y, x + radius, y); } // Top edge //p.AddLine(x + radius, y, x + width - radius, y); // Top right corner if ((corners & RectangleCorners.TopRight) == RectangleCorners.TopRight) { p.AddArc(x + width - 2*radius, y, 2*radius, 2*radius, 270, 90); } else { p.AddLine(x + width - radius, y, x + width, y); p.AddLine(x + width, y, x + width, y + radius); } // Right edge //p.AddLine(x + width, y + radius, x + width, y + height - radius); // Bottom right corner if ((corners & RectangleCorners.BottomRight) == RectangleCorners.BottomRight) { p.AddArc(x + width - 2*radius, y + height - 2*radius, 2*radius, 2*radius, 0, 90); } else { p.AddLine(x + width, y + height - radius, x + width, y + height); p.AddLine(x + width, y + height, x + width - radius, y + height); } // Bottom edge //p.AddLine(x + width - radius, y + height, x + radius, y + height); // Bottom left corner if ((corners & RectangleCorners.BottomLeft) == RectangleCorners.BottomLeft) { p.AddArc(x, y + height - 2*radius, radius*2, radius*2, 90, 90); } else { p.AddLine(x + radius, y + height, x, y + height); p.AddLine(x, y + height, x, y + height - radius); } // Left edge //p.AddLine(x, y + height - radius, x, y + radius); p.CloseFigure(); return p; }
public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners corners) { return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, corners); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners, WhichHalf half) { if (radius <= 0) { GraphicsPath rectp = new GraphicsPath(); rectp.AddRectangle(new Rectangle(x, y, width, height)); return(rectp); } int dia = radius * 2; Rectangle TLarc = new Rectangle(x, y, dia, dia); Rectangle TRarc = new Rectangle(x + width - dia - 1, y, dia, dia); Rectangle BRarc = new Rectangle(x + width - dia - 1, y + height - dia - 1, dia, dia); Rectangle BLarc = new Rectangle(x, y + height - dia - 1, dia, dia); Rectangle TLsquare = new Rectangle(x, y, radius, radius); Rectangle TRsquare = new Rectangle(x + width - radius, y, radius, radius); Rectangle BRsquare = new Rectangle(x + width - radius, y + height - radius, radius, radius); Rectangle BLsquare = new Rectangle(x, y + height - radius, radius, radius); GraphicsPath p = new GraphicsPath(); p.StartFigure(); if (half == WhichHalf.Both || half == WhichHalf.TopLeft) { if (corners.HasFlag(RectangleCorners.BottomLeft)) { p.AddArc(BLarc, 135, 45); } else { p.AddLine(BLsquare.Left, BLsquare.Bottom, BLsquare.Left, BLsquare.Top); } p.AddLine(BLsquare.Left, BLsquare.Top - 1, TLsquare.Left, TLsquare.Bottom + 1); if (corners.HasFlag(RectangleCorners.TopLeft)) { p.AddArc(TLarc, 180, 90); } else { Corner(p, TLsquare.Left, TLsquare.Bottom, TLsquare.Left, TLsquare.Top, TLsquare.Right, TLsquare.Top); } p.AddLine(TLsquare.Right + 1, TLsquare.Top, TRsquare.Left - 1, TRsquare.Top); if (corners.HasFlag(RectangleCorners.TopRight)) { p.AddArc(TRarc, -90, 45); } } if (half == WhichHalf.Both || half == WhichHalf.BottomRight) { if (corners.HasFlag(RectangleCorners.TopRight)) { p.AddArc(TRarc, -45, 45); } else { p.AddLine(TRsquare.Right, TRsquare.Top, TRsquare.Right, TRsquare.Bottom); } p.AddLine(TRsquare.Right, TRsquare.Bottom + 1, BRsquare.Right, BRsquare.Top - 1); if (corners.HasFlag(RectangleCorners.BottomRight)) { p.AddArc(BRarc, 0, 90); } else { Corner(p, BRsquare.Right, BRsquare.Top, BRsquare.Right, BRsquare.Bottom, BRsquare.Left, BRsquare.Bottom); } p.AddLine(BRsquare.Left - 1, BRsquare.Bottom, BLsquare.Right + 1, BLsquare.Bottom); if (corners.HasFlag(RectangleCorners.BottomLeft)) { p.AddArc(BLarc, 90, 45); } else { p.AddLine(BLsquare.Right, BLsquare.Bottom, BLsquare.Left, BLsquare.Bottom); } } return(p); }
public void DrawRectangle(Pen pen, float x, float y, float w, float h, float radius, RectangleCorners corners) { rectList.Add(new Rect { X = x, Y = y, Width = w, Height = h, Fill = "none", Transform = Transform, Stroke = pen.Color.Name, StrokeWidth = pen.Width, Rx = radius, Ry = radius }); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="layout"></param> /// <param name="radius"></param> /// <param name="corners"></param> public static void AddRoundedRectangle(this GraphicsPath path, Rectangle layout, int radius, RectangleCorners corners) { if (path == null) { throw new ArgumentNullException("path"); } if (radius < 0) { throw new ArgumentOutOfRangeException("radius"); } //map the structure int xw = layout.Right, yh = layout.Bottom, xwr = xw - radius, yhr = yh - radius, xr = layout.X + radius, yr = layout.Y + radius, r2 = radius * 2, xwr2 = xw - r2, yhr2 = yh - r2; //create new figure path.StartFigure(); //draw top left corner if (corners.HasFlag(RectangleCorners.TopLeft)) { path.AddArc(layout.X, layout.Y, r2, r2, 180, 90); } else { path.AddLine(layout.X, yr, layout.X, layout.Y); path.AddLine(layout.X, layout.Y, xr, layout.Y); } //draw top line path.AddLine(xr, layout.Y, xwr, layout.Y); //draw top right corner if (corners.HasFlag(RectangleCorners.TopRight)) { path.AddArc(xwr2, layout.Y, r2, r2, 270, 90); } else { path.AddLine(xwr, layout.Y, xw, layout.Y); path.AddLine(xw, layout.Y, xw, yr); } //draw right line path.AddLine(xw, yr, xw, yhr); //draw bottom right corner if (corners.HasFlag(RectangleCorners.BottomRight)) { path.AddArc(xwr2, yhr2, r2, r2, 0, 90); } else { path.AddLine(xw, yhr, xw, yh); path.AddLine(xw, yh, xwr, yh); } //draw bottom line path.AddLine(xwr, yh, xr, yh); //draw bottom left corner if (corners.HasFlag(RectangleCorners.BottomLeft)) { path.AddArc(layout.X, yhr2, r2, r2, 90, 90); } else { path.AddLine(xr, yh, layout.X, yh); path.AddLine(layout.X, yh, layout.X, yhr); } //draw left line path.AddLine(layout.X, yhr, layout.X, yr); //complete figure path.CloseFigure(); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners 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 ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners 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 ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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; }
/// <summary> /// I don't even know what I was doing. /// </summary> public static GraphicsPath CreateFill(int realX, int realY, int realWidth, int realHeight, int borderRadius, RectangleCorners corners) { GraphicsPath p = new GraphicsPath(); p.StartFigure(); for (int radius = 0; radius < borderRadius; ++radius) { int x = realX + radius; int y = realY + radius; int width = realWidth - radius * 2; int height = realHeight - radius * 2; int xw = x + width; int yh = y + height; int xwr = xw - borderRadius; int yhr = yh - borderRadius; int xr = x + borderRadius; int yr = y + borderRadius; int r2 = borderRadius * 2; int xwr2 = xw - r2; int yhr2 = yh - r2; //Top Left Corner if ((RectangleCorners.TopLeft & corners) == RectangleCorners.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 ((RectangleCorners.TopRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomRight & corners) == RectangleCorners.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 ((RectangleCorners.BottomLeft & corners) == RectangleCorners.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.FillMode = FillMode.Alternate; p.CloseFigure(); return p; }
public static GraphicsPath RoundBorders(this Rectangle rect, int radius, RectangleCorners c) { return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c); }
public static IEnumerable <GsVector> CreateRoundRect(GsRectangle rect, float radius, RectangleCorners corners) { float l = rect.Left; float t = rect.Top; float r = rect.Right; float b = rect.Bottom; float lr = rect.Left + radius; float tr = rect.Top + radius; float rr = rect.Right - radius; float br = rect.Bottom - radius; List <GsVector> polygon = new List <GsVector>(); // upper-left if ((corners & RectangleCorners.TopLeft) != 0) { GsVector[] upleft_corner = new GsVector[3] { new GsVector(l, tr), new GsVector(l, t), new GsVector(lr, t), }; polygon.AddRange(CreateBezier(upleft_corner)); } else { polygon.Add(new GsVector(l, t)); } // upper-right if ((corners & RectangleCorners.TopRight) != 0) { GsVector[] upright_corner = new GsVector[3] { new GsVector(rr, t), new GsVector(r, t), new GsVector(r, tr), }; polygon.AddRange(CreateBezier(upright_corner)); } else { polygon.Add(new GsVector(r, t)); } // bottom-right if ((corners & RectangleCorners.BottomRight) != 0) { GsVector[] bottomright_corner = new GsVector[3] { new GsVector(r, br), new GsVector(r, b), new GsVector(rr, b), }; polygon.AddRange(CreateBezier(bottomright_corner)); } else { polygon.Add(new GsVector(r, b)); } // bottom-left if ((corners & RectangleCorners.BottomLeft) != 0) { GsVector[] bottomleft_corner = new GsVector[3] { new GsVector(lr, b), new GsVector(l, b), new GsVector(l, br), }; polygon.AddRange(CreateBezier(bottomleft_corner)); } else { polygon.Add(new GsVector(l, b)); } // close it up polygon.Add(polygon[0]); // return it! return(polygon); }
public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners c) { return(Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c)); }
public void DrawRectangle(Pen pen, float x, float y, float w, float h, float radius, RectangleCorners corners) { rectList.Add(new Rect{ X = x, Y = y, Width = w, Height = h, Fill = "none", Transform = Transform, Stroke = pen.Color.Name, StrokeWidth = pen.Width, Rx = radius, Ry = radius }); }