mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-28 07:18:35 +01:00
Compare commits
No commits in common. "8fdc3546c65601d371504ca6a40f95b837718d48" and "ee2b0266aa65536357069a526915af4e1e89518c" have entirely different histories.
8fdc3546c6
...
ee2b0266aa
4 changed files with 9 additions and 73 deletions
|
@ -27,10 +27,8 @@ Improvements
|
||||||
Additions
|
Additions
|
||||||
- Added the ability to set the anchor that should be used when a tooltip attaches to an element or the mouse
|
- Added the ability to set the anchor that should be used when a tooltip attaches to an element or the mouse
|
||||||
- Added the ability to display tooltips using the auto-nav style even when using the mouse
|
- Added the ability to display tooltips using the auto-nav style even when using the mouse
|
||||||
- Added the ScissorGroup element, which applies a scissor rectangle when drawing its content
|
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- **Include the SpriteBatchContext in OnDrawn, OnElementDrawn and OnSelectedElementDrawn**
|
|
||||||
- Allow scrolling panels to set height based on children by setting TreatSizeAsMaximum
|
- Allow scrolling panels to set height based on children by setting TreatSizeAsMaximum
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
|
|
|
@ -1148,9 +1148,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="alpha">The alpha to draw this element and its children with</param>
|
/// <param name="alpha">The alpha to draw this element and its children with</param>
|
||||||
/// <param name="context">The sprite batch context to use for drawing</param>
|
/// <param name="context">The sprite batch context to use for drawing</param>
|
||||||
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
||||||
this.System.InvokeOnElementDrawn(this, time, batch, alpha, context);
|
this.System.InvokeOnElementDrawn(this, time, batch, alpha);
|
||||||
if (this.IsSelected)
|
if (this.IsSelected)
|
||||||
this.System.InvokeOnSelectedElementDrawn(this, time, batch, alpha, context);
|
this.System.InvokeOnSelectedElementDrawn(this, time, batch, alpha);
|
||||||
|
|
||||||
foreach (var child in this.GetRelevantChildren()) {
|
foreach (var child in this.GetRelevantChildren()) {
|
||||||
if (!child.IsHidden) {
|
if (!child.IsHidden) {
|
||||||
|
@ -1387,8 +1387,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="time">The game's time</param>
|
/// <param name="time">The game's time</param>
|
||||||
/// <param name="batch">The sprite batch used for drawing</param>
|
/// <param name="batch">The sprite batch used for drawing</param>
|
||||||
/// <param name="alpha">The alpha this element is drawn with</param>
|
/// <param name="alpha">The alpha this element is drawn with</param>
|
||||||
/// <param name="context">The sprite batch context to use for drawing</param>
|
public delegate void DrawCallback(Element element, GameTime time, SpriteBatch batch, float alpha);
|
||||||
public delegate void DrawCallback(Element element, GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A generic delegate used inside of <see cref="Element.Update"/>
|
/// A generic delegate used inside of <see cref="Element.Update"/>
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using MLEM.Extensions;
|
|
||||||
using MLEM.Graphics;
|
|
||||||
|
|
||||||
namespace MLEM.Ui.Elements {
|
|
||||||
/// <summary>
|
|
||||||
/// A scissor group is a <see cref="Group"/> that sets the <see cref="GraphicsDevice.ScissorRectangle"/> before drawing its content (and thus, its <see cref="Element.Children"/>), preventing them from being drawn outside of this group's <see cref="Element.DisplayArea"/>'s bounds.
|
|
||||||
/// </summary>
|
|
||||||
public class ScissorGroup : Group {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The rasterizer state that this scissor group should use when drawing.
|
|
||||||
/// By default, <see cref="CullMode"/> is set to <see cref="CullMode.CullCounterClockwiseFace"/> in accordance with <see cref="SpriteBatch"/>'s default behavior, and <see cref="RasterizerState.ScissorTestEnable"/> is set to <see langword="true"/>.
|
|
||||||
/// </summary>
|
|
||||||
public readonly RasterizerState Rasterizer = new RasterizerState {
|
|
||||||
// use the default cull mode from SpriteBatch, but with scissor test enabled
|
|
||||||
CullMode = CullMode.CullCounterClockwiseFace,
|
|
||||||
ScissorTestEnable = true
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new scissor group with the given settings
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="anchor">The group's anchor</param>
|
|
||||||
/// <param name="size">The group's size</param>
|
|
||||||
/// <param name="setHeightBasedOnChildren">Whether the group's height should be based on its children's height, see <see cref="Element.SetHeightBasedOnChildren"/>.</param>
|
|
||||||
public ScissorGroup(Anchor anchor, Vector2 size, bool setHeightBasedOnChildren = true) : base(anchor, size, setHeightBasedOnChildren) {}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new scissor group with the given settings
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="anchor">The group's anchor</param>
|
|
||||||
/// <param name="size">The group's size</param>
|
|
||||||
/// <param name="setWidthBasedOnChildren">Whether the group's width should be based on its children's width, see <see cref="Element.SetWidthBasedOnChildren"/>.</param>
|
|
||||||
/// <param name="setHeightBasedOnChildren">Whether the group's height should be based on its children's height, see <see cref="Element.SetHeightBasedOnChildren"/>.</param>
|
|
||||||
public ScissorGroup(Anchor anchor, Vector2 size, bool setWidthBasedOnChildren, bool setHeightBasedOnChildren) : base(anchor, size, setWidthBasedOnChildren, setHeightBasedOnChildren) {}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
|
||||||
batch.End();
|
|
||||||
|
|
||||||
// apply our scissor rectangle
|
|
||||||
var lastScissor = batch.GraphicsDevice.ScissorRectangle;
|
|
||||||
batch.GraphicsDevice.ScissorRectangle = (Rectangle) this.DisplayArea.OffsetCopy(context.TransformMatrix.Translation.ToVector2());
|
|
||||||
|
|
||||||
// enable scissor test
|
|
||||||
var localContext = context;
|
|
||||||
localContext.RasterizerState = this.Rasterizer;
|
|
||||||
batch.Begin(localContext);
|
|
||||||
|
|
||||||
base.Draw(time, batch, alpha, localContext);
|
|
||||||
|
|
||||||
// revert back to previous behavior
|
|
||||||
batch.End();
|
|
||||||
batch.GraphicsDevice.ScissorRectangle = lastScissor;
|
|
||||||
batch.Begin(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -215,7 +215,7 @@ namespace MLEM.Ui {
|
||||||
this.Controls = new UiControls(this, inputHandler);
|
this.Controls = new UiControls(this, inputHandler);
|
||||||
this.style = style;
|
this.style = style;
|
||||||
|
|
||||||
this.OnElementDrawn += (e, time, batch, alpha, context) => e.OnDrawn?.Invoke(e, time, batch, alpha, context);
|
this.OnElementDrawn += (e, time, batch, alpha) => e.OnDrawn?.Invoke(e, time, batch, alpha);
|
||||||
this.OnElementUpdated += (e, time) => e.OnUpdated?.Invoke(e, time);
|
this.OnElementUpdated += (e, time) => e.OnUpdated?.Invoke(e, time);
|
||||||
this.OnElementPressed += e => e.OnPressed?.Invoke(e);
|
this.OnElementPressed += e => e.OnPressed?.Invoke(e);
|
||||||
this.OnElementSecondaryPressed += e => e.OnSecondaryPressed?.Invoke(e);
|
this.OnElementSecondaryPressed += e => e.OnSecondaryPressed?.Invoke(e);
|
||||||
|
@ -230,7 +230,7 @@ namespace MLEM.Ui {
|
||||||
this.OnMousedElementChanged += e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
|
this.OnMousedElementChanged += e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
|
||||||
this.OnTouchedElementChanged += e => this.ApplyToAll(t => t.OnTouchedElementChanged?.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.OnSelectedElementChanged += e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e));
|
||||||
this.OnSelectedElementDrawn += (element, time, batch, alpha, context) => {
|
this.OnSelectedElementDrawn += (element, time, batch, alpha) => {
|
||||||
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue())
|
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue())
|
||||||
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
|
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
|
||||||
};
|
};
|
||||||
|
@ -427,12 +427,12 @@ namespace MLEM.Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InvokeOnElementDrawn(Element element, GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
internal void InvokeOnElementDrawn(Element element, GameTime time, SpriteBatch batch, float alpha) {
|
||||||
this.OnElementDrawn?.Invoke(element, time, batch, alpha, context);
|
this.OnElementDrawn?.Invoke(element, time, batch, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InvokeOnSelectedElementDrawn(Element element, GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
internal void InvokeOnSelectedElementDrawn(Element element, GameTime time, SpriteBatch batch, float alpha) {
|
||||||
this.OnSelectedElementDrawn?.Invoke(element, time, batch, alpha, context);
|
this.OnSelectedElementDrawn?.Invoke(element, time, batch, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InvokeOnElementUpdated(Element element, GameTime time) {
|
internal void InvokeOnElementUpdated(Element element, GameTime time) {
|
||||||
|
|
Loading…
Reference in a new issue