File TimerBarProgress.cs
File List > LemonUI > LemonUI > TimerBars > TimerBarProgress.cs
Go to the documentation of this file
using LemonUI.Elements;
using System;
using System.Drawing;
namespace LemonUI.TimerBars
{
public class TimerBarProgress : TimerBar
{
#region Constants
private const float barWidth = 108;
private const float barHeight = 15;
#endregion
#region Fields
protected internal readonly ScaledRectangle barBackground = new ScaledRectangle(PointF.Empty, SizeF.Empty)
{
Color = Color.FromArgb(255, 139, 0, 0)
};
protected internal readonly ScaledRectangle barForeground = new ScaledRectangle(PointF.Empty, SizeF.Empty)
{
Color = Color.FromArgb(255, 255, 0, 0)
};
private float progress = 100;
#endregion
#region Properties
public float Progress
{
get => progress;
set
{
if (value < 0 || value > 100)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
progress = value;
barForeground.Size = new SizeF(barWidth * (value * 0.01f), barHeight);
}
}
public Color ForegroundColor
{
get => barForeground.Color;
set => barForeground.Color = value;
}
public Color BackgroundColor
{
get => barBackground.Color;
set => barBackground.Color = value;
}
#endregion
#region Constructors
public TimerBarProgress(string title) : base(title, string.Empty)
{
}
#endregion
#region Functions
public override void Recalculate(PointF pos)
{
// Recalculate the base elements
base.Recalculate(pos);
// And set the size and position of the progress bar
PointF barPos = new PointF(pos.X + 103, pos.Y + 12);
barBackground.Position = barPos;
barBackground.Size = new SizeF(barWidth, barHeight);
barForeground.Position = barPos;
barForeground.Size = new SizeF(barWidth * (progress * 0.01f), barHeight);
}
public override void Draw()
{
background.Draw();
title.Draw();
barBackground.Draw();
barForeground.Draw();
}
#endregion
}
}