56 private const int DialogZOrderStart = 100_000;
57 private const int DialogZOrderGap = 100;
59 private static readonly
object _zOrderSyncRoot =
new();
60 private static int _nextDialogZOrder = DialogZOrderStart;
62 private bool _disposed;
67 public event Action<DialogResult>?
Closed;
85 bool showCloseButton =
true,
86 string? nickname =
null)
93 ValidateBounds(bounds);
97 Panel = CreatePanel(renderSurfaceHost, view, bounds);
98 TitleBar = CreateTitleBar(renderSurfaceHost, view, bounds);
112 CloseButton = CreateCloseButton(renderSurfaceHost, view, bounds);
115 CloseButton.Clicked += OnCloseButtonClicked;
118 CompleteInitialization();
135 bool showCloseButton =
true,
136 string? nickname =
null)
143 ValidateBounds(bounds);
147 Panel = CreatePanel(renderSurfaceHost, sceneLayer, bounds);
148 TitleBar = CreateTitleBar(renderSurfaceHost, sceneLayer, bounds);
162 CloseButton = CreateCloseButton(renderSurfaceHost, sceneLayer, bounds);
165 CloseButton.Clicked += OnCloseButtonClicked;
168 CompleteInitialization();
171 #endregion constructors
173 #region public properties
231 #endregion public properties
233 #region exposed methods and hooks
275 BringVisualTreeToFront();
276 base.ProcessActivated();
279 private void BringVisualTreeToFront()
283 if (visuals.Length == 0)
286 int minimumZOrder = visuals.Min(
static visual => visual.ZOrder);
287 int maximumZOrder = visuals.Max(
static visual => visual.ZOrder);
288 int span = maximumZOrder - minimumZOrder;
292 lock (_zOrderSyncRoot)
294 targetMinimum = _nextDialogZOrder;
295 _nextDialogZOrder = checked(targetMinimum + span + DialogZOrderGap);
298 int delta = targetMinimum - minimumZOrder;
301 visual.ZOrder += delta;
315 yield
return descendant;
322 if (!base.CanStartDrag(args))
325 RectangleF titleBarBounds =
TitleBar.GetDrawLocationScreen(args.
View);
327 titleBarBounds.Offset(
337 base.OnKeyboardInput(args);
373 CloseButton.Clicked -= OnCloseButtonClicked;
377 GC.SuppressFinalize(
this);
380 #endregion exposed methods and hooks
382 #region private methods
384 private void CompleteInitialization()
391 private void OnCloseButtonClicked()
396 private static void ValidateBounds(Rectangle bounds)
400 throw new ArgumentOutOfRangeException(
403 "Dialog bounds must have positive width and enough height for the title bar.");
407 private static Vector2 GetCloseButtonOffset(Size size)
412 private static DirectRectangle CreatePanel(
413 RenderSurfaceHostBase host,
417 return ConfigurePanel(
425 private static DirectRectangle CreatePanel(
426 RenderSurfaceHostBase host,
430 return ConfigurePanel(
438 private static DirectRectangle ConfigurePanel(DirectRectangle panel)
445 panel.ZOrder = 10_000;
450 private static DirectRectangle CreateTitleBar(
451 RenderSurfaceHostBase host,
455 return ConfigureTitleBar(
460 GetTitleBarBounds(bounds)));
463 private static DirectRectangle CreateTitleBar(
464 RenderSurfaceHostBase host,
468 return ConfigureTitleBar(
473 GetTitleBarBounds(bounds)));
476 private static DirectRectangle ConfigureTitleBar(DirectRectangle titleBar)
481 titleBar.ZOrder = 10_001;
486 private static TextBlock CreateTitleText(
487 RenderSurfaceHostBase host,
492 return ConfigureTitleText(
new TextBlock(host, view, GetTitleTextBounds(bounds)), title);
495 private static TextBlock CreateTitleText(
496 RenderSurfaceHostBase host,
501 return ConfigureTitleText(
506 worldBounds: GetTitleTextBounds(bounds)),
510 private static TextBlock ConfigureTitleText(TextBlock titleText,
string title)
513 .
SetFont(SKTypeface.Default, 18f, minSize: 12f)
514 .
SetColors(SKColors.White, SKColors.Transparent)
515 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
518 titleText.HorizontalPadding = 12f;
519 titleText.ZOrder = 10_002;
524 private static ButtonWidget CreateCloseButton(
525 RenderSurfaceHostBase host,
529 return ConfigureCloseButton(
533 GetCloseButtonBounds(bounds),
537 private static ButtonWidget CreateCloseButton(
538 RenderSurfaceHostBase host,
542 return ConfigureCloseButton(
546 GetCloseButtonBounds(bounds),
550 private static ButtonWidget ConfigureCloseButton(ButtonWidget closeButton)
574 private static Rectangle GetTitleBarBounds(Rectangle bounds)
583 private static Rectangle GetTitleTextBounds(
593 private static Rectangle GetCloseButtonBounds(
603 #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.