15 private bool _disposed;
16 private bool _backgroundVisible =
true;
18 private Point _offsetPx;
35 Point? offsetPx =
null,
36 string? nickname =
null)
39 Target = target ??
throw new ArgumentNullException(nameof(target));
40 _text = text ??
string.Empty;
41 _size = ValidateSize(size ??
new Size(128, 26));
42 _offsetPx = offsetPx ?? Point.Empty;
52 new Rectangle(Point.Empty, _size),
53 $
"{Nickname}-name-tag-background")
68 worldBounds:
new Rectangle(Point.Empty, _size),
69 nickname: $
"{Nickname}-name-tag-text")
71 .
SetFont(SKTypeface.Default, 15f, minSize: 9f)
72 .
SetColors(SKColors.White, SKColors.Transparent)
77 Add(
Background, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
78 Add(
TextBlock, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
87 Target.SpriteMoved += OnTargetMoved;
88 Target.VisualBoundsChanged += OnTargetVisualBoundsChanged;
89 Target.Disposing += OnTargetDisposing;
122 Size validated = ValidateSize(value);
124 if (_size == validated)
128 Background.WorldBounds =
new Rectangle(
Background.WorldBounds.Location, _size);
159 _text = text ??
string.Empty;
171 TextBlock.SetColors(color, SKColors.Transparent);
194 _backgroundVisible = visible;
195 Background.Visible = visible;
206 Background.ZOrder = zOrder;
216 Rectangle targetBounds =
Target.DrawLocationWorld;
217 int x = targetBounds.Left + (targetBounds.Width -
Size.Width) / 2 +
OffsetPx.X;
218 int y = targetBounds.Top - Size.Height - 6 +
OffsetPx.Y;
229 Target.SpriteMoved -= OnTargetMoved;
230 Target.VisualBoundsChanged -= OnTargetVisualBoundsChanged;
231 Target.Disposing -= OnTargetDisposing;
239 Background.Visible = _backgroundVisible;
247 private void OnTargetVisualBoundsChanged(
Sprite sprite)
252 private void OnTargetDisposing(
Sprite sprite)
257 private static Size ValidateSize(
Size size)
259 if (size.Width <= 0 || size.Height <= 0)
260 throw new ArgumentOutOfRangeException(nameof(size), size,
"Name-tag size must be positive.");
SceneLayer? SceneLayer
Gets the scene layer shared by all children in scene-layer mode.
virtual DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.
void SetPosition(Vector2 position)
Sets the composite anchor and repositions all children from their stored offsets.
int ZOrder
Gets or sets the Z-order (depth) used for sorting this direct drawing relative to other drawables.
Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns,...
DirectRectangle SetFilled(bool isFilled)
Sets whether the rectangle interior is filled with the base color (or pattern).
DirectRectangle SetBorderColor(Color color)
Sets a distinct border (stroke) color, independent of the fill color.
DirectRectangle SetStrokeWidth(float width)
Sets the width (thickness) of the rectangle's stroke (outline) in pixels.
DirectRectangle SetCornerRadius(float radius)
Sets the radius for rounded corners in pixels.
TextBlock SetFont(SKTypeface typeface, float size, float? minSize=null)
Sets the font face and size (and optional minimum size for auto-shrink).
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
TextBlock SetAlignment(SKTextAlign h, VerticalAlign v)
Sets the horizontal and vertical alignment used when drawing the laid-out lines within the bounds.
TextBlock SetPadding(float horizontal, float vertical)
Sets symmetric horizontal and vertical padding and invalidates cached layout.
TextBlock SetColors(SKColor fg, SKColor bg)
Sets the foreground (text) and background colors using Skia colors.
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Provides data for sprite movement events.
Represents a movable visual element on a scene layer.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.