Exemplo n.º 1
0
        } // Show

        public virtual void Show(Control sender, int x, int y)
        {
            AutoSize();
            base.Show();
            if (sender != null && sender.Root != null && sender.Root is Window)
            {
                (sender.Root as Container).Add(this, false);
            }
            else
            {
                UserInterfaceManager.Add(this);
            }
            
            this.sender = sender;
            
            if (sender != null && sender.Root != null && sender.Root is Container)
            {
                Left = x - Root.ControlLeftAbsoluteCoordinate;
                Top = y - Root.ControlTopAbsoluteCoordinate;
            }
            else
            {
                Left = x;
                Top = y;
            }
            
            if (ControlLeftAbsoluteCoordinate + Width > Screen.Width)
            {
                Left = Left - Width;
                if (ParentMenu != null && ParentMenu is ContextMenu)
                {
                    Left = Left - ParentMenu.Width + 2;
                }
                else if (ParentMenu != null)
                {
                    Left = Screen.Width - (Parent != null ? Parent.ControlLeftAbsoluteCoordinate : 0) - Width - 2;
                }
            }
            if (ControlTopAbsoluteCoordinate + Height > Screen.Height)
            {
                Top = Top - Height;
                if (ParentMenu != null && ParentMenu is ContextMenu)
                {
                    Top = Top + LineHeight();
                }
                else if (ParentMenu != null)
                {
                    Top = ParentMenu.Top - Height - 1;
                }
            }

            Focused = true;
        } // Show
Exemplo n.º 2
0
        } // ListComboClick

        #endregion

        #region Button Down Click

        private void ButtonDownClick(object sender, EventArgs e)
        {
            if (items != null && items.Count > 0)
            {
                if (Root != null && Root is Container)
                {
                    (Root as Container).Add(listCombo, false);
                    listCombo.Alpha = Root.Alpha;
                    listCombo.Left = ControlLeftAbsoluteCoordinate - Root.Left;
                    listCombo.Top = ControlTopAbsoluteCoordinate - Root.Top + Height + 1;
                }
                else
                {
                    UserInterfaceManager.Add(listCombo);
                    listCombo.Alpha = Alpha;
                    listCombo.Left = ControlLeftAbsoluteCoordinate;
                    listCombo.Top = ControlTopAbsoluteCoordinate + Height + 1;
                }

                listCombo.AutoHeight(maxItems);
                // If there is no place to put the list box under the control then is moved up.
                if (listCombo.ControlTopAbsoluteCoordinate + listCombo.Height > Screen.Height)
                    listCombo.Top = listCombo.Top - Height - listCombo.Height - 2;

                listCombo.Visible = !listCombo.Visible;
                if (listCombo.Visible)
                {
                    // The focus is removed to assure that the list box is focused.
                    CanFocus = false;
                    listCombo.Focused = true;
                }
                else
                {
                    // The focus was removed to assure that the list box is focused.
                    CanFocus = true;
                    Focused = true;
                }
                listCombo.Width = Width;
            }
        } // ButtonDownClick
Exemplo n.º 3
0
        /// <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
        /// <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