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
DraggableContainerWidget.cs
1using System.Drawing;
2using System.Numerics;
6
7namespace Gondwana.Widgets;
8
13{
14 private readonly WidgetDragBehavior _dragBehavior;
15
19 public event Action<WidgetDragEventArgs>? DragStarted;
20
24 public event Action<WidgetDragEventArgs>? Dragged;
25
29 public event Action<WidgetDragEventArgs>? DragEnded;
30
39 RenderSurfaceHostBase renderSurfaceHost,
41 PointF anchor = default,
42 string? nickname = null)
43 : base(
44 renderSurfaceHost,
45 mode,
46 anchor,
47 nickname)
48 {
49 _dragBehavior = new WidgetDragBehavior(this);
50 }
51
55 public bool IsDragEnabled
56 {
57 get => _dragBehavior.IsDragEnabled;
58 set => _dragBehavior.IsDragEnabled = value;
59 }
60
64 public bool IsDragging => _dragBehavior.IsDragging;
65
69 public float DragThresholdPx
70 {
71 get => _dragBehavior.DragThresholdPx;
72 set => _dragBehavior.DragThresholdPx = value;
73 }
74
76 protected sealed override void ProcessHidden()
77 {
78 base.ProcessHidden();
79
80 _dragBehavior.ResetPointerState(clearClickSuppression: true);
81 }
82
84 protected sealed override void ProcessCancelled()
85 {
86 base.ProcessCancelled();
87
88 _dragBehavior.ResetPointerState(clearClickSuppression: true);
89 }
90
92 protected sealed override void ProcessPointerDown(WidgetPointerEventArgs args)
93 {
94 base.ProcessPointerDown(args);
95
96 _dragBehavior.ProcessPointerDown(args, CanStartDrag);
97 }
98
100 protected sealed override void ProcessPointerMove(WidgetPointerEventArgs args)
101 {
102 base.ProcessPointerMove(args);
103
104 _dragBehavior.ProcessPointerMove(
105 args,
108 DispatchDragStarted,
109 DispatchDragged);
110 }
111
113 protected sealed override void ProcessPointerUp(WidgetPointerEventArgs args)
114 {
115 base.ProcessPointerUp(args);
116
117 _dragBehavior.ProcessPointerUp(
118 args,
121 DispatchDragEnded);
122 }
123
125 protected sealed override bool ShouldDispatchPointerClick(WidgetPointerEventArgs args)
126 {
127 return base.ShouldDispatchPointerClick(args) &&
128 _dragBehavior.ShouldDispatchPointerClick(args);
129 }
130
136 protected virtual bool CanStartDrag(WidgetPointerEventArgs args)
137 {
138 return _dragBehavior.CanStartDrag(args);
139 }
140
147 protected virtual Vector2 ConvertScreenDeltaToPositionDelta(Vector2 totalScreenDeltaPx, View view)
148 {
149 return _dragBehavior.ConvertScreenDeltaToPositionDelta(totalScreenDeltaPx, view);
150 }
151
157 protected virtual Vector2 ConstrainDragPosition(Vector2 proposedPositionPx)
158 {
159 return proposedPositionPx;
160 }
161
166 protected virtual void OnDragStarted(WidgetDragEventArgs args)
167 {
168 }
169
174 protected virtual void OnDragged(WidgetDragEventArgs args)
175 {
176 }
177
182 protected virtual void OnDragEnded(WidgetDragEventArgs args)
183 {
184 }
185
186 private void DispatchDragStarted(WidgetDragEventArgs args)
187 {
188 OnDragStarted(args);
189 DragStarted?.Invoke(args);
190 }
191
192 private void DispatchDragged(WidgetDragEventArgs args)
193 {
194 OnDragged(args);
195 Dragged?.Invoke(args);
196 }
197
198 private void DispatchDragEnded(WidgetDragEventArgs args)
199 {
200 OnDragEnded(args);
201 DragEnded?.Invoke(args);
202 }
203}
View? View
Gets the view shared by all children in view mode.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
ContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the ContainerWidget class.
override void ProcessPointerDown(WidgetPointerEventArgs args)
Performs processing when a pointer press begins on the widget before notification callbacks are invok...
override void ProcessCancelled()
Performs processing when the widget is cancelled before notification callbacks are invoked.
virtual void OnDragged(WidgetDragEventArgs args)
Called after the container moves during dragging.
bool IsDragEnabled
Gets or sets whether new drag operations may begin.
virtual void OnDragStarted(WidgetDragEventArgs args)
Called when dragging begins.
virtual Vector2 ConstrainDragPosition(Vector2 proposedPositionPx)
Constrains a proposed anchor position before it is applied.
override bool ShouldDispatchPointerClick(WidgetPointerEventArgs args)
Determines whether a pointer-click event should be dispatched for the specified pointer event data....
override void ProcessHidden()
Performs processing when the widget is hidden before notification callbacks are invoked.
virtual Vector2 ConvertScreenDeltaToPositionDelta(Vector2 totalScreenDeltaPx, View view)
Converts total screen movement into this widget's coordinate space.
override void ProcessPointerMove(WidgetPointerEventArgs args)
Performs processing when pointer movement is routed to the widget before notification callbacks are i...
virtual void OnDragEnded(WidgetDragEventArgs args)
Called when dragging ends.
virtual bool CanStartDrag(WidgetPointerEventArgs args)
Determines whether a pointer-down event may begin drag tracking.
float DragThresholdPx
Gets or sets the minimum pointer movement required to begin dragging.
Action< WidgetDragEventArgs >? DragEnded
Raised when an active drag ends.
override void ProcessPointerUp(WidgetPointerEventArgs args)
Performs processing when a pointer press is released for the widget before notification callbacks are...
bool IsDragging
Gets whether a drag operation is active.
Action< WidgetDragEventArgs >? DragStarted
Raised when pointer movement first crosses DragThresholdPx.
Action< WidgetDragEventArgs >? Dragged
Raised after the container is repositioned during an active drag.
DraggableContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the DraggableContainerWidget class.
Event arguments for widget drag callbacks.
Event arguments for pointer-based widget callbacks.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.