using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using Microsoft.VisualBasic.CompilerServices;

namespace Super2d3dGraphLibrary;

[Description("Clase para el dibujado de rectángulos")]
internal class RoundedRectangle
{
	private GraphicsPath p;

	private CustomGraphics _g;

	public RectangleF RECT => p.GetBounds();

	public GraphicsPath PATH => p;

	public RoundedRectangle(CustomGraphics g, RectangleF rf, float sngRoundedEffect)
	{
		p = new GraphicsPath();
		try
		{
			float num = ((!(rf.Width > rf.Height)) ? (rf.Width * sngRoundedEffect) : (rf.Height * sngRoundedEffect));
			float left = rf.Left;
			float top = rf.Top;
			_g = g;
			p.StartFigure();
			GraphicsPath graphicsPath = p;
			RectangleF rect = new RectangleF(left, top, num, num);
			graphicsPath.AddArc(rect, 180f, 90f);
			p.AddLine(left + num, top, left + rf.Width - num, top);
			GraphicsPath graphicsPath2 = p;
			rect = new RectangleF(left + rf.Width - num, top, num, num);
			graphicsPath2.AddArc(rect, -90f, 90f);
			p.AddLine(left + rf.Width, top + num, left + rf.Width, top + rf.Height - num);
			GraphicsPath graphicsPath3 = p;
			rect = new RectangleF(left + rf.Width - num, top + rf.Height - num, num, num);
			graphicsPath3.AddArc(rect, 0f, 90f);
			p.AddLine(left + rf.Width - num, top + rf.Height, left + num, top + rf.Height);
			GraphicsPath graphicsPath4 = p;
			rect = new RectangleF(left, top + rf.Height - num, num, num);
			graphicsPath4.AddArc(rect, 90f, 90f);
			p.CloseFigure();
		}
		catch (ApplicationException ex)
		{
			ProjectData.SetProjectError(ex);
			ApplicationException ex2 = ex;
			ProjectData.ClearProjectError();
		}
	}

	public void Render(Color borderColor, Color backColor)
	{
		_g.FillRoundedRectangle(borderColor, backColor, p);
	}

	public void Render(Color borderColor, LinearGradientBrush brush)
	{
		_g.FillHorizontalRoundedRectangle(new Pen(borderColor), brush, p);
	}
}
