18 private int _padding = 2;
36 string? nickname =
null)
40 ValidateBounds(bounds).Location,
43 ArgumentNullException.ThrowIfNull(view);
46 _orientation = orientation;
48 Track = CreateTrack(renderSurfaceHost, view, bounds);
49 Fill = CreateFill(renderSurfaceHost, view, bounds);
50 CompleteInitialization(value);
68 string? nickname =
null)
72 ValidateBounds(bounds).Location,
75 ArgumentNullException.ThrowIfNull(sceneLayer);
78 _orientation = orientation;
80 Track = CreateTrack(renderSurfaceHost, sceneLayer, bounds);
81 Fill = CreateFill(renderSurfaceHost, sceneLayer, bounds);
82 CompleteInitialization(value);
103 if (!
float.IsFinite(value))
104 throw new ArgumentOutOfRangeException(nameof(value));
106 float clamped = Math.Clamp(value, 0f, 1f);
108 if (_value.Equals(clamped))
124 if (_orientation == value)
127 _orientation = value;
141 throw new ArgumentOutOfRangeException(nameof(value));
160 Track.ScreenBounds =
new Rectangle(
Track.ScreenBounds.Location, value);
162 Track.WorldBounds =
new Rectangle(
Track.WorldBounds.Location, value);
200 Fill.SetColor(color);
201 Fill.SetPosition(
Fill.GetPosition());
212 Track.SetColor(color);
224 Track.ZOrder = zOrder;
225 Fill.ZOrder = zOrder + 1;
233 Fill.Visible =
Value > 0f;
236 private void CompleteInitialization(
float value)
238 Add(
Track, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
239 Add(
Fill, keepCurrentOffset:
false, explicitLocalOffsetPx:
new Vector2(_padding, _padding));
249 float.IsFinite(value) ? value :
throw new ArgumentOutOfRangeException(nameof(value)),
256 private void UpdateFillBounds()
258 int innerWidth = Math.Max(0, _size.Width - _padding * 2);
259 int innerHeight = Math.Max(0, _size.Height - _padding * 2);
266 int fillWidth = (int)MathF.Round(innerWidth * _value);
267 fillSize =
new Size(fillWidth, innerHeight);
268 offset =
new Vector2(_padding, _padding);
272 int fillHeight = (int)MathF.Round(innerHeight * _value);
273 fillSize =
new Size(innerWidth, fillHeight);
274 offset =
new Vector2(_padding, _padding + innerHeight - fillHeight);
278 Rectangle resized =
new(current.Location, fillSize);
281 Fill.ScreenBounds = resized;
283 Fill.WorldBounds = resized;
289 private DirectRectangle CreateTrack(RenderSurfaceHostBase host,
View view, Rectangle bounds)
291 return new DirectRectangle(
309 .SetStrokeAlign(DirectRectangle.StrokeAlign.Inside)
310 .SetCornerRadius(2f);
313 private DirectRectangle CreateTrack(RenderSurfaceHostBase host,
SceneLayer layer, Rectangle bounds)
315 return new DirectRectangle(
333 .SetStrokeAlign(DirectRectangle.StrokeAlign.Inside)
334 .SetCornerRadius(2f);
337 private DirectRectangle CreateFill(RenderSurfaceHostBase host,
View view, Rectangle bounds)
339 return new DirectRectangle(
351 .SetCornerRadius(1f);
354 private DirectRectangle CreateFill(RenderSurfaceHostBase host,
SceneLayer layer, Rectangle bounds)
356 return new DirectRectangle(
368 .SetCornerRadius(1f);
371 private static Rectangle ValidateBounds(Rectangle bounds)
373 ValidateSize(bounds.Size);
377 private static void ValidateSize(
Size size)
379 if (size.Width <= 0 || size.Height <= 0)
380 throw new ArgumentOutOfRangeException(nameof(size), size,
"Progress-bar size must be positive.");
SceneLayer? SceneLayer
Gets the scene layer shared by all children in scene-layer mode.
DirectComposite SetLocalOffset(IDirectCompositeChild child, Vector2 newLocalOffsetPx)
Changes one child's local offset and reapplies its position.
View? View
Gets the view shared by all children in view mode.
virtual DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
bool Visible
Gets or sets a value indicating whether this direct drawing is visible and should be rendered.
Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns,...
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ View
Performs direct drawing at the view level using screen-space coordinates.
@ Fill
Stretches the video to fill the entire bounds, ignoring the aspect ratio.