Example #1
0
        /// <summary>
        ///
        /// Constructor of GUIButton
        /// </summary>
        /// <param name="callbackEvent">Function that will be called when button is pressed</param>
        public GUIButton(Texture2D normal, Texture2D hover, Texture2D pressed, Texture2D disabled, ButtonPressedCallback callbackEvent, GUIButtonState startState, Rectangle rect)
            : base(rect)
        {
            this.normalTexture   = normal;
            this.hoverTexture    = hover;
            this.pressedTexture  = pressed;
            this.disabledTexture = disabled;

            this.myState = startState;

            switch (this.myState)
            {
            case GUIButtonState.DISABLED:
                this.currentTexture = this.disabledTexture;
                break;

            case GUIButtonState.HOVER:
                this.currentTexture = this.hoverTexture;
                break;

            case GUIButtonState.NORMAL:
                this.currentTexture = this.normalTexture;
                break;

            case GUIButtonState.PRESSED:
                this.currentTexture = this.pressedTexture;
                break;
            }

            this.callbackEvent += callbackEvent;
        }
Example #2
0
        /// <summary>
        /// An interactive interface based upon user input
        /// </summary>
        /// <param name="texture">Texture of the button's background</param>
        /// <param name="location">Where is the button located</param>
        /// <param name="activationEvents">A List of void functions/methods that
        /// should be executed when the button is Activated</param>
        /// <param name="font">Font of the button text</param>
        /// <param name="text">Button text</param>
        /// <param name="textLocation">Where the text is located RELATIVE to the
        /// button's location</param>
        /// <param name="textColor">The color of the text</param>
        /// <param name="active">Whether prssing the Button should execute
        /// functions from an activation event</param>
        /// <param name="highlightable">Highlight the button when it's either
        /// Selected or Pressed</param>
        /// <param name="clickable">Can the button be Pressed by a left mouse
        /// click?</param>
        /// <param name="linger">Will the button stay selected if the mouse
        /// moves off of the button while the Button is clickable</param>
        /// <param name="selected">Whether the Button be Selected when it's
        /// first loaded</param>
        public Button(Texture2D texture, Rectangle location,
                      List <ActivationFunction> activationEvents, SpriteFont font,
                      string text, Vector2 textLocation, Color textColor, bool active,
                      bool highlightable, bool clickable, bool linger,
                      bool selected = false)
        {
            buttonTexture = texture;
            position      = location;

            this.font         = font;
            buttonText        = text;
            this.textColor    = textColor;
            this.textLocation = new Vector2(position.X, position.Y)
                                + textLocation;

            foreach (ActivationFunction func in activationEvents)
            {
                if (func != null)
                {
                    ButtonActivationEvent += func;
                }
            }

            this.highlightable = highlightable;
            this.linger        = linger;
            this.clickable     = clickable;

            if (active)
            {
                buttonState = GUIButtonState.Active;
                if (highlightable && selected)
                {
                    buttonColor = Color.LightGray;
                }
                else
                {
                    buttonColor = Color.White;
                }
            }

            else
            {
                if (highlightable && selected)
                {
                    buttonColor = Color.Gray;
                }
                else
                {
                    buttonColor = Color.DarkGray;
                }
            }

            buttonState |=
                (selected ? GUIButtonState.Selected : GUIButtonState.Standby);
        }
Example #3
0
        /// <summary>
        /// An interactive GUI element that can produce output based upon user
        /// input.
        /// </summary>
        /// <param name="texture">The texture of the Button's background</param>
        /// <param name="location">Where the Button is located</param>
        /// <param name="activationEvents">A List of void functions/methods that
        /// should be executed when the button is Activated</param>
        /// <param name="active">Whether prssing the Button should execute
        /// functions from an activation event</param>
        /// <param name="highlightable">Highlight the button when it's either
        /// Selected or Pressed</param>
        /// <param name="clickable">Can the button be Pressed by a left mouse
        /// click?</param>
        /// <param name="linger">Will the button stay selected if the mouse
        /// moves off of the button while the Button is clickable</param>
        /// <param name="selected">Whether the Button be Selected when it's
        /// first loaded</param>
        public Button(Texture2D texture, Rectangle location,
                      List <ActivationFunction> activationEvents, bool active,
                      bool highlightable, bool clickable, bool linger,
                      bool selected = false)
        {
            buttonTexture = texture;
            position      = location;

            font         = null;
            buttonText   = "";
            textColor    = Color.White;
            textLocation = Vector2.Zero;

            foreach (ActivationFunction func in activationEvents)
            {
                if (func != null)
                {
                    ButtonActivationEvent += func;
                }
            }

            this.highlightable = highlightable;
            this.linger        = linger;
            this.clickable     = clickable;

            if (active)
            {
                buttonState = GUIButtonState.Active;
                if (highlightable && selected)
                {
                    buttonColor = Color.LightGray;
                }
                else
                {
                    buttonColor = Color.White;
                }
            }

            else
            {
                if (highlightable && selected)
                {
                    buttonColor = Color.Gray;
                }
                else
                {
                    buttonColor = Color.DarkGray;
                }
            }

            buttonState |=
                (selected ? GUIButtonState.Selected : GUIButtonState.Standby);
        }
