diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 54d77ba..3975ea8 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -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 action) { action(this); foreach (var child in this.Children) diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 578ec8f..d247dd9 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -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 func) {