mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
e962cec448
* mostly restored the tiled importer unit tests * code cleanup * code cleanup * almost got tiled maps serialization independent of the content pipeline * refactored the tiled map content importer so that tiled maps can be loaded at runtime * code cleanup * removed nuspec files * experimenting with an XML based GUI markup parser * a few more markup parser features * finally got a working open file dialog * experimenting with markup bindings * attached properties * working on the gui stuff again * working on a better textbox * multiline textboxing * new text box is really coming along * removed the content explorer experiment * restored the old gui demo back to the way it was before (for now)
92 lines
2.3 KiB
C#
92 lines
2.3 KiB
C#
using System;
|
|
|
|
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public class Button : ContentControl
|
|
{
|
|
public Button()
|
|
{
|
|
}
|
|
|
|
public event EventHandler Clicked;
|
|
public event EventHandler PressedStateChanged;
|
|
|
|
private bool _isPressed;
|
|
public bool IsPressed
|
|
{
|
|
get => _isPressed;
|
|
set
|
|
{
|
|
if (_isPressed != value)
|
|
{
|
|
_isPressed = value;
|
|
PressedStyle?.ApplyIf(this, _isPressed);
|
|
PressedStateChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
|
|
private ControlStyle _pressedStyle;
|
|
public ControlStyle PressedStyle
|
|
{
|
|
get => _pressedStyle;
|
|
set
|
|
{
|
|
if (_pressedStyle != value)
|
|
{
|
|
_pressedStyle = value;
|
|
PressedStyle?.ApplyIf(this, _isPressed);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _isPointerDown;
|
|
|
|
public override bool OnPointerDown(IGuiContext context, PointerEventArgs args)
|
|
{
|
|
if (IsEnabled)
|
|
{
|
|
_isPointerDown = true;
|
|
IsPressed = true;
|
|
}
|
|
|
|
return base.OnPointerDown(context, args);
|
|
}
|
|
|
|
public override bool OnPointerUp(IGuiContext context, PointerEventArgs args)
|
|
{
|
|
_isPointerDown = false;
|
|
|
|
if (IsPressed)
|
|
{
|
|
IsPressed = false;
|
|
|
|
if (BoundingRectangle.Contains(args.Position) && IsEnabled)
|
|
Click();
|
|
}
|
|
|
|
return base.OnPointerUp(context, args);
|
|
}
|
|
|
|
public override bool OnPointerEnter(IGuiContext context, PointerEventArgs args)
|
|
{
|
|
if (IsEnabled && _isPointerDown)
|
|
IsPressed = true;
|
|
|
|
return base.OnPointerEnter(context, args);
|
|
}
|
|
|
|
public override bool OnPointerLeave(IGuiContext context, PointerEventArgs args)
|
|
{
|
|
if (IsEnabled)
|
|
IsPressed = false;
|
|
|
|
return base.OnPointerLeave(context, args);
|
|
}
|
|
|
|
public void Click()
|
|
{
|
|
Clicked?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
} |