2019-09-08 16:30:55 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
|
|
public class CustomDrawGroup : Group {
|
|
|
|
|
|
|
|
public Matrix Transform;
|
|
|
|
public BeginDelegate BeginImpl;
|
|
|
|
|
|
|
|
public CustomDrawGroup(Anchor anchor, Vector2 size, Matrix? transform = null, BeginDelegate beginImpl = null, bool setHeightBasedOnChildren = true) :
|
|
|
|
base(anchor, size, setHeightBasedOnChildren) {
|
|
|
|
this.Transform = transform ?? Matrix.Identity;
|
2019-09-08 16:45:15 +02:00
|
|
|
this.BeginImpl = beginImpl ?? ((element, time, batch, alpha, blendState, samplerState, matrix) => batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, null, null, null, matrix));
|
2019-09-08 16:30:55 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 16:45:15 +02:00
|
|
|
public delegate void BeginDelegate(CustomDrawGroup element, GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix);
|
2019-09-08 16:30:55 +02:00
|
|
|
|
2019-09-20 13:22:05 +02:00
|
|
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
|
|
|
|
// end the usual draw so that we can begin our own
|
|
|
|
batch.End();
|
2019-09-08 16:30:55 +02:00
|
|
|
var mat = matrix * this.Transform;
|
2019-09-08 16:45:15 +02:00
|
|
|
this.BeginImpl(this, time, batch, alpha, blendState, samplerState, mat);
|
2019-09-08 16:30:55 +02:00
|
|
|
// draw child components in custom begin call
|
2019-09-20 13:22:05 +02:00
|
|
|
base.Draw(time, batch, alpha, blendState, samplerState, mat);
|
|
|
|
// end our draw
|
2019-09-08 16:30:55 +02:00
|
|
|
batch.End();
|
2019-09-20 13:22:05 +02:00
|
|
|
// begin the usual draw again for other elements
|
|
|
|
batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, null, null, null, matrix);
|
2019-09-08 16:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|