mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
upgrade images a bit
This commit is contained in:
parent
4d87068090
commit
150d6f771a
2 changed files with 34 additions and 2 deletions
|
@ -30,6 +30,9 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
public bool MaintainImageAspect = true;
|
||||
public SpriteEffects ImageEffects = SpriteEffects.None;
|
||||
public Vector2 ImageScale = Vector2.One;
|
||||
public float ImageRotation;
|
||||
|
||||
public Image(Anchor anchor, Vector2 size, TextureRegion texture, bool scaleToImage = false) : base(anchor, size) {
|
||||
this.texture = texture;
|
||||
|
@ -43,12 +46,14 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
|
||||
var center = new Vector2(this.texture.Width / 2F, this.texture.Height / 2F);
|
||||
if (this.MaintainImageAspect) {
|
||||
var scale = Math.Min(this.DisplayArea.Width / (float) this.texture.Width, this.DisplayArea.Height / (float) this.texture.Height);
|
||||
var imageOffset = new Vector2(this.DisplayArea.Width / 2F - this.texture.Width * scale / 2, this.DisplayArea.Height / 2F - this.texture.Height * scale / 2);
|
||||
batch.Draw(this.texture, this.DisplayArea.Location.ToVector2() + imageOffset, this.Color * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||
batch.Draw(this.texture, this.DisplayArea.Location.ToVector2() + center * scale + imageOffset, this.Color * alpha, this.ImageRotation, center, scale * this.ImageScale, this.ImageEffects, 0);
|
||||
} else {
|
||||
batch.Draw(this.texture, this.DisplayArea, this.Color * alpha);
|
||||
var scale = new Vector2(1F / this.texture.Width, 1F / this.texture.Height) * this.DisplayArea.Size.ToVector2();
|
||||
batch.Draw(this.texture, this.DisplayArea.Location.ToVector2() + center * scale, this.Color * alpha, this.ImageRotation, center, scale * this.ImageScale, this.ImageEffects, 0);
|
||||
}
|
||||
base.Draw(time, batch, alpha);
|
||||
}
|
||||
|
|
27
MLEM.Ui/Elements/SpriteAnimationImage.cs
Normal file
27
MLEM.Ui/Elements/SpriteAnimationImage.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Animations;
|
||||
using MLEM.Textures;
|
||||
|
||||
namespace MLEM.Ui.Elements {
|
||||
public class SpriteAnimationImage : Image {
|
||||
|
||||
public SpriteAnimationGroup Group;
|
||||
|
||||
public SpriteAnimationImage(Anchor anchor, Vector2 size, TextureRegion texture, SpriteAnimationGroup group, bool scaleToImage = false) :
|
||||
base(anchor, size, texture, scaleToImage) {
|
||||
this.Group = group;
|
||||
}
|
||||
|
||||
public SpriteAnimationImage(Anchor anchor, Vector2 size, TextureRegion texture, SpriteAnimation animation, bool scaleToImage = false) :
|
||||
this(anchor, size, texture, new SpriteAnimationGroup().Add(animation, () => true), scaleToImage) {
|
||||
}
|
||||
|
||||
public override void Update(GameTime time) {
|
||||
base.Update(time);
|
||||
this.Group.Update(time);
|
||||
this.Texture = this.Group.CurrentRegion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue