41 private const int DialogZOrderStart = 100_000;
42 private const int DialogZOrderGap = 100;
44 private static readonly
object _zOrderSyncRoot =
new();
45 private static int _nextDialogZOrder = DialogZOrderStart;
47 private bool _disposed;
52 public event Action<DialogResult>?
Closed;
69 bool showCloseButton =
true,
70 string? nickname =
null)
73 ValidateBounds(bounds);
77 Panel = CreatePanel(renderSurfaceHost, view, bounds);
78 TitleBar = CreateTitleBar(renderSurfaceHost, view, bounds);
79 TitleText = CreateTitleText(renderSurfaceHost, view, bounds, title);
87 CloseButton = CreateCloseButton(renderSurfaceHost, view, bounds);
90 CloseButton.Clicked += OnCloseButtonClicked;
93 CompleteInitialization();
109 bool showCloseButton =
true,
110 string? nickname =
null)
113 ValidateBounds(bounds);
117 Panel = CreatePanel(renderSurfaceHost, sceneLayer, bounds);
118 TitleBar = CreateTitleBar(renderSurfaceHost, sceneLayer, bounds);
119 TitleText = CreateTitleText(renderSurfaceHost, sceneLayer, bounds, title);
127 CloseButton = CreateCloseButton(renderSurfaceHost, sceneLayer, bounds);
130 CloseButton.Clicked += OnCloseButtonClicked;
133 CompleteInitialization();
136 #endregion constructors
138 #region public properties
196 #endregion public properties
198 #region exposed methods and hooks
240 BringVisualTreeToFront();
241 base.ProcessActivated();
244 private void BringVisualTreeToFront()
247 if (visuals.Length == 0)
250 int minimumZOrder = visuals.Min(
static visual => visual.ZOrder);
251 int maximumZOrder = visuals.Max(
static visual => visual.ZOrder);
252 int span = maximumZOrder - minimumZOrder;
255 lock (_zOrderSyncRoot)
257 targetMinimum = _nextDialogZOrder;
258 _nextDialogZOrder = checked(targetMinimum + span + DialogZOrderGap);
261 int delta = targetMinimum - minimumZOrder;
263 visual.ZOrder += delta;
277 yield
return descendant;
284 if (!base.CanStartDrag(args))
287 RectangleF titleBarBounds =
TitleBar.GetDrawLocationScreen(args.
View);
296 base.OnKeyboardInput(args);
332 CloseButton.Clicked -= OnCloseButtonClicked;
336 GC.SuppressFinalize(
this);
339 #endregion exposed methods and hooks
341 #region private methods
343 private void CompleteInitialization()
350 private void OnCloseButtonClicked()
355 private static void ValidateBounds(Rectangle bounds)
359 throw new ArgumentOutOfRangeException(
362 "Dialog bounds must have positive width and enough height for the title bar.");
366 private static Vector2 GetCloseButtonOffset(Size size)
371 private static DirectRectangle CreatePanel(RenderSurfaceHostBase host,
381 private static DirectRectangle CreatePanel(RenderSurfaceHostBase host,
391 private static DirectRectangle ConfigurePanel(DirectRectangle panel)
398 panel.ZOrder = 10_000;
403 private static DirectRectangle CreateTitleBar(RenderSurfaceHostBase host,
410 GetTitleBarBounds(bounds)));
413 private static DirectRectangle CreateTitleBar(RenderSurfaceHostBase host,
420 GetTitleBarBounds(bounds)));
423 private static DirectRectangle ConfigureTitleBar(DirectRectangle titleBar)
428 titleBar.ZOrder = 10_001;
433 private static TextBlock CreateTitleText(RenderSurfaceHostBase host,
438 return ConfigureTitleText(
new TextBlock(host, view, GetTitleTextBounds(bounds)), title);
441 private static TextBlock CreateTitleText(RenderSurfaceHostBase host,
446 return ConfigureTitleText(
new TextBlock(host, layer, view:
null, worldBounds: GetTitleTextBounds(bounds)), title);
449 private static TextBlock ConfigureTitleText(TextBlock titleText,
string title)
452 .
SetFont(SKTypeface.Default, 18f, minSize: 12f)
453 .
SetColors(SKColors.White, SKColors.Transparent)
454 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
457 titleText.HorizontalPadding = 12f;
458 titleText.ZOrder = 10_002;
463 private static ButtonWidget CreateCloseButton(RenderSurfaceHostBase host,
467 return ConfigureCloseButton(
new ButtonWidget(host, view, GetCloseButtonBounds(bounds),
"×"));
470 private static ButtonWidget CreateCloseButton(RenderSurfaceHostBase host,
474 return ConfigureCloseButton(
new ButtonWidget(host, layer, GetCloseButtonBounds(bounds),
"×"));
477 private static ButtonWidget ConfigureCloseButton(ButtonWidget closeButton)
480 Color.FromArgb(255, 110, 55, 62),
481 Color.FromArgb(255, 145, 45, 55))
488 private static Rectangle GetTitleBarBounds(Rectangle bounds)
493 private static Rectangle GetTitleTextBounds(
499 private static Rectangle GetCloseButtonBounds(
505 #endregion private methods
SceneLayer? SceneLayer
Gets the scene layer shared by all children in scene-layer mode.
View? View
Gets the view shared by all children in view mode.
Provides the base implementation for direct drawing objects that can be rendered to the backbuffer wi...
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.
A retained-mode text drawable with wrapping, multi-line ( ) support, horizontal/vertical alignment,...
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 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,...
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Viewport Viewport
Gets the viewport that defines the screen-space rectangle, zoom level, and other rendering parameters...
float Zoom
Zoom factor applied to the world when rendering this view. Values greater than 1 zoom in,...
Defines a movable direct drawable that may be owned by a DirectComposite.
Defines a container that can hold and manage a collection of direct composite children.
IReadOnlyCollection< IDirectCompositeChild > Children
Gets the read-only collection of child elements in this container.
@ 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.