diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index a742d3b43..ee7d32dad 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -10,6 +10,32 @@ namespace FlaxEngine.GUI /// public class ProgressBar : ContainerControl { + /// + /// The direction to move the progress bar + /// + public enum BarDirection + { + /// + /// Move the bar horizontally to the left. + /// + HorizontalLeft, + + /// + /// Move the bar horizontally to the right. + /// + HorizontalRight, + + /// + /// Move the bar vertically up. + /// + VerticalUp, + + /// + /// Move the bar vertically down. + /// + VerticalDown, + } + /// /// The value. /// @@ -40,6 +66,18 @@ namespace FlaxEngine.GUI /// Gets a value indicating whether use progress value smoothing. /// public bool UseSmoothing => !Mathf.IsZero(SmoothingScale); + + /// + /// If true, the progress bar will clip instead of stretch. + /// + [EditorOrder(42), Tooltip("Whether or not to clip vs stretch the progress bar.")] + public bool ClipBar = false; + + /// + /// The direction to clip or stretch the bar. + /// + [EditorOrder(42), Tooltip("The direction to clip or stretch the bar.")] + public BarDirection Direction = BarDirection.HorizontalLeft; /// /// Gets or sets the minimum value. @@ -168,12 +206,42 @@ 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); + Rectangle barRect = new Rectangle(0, 0, Width * progressNormalized, Height); + switch (Direction) + { + case BarDirection.HorizontalLeft: + break; + case BarDirection.HorizontalRight: + barRect = new Rectangle(Width - Width * progressNormalized, 0, Width * progressNormalized, Height); + break; + case BarDirection.VerticalUp: + barRect = new Rectangle(0, 0, Width, Height * progressNormalized); + break; + case BarDirection.VerticalDown: + barRect = new Rectangle(0, Height - Height * progressNormalized, Width, Height * progressNormalized); + break; + default: break; + } + + if (ClipBar) + { + 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(); + } else - Render2D.FillRectangle(barRect, BarColor); + { + BarMargin.ShrinkRectangle(ref barRect); + if (BarBrush != null) + BarBrush.Draw(barRect, BarColor); + else + Render2D.FillRectangle(barRect, BarColor); + } } } }