Example #4
0
            /// <summary>
            /// Empty area with button functionality
            /// </summary>
            /// <param name="callbackMethod">Method called on click</param>
            public Button(Rectangle rectangle, Call callbackMethod)
            {
                this.rectangle = rectangle;
                colors         = new Color[0];
                texture        = null;
                textured       = false;

                // All fields must be asigned before local methods can be called
                currentState = GUIButtonState.Neutral;
                currentState = GetState();

                if (currentState == GUIButtonState.Click)
                {
                    callbackMethod.Invoke();
                }
            }
Example #5
0
            /// <summary>
            /// Textured button
            /// </summary>
            /// <param name="callbackMethod">Method called on click</param>
            public Button(Rectangle rectangle, Texture2D texture, Color normalColor, Color hoverColor, Color clickedColor, Call callbackMethod)
            {
                this.rectangle = rectangle;
                colors         = new Color[3] {
                    normalColor, hoverColor, clickedColor
                };
                this.texture = texture;
                textured     = true;

                // All fields must be asigned before local methods can be called
                currentState = GUIButtonState.Neutral;
                currentState = GetState();
                if (currentState == GUIButtonState.Click)
                {
                    callbackMethod.Invoke();
                }
            }
Example #6
0
        /// <summary>
        ///
        /// Changes GUIButton state to passed in params
        /// </summary>
        public void ChangeState(GUIButtonState newState)
        {
            if (this.myState == GUIButtonState.PRESSED && newState == GUIButtonState.HOVER)
            {
                return;
            }
            this.myState        = newState;
            this.currentTexture = null;

            switch (this.myState)
            {
            case GUIButtonState.DISABLED:
                if (this.disabledTexture != null)
                {
                    this.currentTexture = this.disabledTexture;
                }
                break;

            case GUIButtonState.HOVER:
                if (this.hoverTexture != null)
                {
                    this.currentTexture = this.hoverTexture;
                }
                break;

            case GUIButtonState.NORMAL:
                if (this.normalTexture != null)
                {
                    this.currentTexture = this.normalTexture;
                }
                break;

            case GUIButtonState.PRESSED:
                if (this.pressedTexture != null)
                {
                    this.currentTexture = this.pressedTexture;
                }
                break;
            }
        }
Example #7
0
        public void Update(GameTime gameTime)
        {
            if (GarrettTowerDefense.loadingScene)
                return;

            if (MouseHandler.MouseInRect(Rect))
            {
                if (MouseHandler.CurrentMouseState.LeftButton == ButtonState.Pressed)
                {
                    State = GUIButtonState.Down;
                }
                else
                {
                    State = GUIButtonState.Over;
                }
            }
            else
            {
                State = GUIButtonState.Up;
            }
        }
Example #8
0
        /// <summary>
        ///
        /// Draws GUIButton with passed parameters
        /// </summary>
        /// <param name="callbackEvent">Function that will be called when button is pressed</param>
        public void DrawButton(Texture2D normalTexture, Texture2D hoverTexture, Texture2D pressedTexture, Texture2D disabledTexture, GUIButtonState startState, ButtonPressedCallback callbackEvent, Rectangle rect)
        {
            GUIButton guiButton = new GUIButton(normalTexture, hoverTexture, pressedTexture, disabledTexture, callbackEvent, startState, rect);

            this.DrawButton(guiButton);
        }
Example #9
0
        /// <summary>
        ///
        /// Draws GUIButton with passed parameters
        /// </summary>
        /// <param name="callbackEvent">Function that will be called when button is pressed</param>
        public void DrawButton(Texture2D normalTexture, Texture2D hoverTexture, Texture2D pressedTexture, Texture2D disabledTexture, GUIButtonState startState, ButtonPressedCallback callbackEvent, Vector2 position, float width, float height)
        {
            GUIButton guiButton = new GUIButton(normalTexture, hoverTexture, pressedTexture, disabledTexture, callbackEvent, startState, position, width, height);

            this.DrawButton(guiButton);
        }