using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Super2d3dGraphLibrary;

[Description("Clase para el dibujado de rectángulos en 3d")]
internal class Rectangle3dRenderer
{
	private void m_CalculateColorRamp(Color c1, Color c2, ref Color c1a, ref Color c2a)
	{
		c1 = ControlPaint.Dark(c1, 0.2f);
		c2 = ControlPaint.Light(c2, 0.2f);
		c1a = Color.FromArgb(255, c1.R, c1.G, c1.B);
		c2a = Color.FromArgb(255, c2.R, c2.G, c2.B);
	}

	public Rectangle3dRenderer(CustomGraphics g, RectangleF r, float dx, float dy, Rectangle rColor, Color c2, Color c1)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		Pen pen = new Pen(Color.FromArgb(64, 0, 0, 0), 1f)
		{
			LineJoin = LineJoin.Bevel
		};
		Color c1a = default(Color);
		Color c2a = default(Color);
		m_CalculateColorRamp(c1, c2, ref c1a, ref c2a);
		graphicsPath.StartFigure();
		graphicsPath.AddLine(r.Left, r.Top, r.Left + dx, r.Top - dy);
		graphicsPath.AddLine(r.Left + dx, r.Top - dy, r.Right + dx, r.Top - dy);
		graphicsPath.AddLine(r.Right + dx, r.Top - dy, r.Right, r.Top);
		graphicsPath.AddLine(r.Right, r.Top, r.Left, r.Top);
		graphicsPath.CloseFigure();
		g.FillPath(new LinearGradientBrush(graphicsPath.GetBounds(), c2, c1, LinearGradientMode.BackwardDiagonal), graphicsPath);
		g.DrawPath(pen, graphicsPath);
		graphicsPath.Reset();
		graphicsPath.StartFigure();
		graphicsPath.AddLine(r.Right, r.Top, r.Right + dx, r.Top - dy);
		graphicsPath.AddLine(r.Right + dx, r.Top - dy, r.Right + dx, r.Bottom - dy);
		graphicsPath.AddLine(r.Right + dx, r.Bottom - dy, r.Right, r.Bottom);
		graphicsPath.AddLine(r.Right, r.Bottom, r.Right, r.Top);
		graphicsPath.CloseFigure();
		g.FillPath(new LinearGradientBrush(rColor, c2a, c1a, LinearGradientMode.Horizontal), graphicsPath);
		g.DrawPath(pen, graphicsPath);
		Rectangle r2 = checked(Rectangle.FromLTRB((int)Math.Round(r.Left), (int)Math.Round(r.Top), (int)Math.Round(r.Left + r.Width), (int)Math.Round(r.Top + r.Height)));
		g.FillRectangle(new LinearGradientBrush(rColor, c1, c2, LinearGradientMode.Vertical), r2);
		g.DrawRectangle(pen, r2);
	}
}
