5#include "TinyGPU/Emulation.h"
6#include "TinyGPU/Input/TouchDriver.h"
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
124 handleTouched(point, now);
127 }
else if (isDown_) {
133 bool isDown_ =
false;
134 bool dragActive_ =
false;
135 bool longPressFired_ =
false;
136 bool lastTapValid_ =
false;
138 uint32_t downTime_ = 0;
139 uint32_t lastTapTime_ = 0;
143 bool secondActive_ =
false;
144 float initialPinchDistance_ = 1.0f;
145 float lastPinchDistance_ = 0.0f;
146 float initialPinchAngle_ = 0.0f;
147 float lastPinchAngle_ = 0.0f;
149 static int16_t iabs(int16_t v) {
return v < 0 ?
static_cast<int16_t>(-v) : v; }
151 void handleTouched(
Point point, uint32_t now) {
158 longPressFired_ =
false;
162 const int16_t dx =
static_cast<int16_t>(point
.x - downPoint_
.x);
163 const int16_t dy =
static_cast<int16_t>(point
.y - downPoint_
.y);
164 const int16_t adx = iabs(dx);
165 const int16_t ady = iabs(dy);
169 dragType_ = classifyDragType(downPoint_, dx, dy);
171 }
else if (dragActive_) {
172 const int16_t stepDx =
static_cast<int16_t>(point
.x - lastPoint_
.x);
173 const int16_t stepDy =
static_cast<int16_t>(point
.y - lastPoint_
.y);
174 if (stepDx != 0 || stepDy != 0) {
180 longPressFired_ =
true;
187 void handleReleased(uint32_t now) {
189 const uint32_t duration = now - downTime_;
190 const int16_t dx =
static_cast<int16_t>(lastPoint_
.x - downPoint_
.x);
191 const int16_t dy =
static_cast<int16_t>(lastPoint_
.y - downPoint_
.y);
192 const int16_t adx = iabs(dx);
193 const int16_t ady = iabs(dy);
202 emitDiscrete(swipeTypeFor(dx, dy, adx, ady), lastPoint_, dx, dy, duration);
209 lastTapValid_ =
false;
212 lastTapValid_ =
true;
213 lastTapTime_ = downTime_;
217 secondActive_ =
false;
220 GestureType classifyDragType(
Point downPoint, int16_t dx, int16_t dy)
const {
227 static GestureType swipeTypeFor(int16_t dx, int16_t dy, int16_t adx, int16_t ady) {
235 int16_t dy, int16_t stepDx, int16_t stepDy, uint32_t now) {
266 void updatePinchRotate(
bool hasSecond,
Point first,
Point second) {
268 secondActive_ =
false;
272 const float dxp =
static_cast<
float>(second
.x - first
.x);
273 const float dyp =
static_cast<
float>(second
.y - first
.y);
274 const float distance = sqrtf(dxp * dxp + dyp * dyp);
275 const float angle = atan2f(dyp, dxp) * 180.0f / 3.14159265f;
277 if (!secondActive_) {
278 secondActive_ =
true;
279 initialPinchDistance_ = distance > 0.0f ? distance : 1.0f;
280 lastPinchDistance_ = distance;
281 initialPinchAngle_ = angle;
282 lastPinchAngle_ = angle;
287 lastPinchDistance_ = distance;
288 lastPinchAngle_ = angle;
292 const float distDelta = distance - lastPinchDistance_;
293 if (distDelta > 0.5f || distDelta < -0.5f) {
299 ev
.scale = distance / initialPinchDistance_;
304 float angleDelta = angle - lastPinchAngle_;
305 if (angleDelta > 180.0f) angleDelta -= 360.0f;
306 if (angleDelta < -180.0f) angleDelta += 360.0f;
307 if (angleDelta > 1.0f || angleDelta < -1.0f) {
318 lastPinchDistance_ = distance;
319 lastPinchAngle_ = angle;
Recognizes touch gestures from a stream of single-point touch samples, and reports them through a sin...
Definition: GestureDetector.h:102
uint16_t tapMaxMovePx
Definition: GestureDetector.h:109
uint16_t doubleTapMaxGapMs
Definition: GestureDetector.h:110
void(* onGesture)(GestureEvent &)
Definition: GestureDetector.h:104
uint16_t tapMaxDurationMs
Definition: GestureDetector.h:108
void update(TouchDriver &driver)
Definition: GestureDetector.h:118
uint16_t dragStartThresholdPx
Definition: GestureDetector.h:114
uint16_t swipeMaxDurationMs
Definition: GestureDetector.h:113
uint16_t longPressMinDurationMs
Definition: GestureDetector.h:111
bool(* isDraggable)(int16_t x, int16_t y)
Definition: GestureDetector.h:105
uint16_t swipeMinDistancePx
Definition: GestureDetector.h:112
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
virtual bool isTouched()=0
Return whether the panel currently appears touched.
virtual bool getPoint(Point &outPoint)=0
Read the current touch point.
virtual bool getSecondPoint(Point &outPoint)
Read a second, simultaneous touch point, for multi-touch gestures (pinch/rotate).
Definition: TouchDriverCommon.h:110
Definition: DSIBusESP32.h:19
const char * toString(GestureType type)
Human-readable name for a GestureType, useful for logging.
Definition: GestureDetector.h:33
GestureType
Definition: GestureDetector.h:15
@ kDrag
continuous move that started over a draggable target
@ kPan
continuous move over the background, not vertical-dominant
@ kPinchOut
two fingers moving apart (zoom in)
@ kRotate
two-finger rotation
@ kPinchIn
two fingers moving together (zoom out)
@ kScroll
continuous move over the background, vertical-dominant
GesturePhase
Definition: GestureDetector.h:13
unsigned long millis()
Definition: EmulationDesktop.h:43
Definition: GestureDetector.h:66
float scale
pinch: current / initial two-finger distance
Definition: GestureDetector.h:75
int16_t stepDeltaX
movement since the previous kChanged event
Definition: GestureDetector.h:73
Point startPoint
where the touch began
Definition: GestureDetector.h:70
GesturePhase phase
Definition: GestureDetector.h:68
int16_t deltaY
Definition: GestureDetector.h:72
int16_t stepDeltaY
Definition: GestureDetector.h:74
uint32_t durationMs
how long the touch has been held
Definition: GestureDetector.h:77
GestureType type
Definition: GestureDetector.h:67
int16_t deltaX
cumulative movement since the touch began
Definition: GestureDetector.h:71
float rotationDegrees
rotate: cumulative angle change
Definition: GestureDetector.h:76
Point point
current touch position
Definition: GestureDetector.h:69
Touch point.
Definition: TouchDriverCommon.h:32
int16_t x
Definition: TouchDriverCommon.h:33
int16_t y
Definition: TouchDriverCommon.h:34