using LYFZ.OtherExpansion.SkinClass;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace LYFZ.OtherExpansion.SkinControl
{
	internal class CmbRenderHelper
	{
		internal static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, bool drawBorder, bool drawGlass, LinearGradientMode mode)
		{
			CmbRenderHelper.RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, style, 8, drawBorder, drawGlass, mode);
		}
		internal static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, bool drawBorder, bool drawGlass, LinearGradientMode mode)
		{
			CmbRenderHelper.RenderBackgroundInternal(g, rect, baseColor, borderColor, innerBorderColor, style, 8, 0.45f, drawBorder, drawGlass, mode);
		}
		internal static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
		{
			if (drawBorder)
			{
				rect.Width--;
				rect.Height--;
			}
			using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
			{
				Color[] colors = new Color[]
				{
					CmbRenderHelper.GetColor(baseColor, 0, 35, 24, 9),
					CmbRenderHelper.GetColor(baseColor, 0, 13, 8, 3),
					baseColor,
					CmbRenderHelper.GetColor(baseColor, 0, 35, 24, 9)
				};
				brush.InterpolationColors = new ColorBlend
				{
					Positions = new float[]
					{
						0f,
						basePosition,
						basePosition + 0.05f,
						1f
					},
					Colors = colors
				};
				if (style != RoundStyle.None)
				{
					using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
					{
						g.FillPath(brush, path);
					}
					if (baseColor.A > 80)
					{
						Rectangle rectTop = rect;
						if (mode == LinearGradientMode.Vertical)
						{
							rectTop.Height = (int)((float)rectTop.Height * basePosition);
						}
						else
						{
							rectTop.Width = (int)((float)rect.Width * basePosition);
						}
						using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(rectTop, roundWidth, RoundStyle.Top, false))
						{
							using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
							{
								g.FillPath(brushAlpha, pathTop);
							}
						}
					}
					if (drawGlass)
					{
						RectangleF glassRect = rect;
						if (mode == LinearGradientMode.Vertical)
						{
							glassRect.Y = (float)rect.Y + (float)rect.Height * basePosition;
							glassRect.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
						}
						else
						{
							glassRect.X = (float)rect.X + (float)rect.Width * basePosition;
							glassRect.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
						}
						ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
					}
					if (!drawBorder)
					{
						goto IL_412;
					}
					using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
					{
						using (Pen pen = new Pen(borderColor))
						{
							g.DrawPath(pen, path2);
						}
					}
					rect.Inflate(-1, -1);
					using (GraphicsPath path3 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
					{
						using (Pen pen2 = new Pen(innerBorderColor))
						{
							g.DrawPath(pen2, path3);
						}
						goto IL_412;
					}
				}
				g.FillRectangle(brush, rect);
				if (baseColor.A > 80)
				{
					Rectangle rectTop2 = rect;
					if (mode == LinearGradientMode.Vertical)
					{
						rectTop2.Height = (int)((float)rectTop2.Height * basePosition);
					}
					else
					{
						rectTop2.Width = (int)((float)rect.Width * basePosition);
					}
					using (SolidBrush brushAlpha2 = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
					{
						g.FillRectangle(brushAlpha2, rectTop2);
					}
				}
				if (drawGlass)
				{
					RectangleF glassRect2 = rect;
					if (mode == LinearGradientMode.Vertical)
					{
						glassRect2.Y = (float)rect.Y + (float)rect.Height * basePosition;
						glassRect2.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
					}
					else
					{
						glassRect2.X = (float)rect.X + (float)rect.Width * basePosition;
						glassRect2.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
					}
					ControlPaintEx.DrawGlass(g, glassRect2, 200, 0);
				}
				if (drawBorder)
				{
					using (Pen pen3 = new Pen(borderColor))
					{
						g.DrawRectangle(pen3, rect);
					}
					rect.Inflate(-1, -1);
					using (Pen pen4 = new Pen(innerBorderColor))
					{
						g.DrawRectangle(pen4, rect);
					}
				}
				IL_412:;
			}
		}
		internal static Color GetColor(Color colorBase, int a, int r, int g, int b)
		{
			int a2 = (int)colorBase.A;
			int r2 = (int)colorBase.R;
			int g2 = (int)colorBase.G;
			int b2 = (int)colorBase.B;
			if (a + a2 > 255)
			{
				a = 255;
			}
			else
			{
				a = Math.Max(0, a + a2);
			}
			if (r + r2 > 255)
			{
				r = 255;
			}
			else
			{
				r = Math.Max(0, r + r2);
			}
			if (g + g2 > 255)
			{
				g = 255;
			}
			else
			{
				g = Math.Max(0, g + g2);
			}
			if (b + b2 > 255)
			{
				b = 255;
			}
			else
			{
				b = Math.Max(0, b + b2);
			}
			return Color.FromArgb(a, r, g, b);
		}
	}
}