-
Notifications
You must be signed in to change notification settings - Fork 13
/
DrawHelper.cs
43 lines (39 loc) · 1.82 KB
/
DrawHelper.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
using System.Drawing;
using System.Drawing.Drawing2D;
namespace MaterialSkin
{
static class DrawHelper
{
public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddLine(x + radius, y, x + width - (radius * 2), y);
gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(x, y + height - (radius * 2), x, y + radius);
gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
return gp;
}
public static GraphicsPath CreateRoundRect(Rectangle rect, float radius)
{
return CreateRoundRect(rect.X, rect.Y, rect.Width, rect.Height, radius);
}
public static Color BlendColor(Color backgroundColor, Color frontColor, double blend)
{
double ratio = blend / 255d;
double invRatio = 1d - ratio;
int r = (int)((backgroundColor.R * invRatio) + (frontColor.R * ratio));
int g = (int)((backgroundColor.G * invRatio) + (frontColor.G * ratio));
int b = (int)((backgroundColor.B * invRatio) + (frontColor.B * ratio));
return Color.FromArgb(r, g, b);
}
public static Color BlendColor(Color backgroundColor, Color frontColor)
{
return BlendColor(backgroundColor, frontColor, frontColor.A);
}
}
}