2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-03-16 12:10:02 +00:00
|
|
|
#ifndef SkTouchGesture_DEFINED
|
|
|
|
#define SkTouchGesture_DEFINED
|
|
|
|
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkTDArray.h"
|
2011-03-16 12:10:02 +00:00
|
|
|
#include "SkMatrix.h"
|
|
|
|
|
|
|
|
struct SkFlingState {
|
|
|
|
SkFlingState() : fActive(false) {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
bool isActive() const { return fActive; }
|
|
|
|
void stop() { fActive = false; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
void reset(float sx, float sy);
|
|
|
|
bool evaluateMatrix(SkMatrix* matrix);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
private:
|
|
|
|
SkPoint fDirection;
|
|
|
|
SkScalar fSpeed0;
|
|
|
|
double fTime0;
|
|
|
|
bool fActive;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkTouchGesture {
|
|
|
|
public:
|
|
|
|
SkTouchGesture();
|
|
|
|
~SkTouchGesture();
|
|
|
|
|
|
|
|
void touchBegin(void* owner, float x, float y);
|
|
|
|
void touchMoved(void* owner, float x, float y);
|
|
|
|
void touchEnd(void* owner);
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
bool isActive() { return fFlinger.isActive(); }
|
|
|
|
void stop() { fFlinger.stop(); }
|
|
|
|
|
|
|
|
const SkMatrix& localM();
|
|
|
|
const SkMatrix& globalM() const { return fGlobalM; }
|
|
|
|
|
2016-05-20 14:32:19 +00:00
|
|
|
void setTransLimit(const SkRect& contentRect, const SkRect& windowRect);
|
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
private:
|
|
|
|
enum State {
|
|
|
|
kEmpty_State,
|
|
|
|
kTranslate_State,
|
|
|
|
kZoom_State,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Rec {
|
|
|
|
void* fOwner;
|
|
|
|
float fStartX, fStartY;
|
|
|
|
float fPrevX, fPrevY;
|
|
|
|
float fLastX, fLastY;
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
float fPrevT, fLastT;
|
2011-03-16 12:10:02 +00:00
|
|
|
};
|
|
|
|
SkTDArray<Rec> fTouches;
|
|
|
|
|
|
|
|
State fState;
|
|
|
|
SkMatrix fLocalM, fGlobalM;
|
|
|
|
SkFlingState fFlinger;
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
double fLastUpMillis;
|
2011-03-16 12:10:02 +00:00
|
|
|
SkPoint fLastUpP;
|
|
|
|
|
2016-05-20 14:32:19 +00:00
|
|
|
// The following rects are used to limit the translation so the content never leaves the window
|
|
|
|
SkRect fContentRect, fWindowRect;
|
|
|
|
bool fIsTransLimited = false;
|
2011-03-16 12:10:02 +00:00
|
|
|
|
2016-05-20 14:32:19 +00:00
|
|
|
void limitTrans(); // here we only limit the translation with respect to globalM
|
2011-03-16 12:10:02 +00:00
|
|
|
void flushLocalM();
|
|
|
|
int findRec(void* owner) const;
|
|
|
|
void appendNewRec(void* owner, float x, float y);
|
|
|
|
float computePinch(const Rec&, const Rec&);
|
|
|
|
float limitTotalZoom(float scale) const;
|
|
|
|
bool handleDblTap(float, float);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|