Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
TouchGesture Class Reference

#include <TouchGesture.h>

Public Member Functions

 TouchGesture ()
 
 ~TouchGesture ()
 
void touchBegin (void *owner, float x, float y)
 
void touchMoved (void *owner, float x, float y)
 
void touchEnd (void *owner)
 
void reset ()
 
void resetTouchState ()
 
bool isActive ()
 
void stop ()
 
bool isBeingTouched ()
 
bool isFling (SkPoint *dir)
 
void startZoom ()
 
void updateZoom (float scale, float startX, float startY, float lastX, float lastY)
 
void endZoom ()
 
const SkMatrixlocalM ()
 
const SkMatrixglobalM () const
 
void setTransLimit (const SkRect &contentRect, const SkRect &windowRect, const SkMatrix &preTouchM)
 

Detailed Description

Definition at line 17 of file TouchGesture.h.

Constructor & Destructor Documentation

◆ TouchGesture()

TouchGesture::TouchGesture ( )

Definition at line 109 of file TouchGesture.cpp.

109 {
110 this->reset();
111}

◆ ~TouchGesture()

TouchGesture::~TouchGesture ( )

Definition at line 113 of file TouchGesture.cpp.

113 {
114}

Member Function Documentation

◆ endZoom()

void TouchGesture::endZoom ( )

Definition at line 207 of file TouchGesture.cpp.

207 {
208 this->flushLocalM();
209 SkASSERT(kZoom_State == fState);
210 fState = kEmpty_State;
211}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ globalM()

const SkMatrix & TouchGesture::globalM ( ) const
inline

Definition at line 38 of file TouchGesture.h.

38{ return fGlobalM; }

◆ isActive()

bool TouchGesture::isActive ( )
inline

Definition at line 28 of file TouchGesture.h.

28{ return fFlinger.isActive(); }

◆ isBeingTouched()

bool TouchGesture::isBeingTouched ( )
inline

Definition at line 30 of file TouchGesture.h.

30{ return kEmpty_State != fState; }

◆ isFling()

bool TouchGesture::isFling ( SkPoint dir)

Definition at line 305 of file TouchGesture.cpp.

305 {
306 if (fFlinger.isActive()) {
307 SkScalar speed;
308 fFlinger.get(dir, &speed);
309 if (speed > 1000) {
310 return true;
311 }
312 }
313 return false;
314}
float SkScalar
Definition extension.cpp:12

◆ localM()

const SkMatrix & TouchGesture::localM ( )

Definition at line 136 of file TouchGesture.cpp.

136 {
137 if (fFlinger.isActive()) {
138 if (!fFlinger.evaluateMatrix(&fLocalM)) {
139 this->flushLocalM();
140 }
141 }
142 return fLocalM;
143}

◆ reset()

void TouchGesture::reset ( )

Definition at line 126 of file TouchGesture.cpp.

126 {
127 fGlobalM.reset();
128 this->resetTouchState();
129}
SkMatrix & reset()
Definition SkMatrix.cpp:49
void resetTouchState()

◆ resetTouchState()

void TouchGesture::resetTouchState ( )

Definition at line 116 of file TouchGesture.cpp.

116 {
117 fIsTransLimited = false;
118 fTouches.reset();
119 fState = kEmpty_State;
120 fLocalM.reset();
121
122 fLastUpMillis = SkTime::GetMSecs() - 2*MAX_DBL_TAP_INTERVAL;
123 fLastUpP.set(0, 0);
124}
static const SkMSec MAX_DBL_TAP_INTERVAL
void reset()
Definition SkTDArray.h:171
double GetMSecs()
Definition SkTime.h:17
void set(float x, float y)

◆ setTransLimit()

void TouchGesture::setTransLimit ( const SkRect contentRect,
const SkRect windowRect,
const SkMatrix preTouchM 
)

Definition at line 349 of file TouchGesture.cpp.

350 {
351 fIsTransLimited = true;
352 fContentRect = contentRect;
353 fWindowRect = windowRect;
354 fPreTouchM = preTouchMatrix;
355}

◆ startZoom()

void TouchGesture::startZoom ( )

Definition at line 197 of file TouchGesture.cpp.

197 {
198 fState = kZoom_State;
199}

◆ stop()

void TouchGesture::stop ( )
inline

Definition at line 29 of file TouchGesture.h.

29{ fFlinger.stop(); }

◆ touchBegin()

void TouchGesture::touchBegin ( void *  owner,
float  x,
float  y 
)

Definition at line 153 of file TouchGesture.cpp.

