-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundedRectangle.cs
More file actions
48 lines (43 loc) · 1.48 KB
/
RoundedRectangle.cs
File metadata and controls
48 lines (43 loc) · 1.48 KB
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;
using SFML.Graphics;
using SFML.System;
namespace KeyOverlay
{
class RoundedRectangle : ConvexShape
{
public RoundedRectangle(float width, float height, float radius)
{
radius = Math.Min(radius, Math.Min(width, height) / 2);
uint points = ((uint)Math.Ceiling(radius)) * 2;
SetPointCount(points * 4);
float x = 0, y = 0;
for(uint i = 0; i < points; i++)
{
x += radius / points;
y = (float)Math.Sqrt(radius * radius - x * x);
SetPoint(i, new Vector2f(x + width - radius, radius - y));
}
y = 0;
for(uint i = 0; i < points; i++)
{
y += radius / points;
x = (float)Math.Sqrt(radius * radius - y * y);
SetPoint(points + i, new Vector2f(x + width - radius, y + height - radius));
}
x = 0;
for(uint i = 0; i < points; i++)
{
x += radius / points;
y = (float)Math.Sqrt(radius * radius - x * x);
SetPoint(points * 2 + i, new Vector2f(radius - x, y + height - radius));
}
y = 0;
for(uint i = 0; i < points; i++)
{
y += radius / points;
x = (float)Math.Sqrt(radius * radius - y * y);
SetPoint(points * 3 + i, new Vector2f(radius - x, radius - y));
}
}
}
}