diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd5203..19b2844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Fixes Additions - Added UiControls.NavType, which stores the most recently used type of ui navigation - Added SetWidthBasedOnAspect and SetHeightBasedOnAspect to images +- Added the ability to set a custom SamplerState for images Improvements - Allow scrolling panels to contain other scrolling panels diff --git a/MLEM.Ui/Elements/Image.cs b/MLEM.Ui/Elements/Image.cs index f53f64b..2c09d20 100644 --- a/MLEM.Ui/Elements/Image.cs +++ b/MLEM.Ui/Elements/Image.cs @@ -96,6 +96,11 @@ namespace MLEM.Ui.Elements { } } } + /// + /// The sampler state that this image's should be drawn with. + /// If this is , the current 's will be used, which will likely be the same as . + /// + public SamplerState SamplerState; /// public override bool IsHidden => base.IsHidden || this.Texture == null; @@ -153,6 +158,14 @@ namespace MLEM.Ui.Elements { public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { if (this.Texture == null) return; + + if (this.SamplerState != null) { + batch.End(); + var localContext = context; + localContext.SamplerState = this.SamplerState; + batch.Begin(localContext); + } + var center = new Vector2(this.Texture.Width / 2F, this.Texture.Height / 2F); var color = this.Color.OrDefault(Microsoft.Xna.Framework.Color.White) * alpha; if (this.MaintainImageAspect) { @@ -163,6 +176,12 @@ namespace MLEM.Ui.Elements { var scale = new Vector2(1F / this.Texture.Width, 1F / this.Texture.Height) * this.DisplayArea.Size; batch.Draw(this.Texture, this.DisplayArea.Location + center * scale, color, this.ImageRotation, center, scale * this.ImageScale, this.ImageEffects, 0); } + + if (this.SamplerState != null) { + batch.End(); + batch.Begin(context); + } + base.Draw(time, batch, alpha, context); }