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
TabPageWidget.cs
1using System.Drawing;
2using System.Numerics;
5using SkiaSharp;
6
8
17public sealed class TabPageWidget : ContainerWidget
18{
19 private int _pageZOrder;
20 private string _title;
21
31 internal TabPageWidget(
32 RenderSurfaceHostBase renderSurfaceHost,
34 Rectangle contentBounds,
35 string title,
36 char? mnemonic,
37 string? nickname)
38 : base(
39 renderSurfaceHost,
41 ValidateBounds(contentBounds).Location,
42 nickname)
43 {
44 ArgumentNullException.ThrowIfNull(view);
45
46 _title = ValidateTitle(title);
47 Mnemonic = mnemonic;
48
50 DefaultBackgroundColor,
51 renderSurfaceHost,
52 view,
53 contentBounds,
54 $"{Nickname}.background")
55 .SetFilled(true)
56 .SetBorderColor(DefaultBorderColor)
57 .SetStrokeWidth(1f);
58
60
61 DisablePageInput();
62 }
63
73 internal TabPageWidget(
74 RenderSurfaceHostBase renderSurfaceHost,
75 Gondwana.Scenes.SceneLayer sceneLayer,
76 Rectangle contentBounds,
77 string title,
78 char? mnemonic,
79 string? nickname)
80 : base(
81 renderSurfaceHost,
82 DirectDrawingMode.SceneLayer,
83 ValidateBounds(contentBounds).Location,
84 nickname)
85 {
86 ArgumentNullException.ThrowIfNull(sceneLayer);
87
88 _title = ValidateTitle(title);
89 Mnemonic = mnemonic;
90
92 DefaultBackgroundColor,
93 renderSurfaceHost,
94 sceneLayer,
95 contentBounds,
96 $"{Nickname}.background")
97 .SetFilled(true)
98 .SetBorderColor(DefaultBorderColor)
99 .SetStrokeWidth(1f);
100
102
103 DisablePageInput();
104 }
105
110
114 public string Title => _title;
115
119 public char? Mnemonic { get; }
120
125 ? Background.ScreenBounds
126 : Background.WorldBounds;
127
131 public Rectangle HeaderBounds { get; internal set; }
132
139 public TabPageWidget AddWidget(
140 WidgetBase widget,
141 Point? offsetPx = null)
142 {
143 ArgumentNullException.ThrowIfNull(widget);
144
145 Point offset = offsetPx ?? Point.Empty;
146
147 Add(
148 widget,
149 keepCurrentOffset: false,
150 explicitLocalOffsetPx: new Vector2(offset.X, offset.Y));
151
152 SetWidgetZOrder(widget, _pageZOrder + 1);
153
154 return this;
155 }
156
163 public TabPageWidget RemoveWidget(
164 WidgetBase widget,
165 bool dispose = false)
166 {
167 RemoveChild(widget, dispose);
168 return this;
169 }
170
176 public TabPageWidget SetTitle(string title)
177 {
178 string validatedTitle = ValidateTitle(title);
179
180 if (string.Equals(_title, validatedTitle, StringComparison.Ordinal))
181 return this;
182
183 _title = validatedTitle;
184 TitleChanged?.Invoke(this);
185 return this;
186 }
187
193 public TabPageWidget SetBackgroundColor(Color color)
194 {
195 Background.SetColor(color);
196 RefreshBackground();
197 return this;
198 }
199
205 public TabPageWidget SetBorderColor(Color color)
206 {
207 Background.SetBorderColor(color);
208 RefreshBackground();
209 return this;
210 }
211
217 public TabPageWidget SetStrokeWidth(float width)
218 {
219 if (width < 0f)
220 throw new ArgumentOutOfRangeException(nameof(width), "The page border width cannot be negative.");
221
222 Background.SetStrokeWidth(width);
223 RefreshBackground();
224 return this;
225 }
226
232 public TabPageWidget SetCornerRadius(float radius)
233 {
234 if (radius < 0f)
235 throw new ArgumentOutOfRangeException(nameof(radius), "The page corner radius cannot be negative.");
236
237 Background.SetCornerRadius(radius);
238 RefreshBackground();
239 return this;
240 }
241
251 public TabPageWidget SetBackgroundImage(
252 SKBitmap bitmap,
254 float scale = 1f,
255 SKPoint? offsetPx = null,
256 SKFilterQuality filterQuality = SKFilterQuality.Medium)
257 {
258 Background.SetFillImage(
259 bitmap,
260 mode,
261 scale,
262 offsetPx,
263 filterQuality);
264
265 return this;
266 }
267
277 public TabPageWidget SetBackgroundImage(
278 SKImage image,
280 float scale = 1f,
281 SKPoint? offsetPx = null,
282 SKFilterQuality filterQuality = SKFilterQuality.Medium)
283 {
284 Background.SetFillImage(
285 image,
286 mode,
287 scale,
288 offsetPx,
289 filterQuality);
290
291 return this;
292 }
293
298 public TabPageWidget ClearBackgroundImage()
299 {
300 Background.ClearFillImage();
301 return this;
302 }
303
307 internal event Action<TabPageWidget>? TitleChanged;
308
313 internal void SetContentBounds(Rectangle bounds)
314 {
315 ValidateBounds(bounds);
316
317 if (Mode == DirectDrawingMode.View)
318 Background.ScreenBounds = new Rectangle(Background.ScreenBounds.Location, bounds.Size);
319 else
320 Background.WorldBounds = new Rectangle(Background.WorldBounds.Location, bounds.Size);
321 }
322
327 internal void SetPageZOrder(int zOrder)
328 {
329 _pageZOrder = zOrder;
330 Background.ZOrder = zOrder;
331
332 foreach (WidgetBase widget in ChildWidgets)
333 SetWidgetZOrder(widget, zOrder + 1);
334 }
335
336 private const int DefaultBackgroundAlpha = 235;
337
338 private static readonly Color DefaultBackgroundColor = Color.FromArgb(
339 DefaultBackgroundAlpha,
340 25,
341 28,
342 36);
343
344 private static readonly Color DefaultBorderColor = Color.FromArgb(
345 255,
346 110,
347 120,
348 140);
349
350 private void DisablePageInput()
351 {
352 IsInputEnabled = false;
353 IsPointerInputEnabled = false;
355 CanReceiveFocus = false;
356 }
357
358 private void RefreshBackground()
359 {
361 }
362
363 private static Rectangle ValidateBounds(Rectangle bounds)
364 {
365 if (bounds.Width <= 0 || bounds.Height <= 0)
366 {
367 throw new ArgumentOutOfRangeException(
368 nameof(bounds),
369 bounds,
370 "Tab-page bounds must have positive width and height.");
371 }
372
373 return bounds;
374 }
375
376 private static string ValidateTitle(string title)
377 {
378 ArgumentException.ThrowIfNullOrWhiteSpace(title);
379 return title;
380 }
381
382 private static void SetWidgetZOrder(
383 WidgetBase widget,
384 int zOrder)
385 {
386 DirectDrawingBase[] visuals = EnumerateVisuals(widget).ToArray();
387
388 if (visuals.Length == 0)
389 return;
390
391 int currentMinimum = visuals.Min(static visual => visual.ZOrder);
392 int delta = zOrder - currentMinimum;
393
394 foreach (DirectDrawingBase visual in visuals)
395 visual.ZOrder += delta;
396 }
397
398 private static IEnumerable<DirectDrawingBase> EnumerateVisuals(IDirectCompositeContainer container)
399 {
400 foreach (IDirectCompositeChild child in container.Children)
401 {
402 if (child is DirectDrawingBase drawing)
403 yield return drawing;
404
405 if (child is IDirectCompositeContainer nestedContainer)
406 {
407 foreach (DirectDrawingBase nestedDrawing in EnumerateVisuals(nestedContainer))
408 yield return nestedDrawing;
409 }
410 }
411 }
412}
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
Rectangle WorldBounds
Gets or sets the world-space bounds of this direct drawing in pixels.
Rectangle ScreenBounds
Gets or sets the screen-space bounds of this direct drawing in pixels.
Vector2 GetPosition()
Gets the current position of this direct drawing in pixel coordinates.
void SetPosition(Vector2 p)
Sets the position of this direct drawing to the specified pixel coordinates.
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.
ImageFillMode
Defines how an image fills the rectangle interior.
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
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
Definition SceneLayer.cs:40
bool RemoveChild(WidgetBase widget, bool dispose=false)
Removes a child widget from the container.
override DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.The current composite.
ContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the ContainerWidget class.
IReadOnlyList< WidgetBase > ChildWidgets
Gets a snapshot of the child widgets directly owned by this container.
Rectangle ContentBounds
Gets the page's content bounds in its native coordinate space.
TabPageWidget SetStrokeWidth(float width)
Sets the page border width.
TabPageWidget AddWidget(WidgetBase widget, Point? offsetPx=null)
Adds a widget at an offset from the page content area's upper-left corner.
TabPageWidget SetCornerRadius(float radius)
Sets the page corner radius.
Rectangle HeaderBounds
Gets the bounds occupied by this page's tab header in its native coordinate space.
TabPageWidget SetBackgroundImage(SKBitmap bitmap, DirectRectangle.ImageFillMode mode=DirectRectangle.ImageFillMode.Stretch, float scale=1f, SKPoint? offsetPx=null, SKFilterQuality filterQuality=SKFilterQuality.Medium)
Uses a bitmap as the page background.
DirectRectangle Background
Gets the direct rectangle used for this page's content background.
TabPageWidget SetBackgroundColor(Color color)
Sets the page background fill color.
TabPageWidget SetBackgroundImage(SKImage image, DirectRectangle.ImageFillMode mode=DirectRectangle.ImageFillMode.Stretch, float scale=1f, SKPoint? offsetPx=null, SKFilterQuality filterQuality=SKFilterQuality.Medium)
Uses an image as the page background.
TabPageWidget ClearBackgroundImage()
Removes an image background and restores the configured color fill.
char? Mnemonic
Gets the optional Alt-key mnemonic that selects this page.
TabPageWidget RemoveWidget(WidgetBase widget, bool dispose=false)
Removes a child widget from the page.
TabPageWidget SetTitle(string title)
Changes the title displayed by the owning tab control.
string Title
Gets the title displayed by the page's tab header.
TabPageWidget SetBorderColor(Color color)
Sets the page border color.
Provides the base implementation for widgets that can be drawn and receive pointer,...
Definition WidgetBase.cs:12
bool CanReceiveFocus
Gets or sets a value indicating whether the widget can receive keyboard focus.
bool IsPointerInputEnabled
Gets or sets a value indicating whether the widget can receive pointer input.
WidgetBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the WidgetBase class.
Definition WidgetBase.cs:95
bool IsKeyboardInputEnabled
Gets or sets a value indicating whether the widget can receive keyboard input.
bool IsInputEnabled
Gets or sets a value indicating whether the widget can participate in input routing.
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.
@ View
Performs direct drawing at the view level using screen-space coordinates.