Gondwana Game Engine Development (master) - 2.6.1
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(RenderSurfaceHostBase renderSurfaceHost,
47 View view,
48 string applicationName,
49 string version,
50 string? description = null,
51 string? copyright = null,
52 SKImage? logo = null,
53 Rectangle? bounds = null,
54 string? nickname = null,
55 IExternalUriLauncher? uriLauncher = null,
56 Uri? hyperlinkUri = null,
57 string? hyperlinkText = null)
58 : base(renderSurfaceHost,
59 view,
60 ResolveBounds(view, bounds),
61 $"About {applicationName}",
62 showCloseButton: true,
63 nickname: nickname ?? "__gondwana_about__")
64 {
65 ApplicationName = applicationName;
66 Version = version;
67 Description = description;
68 Copyright = copyright;
69
70 bool hasHyperlinkConfiguration = uriLauncher is not null ||
71 hyperlinkUri is not null ||
72 hyperlinkText is not null;
73
74 if (hasHyperlinkConfiguration)
75 {
76 if (uriLauncher is null)
77 {
78 throw new ArgumentNullException(nameof(uriLauncher), "A URI launcher is required when configuring the hyperlink.");
79 }
80
81 if (hyperlinkUri is null)
82 {
83 throw new ArgumentNullException(nameof(hyperlinkUri), "A hyperlink URI is required when configuring the hyperlink.");
84 }
85
86 if (!hyperlinkUri.IsAbsoluteUri)
87 {
88 throw new ArgumentException("The hyperlink URI must be absolute.", nameof(hyperlinkUri));
89 }
90 }
91
92 Rectangle resolvedBounds = ResolveBounds(view, bounds);
93
94 int contentTop = resolvedBounds.Top + 52;
95 int contentLeft = resolvedBounds.Left + 24;
96
97 int contentRightPadding = 24;
98
99 if (logo is not null)
100 {
101 var logoScreenBounds = new Rectangle(contentLeft, contentTop, 112, 112);
102 Logo = new DirectImage(logo,
103 renderSurfaceHost,
104 view,
105 logoScreenBounds,
106 $"{Nickname}.logo").SetScaleMode(DirectImage.ScaleMode.Fit);
107
108 Logo.ZOrder = 10_002;
109 Add(Logo);
110
111 contentLeft += 132;
112 }
113
114 var headerTextScreenBounds = new Rectangle(contentLeft, contentTop, resolvedBounds.Right - contentRightPadding - contentLeft, 44);
115 HeaderText = new TextBlock(renderSurfaceHost,
116 view,
117 headerTextScreenBounds,
118 $"{Nickname}.header").SetText(applicationName)
119 .SetFont(SKTypeface.Default, 26f, minSize: 16f)
120 .SetColors(SKColors.White, SKColors.Transparent)
121 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
122 .EnableWrapping(false);
123
124 HeaderText.ZOrder = 10_002;
126
127 var versionTextScreenBounds = new Rectangle(contentLeft, contentTop + 44, resolvedBounds.Right - contentRightPadding - contentLeft, 30);
128 VersionText = new TextBlock(renderSurfaceHost,
129 view,
130 versionTextScreenBounds,
131 $"{Nickname}.version").SetText($"Version {version}")
132 .SetFont(SKTypeface.Default, 15f, minSize: 11f)
133 .SetColors(new SKColor(205, 205, 215), SKColors.Transparent)
134 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
135 .EnableWrapping(false);
136
137 VersionText.ZOrder = 10_002;
139
140 if (uriLauncher is not null && hyperlinkUri is not null)
141 {
142 Rectangle hyperlinkBounds = new(contentLeft,
143 contentTop + 74,
144 resolvedBounds.Right - contentRightPadding - contentLeft,
145 28);
146
147 Hyperlink = new HyperlinkWidget(uriLauncher,
148 renderSurfaceHost,
149 view,
150 hyperlinkBounds,
151 hyperlinkText ?? hyperlinkUri.ToString(),
152 hyperlinkUri,
153 $"{Nickname}.hyperlink");
154
155 Hyperlink.Label.ZOrder = 10_002;
156 Add(Hyperlink, new Vector2(hyperlinkBounds.Left - resolvedBounds.Left,
157 hyperlinkBounds.Top - resolvedBounds.Top));
158 }
159
160 var detailsTextScreenBounds = new Rectangle(resolvedBounds.Left + 24, contentTop + 126, resolvedBounds.Width - 48, resolvedBounds.Height - 222);
161 string detailText = string.Join(Environment.NewLine + Environment.NewLine,
162 new[] { description, copyright }
163 .Where(static value => !string.IsNullOrWhiteSpace(value)));
164
165 DetailsText = new TextBlock(renderSurfaceHost,
166 view,
167 detailsTextScreenBounds,
168 $"{Nickname}.details").SetText(detailText)
169 .SetFont(SKTypeface.Default, 14f, minSize: 10f)
170 .SetColors(new SKColor(225, 225, 232), SKColors.Transparent)
171 .SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Top)
172 .EnableWrapping(true);
173
174 DetailsText.ZOrder = 10_002;
176
177 Rectangle okBounds = new(resolvedBounds.Right - 116, resolvedBounds.Bottom - 54, 92, 34);
178 OkButton = new ButtonWidget(renderSurfaceHost, view, okBounds, "OK", $"{Nickname}.ok");
179
180 Add(OkButton, new Vector2(resolvedBounds.Width - 116, resolvedBounds.Height - 54));
181
182 OkButton.SetButtonZOrder(10_003);
183 OkButton.Clicked += OnOkClicked;
184 }
185
186 #endregion constructors
187
188 #region public properties
189
193 public string ApplicationName { get; }
194
198 public string Version { get; }
199
203 public string? Description { get; }
204
208 public string? Copyright { get; }
209
213 public DirectImage? Logo { get; }
214
218 public TextBlock HeaderText { get; }
219
223 public TextBlock VersionText { get; }
224
228 public TextBlock DetailsText { get; }
229
233 public ButtonWidget OkButton { get; }
234
238 public HyperlinkWidget? Hyperlink { get; }
239
240 #endregion public properties
241
242 #region exposed methods
243
245 protected override void OnAcceptRequested()
246 {
248 }
249
251 public override void Dispose()
252 {
253 if (_disposed)
254 return;
255
256 _disposed = true;
257 OkButton.Clicked -= OnOkClicked;
258
259 base.Dispose();
260 }
261
262 #endregion exposed methods
263
264 #region private methods
265
266 private void OnOkClicked()
267 {
269 }
270
271 private static Rectangle ResolveBounds(View view, Rectangle? bounds)
272 {
273 ArgumentNullException.ThrowIfNull(view);
274
275 if (bounds is not null)
276 return bounds.Value;
277
278 Rectangle viewport = view.Viewport.TargetRectPx;
279
280 int availableWidth = Math.Max(1, viewport.Width - 40);
281 int availableHeight = Math.Max(1, viewport.Height - 40);
282 int width = Math.Min(DefaultWidth, availableWidth);
283 int height = Math.Min(DefaultHeight, availableHeight);
284
285 return new Rectangle(viewport.Left + (viewport.Width - width) / 2,
286 viewport.Top + (viewport.Height - height) / 2,
287 width,
288 height);
289 }
290
291 #endregion private methods
292}
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:394
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
Definition TextBlock.cs:503
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:433
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:410
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Definition TextBlock.cs:358
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:35
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:245
HyperlinkWidget? Hyperlink
Gets the optional external hyperlink displayed by the dialog.
Definition AboutBox.cs:238
TextBlock VersionText
Gets the version text block.
Definition AboutBox.cs:223
string Version
Gets the version text.
Definition AboutBox.cs:198
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:251
string? Description
Gets the optional description.
Definition AboutBox.cs:203
TextBlock DetailsText
Gets the detail text block.
Definition AboutBox.cs:228
string ApplicationName
Gets the application name.
Definition AboutBox.cs:193
DirectImage? Logo
Gets the optional logo drawing.
Definition AboutBox.cs:213
string? Copyright
Gets the optional copyright text.
Definition AboutBox.cs:208
ButtonWidget OkButton
Gets the OK button.
Definition AboutBox.cs:233
TextBlock HeaderText
Gets the application-name text block.
Definition AboutBox.cs:218
DialogBox(RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle bounds, string title, bool showCloseButton=true, string? nickname=null)
Initializes a view-level dialog.
Definition DialogBox.cs:65
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.