Exemple #1
0
 public Button()
 {
     hoverTexture = hoverDefault;
     clickTexture = clickDefault;
     idleTexture = idleDefault;
     lastState = new ButtonState();
 }
Exemple #2
0
        public override void Update()
        {
            bool hovered = (Forgottenvoxels.mouse.X >= x && Forgottenvoxels.mouse.Y >= y) && (Forgottenvoxels.mouse.X < x + width && Forgottenvoxels.mouse.Y < y + height);
            bool clicked = Forgottenvoxels.mouse[MouseButton.Left];
            ButtonState newState = new ButtonState();
            newState.hovered = hovered;
            newState.clicked = clicked;

            texture = idleTexture;

            if(newState.hovered){
                texture = hoverTexture;
            }
            if(newState.clicked && newState.hovered){
                texture = clickTexture;
            }

            if(newState.hovered && !lastState.hovered){
                if (HoverChange != null)
                    HoverChange(this, hovered);
            }
            else if(!newState.hovered && lastState.hovered)
            {
                if (HoverChange != null)
                    HoverChange(this, hovered);
            }

            if(newState.clicked && !lastState.clicked)
            {
                if (ClickChange != null)
                    ClickChange(this, clicked, clicked && hovered);
            }
            else if(!newState.clicked && lastState.clicked){
                if (ClickChange != null)
                    ClickChange(this, clicked, clicked && hovered);
            }

            lastState = newState;
        }