using System;
using System.Windows.Forms;
using System.Drawing;
namespace DevComponents.DotNetBar
{
	/// 
	/// Base class for painting expandable splitter control.
	/// 
	internal abstract class SplitterPainter
	{
		#region Private Variables
		private int m_ArrowSize=6;
		#endregion
		/// 
		/// Default constructor.
		/// 
		public SplitterPainter()
		{
		}
		#region Methods
		/// 
		/// Paints splitter.
		/// 
		/// Paint information.
		public virtual void Paint(SplitterPaintInfo info)
		{
		}
		protected virtual void PaintArrow(Point p, SplitterPaintInfo info)
		{
			System.Drawing.Drawing2D.GraphicsPath path=UIGraphics.GetTrianglePath(p,ArrowSize,this.GetDirection(info));
			if(!info.Colors.ExpandFillColor.IsEmpty)
			{
				using(SolidBrush brush=new SolidBrush(info.Colors.ExpandFillColor))
					info.Graphics.FillPath(brush,path);
			}
			if(!info.Colors.ExpandLineColor.IsEmpty)
			{
				using(Pen pen=new Pen(info.Colors.ExpandLineColor,1))
					info.Graphics.DrawPath(pen,path);
			}
			path.Dispose();
		}
		protected eTriangleDirection GetDirection(SplitterPaintInfo info)
		{
			if(info.Dock==DockStyle.Top && info.Expanded || info.Dock==DockStyle.Bottom && !info.Expanded)
			{
				// Points up
				return eTriangleDirection.Top;
			}
			else if(info.Dock==DockStyle.Top && !info.Expanded || info.Dock==DockStyle.Bottom && info.Expanded)
			{
				// Points down
				return eTriangleDirection.Bottom;
			}
			else if(info.Dock==DockStyle.Left && info.Expanded || info.Dock==DockStyle.Right && !info.Expanded)
			{
				// Points left
				return eTriangleDirection.Left;
			}
			return eTriangleDirection.Right;
		}
		protected System.Drawing.Drawing2D.LinearGradientBrush CreateLinearGradientBrush(Rectangle r,Color color1, Color color2,float gradientAngle)
		{
			return new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(r.X-1,r.Y-1,r.Width+1,r.Height+1),color1,color2,gradientAngle);
		}
		protected virtual void PaintBackground(SplitterPaintInfo info)
		{
			int gradientAngle=info.Colors.BackColorGradientAngle;
			Rectangle r=info.DisplayRectangle;
			if(info.Dock==DockStyle.Top || info.Dock==DockStyle.Bottom)
				gradientAngle+=90;
			if(info.Colors.BackColor2.IsEmpty)
			{
				using(SolidBrush brush=new SolidBrush(info.Colors.BackColor))
					info.Graphics.FillRectangle(brush,r);
			}
			else
			{
				using(System.Drawing.Drawing2D.LinearGradientBrush brush=CreateLinearGradientBrush(r,info.Colors.BackColor,info.Colors.BackColor2,gradientAngle))
					info.Graphics.FillRectangle(brush,r);
			}
		}
		#endregion
		#region Properties
		protected int ArrowSize
		{
			get {return m_ArrowSize;}
			set {m_ArrowSize=value;}
		}
		#endregion
	}
	#region SplitterPaintInfo
	/// 
	/// Represents class that holds information neccessary to paint the expandable splitter.
	/// 
	internal class SplitterPaintInfo
	{
		/// 
		/// Specifies reference to graphics canvas.
		/// 
		public System.Drawing.Graphics Graphics;
		/// 
		/// Specifies splitter display rectangle.
		/// 
		public System.Drawing.Rectangle DisplayRectangle;
		/// 
		/// Holds color settings for painting.
		/// 
		public SplitterColors Colors;
		/// 
		/// Specifies whether splitter is expandable or not.
		/// 
		public bool Expandable;
		/// 
		/// Specifies whether splitter is expanded or not.
		/// 
		public bool Expanded;
		/// 
		/// Specifies the splitter dock.
		/// 
		public System.Windows.Forms.DockStyle Dock;
	}
	#endregion
	#region SplitterColors
	/// 
	/// Represents class that holds colors for the splitter display.
	/// 
	internal class SplitterColors
	{
		/// 
		/// Specifies back color.
		/// 
		public Color BackColor=Color.Empty;
		/// 
		/// Specifies target gradient background color.
		/// 
		public Color BackColor2=Color.Empty;
		/// 
		/// Specifies background gradient angle.
		/// 
		public int BackColorGradientAngle=0;
		/// 
		/// Specifies grip part dark color.
		/// 
		public Color GripDarkColor=Color.Empty;
		/// 
		/// Specifies grip part light color.
		/// 
		public Color GripLightColor=Color.Empty;
		/// 
		/// Specifies expand part line color.
		/// 
		public Color ExpandLineColor=Color.Empty;
		/// 
		/// Specifies expand part fill color.
		/// 
		public Color ExpandFillColor=Color.Empty;
	}
	#endregion
}