Esempio n. 1
0
        public override void Update(GameTime time)
        {
            cursor = ((int)Math.Round((float)(time.TotalGameTime.Milliseconds / 250)) * 250) % 750 == 0;

            if (Enabled && InterfaceManager.Focus == this)
            {
                foreach (Keys key in Keyboard.GetState().GetPressedKeys())
                {
                    if (!lastKeyboardState.IsKeyDown(key))
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Back))
                        {
                            Text = Text.Remove(Text.Length - 1);
                        }
                        else if (Text.Length < MaxLength && TextRenderer.KeyToChar(key) != (char)1)
                        {
                            if (Mode == TextBoxInputMode.Anything)
                            {
                                Text += TextRenderer.KeyToChar(key);
                            }
                            else if (Mode == TextBoxInputMode.Alphabetical && "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(TextRenderer.KeyToChar(key)))
                            {
                                Text += TextRenderer.KeyToChar(key);
                            }
                            else if (Mode == TextBoxInputMode.Numerical && "1234567890.".Contains(TextRenderer.KeyToChar(key)))
                            {
                                Text += TextRenderer.KeyToChar(key);
                            }
                        }
                    }
                }
            }

            lastKeyboardState = Keyboard.GetState();

            TextRenderer.SaveState();

            TextRenderer.SetScale(Scale);

            MouseState mouseState  = Mouse.GetState();
            Rectangle  mouseRect   = new Rectangle((int)mouseState.X, (int)mouseState.Y, 1, 1);
            Vector2    textboxSize = CalculateDimensions();

            TextRenderer.RestoreState();

            if (State != ButtonState.Disabled)
            {
                if (State != ButtonState.Pressed)
                {
                    if (mouseRect.Intersects(new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, (int)textboxSize.X, (int)textboxSize.Y)))
                    {
                        //System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.IBeam;

                        if (State != ButtonState.Hovered)
                        {
                            EventHandler handler = OnHover;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Hovered;
                        }
                        else
                        {
                            if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && lastMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                            {
                                EventHandler handler = OnPress;

                                if (handler != null)
                                {
                                    handler(this, new EventArgs());
                                }

                                State = ButtonState.Pressed;
                            }
                        }
                    }
                    else
                    {
                        if (State != ButtonState.Idle)
                        {
                            EventHandler handler = OnIdle;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Idle;
                        }
                    }
                }
                else
                {
                    if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                    {
                        if (mouseRect.Intersects(new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, (int)textboxSize.X, (int)textboxSize.Y)))
                        {
                            EventHandler handler = OnRelease;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Hovered;
                            InterfaceManager.SetFocus(this);
                        }
                        else
                        {
                            EventHandler handler = OnRelease;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Idle;
                        }
                    }
                }
            }

            lastMouseState = mouseState;
        }
Esempio n. 2
0
        public override void Update(GameTime time)
        {
            MouseState mouseState = Mouse.GetState();
            Rectangle  mouseRect  = new Rectangle((int)mouseState.X, (int)mouseState.Y, 1, 1);
            Vector2    buttonSize = new Vector2(Scale * 7, Scale * 7);

            if (State != ButtonState.Disabled)
            {
                if (State != ButtonState.Pressed)
                {
                    if (mouseRect.Intersects(new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, (int)buttonSize.X, (int)buttonSize.Y)))
                    {
                        //System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Hand;

                        if (State != ButtonState.Hovered)
                        {
                            EventHandler handler = OnHover;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Hovered;
                        }
                        else
                        {
                            if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && lastMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                            {
                                EventHandler handler = OnPress;

                                if (handler != null)
                                {
                                    handler(this, new EventArgs());
                                }

                                State = ButtonState.Pressed;
                            }
                        }
                    }
                    else
                    {
                        if (State != ButtonState.Idle)
                        {
                            EventHandler handler = OnIdle;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Idle;
                        }
                    }
                }
                else
                {
                    if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                    {
                        if (mouseRect.Intersects(new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, (int)buttonSize.X, (int)buttonSize.Y)))
                        {
                            EventHandler handler = OnRelease;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Hovered;
                            InterfaceManager.SetFocus(this);

                            Checked = !Checked;
                        }
                        else
                        {
                            EventHandler handler = OnRelease;

                            if (handler != null)
                            {
                                handler(this, new EventArgs());
                            }

                            State = ButtonState.Idle;
                        }
                    }
                }
            }

            lastMouseState = mouseState;
        }