mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
fixed an element transform issue and added a fancy button to the ui demo
This commit is contained in:
parent
ec370479ef
commit
abffa4db57
2 changed files with 17 additions and 1 deletions
|
@ -142,6 +142,22 @@ namespace Demos {
|
|||
OnPressed = element => CoroutineHandler.Start(WobbleButton(element)),
|
||||
PositionOffset = new Vector2(0, 1)
|
||||
});
|
||||
// Another button that shows animations!
|
||||
var fancyHoverTimer = 0D;
|
||||
var fancyButton = this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Fancy Hover") {
|
||||
PositionOffset = new Vector2(0, 1),
|
||||
OnUpdated = (e, time) => {
|
||||
if (e.IsMouseOver && fancyHoverTimer <= 0.5F)
|
||||
return;
|
||||
if (fancyHoverTimer > 0) {
|
||||
fancyHoverTimer -= time.ElapsedGameTime.TotalSeconds * 3;
|
||||
e.ScaleTransform(1 + (float) Math.Sin(fancyHoverTimer * MathHelper.Pi) * 0.05F);
|
||||
} else {
|
||||
e.Transform = Matrix.Identity;
|
||||
}
|
||||
}
|
||||
});
|
||||
fancyButton.OnMouseEnter += e => fancyHoverTimer = 1;
|
||||
this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Transform Ui", "This button causes the entire ui to be transformed (both in positioning, rotation and scale)") {
|
||||
OnPressed = element => {
|
||||
if (element.Root.Transform == Matrix.Identity) {
|
||||
|
|
|
@ -834,7 +834,7 @@ namespace MLEM.Ui.Elements {
|
|||
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 = matrix * transform;
|
||||
var mat = transform * matrix;
|
||||
if (customDraw) {
|
||||
// end the usual draw so that we can begin our own
|
||||
batch.End();
|
||||
|
|
Loading…
Reference in a new issue