1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-23 00:53:37 +02:00

made elements also show their mouse over graphic when they're being touched

This commit is contained in:
Ellpeck 2020-06-03 15:58:08 +02:00
parent 3d1b660c9f
commit d7f43617c6
3 changed files with 43 additions and 1 deletions

View file

@ -259,7 +259,7 @@ namespace MLEM.Ui.Elements {
public float DrawAlpha = 1;
/// <summary>
/// Stores whether this element is currently being moused over.
/// Stores whether this element is currently being moused over or touched.
/// </summary>
public bool IsMouseOver { get; protected set; }
/// <summary>
@ -300,6 +300,14 @@ namespace MLEM.Ui.Elements {
/// </summary>
public GenericCallback OnMouseExit;
/// <summary>
/// Event that is called when this element starts being touched
/// </summary>
public GenericCallback OnTouchEnter;
/// <summary>
/// Event that is called when this element stops being touched
/// </summary>
public GenericCallback OnTouchExit;
/// <summary>
/// Event that is called when text input is made.
/// Note that this event is called for every element, even if it is not selected.
/// Also note that if <see cref="TextInputWrapper.RequiresOnScreenKeyboard"/> is true, this event is never called.
@ -315,6 +323,11 @@ namespace MLEM.Ui.Elements {
/// </summary>
public OtherElementCallback OnMousedElementChanged;
/// <summary>
/// Event that is called when the element that is currently being touched changes within the ui system.
/// Note that the event fired doesn't necessarily correlate to this specific element.
/// </summary>
public OtherElementCallback OnTouchedElementChanged;
/// <summary>
/// Event that is called when the element that is currently selected changes within the ui system.
/// Note that the event fired doesn't necessarily correlate to this specific element.
/// </summary>
@ -362,6 +375,8 @@ namespace MLEM.Ui.Elements {
this.OnMouseEnter += element => this.IsMouseOver = true;
this.OnMouseExit += element => this.IsMouseOver = false;
this.OnTouchEnter += element => this.IsMouseOver = true;
this.OnTouchExit += element => this.IsMouseOver = false;
this.OnSelected += element => this.IsSelected = true;
this.OnDeselected += element => this.IsSelected = false;
this.GetTabNextElement += (backward, next) => next;

View file

@ -40,6 +40,10 @@ namespace MLEM.Ui {
/// The <see cref="Element"/> that the mouse is currently over.
/// </summary>
public Element MousedElement { get; private set; }
/// <summary>
/// The <see cref="Element"/> that is currently touched.
/// </summary>
public Element TouchedElement { get; private set; }
private readonly Dictionary<string, Element> selectedElements = new Dictionary<string, Element>();
/// <summary>
/// The element that is currently selected.
@ -200,6 +204,16 @@ namespace MLEM.Ui {
this.SelectElement(this.ActiveRoot, held);
if (held != null && held.CanBePressed)
this.System.OnElementSecondaryPressed?.Invoke(held);
} else {
var held = this.Input.TouchState.Select(l => this.GetElementUnderPos(l.Position)).FirstOrDefault();
if (held != this.TouchedElement) {
if (this.TouchedElement != null)
this.System.OnElementTouchExit?.Invoke(this.TouchedElement);
if (held != null)
this.System.OnElementTouchEnter?.Invoke(held);
this.TouchedElement = held;
this.System.OnTouchedElementChanged?.Invoke(held);
}
}
}

View file

@ -141,6 +141,14 @@ namespace MLEM.Ui {
/// </summary>
public Element.GenericCallback OnElementMouseExit = e => e.OnMouseExit?.Invoke(e);
/// <summary>
/// Event that is invoked when an <see cref="Element"/> starts being touched
/// </summary>
public Element.GenericCallback OnElementTouchEnter = e => e.OnTouchEnter?.Invoke(e);
/// <summary>
/// Event that is invoked when an <see cref="Element"/> stops being touched
/// </summary>
public Element.GenericCallback OnElementTouchExit = e => e.OnTouchExit?.Invoke(e);
/// <summary>
/// Event that is invoked when an <see cref="Element"/>'s display area changes
/// </summary>
public Element.GenericCallback OnElementAreaUpdated = e => e.OnAreaUpdated?.Invoke(e);
@ -149,6 +157,10 @@ namespace MLEM.Ui {
/// </summary>
public Element.GenericCallback OnMousedElementChanged;
/// <summary>
/// Event that is invoked when the <see cref="Element"/> that is being touched changes
/// </summary>
public Element.GenericCallback OnTouchedElementChanged;
/// <summary>
/// Event that is invoked when the selected <see cref="Element"/> changes, either through automatic navigation, or by pressing on an element with the mouse
/// </summary>
public Element.GenericCallback OnSelectedElementChanged;
@ -184,6 +196,7 @@ namespace MLEM.Ui {
TextInputWrapper.Current.AddListener(window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character)));
this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
this.OnTouchedElementChanged = e => this.ApplyToAll(t => t.OnTouchedElementChanged?.Invoke(t, e));
this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e));
this.OnSelectedElementDrawn = (element, time, batch, alpha) => {
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue()) {