This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/RyzStudio/Drawing/LeftRectangoid.cs
2020-04-27 13:17:13 +01:00

137 lines
2.9 KiB
C#

namespace RyzStudio.Drawing
{
using System.Drawing;
using System.Drawing.Drawing2D;
public struct LeftRectangoid
{
private int X;
private int Y;
private int Width;
private int Height;
private int Radius;
public LeftRectangoid(Rectangle rect, int radius)
{
X = rect.X;
Y = rect.Y;
Width = rect.Width;
Height = rect.Height;
Radius = radius;
}
public LeftRectangoid(Rectangle rect, int radius, int borderWidth)
{
rect.Inflate((-1 * borderWidth), (-1 * borderWidth));
X = rect.X;
Y = rect.Y;
Width = rect.Width;
Height = rect.Height;
Radius = radius;
}
public LeftRectangoid(int x, int y, int width, int height, int radius)
{
X = x;
Y = y;
Width = width;
Height = height;
Radius = radius;
}
public LeftRectangoid(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
Radius = 0;
}
public LeftRectangoid(int width, int height, int radius)
{
X = 0;
Y = 0;
Width = width;
Height = height;
Radius = radius;
}
public LeftRectangoid(int width, int height)
{
X = 0;
Y = 0;
Width = width;
Height = height;
Radius = 0;
}
public LeftRectangoid(int width)
{
X = 0;
Y = 0;
Width = width;
Height = width;
Radius = 0;
}
public GraphicsPath ToGraphicsPath()
{
GraphicsPath rv = new GraphicsPath();
rv.AddLine(X + Width, Y + Height, X + this.Radius, Y + Height);
if (this.Radius > 0)
{
rv.AddArc(X, Y + Height - (this.Radius * 2), this.Radius * 2, this.Radius * 2, 90, 90);
}
rv.AddLine(X, Y + Height - (this.Radius * 2), X, Y + this.Radius);
if (this.Radius > 0)
{
rv.AddArc(X, Y, this.Radius * 2, this.Radius * 2, 180, 90);
}
rv.AddLine(X + Width, Y, X + this.Radius, Y);
return rv;
}
public GraphicsPath ToClosedGraphicsPath()
{
GraphicsPath rv = new GraphicsPath();
rv.AddLine(X + this.Radius, Y, X + Width, Y);
rv.AddLine(X + Width + this.Radius, Y + this.Radius, X + Width + this.Radius, Y + Height);
rv.AddLine(X + Width + this.Radius, Y + Height, X + this.Radius, Y + Height);
if (this.Radius > 0)
{
rv.AddArc(X, Y + Height - (this.Radius * 2), this.Radius * 2, this.Radius * 2, 90, 90);
}
rv.AddLine(X, Y + Height - (this.Radius * 2), X, Y + this.Radius);
if (this.Radius > 0)
{
rv.AddArc(X, Y, this.Radius * 2, this.Radius * 2, 180, 90);
}
rv.AddLine(X + Width + this.Radius, Y, X + this.Radius, Y);
return rv;
}
public PointF GetOrigin()
{
PointF rv = new PointF();
rv.X = ((float)Width / 2) + X;
rv.Y = ((float)Height / 2) + Y;
return rv;
}
}
}