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
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
38 protected DraggableWidgetBase(RenderSurfaceHostBase renderSurfaceHost,
40 PointF anchor = default,
41 string? nickname = null)
42 : base(renderSurfaceHost, mode, anchor, nickname)
43 {
44 _dragBehavior = new WidgetDragBehavior(this);
45 }
46
50 public bool IsDragEnabled
51 {
52 get => _dragBehavior.IsDragEnabled;
53 set => _dragBehavior.IsDragEnabled = value;
54 }
55
59 public bool IsDragging => _dragBehavior.IsDragging;
60
64 public float DragThresholdPx
65 {
66 get => _dragBehavior.DragThresholdPx;
67 set => _dragBehavior.DragThresholdPx = value;
68 }
69
71 protected sealed override void ProcessHidden()
72 {
73 base.ProcessHidden();
74 _dragBehavior.ResetPointerState(clearClickSuppression: true);
75 }
76
78 protected sealed override void ProcessCancelled()
79 {
80 base.ProcessCancelled();
81 _dragBehavior.ResetPointerState(clearClickSuppression: true);
82 }
83
85 protected sealed override void ProcessPointerDown(WidgetPointerEventArgs args)
86 {
87 base.ProcessPointerDown(args);
88 _dragBehavior.ProcessPointerDown(args, CanStartDrag);
89 }
90
92 protected sealed override void ProcessPointerMove(WidgetPointerEventArgs args)
93 {
94 base.ProcessPointerMove(args);
95
96 _dragBehavior.ProcessPointerMove(
97 args,
100 DispatchDragStarted,
101 DispatchDragged);
102 }
103
105 protected sealed override void ProcessPointerUp(WidgetPointerEventArgs args)
106 {
107 base.ProcessPointerUp(args);
108
109 _dragBehavior.ProcessPointerUp(
110 args,
113 DispatchDragEnded);
114 }
115
117 protected sealed override bool ShouldDispatchPointerClick(WidgetPointerEventArgs args)
118 {
119 return base.ShouldDispatchPointerClick(args) &&
120 _dragBehavior.ShouldDispatchPointerClick(args);
121 }
122
128 protected virtual bool CanStartDrag(WidgetPointerEventArgs args)
129 {
130 return _dragBehavior.CanStartDrag(args);
131 }
132
139 protected virtual Vector2 ConvertScreenDeltaToPositionDelta(Vector2 totalScreenDeltaPx,
140 View view)
141 {
142 return _dragBehavior.ConvertScreenDeltaToPositionDelta(totalScreenDeltaPx, view);
143 }
144
150 protected virtual Vector2 ConstrainDragPosition(Vector2 proposedPositionPx)
151 {
152 return proposedPositionPx;
153 }
154
159 protected virtual void OnDragStarted(WidgetDragEventArgs args)
160 {
161 }
162
167 protected virtual void OnDragged(WidgetDragEventArgs args)
168 {
169 }
170
175 protected virtual void OnDragEnded(WidgetDragEventArgs args)
176 {
177 }
178
179 private void DispatchDragStarted(WidgetDragEventArgs args)
180 {
181 OnDragStarted(args);
182 DragStarted?.Invoke(args);
183 }
184
185 private void DispatchDragged(WidgetDragEventArgs args)
186 {
187 OnDragged(args);
188 Dragged?.Invoke(args);
189 }
190
191 private void DispatchDragEnded(WidgetDragEventArgs args)
192 {
193 OnDragEnded(args);
194 DragEnded?.Invoke(args);
195 }
196}
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.