Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Generate a curved path from a rectangle
- /// </summary>
- /// <param name="rec">The Rectangle to base the shape on</param>
- /// <param name="gp">The GraphicsPath to modify</param>
- /// <param name="radius">A float value to set the radius of the curve</param>
- /// <param name="inflate">The amount to inflate the Rectangle by (negative values will deflate)</param>
- public void makeCurve(RectangleF rec, ref GraphicsPath gp, float radius, float inflate)
- {
- radius += inflate;
- if (radius < 1)
- radius = 1;
- inflate = inflate / 2;
- rec.Width += inflate;
- rec.Height += inflate;
- rec.X -= inflate;
- rec.Y -= inflate;
- gp.AddArc(new RectangleF(rec.Location, new SizeF(radius, radius)), 180, 90); // Left-Top
- gp.AddLine(gp.GetLastPoint(), new PointF(rec.Width - radius, rec.Y)); // Top
- gp.AddArc(new RectangleF(gp.GetLastPoint(), new SizeF(radius, radius)), -90, 90); // Right-Top
- gp.AddLine(gp.GetLastPoint(), new PointF(rec.Width, rec.Height - radius)); // Right
- gp.AddArc(new RectangleF(new PointF(gp.GetLastPoint().X - radius, gp.GetLastPoint().Y), new SizeF(radius, radius)), 0, 90); // Right-Bottom
- gp.AddLine(gp.GetLastPoint(), new PointF(rec.X + radius, rec.Height)); // Bottom
- gp.AddArc(new RectangleF(new PointF(rec.X, gp.GetLastPoint().Y - radius), new SizeF(radius, radius)), 90, 90); // Left-Bottom
- gp.AddLine(gp.GetLastPoint(), new PointF(rec.X, rec.Y + radius)); // Left
- gp.CloseFigure();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement