Gondwana Game Engine Development (master) - 2.7.0
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
AboutBox.cs
1using System.Drawing;
2using System.Numerics;
7using SkiaSharp;
8
10
14public sealed class AboutBox : DialogBox
15{
16 private const int DefaultWidth = 520;
17 private const int DefaultHeight = 330;
18
19 private bool _disposed;
20
21 #region constructors
22
46 public AboutBox(
47 RenderSurfaceHostBase renderSurfaceHost,
48 View view,
49 string applicationName,
50 string version,
51 string? description = null,
52 string? copyright = null,
53 SKImage? logo = null,
54 Rectangle? bounds = null,
55 string? nickname = null,
56 IExternalUriLauncher? uriLauncher = null,
57 Uri? hyperlinkUri = null,
58 string? hyperlinkText = null)
59 : base(
60 renderSurfaceHost,
61 view,
62 ResolveBounds(view, bounds),
63 $"About {applicationName}",
64 showCloseButton: true,
65 nickname: nickname ?? "__gondwana_about__")
66 {
67 ApplicationName = applicationName;
68 Version = version;
69 Description = description;
70 Copyright = copyright;
71
72 bool hasHyperlinkConfiguration = uriLauncher is not null ||
73 hyperlinkUri is not null ||
74 hyperlinkText is not null;
75
76 if (hasHyperlinkConfiguration)
77 {
78 if (uriLauncher is null)
79 {
80 throw new ArgumentNullException(
81 nameof(uriLauncher),
82 "A URI launcher is required when configuring the hyperlink.");
83 }
84
85 if (hyperlinkUri is null)
86 {
87 throw new ArgumentNullException(
88 nameof(hyperlinkUri),
89 "A hyperlink URI is required when configuring the hyperlink.");
90 }
91
92 if (!hyperlinkUri.IsAbsoluteUri)
93 {
94 throw new ArgumentException("The hyperlink URI must be absolute.", nameof(hyperlinkUri));
95 }
96 }
97
98 Rectangle resolvedBounds = ResolveBounds(view, bounds);
99
100 int contentTop = resolvedBounds.Top + 52;
101 int contentLeft = resolvedBounds.Left + 24;
102
103 int contentRightPadding = 24;
104
105 if (logo is not null)
106 {
107 var logoScreenBounds = new Rectangle(
108 contentLeft,
109 contentTop,
110 112,
111 112);
112
113 Logo = new DirectImage(
114 logo,
115 renderSurfaceHost,
116 view,
117 logoScreenBounds,
118 $"{Nickname}.logo").SetScaleMode(DirectImage.ScaleMode.Fit);
119
120 Logo.ZOrder = 10_002;
121 Add(Logo);
122
123 contentLeft += 132;
124 }
125
126 var headerTextScreenBounds = new Rectangle(
127 contentLeft,
128 contentTop,
129 resolvedBounds.Right - contentRightPadding - contentLeft,
130 44);
131
132 HeaderText = new TextBlock(
133 renderSurfaceHost,
134 view,
135 headerTextScreenBounds,
136 $"{Nickname}.header").SetText(applicationName)
137 .SetFont(SKTypeface.Default, 26f, minSize: 16f)
138 .SetColors(SKColors.White, SKColors.Transparent)
139 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
140 .EnableWrapping(false);
141
142 HeaderText.ZOrder = 10_002;
144
145 var versionTextScreenBounds = new Rectangle(
146 contentLeft,
147 contentTop + 44,
148 resolvedBounds.Right - contentRightPadding - contentLeft,
149 30);
150
152 renderSurfaceHost,
153 view,
154 versionTextScreenBounds,
155 $"{Nickname}.version").SetText($"Version {version}")
156 .SetFont(SKTypeface.Default, 15f, minSize: 11f)
157 .SetColors(new SKColor(205, 205, 215), SKColors.Transparent)
158 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
159 .EnableWrapping(false);
160
161 VersionText.ZOrder = 10_002;
163
164 if (uriLauncher is not null && hyperlinkUri is not null)
165 {
166 Rectangle hyperlinkBounds = new(
167 contentLeft,
168 contentTop + 74,
169 resolvedBounds.Right - contentRightPadding - contentLeft,
170 28);
171
173 uriLauncher,
174 renderSurfaceHost,
175 view,
176 hyperlinkBounds,
177 hyperlinkText ?? hyperlinkUri.ToString(),
178 hyperlinkUri,
179 $"{Nickname}.hyperlink");
180
181 Hyperlink.Label.ZOrder = 10_002;
182
183 Add(
184 Hyperlink,
185 new Vector2(
186 hyperlinkBounds.Left - resolvedBounds.Left,
187 hyperlinkBounds.Top - resolvedBounds.Top));
188 }
189
190 var detailsTextScreenBounds = new Rectangle(
191 resolvedBounds.Left + 24,
192 contentTop + 126,
193 resolvedBounds.Width - 48,
194 resolvedBounds.Height - 222);
195
196 string detailText = string.Join(
197 Environment.NewLine + Environment.NewLine,
198 new[] { description, copyright }
199 .Where(static value => !string.IsNullOrWhiteSpace(value)));
200
202 renderSurfaceHost,
203 view,
204 detailsTextScreenBounds,
205 $"{Nickname}.details").SetText(detailText)
206 .SetFont(SKTypeface.Default, 14f, minSize: 10f)
207 .SetColors(new SKColor(225, 225, 232), SKColors.Transparent)
208 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Top)
209 .EnableWrapping(true);
210
211 DetailsText.ZOrder = 10_002;
213
214 Rectangle okBounds = new(
215 resolvedBounds.Right - 116,
216 resolvedBounds.Bottom - 54,
217 92,
218 34);
219
221 renderSurfaceHost,
222 view,
223 okBounds,
224 "OK",
225 $"{Nickname}.ok");
226
227 Add(OkButton, new Vector2(resolvedBounds.Width - 116, resolvedBounds.Height - 54));
228
229 OkButton.SetButtonZOrder(10_003);
230 OkButton.Clicked += OnOkClicked;
231 }
232
233 #endregion constructors
234
235 #region public properties
236
240 public string ApplicationName { get; }
241
245 public string Version { get; }
246
250 public string? Description { get; }
251
255 public string? Copyright { get; }
256
260 public DirectImage? Logo { get; }
261
265 public TextBlock HeaderText { get; }
266
270 public TextBlock VersionText { get; }
271
275 public TextBlock DetailsText { get; }
276
280 public ButtonWidget OkButton { get; }
281
285 public HyperlinkWidget? Hyperlink { get; }
286
287 #endregion public properties
288
289 #region exposed methods
290
292 protected override void OnAcceptRequested()
293 {
295 }
296
298 public override void Dispose()
299 {
300 if (_disposed)
301 return;
302
303 _disposed = true;
304 OkButton.Clicked -= OnOkClicked;
305
306 base.Dispose();
307 }
308
309 #endregion exposed methods
310
311 #region private methods
312
313 private void OnOkClicked()
314 {
316 }
317
318 private static Rectangle ResolveBounds(View view, Rectangle? bounds)
319 {
320 ArgumentNullException.ThrowIfNull(view);
321
322 if (bounds is not null)
323 return bounds.Value;
324
325 Rectangle viewport = view.Viewport.TargetRectPx;
326
327 int availableWidth = Math.Max(1, viewport.Width - 40);
328 int availableHeight = Math.Max(1, viewport.Height - 40);
329 int width = Math.Min(DefaultWidth, availableWidth);
330 int height = Math.Min(DefaultHeight, availableHeight);
331
332 return new Rectangle(
333 viewport.Left + (viewport.Width - width) / 2,
334 viewport.Top + (viewport.Height - height) / 2,
335 width,
336 height);
337 }
338
339 #endregion private methods
340}
View? View
Gets the view shared by all children in view mode.
Renders a bitmap or image to a rectangular region with support for scaling modes, source clipping,...
DirectImage SetScaleMode(ScaleMode mode)
Sets how the image is scaled to fit within the destination rectangle.
ScaleMode
Defines how an image is scaled to fit within the destination rectangle.
A retained-mode text drawable with wrapping, multi-line ( ) support, horizontal/vertical alignment,...
Definition TextBlock.cs:44
TextBlock SetFont(SKTypeface typeface, float size, float? minSize=null)
Sets the font face and size (and optional minimum size for auto-shrink).
Definition TextBlock.cs:414
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
Definition TextBlock.cs:527
TextBlock SetAlignment(SKTextAlign h, VerticalAlign v)
Sets the horizontal and vertical alignment used when drawing the laid-out lines within the bounds.
Definition TextBlock.cs:453
VerticalAlign
Vertical alignment options for multi-line text within the control's bounds.
Definition TextBlock.cs:49
TextBlock SetColors(SKColor fg, SKColor bg)
Sets the foreground (text) and background colors using Skia colors.
Definition TextBlock.cs:430
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Definition TextBlock.cs:378
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Represents a rendered view of a scene, combining a camera position with a viewport configuration to c...
Definition View.cs:14
Viewport Viewport
Gets the viewport that defines the screen-space rectangle, zoom level, and other rendering parameters...
Definition View.cs:44
Rectangle TargetRectPx
Screen-space rectangle (in SCREEN / RenderSurface pixels) where this view is drawn....
Definition Viewport.cs:40
override DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.The current composite.
Represents a basic text button composed from a rectangle and text block.
Represents an interactive text link that opens an external URI.
override void OnAcceptRequested()
Called when the accept key is pressed.
Definition AboutBox.cs:292
HyperlinkWidget? Hyperlink
Gets the optional external hyperlink displayed by the dialog.
Definition AboutBox.cs:285
TextBlock VersionText
Gets the version text block.
Definition AboutBox.cs:270
string Version
Gets the version text.
Definition AboutBox.cs:245
AboutBox(RenderSurfaceHostBase renderSurfaceHost, View view, string applicationName, string version, string? description=null, string? copyright=null, SKImage? logo=null, Rectangle? bounds=null, string? nickname=null, IExternalUriLauncher? uriLauncher=null, Uri? hyperlinkUri=null, string? hyperlinkText=null)
Initializes a new instance of the AboutBox class.
Definition AboutBox.cs:46
override void Dispose()
Disposes the composite and every child it owns.
Definition AboutBox.cs:298
string? Description
Gets the optional description.
Definition AboutBox.cs:250
TextBlock DetailsText
Gets the detail text block.
Definition AboutBox.cs:275
string ApplicationName
Gets the application name.
Definition AboutBox.cs:240
DirectImage? Logo
Gets the optional logo drawing.
Definition AboutBox.cs:260
string? Copyright
Gets the optional copyright text.
Definition AboutBox.cs:255
ButtonWidget OkButton
Gets the OK button.
Definition AboutBox.cs:280
TextBlock HeaderText
Gets the application-name text block.
Definition AboutBox.cs:265
DialogBox(RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle bounds, string title, bool showCloseButton=true, string? nickname=null)
Initializes a view-level dialog.
Definition DialogBox.cs:80
Defines a platform-specific service for opening external URIs.
DialogResult
Represents the result produced when a dialog closes.
@ Close
The dialog was closed without a more specific result.