using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;

namespace TD.SandDock.Rendering
{
	[TypeConverter(typeof(RendererBaseConverter))]
	public abstract class RendererBase : IDisposable
	{
		public RendererBase()
		{
			SystemEvents.UserPreferenceChanged += this.a;
			this.CalculateBaseColors();
		}

		public void Dispose()
		{
			SystemEvents.UserPreferenceChanged -= this.a;
		}

		private void a(object A_0, UserPreferenceChangedEventArgs A_1)
		{
			if (A_1.Category == UserPreferenceCategory.Color && !this.a)
			{
				this.CalculateBaseColors();
			}
		}

		public bool CustomColors
		{
			get
			{
				return this.a;
			}
			set
			{
				this.a = value;
				if (!this.a)
				{
					this.CalculateBaseColors();
				}
			}
		}

		protected internal static Color InterpolateColors(Color color1, Color color2, float percentage)
		{
			int r = (int)color1.R;
			int g = (int)color1.G;
			int b = (int)color1.B;
			int num = (int)color1.A;
			int r2 = (int)color2.R;
			int g2 = (int)color2.G;
			int b2 = (int)color2.B;
			int num2 = (int)color2.A;
			byte red = Convert.ToByte((float)r + (float)(r2 - r) * percentage);
			byte green = Convert.ToByte((float)g + (float)(g2 - g) * percentage);
			byte blue = Convert.ToByte((float)b + (float)(b2 - b) * percentage);
			byte alpha = Convert.ToByte((float)num + (float)(num2 - num) * percentage);
			return Color.FromArgb((int)alpha, (int)red, (int)green, (int)blue);
		}

		protected virtual void CalculateBaseColors()
		{
		}

		protected internal abstract Size DocumentClientPadding { get; }

		protected internal abstract Size ControlClientPadding { get; }

		protected internal abstract BoxModel TabStripMetrics { get; }

		protected internal abstract BoxModel TabMetrics { get; }

		protected internal abstract BoxModel TitleBarMetrics { get; }

		protected internal abstract TabTextDisplayMode TabTextDisplay { get; }

		protected internal abstract Size MeasureDocumentStripTab(Graphics graphics, Image image, string text, Font font, DrawItemState state);

		protected internal abstract void DrawDocumentStripBackground(Graphics graphics, Rectangle bounds);

		protected internal abstract void DrawControlClientBackground(Graphics graphics, Rectangle bounds, Color backColor);

		protected internal abstract void DrawDocumentClientBackground(Graphics graphics, Rectangle bounds, Color backColor);

		protected internal abstract void DrawDocumentStripTab(Graphics graphics, Rectangle bounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator);

		protected internal abstract void DrawDocumentContainerBackground(Graphics graphics, Rectangle bounds);

		protected internal abstract void DrawDocumentStripButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state);

		protected internal abstract int DocumentTabExtra { get; }

		protected internal abstract int DocumentTabSize { get; }

		protected internal abstract int DocumentTabStripSize { get; }

		protected internal abstract void StartRenderSession();

		protected internal abstract void DrawDockContainerBackground(Graphics graphics, Rectangle bounds);

		protected internal abstract void DrawTabStripBackground(Graphics graphics, Rectangle bounds, int selectedTabOffset);

		protected internal abstract void DrawSplitter(Graphics graphics, Rectangle bounds, Orientation orientation);

		protected internal abstract void DrawTabStripTab(Graphics graphics, Rectangle bounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator);

		protected internal abstract void DrawCollapsedBackground(Graphics graphics, Rectangle bounds);

		protected internal abstract void DrawCollapsedTab(Graphics graphics, Rectangle bounds, DockSide dockSide, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool vertical);

		protected internal abstract void DrawTitleBarBackground(Graphics graphics, Rectangle bounds, bool focused);

		protected internal abstract void DrawTitleBarText(Graphics graphics, Rectangle bounds, bool focused, string text, Font font);

		protected internal abstract void DrawTitleBarButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state, bool focused, bool toggled);

		protected internal abstract void FinishRenderSession();

		private bool a = false;
	}
}
