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
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(
40 RenderSurfaceHostBase renderSurfaceHost,
42 PointF anchor = default,
43 string? nickname = null)
44 : base(
45 renderSurfaceHost,
46 mode,
47 anchor,
48 nickname)
49 {
50 }
51
52 #endregion constructors
53
54 #region public properties
55
59 public IReadOnlyList<WidgetBase> ChildWidgets => Children.OfType<WidgetBase>().ToArray();
60
61 #endregion public properties
62
63 #region public methods
64
66 public override DirectComposite Add(
68 bool keepCurrentOffset = true,
69 Vector2? explicitLocalOffsetPx = null)
70 {
71 ArgumentNullException.ThrowIfNull(child);
72
73 bool alreadyAdded =
74 Children.Contains(child);
75
76 base.Add(
77 child,
78 keepCurrentOffset,
79 explicitLocalOffsetPx);
80
81 if (!alreadyAdded &&
82 _isShown &&
83 child is WidgetBase widget)
84 {
85 widget.Show();
86 }
87
88 return this;
89 }
90
92 public override DirectComposite Remove(
94 {
95 ArgumentNullException.ThrowIfNull(child);
96
97 if (_isShown &&
98 child is WidgetBase widget &&
99 Children.Contains(child))
100 {
101 widget.Hide();
102 }
103
104 return base.Remove(child);
105 }
106
108 public override DirectComposite Clear()
109 {
110 if (_isShown)
111 {
112 foreach (WidgetBase child in GetChildWidgetSnapshot())
113 child.Hide();
114 }
115
116 return base.Clear();
117 }
118
119 #endregion public methods
120
121 #region protected methods
122
136 protected TWidget Add<TWidget>(
137 TWidget widget,
138 Vector2 localOffsetPx)
139 where TWidget : WidgetBase
140 {
141 ArgumentNullException.ThrowIfNull(widget);
142
143 Add(
144 (IDirectCompositeChild)widget,
145 keepCurrentOffset: false,
146 explicitLocalOffsetPx: localOffsetPx);
147
148 return widget;
149 }
150
165 protected bool RemoveChild(
166 WidgetBase widget,
167 bool dispose = false)
168 {
169 ArgumentNullException.ThrowIfNull(widget);
170
171 if (!Children.Contains(widget))
172 return false;
173
174 Remove(widget);
175
176 if (dispose)
177 widget.Dispose();
178
179 return true;
180 }
181
183 protected override void OnChildAdded(
185 {
186 base.OnChildAdded(child);
187
188 if (child is WidgetBase widget)
189 widget.KeyboardInput += OnChildKeyboardInput;
190 }
191
193 protected override void OnChildRemoved(
195 {
196 if (child is WidgetBase widget)
197 widget.KeyboardInput -= OnChildKeyboardInput;
198
199 base.OnChildRemoved(child);
200 }
201
203 protected override void ProcessShown()
204 {
205 base.ProcessShown();
206
207 _isShown = true;
208
209 foreach (WidgetBase child in GetChildWidgetSnapshot())
210 child.Show();
211 }
212
214 protected override void ProcessHidden()
215 {
216 foreach (WidgetBase child in GetChildWidgetSnapshot())
217 child.Hide();
218
219 _isShown = false;
220
221 base.ProcessHidden();
222 }
223
225 protected override void ProcessActivated()
226 {
227 base.ProcessActivated();
228
229 // Children are activated after their parent so they appear later in
230 // the router's hit-test order.
231 foreach (WidgetBase child in GetChildWidgetSnapshot())
232 child.Activate();
233 }
234
236 protected override void ProcessCancelled()
237 {
238 foreach (WidgetBase child in GetChildWidgetSnapshot())
239 child.Cancel();
240
241 base.ProcessCancelled();
242 }
243
244 #endregion protected methods
245
246 #region private methods
247
248 private void OnChildKeyboardInput(
250 {
251 if (args.Handled)
252 return;
253
254 var parentArgs = new WidgetKeyboardEventArgs(
255 this,
256 args.Key,
257 args.KeyAction,
258 args.Modifiers,
259 args.Tick);
260
261 DispatchKeyboardInput(parentArgs);
262
263 args.Handled = parentArgs.Handled;
264 }
265
266 private WidgetBase[] GetChildWidgetSnapshot()
267 {
268 return Children
269 .OfType<WidgetBase>()
270 .ToArray();
271 }
272
273 #endregion private methods
274}
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.