-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgressBar.cs
More file actions
99 lines (90 loc) · 2.41 KB
/
ProgressBar.cs
File metadata and controls
99 lines (90 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using JetBrains.Annotations;
using SharpEngine.Core.Math;
using SharpEngine.Core.Renderer;
using SharpEngine.Core.Utils;
namespace SharpEngine.Core.Widget;
/// <summary>
/// Class which represents ProgressBar
/// </summary>
public class ProgressBar : Widget
{
/// <summary>
/// Value of Bar (0 to 100)
/// </summary>
[UsedImplicitly]
public float Value
{
get;
set => field = MathHelper.Clamp(value, 0, 100);
}
/// <summary>
/// Size of Bar
/// </summary>
[UsedImplicitly]
public Vec2 Size { get; set; }
/// <summary>
/// Color of Bar
/// </summary>
[UsedImplicitly]
public Color Color { get; set; }
/// <summary>
/// If Bar is Horizontal
/// </summary>
[UsedImplicitly]
public bool Horizontal { get; set; }
/// <summary>
/// Create a ProgressBar
/// </summary>
/// <param name="position">Position</param>
/// <param name="size">Size (Vec2(150, 60))</param>
/// <param name="color">Color (Color.Green)</param>
/// <param name="value">Value (0)</param>
/// <param name="horizontal">Horizontal (true)</param>
/// <param name="zLayer">ZLayer (0)</param>
public ProgressBar(
Vec2 position,
Vec2? size = null,
Color? color = null,
float value = 0,
bool horizontal = true,
int zLayer = 0
)
: base(position, zLayer)
{
Size = size ?? new Vec2(150, 60);
Color = color ?? Color.Green;
Value = value;
Horizontal = horizontal;
}
/// <inheritdoc />
public override void Draw()
{
base.Draw();
if (!Displayed || Size == Vec2.Zero)
return;
SERender.DrawRectangle(
new Rect(RealPosition, Size),
Size / 2,
0,
Color.Black,
InstructionSource.Ui,
ZLayer
);
SERender.DrawRectangle(
new Rect(RealPosition, Size - 4),
(Size - 4) / 2,
0,
Color.White,
InstructionSource.Ui,
ZLayer + 0.00001f
);
SERender.DrawRectangle(
Horizontal ? new Rect(RealPosition, (Size.X - 8) * Value / 100, Size.Y - 8) : new Rect(RealPosition, Size.X - 8, (Size.Y - 8) * Value / 100),
(Size - 8) / 2,
0,
Color,
InstructionSource.Ui,
ZLayer + 0.00002f
);
}
}