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
ContainerWidget.cs
1using System.Drawing;
2using System.Numerics;
5
7
18public abstract class ContainerWidget : WidgetBase
19{
20 private bool _isShown;
21
22 #region constructors
23
39 protected ContainerWidget(RenderSurfaceHostBase renderSurfaceHost,
41 PointF anchor = default,
42 string? nickname = null)
43 : base(renderSurfaceHost, mode, anchor, nickname)
44 {
45 }
46
47 #endregion constructors
48
49 #region public properties
50
54 public IReadOnlyList<WidgetBase> ChildWidgets => Children.OfType<WidgetBase>().ToArray();
55
56 #endregion public properties
57
58 #region public methods
59
62 bool keepCurrentOffset = true,
63 Vector2? explicitLocalOffsetPx = null)
64 {
65 ArgumentNullException.ThrowIfNull(child);
66
67 bool alreadyAdded =
68 Children.Contains(child);
69
70 base.Add(
71 child,
72 keepCurrentOffset,
73 explicitLocalOffsetPx);
74
75 if (!alreadyAdded &&
76 _isShown &&
77 child is WidgetBase widget)
78 {
79 widget.Show();
80 }
81
82 return this;
83 }
84
86 public override DirectComposite Remove(
88 {
89 ArgumentNullException.ThrowIfNull(child);
90
91 if (_isShown &&
92 child is WidgetBase widget &&
93 Children.Contains(child))
94 {
95 widget.Hide();
96 }
97
98 return base.Remove(child);
99 }
100
102 public override DirectComposite Clear()
103 {
104 if (_isShown)
105 {
106 foreach (WidgetBase child in GetChildWidgetSnapshot())
107 child.Hide();
108 }
109
110 return base.Clear();
111 }
112
113 #endregion public methods
114
115 #region protected methods
116
130 protected TWidget Add<TWidget>(
131 TWidget widget,
132 Vector2 localOffsetPx)
133 where TWidget : WidgetBase
134 {
135 ArgumentNullException.ThrowIfNull(widget);
136
137 Add(
138 (IDirectCompositeChild)widget,
139 keepCurrentOffset: false,
140 explicitLocalOffsetPx: localOffsetPx);
141
142 return widget;
143 }
144
159 protected bool RemoveChild(
160 WidgetBase widget,
161 bool dispose = false)
162 {
163 ArgumentNullException.ThrowIfNull(widget);
164
165 if (!Children.Contains(widget))
166 return false;
167
168 Remove(widget);
169
170 if (dispose)
171 widget.Dispose();
172
173 return true;
174 }
175
177 protected override void OnChildAdded(
179 {
180 base.OnChildAdded(child);
181
182 if (child is WidgetBase widget)
183 widget.KeyboardInput += OnChildKeyboardInput;
184 }
185
187 protected override void OnChildRemoved(
189 {
190 if (child is WidgetBase widget)
191 widget.KeyboardInput -= OnChildKeyboardInput;
192
193 base.OnChildRemoved(child);
194 }
195
197 protected override void ProcessShown()
198 {
199 base.ProcessShown();
200
201 _isShown = true;
202
203 foreach (WidgetBase child in GetChildWidgetSnapshot())
204 child.Show();
205 }
206
208 protected override void ProcessHidden()
209 {
210 foreach (WidgetBase child in GetChildWidgetSnapshot())
211 child.Hide();
212
213 _isShown = false;
214
215 base.ProcessHidden();
216 }
217
219 protected override void ProcessActivated()
220 {
221 base.ProcessActivated();
222
223 // Children are activated after their parent so they appear later in
224 // the router's hit-test order.
225 foreach (WidgetBase child in GetChildWidgetSnapshot())
226 child.Activate();
227 }
228
230 protected override void ProcessCancelled()
231 {
232 foreach (WidgetBase child in GetChildWidgetSnapshot())
233 child.Cancel();
234
235 base.ProcessCancelled();
236 }
237
238 #endregion protected methods
239
240 #region private methods
241
242 private void OnChildKeyboardInput(
244 {
245 if (args.Handled)
246 return;
247
248 var parentArgs = new WidgetKeyboardEventArgs(
249 this,
250 args.Key,
251 args.KeyAction,
252 args.Modifiers,
253 args.Tick);
254
255 DispatchKeyboardInput(parentArgs);
256
257 args.Handled = parentArgs.Handled;
258 }
259
260 private WidgetBase[] GetChildWidgetSnapshot()
261 {
262 return Children
263 .OfType<WidgetBase>()
264 .ToArray();
265 }
266
267 #endregion private methods
268}
virtual DirectComposite Remove(IDirectCompositeChild child)
Removes a child without disposing it.
ReadOnlyCollection< IDirectCompositeChild > Children
Gets the children owned by the composite.
virtual DirectComposite Clear()
Removes every child without disposing them.
virtual void Dispose()
Disposes the composite and every child it owns.
DirectComposite(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the DirectComposite class.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
override DirectComposite Clear()
Removes every child without disposing them.The current composite.
bool RemoveChild(WidgetBase widget, bool dispose=false)
Removes a child widget from the container.
override DirectComposite Remove(IDirectCompositeChild child)
Removes a child without disposing it.The current composite.
TWidget Add< TWidget >(TWidget widget, Vector2 localOffsetPx)
Adds a child widget at a local offset from this container's anchor.
override void OnChildRemoved(IDirectCompositeChild child)
Called after a child has been removed from the composite.
override DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.The current composite.
override void ProcessShown()
Performs processing when the widget is shown before notification callbacks are invoked.
override void ProcessActivated()
Performs processing when the widget is activated before notification callbacks are invoked.
override void ProcessHidden()
Performs processing when the widget is hidden before notification callbacks are invoked.
ContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the ContainerWidget class.
override void OnChildAdded(IDirectCompositeChild child)
Called after a child has been successfully added.Overrides should perform only non-throwing bookkeepi...
IReadOnlyList< WidgetBase > ChildWidgets
Gets a snapshot of the child widgets directly owned by this container.
override void ProcessCancelled()
Performs processing when the widget is cancelled before notification callbacks are invoked.
virtual void ProcessCancelled()
Performs processing when the widget is cancelled before notification callbacks are invoked.
WidgetBase Show()
Shows the widget and registers it for input routing.
WidgetBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the WidgetBase class.
Definition WidgetBase.cs:95
WidgetBase Activate()
Activates the widget and brings it to the front of the input order.
WidgetBase Hide()
Hides the widget and releases any routed input state.
WidgetBase Cancel()
Cancels the widget.
virtual void ProcessHidden()
Performs processing when the widget is hidden before notification callbacks are invoked.
bool Handled
Gets or sets whether this widget interaction was handled.
long Tick
Gets the engine or timer tick associated with the callback.
Provides data for widget keyboard input events routed by WidgetInputRouter.
KeyboardModifierState Modifiers
Gets the keyboard modifier state at the time of the event.
int Key
Gets the integer key identifier.
KeyAction KeyAction
Gets the action associated with this key event.
Defines a movable direct drawable that may be owned by a DirectComposite.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.