-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathRoundedRectangleF.cs
48 lines (41 loc) · 1.59 KB
/
RoundedRectangleF.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Drawing;
using System.Drawing.Drawing2D;
namespace AndroidSideloader
{
public class RoundedRectangleF
{
private Point location;
private readonly float x, y;
private readonly float width, height;
public RoundedRectangleF(float width, float height, float radius, float x = 0, float y = 0)
{
location = new Point(0, 0);
Radius = radius;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
Path = new GraphicsPath();
if (radius <= 0)
{
Path.AddRectangle(new RectangleF(x, y, width, height));
return;
}
RectangleF upperLeftRect = new RectangleF(x, y, 2 * radius, 2 * radius);
RectangleF upperRightRect = new RectangleF(width - (2 * radius) - 1, x, 2 * radius, 2 * radius);
RectangleF lowerLeftRect = new RectangleF(x, height - (2 * radius) - 1, 2 * radius, 2 * radius);
RectangleF lowerRightRect = new RectangleF(width - (2 * radius) - 1, height - (2 * radius) - 1, 2 * radius, 2 * radius);
Path.AddArc(upperLeftRect, 180, 90);
Path.AddArc(upperRightRect, 270, 90);
Path.AddArc(lowerRightRect, 0, 90);
Path.AddArc(lowerLeftRect, 90, 90);
Path.CloseAllFigures();
}
public RoundedRectangleF()
{
}
public GraphicsPath Path { get; }
public RectangleF Rect => new RectangleF(x, y, width, height);
public float Radius { get; set; }
}
}