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
DraggableWidgetBase.cs
1using System.Drawing;
2using System.Numerics;
6
7namespace Gondwana.Widgets;
8
12public abstract class DraggableWidgetBase : WidgetBase
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 _dragBehavior.ResetPointerState(clearClickSuppression: true);
80 }
81
83 protected sealed override void ProcessCancelled()
84 {
85 base.ProcessCancelled();
86 _dragBehavior.ResetPointerState(clearClickSuppression: true);
87 }
88
90 protected sealed override void ProcessPointerDown(WidgetPointerEventArgs args)
91 {
92 base.ProcessPointerDown(args);
93 _dragBehavior.ProcessPointerDown(args, CanStartDrag);
94 }
95
97 protected sealed override void ProcessPointerMove(WidgetPointerEventArgs args)
98 {
99 base.ProcessPointerMove(args);
100
101 _dragBehavior.ProcessPointerMove(
102 args,
105 DispatchDragStarted,
106 DispatchDragged);
107 }
108
110 protected sealed override void ProcessPointerUp(WidgetPointerEventArgs args)
111 {
112 base.ProcessPointerUp(args);
113
114 _dragBehavior.ProcessPointerUp(
115 args,
118 DispatchDragEnded);
119 }
120
122 protected sealed override bool ShouldDispatchPointerClick(WidgetPointerEventArgs args)
123 {
124 return base.ShouldDispatchPointerClick(args) &&
125 _dragBehavior.ShouldDispatchPointerClick(args);
126 }
127
133 protected virtual bool CanStartDrag(WidgetPointerEventArgs args)
134 {
135 return _dragBehavior.CanStartDrag(args);
136 }
137
144 protected virtual Vector2 ConvertScreenDeltaToPositionDelta(
145 Vector2 totalScreenDeltaPx,
146 View view)
147 {
148 return _dragBehavior.ConvertScreenDeltaToPositionDelta(totalScreenDeltaPx, view);
149 }
150
156 protected virtual Vector2 ConstrainDragPosition(Vector2 proposedPositionPx)
157 {
158 return proposedPositionPx;
159 }
160
165 protected virtual void OnDragStarted(WidgetDragEventArgs args)
166 {
167 }
168
173 protected virtual void OnDragged(WidgetDragEventArgs args)
174 {
175 }
176
181 protected virtual void OnDragEnded(WidgetDragEventArgs args)
182 {
183 }
184
185 private void DispatchDragStarted(WidgetDragEventArgs args)
186 {
187 OnDragStarted(args);
188 DragStarted?.Invoke(args);
189 }
190
191 private void DispatchDragged(WidgetDragEventArgs args)
192 {
193 OnDragged(args);
194 Dragged?.Invoke(args);
195 }
196
197 private void DispatchDragEnded(WidgetDragEventArgs args)
198 {
199 OnDragEnded(args);
200 DragEnded?.Invoke(args);
201 }
202}
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 ...
override bool ShouldDispatchPointerClick(WidgetPointerEventArgs args)
Determines whether a pointer-click event should be dispatched for the specified pointer event data....
bool IsDragging
Gets whether a drag operation is active.
virtual void OnDragged(WidgetDragEventArgs args)
Called after the widget moves during dragging.
override void ProcessHidden()
Performs processing when the widget is hidden before notification callbacks are invoked.
bool IsDragEnabled
Gets or sets whether new drag operations may begin.
override void ProcessPointerDown(WidgetPointerEventArgs args)
Performs processing when a pointer press begins on the widget before notification callbacks are invok...
DraggableWidgetBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the DraggableWidgetBase class.
Action< WidgetDragEventArgs >? Dragged
Raised after the widget is repositioned during an active drag.
float DragThresholdPx
Gets or sets the minimum pointer movement required to begin dragging.
virtual void OnDragStarted(WidgetDragEventArgs args)
Called when dragging begins.
Action< WidgetDragEventArgs >? DragStarted
Raised when pointer movement first crosses DragThresholdPx.
override void ProcessCancelled()
Performs processing when the widget is cancelled before notification callbacks are invoked.
override void ProcessPointerUp(WidgetPointerEventArgs args)
Performs processing when a pointer press is released for the widget before notification callbacks are...
virtual bool CanStartDrag(WidgetPointerEventArgs args)
Determines whether a pointer-down event may begin drag tracking.
virtual void OnDragEnded(WidgetDragEventArgs args)
Called when dragging ends.
Action< WidgetDragEventArgs >? DragEnded
Raised when an active drag ends.
override void ProcessPointerMove(WidgetPointerEventArgs args)
Performs processing when pointer movement is routed to the widget before notification callbacks are i...
virtual Vector2 ConvertScreenDeltaToPositionDelta(Vector2 totalScreenDeltaPx, View view)
Converts total screen movement into this widget's coordinate space.
virtual Vector2 ConstrainDragPosition(Vector2 proposedPositionPx)
Constrains a proposed anchor position before it is applied.
WidgetBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the WidgetBase class.
Definition WidgetBase.cs:95
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.