mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
added clicked event to gui button
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
@@ -21,6 +22,8 @@ namespace MonoGame.Extended.Gui
|
||||
public bool IsPressed { get; private set; }
|
||||
public bool IsHovered { get; private set; }
|
||||
|
||||
public event EventHandler Clicked;
|
||||
|
||||
public override GuiControlStyle CurrentStyle
|
||||
{
|
||||
get
|
||||
@@ -38,9 +41,13 @@ namespace MonoGame.Extended.Gui
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
var mouseState = Mouse.GetState();
|
||||
var previouslyPressed = IsPressed;
|
||||
|
||||
IsHovered = Shape.Contains(mouseState.X, mouseState.Y);
|
||||
IsPressed = IsHovered && mouseState.LeftButton == ButtonState.Pressed;
|
||||
|
||||
if(previouslyPressed && !IsPressed && IsHovered)
|
||||
Clicked.Raise(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,10 @@ namespace SpaceGame
|
||||
{
|
||||
Position = new Vector2(400, 370)
|
||||
};
|
||||
button.Clicked += (sender, args) =>
|
||||
{
|
||||
_player.Destroy();
|
||||
};
|
||||
_guiManager.Layout.Controls.Add(button);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user