diff --git a/MLEM.Ui/Elements/CustomDrawGroup.cs b/MLEM.Ui/Elements/CustomDrawGroup.cs
index b28e07a..23c71ad 100644
--- a/MLEM.Ui/Elements/CustomDrawGroup.cs
+++ b/MLEM.Ui/Elements/CustomDrawGroup.cs
@@ -10,13 +10,15 @@ namespace MLEM.Ui.Elements {
///
[Obsolete("CustomDrawGroup mechanics have been moved down to Element, which means custom draw groups are no longer necessary.")]
public class CustomDrawGroup : Group {
+
+ public readonly TransformCallback TransformGetter;
///
/// Creates a new custom draw group with the given settings
///
/// The group's anchor
/// The group's size
- /// The group's
+ /// The group's
/// The group's
/// Whether this group should automatically calculate its height based on its children
public CustomDrawGroup(Anchor anchor, Vector2 size, TransformCallback transformGetter = null, BeginDelegate beginImpl = null, bool setHeightBasedOnChildren = true) :
@@ -31,5 +33,20 @@ namespace MLEM.Ui.Elements {
this.ScaleTransform(scale, origin);
}
+ ///
+ public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
+ if (this.Transform == Matrix.Identity)
+ this.Transform = this.TransformGetter(this, time, matrix);
+ base.Draw(time, batch, alpha, blendState, samplerState, matrix);
+ }
+
+ ///
+ /// A delegate method used for
+ ///
+ /// The element whose transform to get
+ /// The game's time
+ /// The regular transform matrix
+ public delegate Matrix TransformCallback(Element element, GameTime time, Matrix matrix);
+
}
}
\ No newline at end of file
diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs
index dd6f991..6be612d 100644
--- a/MLEM.Ui/Elements/Element.cs
+++ b/MLEM.Ui/Elements/Element.cs
@@ -230,11 +230,7 @@ namespace MLEM.Ui.Elements {
/// Can easily be scaled using .
/// Note that, when this is non-null, a new call is used for this element.
///
- public Matrix? Transform;
- ///
- /// A callback for retrieving this element's automatically.
- ///
- public TransformCallback TransformGetter = (e, time, m) => Matrix.Identity;
+ public Matrix Transform = Matrix.Identity;
///
/// The call that this element should make to to begin drawing.
/// Note that, when this is non-null, a new call is used for this element.
@@ -832,9 +828,8 @@ namespace MLEM.Ui.Elements {
/// The sampler state that is used for drawing
/// The transformation matrix that is used for drawing
public void DrawTransformed(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
- var transform = this.Transform ?? this.TransformGetter(this, time, matrix);
- var customDraw = this.BeginImpl != null || transform != Matrix.Identity;
- var mat = transform * matrix;
+ var customDraw = this.BeginImpl != null || this.Transform != Matrix.Identity;
+ var mat = this.Transform * matrix;
if (customDraw) {
// end the usual draw so that we can begin our own
batch.End();
@@ -902,6 +897,8 @@ namespace MLEM.Ui.Elements {
public virtual Element GetElementUnderPos(Vector2 position) {
if (this.IsHidden)
return null;
+ if (this.Transform != Matrix.Identity)
+ position = Vector2.Transform(position, Matrix.Invert(this.Transform));
var children = this.GetRelevantChildren();
for (var i = children.Count - 1; i >= 0; i--) {
var element = children[i].GetElementUnderPos(position);
@@ -1020,13 +1017,5 @@ namespace MLEM.Ui.Elements {
/// The transform matrix used for drawing
public delegate void BeginDelegate(Element element, GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix);
- ///
- /// A delegate method used for
- ///
- /// The element whose transform to get
- /// The game's time
- /// The regular transform matrix
- public delegate Matrix TransformCallback(Element element, GameTime time, Matrix matrix);
-
}
}
\ No newline at end of file