public Button(Rectangle rectangle, string text, Texture2D defaultTexture, Texture2D mouseOverTexture, SpriteFont spriteFont, string tag, DxOnClickAction OnClickAction)
        {
            this.rectangle        = rectangle;
            this.defaultTexture   = defaultTexture;
            this.mouseOverTexture = mouseOverTexture;
            this.isMouseOver      = false;

            this.label = new Label(rectangle, spriteFont, text, Label.TextAlignment.Midle_Center, tag: "");

            this.tag = tag;

            this.OnClickAction = OnClickAction;


            this.dxUpdateSystem = (InputState lastInputState, InputState inputState) => UpdateSystem(lastInputState, inputState);
            this.dxDrawSystem   = (SpriteBatch spriteBatch) => DrawSystem(spriteBatch);
            this.isActive       = true;
        }
Beispiel #2
0
        public void Update(DxOnClickAction OnClickAction)
        {
            MouseState mouseState = Mouse.GetState();

            if (rectangle.Contains(mouseState.X, mouseState.Y))
            {
                isMouseOver = true;
                if (previousMouseState.LeftButton == ButtonState.Released
                    &&
                    Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    OnClickAction();
                }
            }
            else
            {
                isMouseOver = false;
            }

            previousMouseState = Mouse.GetState();
        }