diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index a742d3b43..760f031a7 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -10,6 +10,48 @@ namespace FlaxEngine.GUI /// public class ProgressBar : ContainerControl { + /// + /// The method used to effect the bar. + /// + public enum BarMethod + { + /// + /// Stretch the bar. + /// + Stretch, + + /// + /// Clip the bar. + /// + Clip, + } + + /// + /// The origin to move the progress bar to. + /// + public enum BarOrigin + { + /// + /// Move the bar horizontally to the left. + /// + HorizontalLeft, + + /// + /// Move the bar horizontally to the right. + /// + HorizontalRight, + + /// + /// Move the bar vertically up. + /// + VerticalTop, + + /// + /// Move the bar vertically down. + /// + VerticalBottom, + } + /// /// The value. /// @@ -41,6 +83,18 @@ namespace FlaxEngine.GUI /// public bool UseSmoothing => !Mathf.IsZero(SmoothingScale); + /// + /// The method used to effect the bar. + /// + [EditorOrder(41), Tooltip("The method used to effect the bar.")] + public BarMethod Method = BarMethod.Stretch; + + /// + /// The origin or where the bar decreases to. + /// + [EditorOrder(42), Tooltip("The origin or where the bar decreases to.")] + public BarOrigin Origin = BarOrigin.HorizontalLeft; + /// /// Gets or sets the minimum value. /// @@ -168,12 +222,44 @@ namespace FlaxEngine.GUI float progressNormalized = (_current - _minimum) / _maximum; if (progressNormalized > 0.001f) { - var barRect = new Rectangle(0, 0, Width * progressNormalized, Height); - BarMargin.ShrinkRectangle(ref barRect); - if (BarBrush != null) - BarBrush.Draw(barRect, BarColor); - else - Render2D.FillRectangle(barRect, BarColor); + Rectangle barRect = new Rectangle(0, 0, Width * progressNormalized, Height); + switch (Origin) + { + case BarOrigin.HorizontalLeft: + break; + case BarOrigin.HorizontalRight: + barRect = new Rectangle(Width - Width * progressNormalized, 0, Width * progressNormalized, Height); + break; + case BarOrigin.VerticalTop: + barRect = new Rectangle(0, 0, Width, Height * progressNormalized); + break; + case BarOrigin.VerticalBottom: + barRect = new Rectangle(0, Height - Height * progressNormalized, Width, Height * progressNormalized); + break; + default: break; + } + + switch (Method) + { + case BarMethod.Stretch: + BarMargin.ShrinkRectangle(ref barRect); + if (BarBrush != null) + BarBrush.Draw(barRect, BarColor); + else + Render2D.FillRectangle(barRect, BarColor); + break; + case BarMethod.Clip: + var rect = new Rectangle(0, 0, Width, Height); + BarMargin.ShrinkRectangle(ref rect); + Render2D.PushClip(ref barRect); + if (BarBrush != null) + BarBrush.Draw(rect, BarColor); + else + Render2D.FillRectangle(rect, BarColor); + Render2D.PopClip(); + break; + default: break; + } } } }