Merge branch 'Tryibion-progress-bar-improv'

This commit is contained in:
Wojtek Figat
2023-09-01 11:59:12 +02:00

View File

@@ -10,6 +10,48 @@ namespace FlaxEngine.GUI
/// <seealso cref="FlaxEngine.GUI.Control" />
public class ProgressBar : ContainerControl
{
/// <summary>
/// The method used to effect the bar.
/// </summary>
public enum BarMethod
{
/// <summary>
/// Stretch the bar.
/// </summary>
Stretch,
/// <summary>
/// Clip the bar.
/// </summary>
Clip,
}
/// <summary>
/// The origin to move the progress bar to.
/// </summary>
public enum BarOrigin
{
/// <summary>
/// Move the bar horizontally to the left.
/// </summary>
HorizontalLeft,
/// <summary>
/// Move the bar horizontally to the right.
/// </summary>
HorizontalRight,
/// <summary>
/// Move the bar vertically up.
/// </summary>
VerticalTop,
/// <summary>
/// Move the bar vertically down.
/// </summary>
VerticalBottom,
}
/// <summary>
/// The value.
/// </summary>
@@ -41,6 +83,18 @@ namespace FlaxEngine.GUI
/// </summary>
public bool UseSmoothing => !Mathf.IsZero(SmoothingScale);
/// <summary>
/// The method used to effect the bar.
/// </summary>
[EditorOrder(41), Tooltip("The method used to effect the bar.")]
public BarMethod Method = BarMethod.Stretch;
/// <summary>
/// The origin or where the bar decreases to.
/// </summary>
[EditorOrder(42), Tooltip("The origin or where the bar decreases to.")]
public BarOrigin Origin = BarOrigin.HorizontalLeft;
/// <summary>
/// Gets or sets the minimum value.
/// </summary>
@@ -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;
}
}
}
}