Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Implemented negative border-radius (Used to make concave border)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piripe committed Jul 22, 2022
1 parent 8c766dd commit 8fd2ec0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
13 changes: 3 additions & 10 deletions Oxygen/Modules/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void RenderSrc()
}
if (int.TryParse((tgaInfo.Attribute("height") ?? new XAttribute("height", imageWidth.ToString())).Value, out int srcHeight))
{
if (srcWidth < 1)
if (srcHeight < 1)
{
ErrorManager.Error("\"height\" Attribute must be positive.", file, destfile);
return;
Expand All @@ -403,20 +403,13 @@ void RenderSrc()
if (float.TryParse((tgaInfo.Attribute("stroke-width") ?? new XAttribute("stroke-width", "1")).Value, out float strokeWidth))
{

if (srcWidth < 1)
if (strokeWidth < 1)
{
ErrorManager.Error("\"stroke-width\" Attribute must be positive.", file, destfile);
return;
}
if (int.TryParse((tgaInfo.Attribute("border-radius") ?? new XAttribute("border-radius", "0")).Value, out int borderRadius))
{

if (srcWidth < 0)
{
ErrorManager.Error("\"border-radius\" Attribute must be greater or equal to 0.", file, destfile);
return;
}

int strokePathOffset = 0;

switch (strokeAlign)
Expand Down Expand Up @@ -453,7 +446,7 @@ void RenderSrc()
{
img_g.SmoothingMode = SmoothingMode.HighQuality;
graphicsPath.AddRoundedRectangle(new RectangleF(srcX - 0.5f, srcY - 0.5f, srcWidth, srcHeight), borderRadius);
strokeGraphicsPath.AddRoundedRectangle(new RectangleF(srcX - strokePathOffset / 2f - 0.5f, srcY - strokePathOffset / 2f - 0.5f, srcWidth + strokePathOffset, srcHeight + strokePathOffset), borderRadius + strokePathOffset/2);
strokeGraphicsPath.AddRoundedRectangle(new RectangleF(srcX - strokePathOffset / 2f - 0.5f, srcY - strokePathOffset / 2f - 0.5f, srcWidth + strokePathOffset, srcHeight + strokePathOffset), borderRadius + (borderRadius > 0 ? strokePathOffset : -strokePathOffset) / 2);
}
break;
case "ellipse":
Expand Down
35 changes: 26 additions & 9 deletions Oxygen/Modules/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,32 @@ internal static void SetOrAdd<T, U>(this Dictionary<T, U> dict, T key, U value)

internal static void AddRoundedRectangle(this GraphicsPath path, RectangleF rect, float radius)
{
radius = Math.Min(radius, rect.Width/2);
path.AddArc(rect.Left, rect.Top, radius*2, radius * 2, 180, 90);
path.AddLine(rect.Left+radius,rect.Top,rect.Right-radius,rect.Top);
path.AddArc(rect.Right-radius * 2, rect.Top, radius * 2, radius * 2, 270, 90);
path.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom-radius);
path.AddArc(rect.Right - radius * 2, rect.Bottom-radius * 2, radius * 2, radius * 2, 0, 90);
path.AddLine(rect.Right-radius, rect.Bottom, rect.Left+radius, rect.Bottom);
path.AddArc(rect.Left, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
path.AddLine(rect.Left, rect.Bottom-radius, rect.Left, rect.Top+radius);
if (radius > 0)
{
radius = Math.Min(radius, rect.Width / 2);
path.AddArc(rect.Left, rect.Top, radius * 2, radius * 2, 180, 90);
path.AddLine(rect.Left + radius, rect.Top, rect.Right - radius, rect.Top);
path.AddArc(rect.Right - radius * 2, rect.Top, radius * 2, radius * 2, 270, 90);
path.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius);
path.AddArc(rect.Right - radius * 2, rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90);
path.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom);
path.AddArc(rect.Left, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
path.AddLine(rect.Left, rect.Bottom - radius, rect.Left, rect.Top + radius);
path.CloseFigure();
}
else
{
radius = Math.Max(radius, -rect.Width / 2);
path.AddArc(rect.Left+radius, rect.Top+radius, radius * -2, radius * -2, 90, -90);
path.AddLine(rect.Left - radius, rect.Top, rect.Right + radius, rect.Top);
path.AddArc(rect.Right + radius, rect.Top + radius, radius * -2, radius * -2, 180, -90);
path.AddLine(rect.Right, rect.Top - radius, rect.Right, rect.Bottom + radius);
path.AddArc(rect.Right + radius, rect.Bottom + radius, radius * -2, radius * -2, 270, -90);
path.AddLine(rect.Right + radius, rect.Bottom, rect.Left - radius, rect.Bottom);
path.AddArc(rect.Left + radius, rect.Bottom + radius, radius * -2, radius * -2, 0, -90);
path.AddLine(rect.Left, rect.Bottom + radius, rect.Left, rect.Top - radius);
path.CloseFigure();
}
}

#endregion
Expand Down

0 comments on commit 8fd2ec0

Please sign in to comment.