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

namespace Super2d3dGraphLibrary;

[Description("Clase para el dibujado de áreas en 3d")]
internal class Area3dRenderer
{
	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 Area3dRenderer(CustomGraphics g, PointF[] points, float dx, float dy, Rectangle rColor, Color c2, Color c1, bool blnPrimero, bool blnUltimo)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		GraphicsPath graphicsPath2 = new GraphicsPath();
		GraphicsPath graphicsPath3 = new GraphicsPath();
		Pen pen = new Pen(Color.FromArgb(32, 0, 0, 0), 1f)
		{
			LineJoin = LineJoin.Bevel
		};
		Color c1a = default(Color);
		Color c2a = default(Color);
		m_CalculateColorRamp(c1, c2, ref c1a, ref c2a);
		if (points[0].Y >= points[1].Y)
		{
			graphicsPath.StartFigure();
			graphicsPath.AddLine(points[1].X, points[1].Y, points[1].X + dx, points[1].Y - dy);
			graphicsPath.AddLine(points[1].X + dx, points[1].Y - dy, points[2].X + dx, points[2].Y - dy);
			graphicsPath.AddLine(points[2].X + dx, points[2].Y - dy, points[2].X, points[2].Y);
			graphicsPath.CloseFigure();
			g.FillPath(new LinearGradientBrush(rColor, c1a, c2a, LinearGradientMode.Vertical), graphicsPath);
			graphicsPath2.StartFigure();
			graphicsPath2.AddLine(points[2].X, points[2].Y, points[2].X + dx, points[2].Y - dy);
			graphicsPath2.AddLine(points[2].X + dx, points[2].Y - dy, points[2].X + dx, points[3].Y - dy);
			graphicsPath2.AddLine(points[2].X + dx, points[3].Y - dy, points[3].X, points[3].Y);
			graphicsPath2.CloseFigure();
			g.FillPath(new LinearGradientBrush(rColor, c1a, c2a, LinearGradientMode.Vertical), graphicsPath2);
			g.FillPolygon(new LinearGradientBrush(rColor, c1, c2, LinearGradientMode.Vertical), points);
			if ((points[2].Y > points[1].Y) | (Math.Abs(points[1].X - points[2].X) > Math.Abs(points[1].Y - points[2].Y)))
			{
				g.DrawPath(pen, graphicsPath);
			}
			else
			{
				g.DrawLine(pen, points[1].X, points[1].Y, points[2].X, points[2].Y);
			}
		}
		else
		{
			graphicsPath.StartFigure();
			graphicsPath.AddLine(points[1].X, points[1].Y, points[1].X + dx, points[1].Y - dy);
			graphicsPath.AddLine(points[1].X + dx, points[1].Y - dy, points[2].X + dx, points[2].Y - dy);
			graphicsPath.AddLine(points[2].X + dx, points[2].Y - dy, points[2].X, points[2].Y);
			graphicsPath.CloseFigure();
			g.FillPath(new LinearGradientBrush(rColor, c1a, c2a, LinearGradientMode.Vertical), graphicsPath);
			graphicsPath2.StartFigure();
			graphicsPath2.AddLine(points[2].X, points[2].Y, points[2].X + dx, points[2].Y - dy);
			graphicsPath2.AddLine(points[2].X + dx, points[2].Y - dy, points[2].X + dx, points[3].Y - dy);
			graphicsPath2.AddLine(points[2].X + dx, points[3].Y - dy, points[3].X, points[3].Y);
			graphicsPath2.CloseFigure();
			g.FillPath(new LinearGradientBrush(rColor, c1a, c2a, LinearGradientMode.Vertical), graphicsPath2);
			graphicsPath3.StartFigure();
			graphicsPath3.AddLine(points[0].X, points[0].Y, points[0].X + dx, points[0].Y - dy);
			graphicsPath3.AddLine(points[0].X + dx, points[0].Y - dy, points[2].X + dx, points[3].Y - dy);
			graphicsPath3.AddLine(points[2].X + dx, points[3].Y - dy, points[3].X, points[3].Y);
			graphicsPath3.CloseFigure();
			g.FillPath(new LinearGradientBrush(rColor, c1a, c2a, LinearGradientMode.Vertical), graphicsPath3);
			g.FillPolygon(new LinearGradientBrush(rColor, c1, c2, LinearGradientMode.Vertical), points);
		}
		if (blnPrimero)
		{
			g.DrawLine(pen, points[0].X, points[0].Y, points[1].X, points[1].Y);
		}
		else if (blnUltimo)
		{
			g.DrawLine(pen, points[2].X, points[2].Y, points[3].X, points[3].Y);
		}
	}
}
