using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar.Keyboard
{
    /// 
    /// Defines the VirtualKeyboard colors.
    /// 
    /// 
    /// This class maintains internally a Brush for each Color. These Brush objects are disposed internally when not needed anymore.
    /// A Brush of a certain color is obtained by setting the same Color property to that color.
    /// Maintaining the brushes here helps to have less GDI handles created / destroyed on each drawing of the keyboard.
    /// 
    public sealed class VirtualKeyboardColorTable : IDisposable
    {
        /// 
        /// Creates a new color table for the VirtualKeyoard.
        /// 
        public VirtualKeyboardColorTable()
        {
            _BackgroundBrush = new SolidBrush(BackgroundColor);
            _KeysBrush = new SolidBrush(KeysColor);
            _LightKeysBrush = new SolidBrush(LightKeysColor);
            _DarkKeysBrush = new SolidBrush(DarkKeysColor);
            _PressedKeysBrush = new SolidBrush(PressedKeysColor);
            _TextBrush = new SolidBrush(TextColor);
            _DownKeysBrush = new SolidBrush(DownKeysColor);
            _DownTextBrush = new SolidBrush(DownTextColor);
            _TopBarTextBrush = new SolidBrush(TopBarTextColor);
            _ToggleTextBrush = new SolidBrush(ToggleTextColor);
        }
        private static void ReCreateBrush(ref Brush brush, Color color)
        {
            if (brush != null)
                brush.Dispose();
            brush = new SolidBrush(color);
        }
        private Color _BackgroundColor = Color.Black;
        /// 
        /// Gets or sets the color used to draw the background of the keyboard.
        /// 
        public Color BackgroundColor
        {
            get { return _BackgroundColor; }
            set { _BackgroundColor = value; ReCreateBrush(ref _BackgroundBrush, _BackgroundColor); }
        }
        private Brush _BackgroundBrush;
        /// 
        /// Gets a brush used for drawing the background of the keyboard.
        /// 
        public Brush BackgroundBrush
        {
            get { return _BackgroundBrush; }
        }
        
        private Color _KeysColor = Color.FromArgb(0x30, 0x2f, 0x37);
        /// 
        /// Gets or sets the color used for drawing normal keys.
        /// 
        public Color KeysColor
        {
            get { return _KeysColor; }
            set { _KeysColor = value; ReCreateBrush(ref _KeysBrush, _KeysColor); }
        }
        private Brush _KeysBrush;
        /// 
        /// Gets a brush used for drawing normal keys. 
        /// 
        public Brush KeysBrush
        {
            get { return _KeysBrush; }
        }
        
        
        private Color _LightKeysColor = Color.FromArgb(0x45, 0x44, 0x4c);
        /// 
        /// Gets or sets the color used for drawing light keys.
        /// 
        public Color LightKeysColor
        {
            get { return _LightKeysColor; }
            set { _LightKeysColor = value; ReCreateBrush(ref _LightKeysBrush, _LightKeysColor); }
        }
        private Brush _LightKeysBrush;
        /// 
        /// Gets a brush used for drawing light keys.
        /// 
        public Brush LightKeysBrush
        {
            get { return _LightKeysBrush; }
        }
        private Color _DarkKeysColor = Color.FromArgb(0x1d, 0x1c, 0x21);
        /// 
        /// Gets or sets the color used for drawing dark keys.
        /// 
        public Color DarkKeysColor
        {
            get { return _DarkKeysColor; }
            set { _DarkKeysColor = value; ReCreateBrush(ref _DarkKeysBrush, _DarkKeysColor); }
        }
        
        private Brush _DarkKeysBrush;
        /// 
        /// Gets a brush used for drawing dark keys.
        /// 
        public Brush DarkKeysBrush
        {
            get { return _DarkKeysBrush; }
        }
        private Color _PressedKeysColor = Color.FromArgb(0x10, 0xa1, 0x51);
        /// 
        /// Gets or sets a brush used for drawing pressed keys.
        /// 
        public Color PressedKeysColor
        {
            get { return _PressedKeysColor; }
            set { _PressedKeysColor = value; ReCreateBrush(ref _PressedKeysBrush, _PressedKeysColor); }
        }
        private Brush _PressedKeysBrush;
        /// 
        /// Gets a brush used for drawing pressed keys.
        /// 
        public Brush PressedKeysBrush
        {
            get { return _PressedKeysBrush; }
        }
        private Color _DownKeysColor = Color.White;
        /// 
        /// Gets or sets a brush used for drawing pressed key when the key is down.
        /// 
        public Color DownKeysColor
        {
            get { return _DownKeysColor; }
            set { _DownKeysColor = value; ReCreateBrush(ref _DownKeysBrush, _DownKeysColor); }
        }
        private Brush _DownKeysBrush;
        /// 
        /// Gets a brush used for drawing pressed key when the key is down.
        /// 
        public Brush DownKeysBrush
        {
            get { return _DownKeysBrush; }
        }
        private Color _TextColor = Color.White;
        /// 
        ///  Gets or sets a color used for drawing the text on the keys.
        /// 
        public Color TextColor
        {
            get { return _TextColor; }
            set { _TextColor = value; ReCreateBrush(ref _TextBrush, _TextColor); }
        }
        private Brush _TextBrush;
        /// 
        /// Gets a brush used for drawing the text on the keys.
        /// 
        public Brush TextBrush
        {
            get { return _TextBrush; }
        }
        private Color _DownTextColor = Color.FromArgb(0x20, 0x20, 0x20);
        /// 
        ///  Gets or sets a color used for drawing the text on a key when the key is down.
        /// 
        public Color DownTextColor
        {
            get { return _DownTextColor; }
            set { _DownTextColor = value; ReCreateBrush(ref _DownTextBrush, _DownTextColor); }
        }
        private Brush _DownTextBrush;
        /// 
        /// Gets a brush used for drawing the text on a key when the key is down.
        /// 
        public Brush DownTextBrush
        {
            get { return _DownTextBrush; }
        }
        private Color _TopBarTextColor = Color.White;
        /// 
        ///  Gets or sets a color used for drawing the text on the top bar.
        /// 
        public Color TopBarTextColor
        {
            get { return _TopBarTextColor; }
            set { _TopBarTextColor = value; ReCreateBrush(ref _TopBarTextBrush, _TopBarTextColor); }
        }
        private Brush _TopBarTextBrush;
        /// 
        /// Gets a brush used for drawing the text on the top bar.
        /// 
        public Brush TopBarTextBrush
        {
            get { return _TopBarTextBrush; }
        }
        private Color _ToggleTextColor = Color.Green;
        /// 
        /// Gets or sets a color used for drawing the text on a key when the key is in its toggled state.
        /// 
        public Color ToggleTextColor
        {
            get { return _ToggleTextColor; }
            set { _ToggleTextColor = value; ReCreateBrush(ref _ToggleTextBrush, _ToggleTextColor); }
        }
        private Brush _ToggleTextBrush;
        /// 
        /// Gets a brush used for drawing the text on a key when the key is in its toggled state.
        /// 
        public Brush ToggleTextBrush
        {
            get { return _ToggleTextBrush; }
        }
        public void Dispose()
        {
            if (_BackgroundBrush != null)
                _BackgroundBrush.Dispose();
            if (_KeysBrush != null)
                _KeysBrush.Dispose();
            if (_LightKeysBrush != null)
                _LightKeysBrush.Dispose();
            if (_DarkKeysBrush != null)
                _DarkKeysBrush.Dispose();
            if (_PressedKeysBrush != null)
                _PressedKeysBrush.Dispose();
            if (_TextBrush != null)
                _TextBrush.Dispose();
            if (_DownTextBrush != null)
                _DownTextBrush.Dispose();
            if (_DownKeysBrush != null)
                _DownKeysBrush.Dispose();
            if (_TopBarTextBrush != null)
                _TopBarTextBrush.Dispose();
            if (_ToggleTextBrush != null)
                _ToggleTextBrush.Dispose();
        }
    }
}