15 private bool _disposed;
16 private bool _backgroundVisible =
true;
18 private Point _offsetPx;
34 Point? offsetPx =
null,
35 string? nickname =
null)
38 Target = target ??
throw new ArgumentNullException(nameof(target));
39 _text = text ??
string.Empty;
40 _size = ValidateSize(size ??
new Size(128, 26));
41 _offsetPx = offsetPx ?? Point.Empty;
44 Color.FromArgb(185, 20, 22, 28),
47 new Rectangle(Point.Empty, _size),
48 $
"{Nickname}-name-tag-background")
58 worldBounds:
new Rectangle(Point.Empty, _size),
59 nickname: $
"{Nickname}-name-tag-text")
61 .
SetFont(SKTypeface.Default, 15f, minSize: 9f)
62 .
SetColors(SKColors.White, SKColors.Transparent)
67 Add(
Background, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
68 Add(
TextBlock, keepCurrentOffset:
false, explicitLocalOffsetPx: Vector2.Zero);
77 Target.SpriteMoved += OnTargetMoved;
78 Target.VisualBoundsChanged += OnTargetVisualBoundsChanged;
79 Target.Disposing += OnTargetDisposing;
112 Size validated = ValidateSize(value);
113 if (_size == validated)
117 Background.WorldBounds =
new Rectangle(
Background.WorldBounds.Location, _size);
148 _text = text ??
string.Empty;
160 TextBlock.SetColors(color, SKColors.Transparent);
183 _backgroundVisible = visible;
184 Background.Visible = visible;
195 Background.ZOrder = zOrder;
205 Rectangle targetBounds =
Target.DrawLocationWorld;
206 int x = targetBounds.Left + (targetBounds.Width -
Size.Width) / 2 +
OffsetPx.X;
207 int y = targetBounds.Top - Size.Height - 6 +
OffsetPx.Y;
218 Target.SpriteMoved -= OnTargetMoved;
219 Target.VisualBoundsChanged -= OnTargetVisualBoundsChanged;
220 Target.Disposing -= OnTargetDisposing;
228 Background.Visible = _backgroundVisible;
236 private void OnTargetVisualBoundsChanged(
Sprite sprite)
241 private void OnTargetDisposing(
Sprite sprite)
246 private static Size ValidateSize(
Size size)
248 if (size.Width <= 0 || size.Height <= 0)
249 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.