From 026b79b61e052cadca9afa0c9cd7654cf0d833d4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 25 Sep 2019 16:39:17 +0200 Subject: [PATCH] fixed progress bars overshooting their ninepatch areas --- MLEM.Ui/Elements/ProgressBar.cs | 6 ++++-- Sandbox/GameImpl.cs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/MLEM.Ui/Elements/ProgressBar.cs b/MLEM.Ui/Elements/ProgressBar.cs index 4bb8f3f..9ca988f 100644 --- a/MLEM.Ui/Elements/ProgressBar.cs +++ b/MLEM.Ui/Elements/ProgressBar.cs @@ -36,8 +36,10 @@ namespace MLEM.Ui.Elements { batch.Draw(this.Texture, this.DisplayArea, this.Color * alpha, this.Scale); var percentage = this.CurrentValue / this.MaxValue; - var width = (percentage * this.DisplayArea.Width).Floor(); - var height = (percentage * this.DisplayArea.Height).Floor(); + var padHor = this.ProgressTexture != null ? (this.ProgressTexture.PaddingLeft + this.ProgressTexture.PaddingRight) * this.Scale : 0; + var padVer = this.ProgressTexture != null ? (this.ProgressTexture.PaddingTop + this.ProgressTexture.PaddingBottom) * this.Scale : 0; + var width = (percentage * (this.DisplayArea.Width - padHor) + padHor).Floor(); + var height = (percentage * (this.DisplayArea.Height - padVer) + padVer).Floor(); Rectangle progressArea; switch (this.Direction) { case Direction2.Up: diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 974c91c..21e17f7 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -1,9 +1,11 @@ +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MLEM.Cameras; using MLEM.Extended.Extensions; using MLEM.Extended.Tiled; using MLEM.Font; +using MLEM.Misc; using MLEM.Startup; using MLEM.Textures; using MLEM.Ui; @@ -17,6 +19,7 @@ namespace Sandbox { private Camera camera; private TiledMap map; private IndividualTiledMapRenderer mapRenderer; + private ProgressBar progress; public GameImpl() { this.IsMouseVisible = true; @@ -49,6 +52,20 @@ namespace Sandbox { this.UiSystem.Add("Root", root); var group = root.AddChild(new CustomDrawGroup(Anchor.AutoLeft, new Vector2(1, 10))); group.AddChild(new Button(Anchor.AutoLeft, Vector2.One, "Test text")); + + this.progress = new ProgressBar(Anchor.Center, new Vector2(0.8F, 0.5F), Direction2.Down, 1) { + HasCustomStyle = true, + Texture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8), + Color = Color.White, + ProgressTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4), + ProgressColor = Color.White + }; + this.UiSystem.Add("Progress", this.progress); + } + + protected override void Update(GameTime gameTime) { + base.Update(gameTime); + this.progress.CurrentValue = (float) (Math.Sin(gameTime.TotalGameTime.TotalSeconds/2) + 1) / 2; } protected override void DoDraw(GameTime gameTime) {