namespace InstrumentationControls
{
	using System;
	using System.ComponentModel;
	using System.Drawing;
	using System.Drawing.Drawing2D;
	using System.Runtime.CompilerServices;
	using System.Windows.Forms;

	public abstract class MultimediaButtonBase : ButtonBase
	{
		private Color activeLedColor = Color.LightGreen;
		private bool fGrayed = false;
		private int imageIndex = 0;
		private System.Windows.Forms.ImageList imageList;
		private Color inactiveLedColor = Color.Green;
		private ShapeKinds ledShape = ShapeKinds.None;

		[Description("Occurs when the ImageIndex property changed"), Category("Property Changed")]
		public event EventHandler ImageIndexChanged;

		[Category("Property Changed"), Description("Occurs when the ImageList property changed")]
		public event EventHandler ImageListChanged;

		[Category("Property Changed"), Description("Occurs when the Shape property changed")]
		public event EventHandler LedShapeChanged;

		protected void DrawCaption(Graphics g, Rectangle captionRect)
		{
			StringFormat format = new StringFormat();
			format.Alignment = StringAlignment.Center;
			format.LineAlignment = StringAlignment.Center;
			SizeF ef = g.MeasureString(this.Text, this.Font, (SizeF)captionRect.Size, format);
			int num = 0;
			if ((this.imageList != null) && (this.imageIndex < this.imageList.Images.Count))
			{
				int num2 = ((captionRect.X + (captionRect.Width / 2)) - (this.imageList.ImageSize.Width / 2)) - (((int)ef.Width) / 2);
				int num3 = (captionRect.Y + (captionRect.Height / 2)) - (this.imageList.ImageSize.Height / 2);
				this.imageList.Draw(g, num2, num3, this.imageIndex);
				num += (this.imageList.ImageSize.Width / 2) + 2;
			}
			Brush CaptBrush;
			if (fGrayed)
			{
				CaptBrush = new SolidBrush(Color.LightGray);
			}
			else
				CaptBrush = new SolidBrush(this.ForeColor);
			if (this.ledShape != ShapeKinds.None)
			{
				Brush brush;
				Size size = new Size(9, 9);
				int num4 = ((captionRect.X + (captionRect.Width / 2)) - (size.Width / 2)) - (((int)ef.Width) / 2);
				int y = (captionRect.Y + (captionRect.Height / 2)) - (size.Height / 2);
				Rectangle rectangle = new Rectangle(new Point(num4 + num, y), size);
				GraphicsPath path = ShapeGenerator.GenerateShape(this.ledShape, rectangle);
				if (base.Pressed)
				{
					brush = new SolidBrush(this.activeLedColor);
				}
				else
				{
					brush = new SolidBrush(this.inactiveLedColor);
				}
				g.FillPath(brush, path);
				num += (size.Width / 2) + 2;
			}
			captionRect.X += num;
			g.SmoothingMode = SmoothingMode.HighSpeed;
			g.DrawString(this.Text, this.Font, CaptBrush, captionRect, format);
			g.SmoothingMode = SmoothingMode.AntiAlias;
		}

		protected virtual void OnImageIndexChanged(EventArgs e)
		{
			if (this.ImageIndexChanged != null)
			{
				this.ImageIndexChanged(this, e);
			}
		}

		protected virtual void OnImageListChanged(EventArgs e)
		{
			if (this.ImageListChanged != null)
			{
				this.ImageListChanged(this, e);
			}
		}

		protected virtual void OnLedShapeChanged(EventArgs e)
		{
			if (this.LedShapeChanged != null)
			{
				this.LedShapeChanged(this, e);
			}
		}

		[DefaultValue(typeof(Color), "LightGreen"), Description("Active led color"), Category("Appearance")]
		public Color ActiveLedColor
		{
			get
			{
				return this.activeLedColor;
			}
			set
			{
				if (value != this.activeLedColor)
				{
					this.activeLedColor = value;
					base.Invalidate();
				}
			}
		}

		[Description("ImageIndex"), Category("Appearance"), DefaultValue(0), TypeConverter(typeof(ImageIndexConverter))]
		public int ImageIndex
		{
			get
			{
				return this.imageIndex;
			}
			set
			{
				if (this.imageIndex != value)
				{
					this.imageIndex = value;
					base.Invalidate();
					this.OnImageIndexChanged(new EventArgs());
				}
			}
		}

		[Category("Appearance"), DefaultValue((string)null), Description("ImageList shape style")]
		public System.Windows.Forms.ImageList ImageList
		{
			get
			{
				return this.imageList;
			}
			set
			{
				if (this.imageList != value)
				{
					this.imageList = value;
					base.Invalidate();
					this.OnImageListChanged(new EventArgs());
				}
			}
		}

		[Description("Inactive led color"), Category("Appearance"), DefaultValue(typeof(Color), "Green")]
		public Color InactiveLedColor
		{
			get
			{
				return this.inactiveLedColor;
			}
			set
			{
				if (value != this.inactiveLedColor)
				{
					this.inactiveLedColor = value;
					base.Invalidate();
				}
			}
		}

		[DefaultValue(0x12), Category("Appearance"), Description("Led shape")]
		public ShapeKinds LedShape
		{
			get
			{
				return this.ledShape;
			}
			set
			{
				if (this.ledShape != value)
				{
					this.ledShape = value;
					base.Invalidate();
					this.OnLedShapeChanged(new EventArgs());
				}
			}
		}

		public bool Grayed
		{
			get { return fGrayed; }
			set
			{
				if (fGrayed != value)
				{
					fGrayed = value;
					Invalidate();
				}
			}
		}


	}
}
