18 private int _padding = 2;
35 string? nickname =
null)
38 ArgumentNullException.ThrowIfNull(view);
41 _orientation = orientation;
43 Track = CreateTrack(renderSurfaceHost, view, bounds);
44 Fill = CreateFill(renderSurfaceHost, view, bounds);
45 CompleteInitialization(value);
62 string? nickname =
null)
65 ArgumentNullException.ThrowIfNull(sceneLayer);
68 _orientation = orientation;
70 Track = CreateTrack(renderSurfaceHost, sceneLayer, bounds);
71 Fill = CreateFill(renderSurfaceHost, sceneLayer, bounds);
72 CompleteInitialization(value);
93 if (!
float.IsFinite(value))
94 throw new ArgumentOutOfRangeException(nameof(value));
96 float clamped = Math.Clamp(value, 0f, 1f);
97 if (_value.Equals(clamped))
113 if (_orientation == value)
116 _orientation = value;
130 throw new ArgumentOutOfRangeException(nameof(value));
149 Track.ScreenBounds =
new Rectangle(
Track.ScreenBounds.Location, value);
151 Track.WorldBounds =
new Rectangle(
Track.WorldBounds.Location, value);
189 Fill.SetColor(color);
190 Fill.SetPosition(
Fill.GetPosition());
201 Track.SetColor(color);
213 Track.ZOrder = zOrder;
214 Fill.ZOrder = zOrder + 1;
222 Fill.Visible =
Value > 0f;
225 private void CompleteInitialization(
float value)
227 Add(
Track, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
228 Add(
Fill, keepCurrentOffset:
false, explicitLocalOffsetPx:
new Vector2(_padding, _padding));
236 _value = Math.Clamp(
float.IsFinite(value) ? value :
throw new ArgumentOutOfRangeException(nameof(value)), 0f, 1f);
240 private void UpdateFillBounds()
242 int innerWidth = Math.Max(0, _size.Width - _padding * 2);
243 int innerHeight = Math.Max(0, _size.Height - _padding * 2);
250 int fillWidth = (int)MathF.Round(innerWidth * _value);
251 fillSize =
new Size(fillWidth, innerHeight);
252 offset =
new Vector2(_padding, _padding);
256 int fillHeight = (int)MathF.Round(innerHeight * _value);
257 fillSize =
new Size(innerWidth, fillHeight);
258 offset =
new Vector2(_padding, _padding + innerHeight - fillHeight);
262 Rectangle resized =
new(current.Location, fillSize);
265 Fill.ScreenBounds = resized;
267 Fill.WorldBounds = resized;
273 private DirectRectangle CreateTrack(RenderSurfaceHostBase host,
View view, Rectangle bounds)
275 return new DirectRectangle(Color.FromArgb(220, 28, 30, 36), host, view, bounds, $
"{Nickname}.track")
277 .SetBorderColor(Color.FromArgb(235, 225, 228, 234))
279 .SetStrokeAlign(DirectRectangle.StrokeAlign.Inside)
280 .SetCornerRadius(2f);
283 private DirectRectangle CreateTrack(RenderSurfaceHostBase host,
SceneLayer layer, Rectangle bounds)
285 return new DirectRectangle(Color.FromArgb(220, 28, 30, 36), host, layer, bounds, $
"{Nickname}.track")
287 .SetBorderColor(Color.FromArgb(235, 225, 228, 234))
289 .SetStrokeAlign(DirectRectangle.StrokeAlign.Inside)
290 .SetCornerRadius(2f);
293 private DirectRectangle CreateFill(RenderSurfaceHostBase host,
View view, Rectangle bounds)
295 return new DirectRectangle(Color.FromArgb(245, 55, 210, 105), host, view, bounds, $
"{Nickname}.fill")
298 .SetCornerRadius(1f);
301 private DirectRectangle CreateFill(RenderSurfaceHostBase host,
SceneLayer layer, Rectangle bounds)
303 return new DirectRectangle(Color.FromArgb(245, 55, 210, 105), host, layer, bounds, $
"{Nickname}.fill")
306 .SetCornerRadius(1f);
309 private static Rectangle ValidateBounds(Rectangle bounds)
311 ValidateSize(bounds.Size);
315 private static void ValidateSize(
Size size)
317 if (size.Width <= 0 || size.Height <= 0)
318 throw new ArgumentOutOfRangeException(nameof(size), size,
"Progress-bar size must be positive.");
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.