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

added the ability to easily change how a selected element is drawn

This commit is contained in:
Ellpeck 2019-08-31 18:07:43 +02:00
parent 3862f78c9b
commit 3464fff6e5
2 changed files with 16 additions and 3 deletions

View file

@ -425,14 +425,15 @@ namespace MLEM.Ui.Elements {
}
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) {
this.System.OnElementDrawn?.Invoke(this, time, batch, alpha, offset);
foreach (var child in this.SortedChildren) {
if (!child.IsHidden)
child.Draw(time, batch, alpha * child.DrawAlpha, offset);
}
if (this.IsSelected && !this.Controls.SelectedLastElementWithMouse && this.SelectionIndicator != null) {
batch.Draw(this.SelectionIndicator, this.DisplayArea.OffsetCopy(offset), Color.White * alpha);
}
if (this.IsSelected)
this.System.OnSelectedElementDrawn?.Invoke(this, time, batch, alpha, offset);
}
public virtual void DrawEarly(GameTime time, SpriteBatch batch, float alpha, BlendState blendState = null, SamplerState samplerState = null) {
@ -463,6 +464,8 @@ namespace MLEM.Ui.Elements {
public delegate void OtherElementCallback(Element thisElement, Element otherElement);
public delegate void DrawCallback(Element element, GameTime time, SpriteBatch batch, float alpha, Point offset);
internal void Propagate(Action<Element> action) {
action(this);
foreach (var child in this.Children)

View file

@ -7,6 +7,7 @@ using Microsoft.Xna.Framework.Input;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Input;
using MLEM.Textures;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
@ -49,6 +50,9 @@ namespace MLEM.Ui {
public SamplerState SamplerState = SamplerState.PointClamp;
public UiControls Controls;
public Element.DrawCallback OnElementDrawn;
public Element.DrawCallback OnSelectedElementDrawn;
public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) {
this.Controls = new UiControls(this, inputHandler);
this.GraphicsDevice = device;
@ -68,6 +72,12 @@ namespace MLEM.Ui {
root.Element.Propagate(e => e.OnTextInput?.Invoke(e, key, character));
});
}
this.OnSelectedElementDrawn = (element, time, batch, alpha, offset) => {
if (!this.Controls.SelectedLastElementWithMouse && element.SelectionIndicator != null) {
batch.Draw(element.SelectionIndicator, element.DisplayArea.OffsetCopy(offset), Color.White * alpha);
}
};
}
private static void AddToTextInput(GameWindow window, Action<Keys, char> func) {