153 {
154// SkDebugf("--- %d touchBegin %p %g %g\n", fTouches.count(), owner, x, y);
155
156 int index = this->findRec(owner);
157 if (index >= 0) {
158 this->flushLocalM();
159 fTouches.removeShuffle(index);
160 SkDebugf("---- already exists, removing\n");
161 }
162
163 if (fTouches.size() == 2) {
164 return;
165 }
166
167 this->flushLocalM();
168 fFlinger.stop();
169
170 this->appendNewRec(owner, x, y);
171
172 switch (fTouches.size()) {
173 case 1:
174 fState = kTranslate_State;
175 break;
176 case 2:
177 this->startZoom();
178 break;
179 default:
180 break;
181 }
182}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
int size() const
Definition SkTDArray.h:138
void removeShuffle(int index)
Definition SkTDArray.h:214
double y
double x

◆ touchEnd()

void TouchGesture::touchEnd ( void *  owner)

Definition at line 266 of file TouchGesture.cpp.

266 {
267// SkDebugf("--- %d touchEnd %p\n", fTouches.count(), owner);
268
269 int index = this->findRec(owner);
270 if (index < 0) {
271 SkDebugf("--- not found\n");
272 return;
273 }
274
275 const Rec& rec = fTouches[index];
276 if (this->handleDblTap(rec.fLastX, rec.fLastY)) {
277 return;
278 }
279
280 // count() reflects the number before we removed the owner
281 switch (fTouches.size()) {
282 case 1: {
283 this->flushLocalM();
284 float dx = rec.fLastX - rec.fPrevX;
285 float dy = rec.fLastY - rec.fPrevY;
286 float dur = rec.fLastT - rec.fPrevT;
287 if (dur > 0) {
288 fFlinger.reset(dx / dur, dy / dur);
289 }
290 fState = kEmpty_State;
291 } break;
292 case 2:
293 this->endZoom();
294 break;
295 default:
296 SkASSERT(kZoom_State == fState);
297 break;
298 }
299
300 fTouches.removeShuffle(index);
301
302 limitTrans();
303}
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition SkRecords.h:208

◆ touchMoved()

void TouchGesture::touchMoved ( void *  owner,
float  x,
float  y 
)

Definition at line 213 of file TouchGesture.cpp.

213 {
214// SkDebugf("--- %d touchMoved %p %g %g\n", fTouches.count(), owner, x, y);
215
216 if (kEmpty_State == fState) {
217 return;
218 }
219
220 int index = this->findRec(owner);
221 if (index < 0) {
222 SkDebugf("---- ignoring move without begin\n");
223 return;
224 }
225
226 Rec& rec = fTouches[index];
227
228 // not sure how valuable this is
229 if (fTouches.size() == 2) {
230 if (close_enough_for_jitter(rec.fLastX, rec.fLastY, x, y)) {
231// SkDebugf("--- drop touchMove, within jitter tolerance %g %g\n", rec.fLastX - x, rec.fLastY - y);
232 return;
233 }
234 }
235
236 rec.fPrevX = rec.fLastX; rec.fLastX = x;
237 rec.fPrevY = rec.fLastY; rec.fLastY = y;
238 rec.fPrevT = rec.fLastT;
239 rec.fLastT = static_cast<float>(SkTime::GetSecs());
240
241 switch (fTouches.size()) {
242 case 1: {
243 float dx = rec.fLastX - rec.fStartX;
244 float dy = rec.fLastY - rec.fStartY;
246 dy = (float)sk_float_round2int(dy);
247 fLocalM.setTranslate(dx, dy);
248 } break;
249 case 2: {
250 SkASSERT(kZoom_State == fState);
251 const Rec& rec0 = fTouches[0];
252 const Rec& rec1 = fTouches[1];
253
254 float scale = this->computePinch(rec0, rec1);
255 this->updateZoom(scale,
256 center(rec0.fStartX, rec1.fStartX),
257 center(rec0.fStartY, rec1.fStartY),
258 center(rec0.fLastX, rec1.fLastX),
259 center(rec0.fLastY, rec1.fLastY));
260 } break;
261 default:
262 break;
263 }
264}
#define sk_float_round2int(x)
static SkScalar center(float pos0, float pos1)
static bool close_enough_for_jitter(float x0, float y0, float x1, float y1)
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:254
void updateZoom(float scale, float startX, float startY, float lastX, float lastY)
double GetSecs()
Definition SkTime.h:16
const Scalar scale

◆ updateZoom()

void TouchGesture::updateZoom ( float  scale,
float  startX,
float  startY,
float  lastX,
float  lastY 
)

Definition at line 201 of file TouchGesture.cpp.

201 {
202 fLocalM.setTranslate(-startX, -startY);
203 fLocalM.postScale(scale, scale);
204 fLocalM.postTranslate(lastX, lastY);
205}
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:281
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:360

The documentation for this class was generated from the following files: