示例#1
0
        public void Update(bool independent)
        {
            keyState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();

            if (independent)
            {
                Hovered = CollideBox.Contains(new Vector2(mouseState.X, mouseState.Y));
                if (lastMouseState.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed)
                {
                    Selected = Hovered;
                }
            }

            CheckSpecialChar(Keys.Back, '\b');
            CheckSpecialChar(Keys.Enter, '\r');
            CheckSpecialChar(Keys.Tab, '\t');

            lastKeyState   = keyState;
            lastMouseState = mouseState;
        }
示例#2
0
        public void Update(int mouseX, int mouseY)
        {
            MouseState mouseState = Mouse.GetState();

            activated = CollideBox.Contains(mouseX, mouseY);
            if (activated)
            {
                if (DrawColor == Color.White)
                {
                    DrawColor = new Color(200, 200, 200);
                }
                if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                {
                    DrawColor = new Color(150, 150, 150);
                    clicked   = true;
                    if (!actOnRelease && lastMouseState.LeftButton == ButtonState.Released)
                    {
                        PerformAction();
                    }
                }
                else if (clicked && mouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed)
                {
                    DrawColor = new Color(200, 200, 200);
                    clicked   = false;
                    if (actOnRelease)
                    {
                        PerformAction();
                    }
                }
            }
            else
            {
                DrawColor = Color.White;
                clicked   = false;
            }

            lastMouseState = mouseState;
        }