namespace InstrumentationControls
{
	using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;

	[ToolboxBitmap(typeof(ShapeLed))]
    public class ShapeLed : ButtonBase
    {
        private Color activeLedColor = Color.LightGreen;
        private Color inactiveLedColor = Color.Green;
        private ShapeKinds shape = ShapeKinds.Ellipse;

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

        protected override void Draw(Graphics g, Rectangle r)
        {
            base.Draw(g, r);
            this.DrawShape(g);
        }

        private void DrawShape(Graphics g)
        {
            Brush brush;
            Rectangle workRectangle = this.WorkRectangle;
            workRectangle.Width--;
            workRectangle.Height--;
            GraphicsPath path = ShapeGenerator.GenerateShape(this.shape, workRectangle);
            if (base.Pressed)
            {
                brush = new SolidBrush(this.activeLedColor);
            }
            else
            {
                brush = new SolidBrush(this.inactiveLedColor);
            }
            g.FillPath(brush, path);
            g.DrawPath(Pens.Black, path);
        }

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

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

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

        [Category("Appearance"), Description("Button shape"), DefaultValue(2)]
        public ShapeKinds Shape
        {
            get
            {
                return this.shape;
            }
            set
            {
                if (this.shape != value)
                {
                    this.shape = value;
                    base.Invalidate();
                    this.OnShapeChanged(new EventArgs());
                }
            }
        }
    }
}
