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 Cylinder3dRenderer
{
	private void m_CalculateColorRamp(Color col, ref Color c1, ref Color c2)
	{
		c1 = ControlPaint.Dark(col, 0.2f);
		c2 = ControlPaint.Light(col, 0.2f);
	}

	public Cylinder3dRenderer(CustomGraphics g, RectangleF r, float dx, float dy, Color col)
	{
		GraphicsPath graphicsPath = new GraphicsPath();
		Pen pen = new Pen(Color.Black, 2f)
		{
			LineJoin = LineJoin.Bevel
		};
		Color c = default(Color);
		Color c2 = default(Color);
		m_CalculateColorRamp(col, ref c, ref c2);
		checked
		{
			int num = (int)Math.Round(r.Bottom);
			int num2 = (int)Math.Round(r.Top);
			for (int i = num; i >= num2; i += -1)
			{
				Rectangle rectangle = new Rectangle((int)Math.Round(r.Left + r.Width / 2f - dx / 2f), (int)Math.Round((float)i - dy / 2f), (int)Math.Round(dx), (int)Math.Round(dy));
				if (((float)i == r.Bottom) | ((float)i == r.Top))
				{
					GraphicsPath graphicsPath2 = new GraphicsPath();
					graphicsPath2.AddEllipse(rectangle);
					PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath2);
					PointF centerPoint = new PointF((float)((double)rectangle.X + (double)rectangle.Width / 3.0), (float)((double)rectangle.Y + (double)rectangle.Height / 3.0));
					pathGradientBrush.CenterPoint = centerPoint;
					pathGradientBrush.SurroundColors = new Color[1] { c };
					pathGradientBrush.CenterColor = c2;
					g.FillEllipse(pathGradientBrush, rectangle);
				}
				else
				{
					g.DrawEllipse(new Pen(new LinearGradientBrush(rectangle, c, c2, LinearGradientMode.Horizontal)), rectangle);
				}
			}
		}
	}
}
