/// <summary>
        /// Slider for numeric values.
        /// </summary>
        public SliderColor()
        {

            Anchor = Anchors.Left | Anchors.Right | Anchors.Top;
            CanFocus = false;
            Passive = true;
            Width = 420;
            Height = 75;
            var label = new Label
            {
                Parent = this,
                Width = 150,
                Top = 25,
            };
            TextChanged += delegate { label.Text = Text; };

            #region Square Color

            // Square color
            Control squareColor = new Panel
            {
                Left = label.Left + label.Width + 5,
                Top = 17,
                Width = 40,
                Height = 40,
                Color = Color,
                BevelBorder = BevelBorder.All,
                BevelStyle = BevelStyle.Etched,
                BevelColor = Color.Black,
            };
            Add(squareColor);
            squareColor.MouseDown += delegate
                                    {
                                        colorPickerDialog = new ColorPickerDialog(Color);
                                        UserInterfaceManager.Add(colorPickerDialog);
                                        colorPickerDialog.SquareColorDown  += OnSliderDown;
                                        colorPickerDialog.SquareColorUp    += OnSliderUp;
                                        colorPickerDialog.SquareColorPress += OnSliderPress;

                                        colorPickerDialog.Closed += delegate
                                        {
                                            Focused = true;
                                            colorPickerDialog.SquareColorDown  -= OnSliderDown;
                                            colorPickerDialog.SquareColorUp    -= OnSliderUp;
                                            colorPickerDialog.SquareColorPress -= OnSliderPress;
                                        };
                                        
                                        #region Color Picker Position
                                        
                                        int left = squareColor.ControlLeftAbsoluteCoordinate;
                                        if (left + colorPickerDialog.Width > Screen.Width)
                                            left -= colorPickerDialog.Width;
                                        int top = squareColor.ControlTopAbsoluteCoordinate + squareColor.Height;
                                        if (top + colorPickerDialog.Height > Screen.Height)
                                            top -= colorPickerDialog.Height + squareColor.Height;
                                        colorPickerDialog.SetPosition(left, top);
                                        
                                        #endregion

                                        colorPickerDialog.ColorChanged += delegate
                                        {
                                            Color = colorPickerDialog.Color;
                                        };
                                    };

            #endregion

            #region R

            textBoxR = new TextBox
            {
                Parent = this,
                Top = 4,
                Width = 40,
                Left = label.Left + label.Width + 5 + 45,
                Text = "1",
            };
            sliderR = new TrackBar
            {
                Parent = this,
                Anchor = Anchors.Left | Anchors.Top | Anchors.Right,
                Left = textBoxR.Left + textBoxR.Width + 4,
                Top = 6,
                MinimumWidth = 100,
                Height = 15,
                MinimumValue = 0,
                MaximumValue = 1,
                Width = 176,
                ValueCanBeOutOfRange = false,
                IfOutOfRangeRescale = false,
                ScaleBarColor = ScaleColor.Red,
            };
            sliderR.ValueChanged += delegate
                                    {
                                        updatingRGB = true;
                                        textBoxR.Text = Math.Round(sliderR.Value, 3).ToString();
                                        if (!updatingColor)
                                        {
                                            if (XNAFinalEngine.Input.Keyboard.KeyPressed(Keys.LeftControl))
                                            {
                                                sliderG.Value = sliderR.Value;
                                                sliderB.Value = sliderR.Value;
                                            }
                                            UpdateColorFromRGB();
                                        }
                                        updatingRGB = false;
                                    };
            textBoxR.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.Key == Keys.Enter)
                {
                    updatingRGB = true;
                    try
                    {
                        sliderR.Value = (float)double.Parse(textBoxR.Text);
                        UpdateColorFromRGB();
                    }
                    catch // If not numeric
                    {
                        textBoxR.Text = sliderR.Value.ToString();
                    }
                    updatingRGB = false;
                }
            };
            // For tabs and other not so common things.
            textBoxR.FocusLost += delegate
            {
                updatingRGB = true;
                try
                {
                    sliderR.Value = (float)double.Parse(textBoxR.Text);
                    UpdateColorFromRGB();
                }
                catch // If not numeric
                {
                    textBoxR.Text = sliderR.Value.ToString();
                }
                updatingRGB = false;
            };

            #endregion

            #region G

            textBoxG = new TextBox
            {
                Parent = this,
                Top = 4 + textBoxR.Top + textBoxR.Height,
                Width = 40,
                Left = label.Left + label.Width + 4 + 45,
                Text = "1"
            };
            sliderG = new TrackBar
            {
                Parent = this,
                Anchor = Anchors.Left | Anchors.Top | Anchors.Right,
                Left = textBoxG.Left + textBoxG.Width + 4,
                Top = 6 + textBoxR.Top + textBoxR.Height,
                Height = 15,
                MinimumWidth = 100,
                MinimumValue = 0,
                MaximumValue = 1,
                Width = 176,
                ValueCanBeOutOfRange = false,
                IfOutOfRangeRescale = false,
                ScaleBarColor = ScaleColor.Green,
            };
            sliderG.ValueChanged += delegate
                                        {
                                            updatingRGB = true;
                                            textBoxG.Text = Math.Round(sliderG.Value, 3).ToString();
                                            if (!updatingColor)
                                            {
                                                if (XNAFinalEngine.Input.Keyboard.KeyPressed(Keys.LeftControl))
                                                {
                                                    sliderR.Value = sliderG.Value;
                                                    sliderB.Value = sliderG.Value;
                                                }
                                                UpdateColorFromRGB();
                                            }
                                            updatingRGB = false;
                                        };
            textBoxG.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.Key == Keys.Enter)
                {
                    updatingRGB = true;
                    try
                    {
                        sliderG.Value = (float)double.Parse(textBoxG.Text);
                        UpdateColorFromRGB();
                    }
                    catch // If not numeric
                    {
                        textBoxG.Text = sliderG.Value.ToString();
                    }
                    updatingRGB = false;
                }
            };
            // For tabs and other not so common things.
            textBoxG.FocusLost += delegate
            {
                updatingRGB = true;
                try
                {
                    sliderG.Value = (float)double.Parse(textBoxG.Text);
                    UpdateColorFromRGB();
                }
                catch // If not numeric
                {
                    textBoxG.Text = sliderG.Value.ToString();
                }
                updatingRGB = false;
            };

            #endregion

            #region B

            textBoxB = new TextBox
            {
                Parent = this,
                Top = 4 + textBoxG.Top + textBoxG.Height,
                Width = 40,
                Left = label.Left + label.Width + 4 + 45,
                Text = "1"
            };
            sliderB = new TrackBar
            {
                Parent = this,
                Anchor = Anchors.Left | Anchors.Top | Anchors.Right,
                Left = textBoxB.Left + textBoxB.Width + 4,
                Top = 6 + textBoxG.Top + textBoxG.Height,
                Height = 15,
                MinimumWidth = 100,
                MinimumValue = 0,
                MaximumValue = 1,
                Width = 176,
                ValueCanBeOutOfRange = false,
                IfOutOfRangeRescale = false,
                ScaleBarColor = ScaleColor.Blue,
            };
            sliderB.ValueChanged += delegate
                                    {
                                        updatingRGB = true;
                                        textBoxB.Text = Math.Round(sliderB.Value, 3).ToString();
                                        if (!updatingColor)
                                        {
                                            if (XNAFinalEngine.Input.Keyboard.KeyPressed(Keys.LeftControl))
                                            {
                                                sliderR.Value = sliderB.Value;
                                                sliderG.Value = sliderB.Value;
                                            }
                                            UpdateColorFromRGB();
                                        }
                                        updatingRGB = false;
                                    };
            textBoxB.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.Key == Keys.Enter)
                {
                    updatingRGB = true;
                    try
                    {
                        sliderB.Value = (float)double.Parse(textBoxB.Text);
                        UpdateColorFromRGB();
                    }
                    catch // If not numeric
                    {
                        textBoxB.Text = sliderB.Value.ToString();
                    }
                    updatingRGB = false;
                }
            };
            // For tabs and other not so common things.
            textBoxB.FocusLost += delegate
            {
                updatingRGB = true;
                try
                {
                    sliderB.Value = (float)double.Parse(textBoxB.Text);
                    UpdateColorFromRGB();
                }
                catch // If not numeric
                {
                    textBoxB.Text = sliderB.Value.ToString();
                }
                updatingRGB = false;
            };

            #endregion

            ColorChanged += delegate
            {
                updatingColor = true;
                    squareColor.Color = Color;
                    if (!updatingRGB)
                        UpdateRGBFromColor();
                updatingColor = false;
                if (colorPickerDialog != null && !colorPickerDialog.IsDisposed && colorPickerDialog.Color != Color)
                    colorPickerDialog.Color = Color;
            };

            // To init all values with a color
            Color = Color.Gray;

            sliderR.SliderDown  += OnSliderDown;
            sliderR.SliderUp    += OnSliderUp;
            sliderR.SliderPress += OnSliderPress;
            sliderG.SliderDown  += OnSliderDown;
            sliderG.SliderUp    += OnSliderUp;
            sliderG.SliderPress += OnSliderPress;
            sliderB.SliderDown  += OnSliderDown;
            sliderB.SliderUp    += OnSliderUp;
            sliderB.SliderPress += OnSliderPress;

        } // SliderColor
        } // MultiplyColorByFloat

        #endregion

        #region Close

        /// <summary>
        /// Close
        /// </summary>
        public override void Close()
        {
            base.Close();
            UserInterfaceManager.Remove(background);
            background.Dispose();
        } // Close
        /// <summary>
        /// Color picker dialog.
        /// </summary>
        public ColorPickerDialog(Color _oldColor)
        {

            ClientWidth = 5 + 132 + 10;
            ClientHeight = 235;
            TopPanel.Visible = false;
            IconVisible = false;
            Resizable = false;
            BorderVisible = false;
            Movable = false;
            StayOnTop = true;
            AutoScroll = false;
           
            #region Background

            // The background object is invisible, it serves input actions.
            background = new Control
            {
                Left = 0,
                Top = 0,
                Width = Screen.Width,
                Height = Screen.Height,
                StayOnTop = true, // To bring it to the second place (first is the main control)
                Color = new Color(0, 0, 0, 0)
            };
            UserInterfaceManager.Add(background);
            // If we click outside the window close it.
            background.MouseDown += delegate(object sender, MouseEventArgs e)
                                         {
                                             if (e.Button == MouseButton.Left)
                                             {
                                                 if (isPicking)
                                                 {
                                                    // If you want to use the user interface outside my engine you will need to change 
                                                    // only the following two lines (I presume the compiler it is telling this right now)
                                                    // Create an event in the dialog called like "PickRequested"
                                                    // In the color slider you will need to have the same event (to propagate this)
                                                    // And then you read the event and do whatever you need to do.
                                                    // The editor should read this event and not the other way around.
                                                    EditorManager.colorPickerNeedsToPick = true;
                                                    EditorManager.colorPickerDialog = this;
                                                    isPicking = false;
                                                    // The background control takes the first place (z order), now it needs to be in second.
                                                    background.StayOnTop = false;  // We need to change this so that the main control can take first place.
                                                    BringToFront();
                                                 }
                                                 else
                                                     Close();
                                             }
                                         };

            #endregion

            #region Buttons

            // Button pick
            buttonPick = new Button
            {
                Top = 8,
                Glyph = new Glyph(Skin.Images["Dropper"].Texture) { SizeMode = SizeMode.Centered },
            };

            buttonPick.Left = (BottomPanel.ClientWidth / 2) - buttonPick.Width - 4;
            BottomPanel.Add(buttonPick);
            buttonPick.Click += delegate
            {
                //picker = new Picker();
                isPicking = true;
                background.StayOnTop = true;
                background.BringToFront();
            };
            // Button close
            buttonClose = new Button
            {
                Left = (BottomPanel.ClientWidth / 2) + 4,
                Top = 8,
                Text = "Close",
                ModalResult = ModalResult.No
            };
            BottomPanel.Add(buttonClose);
            buttonClose.Click += delegate
            {
                Close();
            };
            DefaultControl = buttonClose;

            #endregion

            #region Square color palette

            // Square color
            squareColorPalette = new Control
            {
                Left = squareColorLeft,
                Top = squareColorTop,
                Width = squareColorlenght,
                Height = squareColorlenght,
                Color = new Color(0, 0, 0, 0),
                Movable = true, // To implement a roboust color picker when you can move the mouse outside the color palette limits.
            };
            Add(squareColorPalette);
            
            #endregion

            #region Intensity level bar

            // Intensity level bar
            intensityLevelBar = new Control
            {
                Left = 5 + squareColorlenght,
                Top = 5,
                Width = 20,
                Height = squareColorlenght,
                Color = new Color(0, 0, 0, 0),
                Movable = true, // To implement a roboust level picker when you can move the mouse outside the intensity level bar limits.
            };
            Add(intensityLevelBar);

            #endregion

            #region R G B Text Boxes

            // R
            var labelRed = new Label
            {
                Parent = this,
                Text = " R",
                Width = 40,
                Top = 5 + squareColorlenght + 50,
                Left = 5,
            };
            textBoxRed = new TextBox
            {
                Parent = this,
                Left = 5,
                Top = labelRed.Top + labelRed.Height + 2,
                Width = 40,
                Text = "1"
            };
            // G
            var labelGreen = new Label
            {
                Parent = this,
                Text = " G",
                Width = 40,
                Top = 5 + squareColorlenght + 50,
                Left = labelRed.Width + 10,
            };
            textBoxGreen = new TextBox
                                   {
                Parent = this,
                Left = labelRed.Width + 10,
                Top = labelRed.Top + labelRed.Height + 2,
                Width = 40,
                Text = "1"
            };
            // B
            var labelBlue = new Label
                                {
                Parent = this,
                Text = " B",
                Width = 40,
                Top = 5 + squareColorlenght + 50,
                Left = labelRed.Width * 2 + 15,
            };
            textBoxBlue = new TextBox
                                  {
                Parent = this,
                Left = labelRed.Width * 2 + 15,
                Top = labelRed.Top + labelRed.Height + 2,
                Width = 40,
                Text = "1"
            };

            UpdateRGBFromColor();

            #endregion

            background.BringToFront();
            oldColor = _oldColor;
            Color = oldColor;
            positionSquareColor = PositionFromColor(Color);

            #region Events

            squareColorPalette.MouseDown  += delegate { OnMouseDown(new MouseEventArgs()); };
            squareColorPalette.MousePress += delegate { OnMousePress(new MouseEventArgs()); };
            squareColorPalette.MouseUp    += delegate { OnMouseUp(new MouseEventArgs()); };
            intensityLevelBar.MouseDown   += delegate { OnMouseDown(new MouseEventArgs()); };
            intensityLevelBar.MousePress  += delegate { OnMousePress(new MouseEventArgs()); };
            intensityLevelBar.MouseUp     += delegate { OnMouseUp(new MouseEventArgs()); };

            #endregion

        } // ColorPickerDialog
 /// <summary>
 /// Tasks executed during the last stage of the scene render.
 /// </summary>
 public override void PostRenderUpdate()
 {
     UserInterfaceManager.RenderUserInterfaceToScreen();
 }
 /// <summary>
 /// Tasks executed during the first stage of the scene render.
 /// </summary>
 public override void PreRenderUpdate()
 {
     UserInterfaceManager.PreRenderControls();
 }
 /// <summary>
 /// Update.
 /// </summary>
 public override void Update()
 {
     UserInterfaceManager.Update();
 }