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();
|
2018-01-05 16:58:16 +00:00
|
|
|
void resetTouchState();
|
2011-03-16 12:10:02 +00:00
|
|
|
|
|
|
|
bool isActive() { return fFlinger.isActive(); }
|
|
|
|
void stop() { fFlinger.stop(); }
|
2017-06-07 14:00:30 +00:00
|
|
|
bool isBeingTouched() { return kEmpty_State != fState; }
|
2011-03-16 12:10:02 +00:00
|
|
|
|
|
|
|
const SkMatrix& localM();
|
|
|
|
const SkMatrix& globalM() const { return fGlobalM; }
|
|
|
|
|
Simplify some Viewer code, and fix a few bugs
The content rect was always identical to the window rect,
so most of the related code did nothing. The translation
limit code is always useful (to avoid dragging the slide
way off-screen with the mouse), so always include it.
The auto-scaling to fit the screen is also still useful,
but just base it on the window rect.
The zoom code has four state variables, only used two of
them, and one was a trivially derived computation. Fold
most of that work into computeMatrix. (The translation
was always zero -- we never changed the zoom center.)
Include fDefaultMatrix in the matrix from computeMatrix,
rather than needing to apply it specially to the canvas.
Don't apply the inverse default matrix to touch or mouse
points. The absolute positions of those touch points is
not important, but because that matrix includes scale
(and sometimes very large or very small scale), it just
had the effect of greatly amplifying or damping the drag
speed. Without it, the slide always pans at the speed of
the touch/mouse drag -- which seems more desirable.
The use of the inverse default matrix was a clever trick,
but it caused the translation (applied to the global mtx)
to be scaled, so the slide was always pinned incorrectly.
Instead, supply the unmodified window rect and the default
matrix, so the trans limit code can do the obvious correct
thing: xform the slide bounds completely, then limit the
translation that will be applied after that. Slides are
now correctly pinned to screen edge regardless of how
much zoom is present in the default matrix.
Note: There are still several bugs related to all of this
code, but given the web of xform state, it's hard to
unravel. The touch gesture still doesn't know about
viewer's zoom, so that's ignored when doing the pinning.
Beyond that, it doesn't even know about window resize -
it only configures the translation limit when setting up
a slide. I had a fix for all of this (doing the
translation limiting in computeMatrix), but then the touch
gesture doesn't know about it, and can accumulate drag
motion that needs to be un-dragged to get back on-screen,
even though the slide is never really translated that far.
SkTouchGesture is in include. No one uses it except viewer:
TBR=bsalomon@google.com
Bug: skia:
Change-Id: I460cc07c3de6d36e63826f57d359faf1facf5ab3
Reviewed-on: https://skia-review.googlesource.com/18524
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-06-05 12:46:04 +00:00
|
|
|
void setTransLimit(const SkRect& contentRect, const SkRect& windowRect,
|
|
|
|
const SkMatrix& preTouchM);
|
2016-05-20 14:32:19 +00:00
|
|
|
|
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;
|
Simplify some Viewer code, and fix a few bugs
The content rect was always identical to the window rect,
so most of the related code did nothing. The translation
limit code is always useful (to avoid dragging the slide
way off-screen with the mouse), so always include it.
The auto-scaling to fit the screen is also still useful,
but just base it on the window rect.
The zoom code has four state variables, only used two of
them, and one was a trivially derived computation. Fold
most of that work into computeMatrix. (The translation
was always zero -- we never changed the zoom center.)
Include fDefaultMatrix in the matrix from computeMatrix,
rather than needing to apply it specially to the canvas.
Don't apply the inverse default matrix to touch or mouse
points. The absolute positions of those touch points is
not important, but because that matrix includes scale
(and sometimes very large or very small scale), it just
had the effect of greatly amplifying or damping the drag
speed. Without it, the slide always pans at the speed of
the touch/mouse drag -- which seems more desirable.
The use of the inverse default matrix was a clever trick,
but it caused the translation (applied to the global mtx)
to be scaled, so the slide was always pinned incorrectly.
Instead, supply the unmodified window rect and the default
matrix, so the trans limit code can do the obvious correct
thing: xform the slide bounds completely, then limit the
translation that will be applied after that. Slides are
now correctly pinned to screen edge regardless of how
much zoom is present in the default matrix.
Note: There are still several bugs related to all of this
code, but given the web of xform state, it's hard to
unravel. The touch gesture still doesn't know about
viewer's zoom, so that's ignored when doing the pinning.
Beyond that, it doesn't even know about window resize -
it only configures the translation limit when setting up
a slide. I had a fix for all of this (doing the
translation limiting in computeMatrix), but then the touch
gesture doesn't know about it, and can accumulate drag
motion that needs to be un-dragged to get back on-screen,
even though the slide is never really translated that far.
SkTouchGesture is in include. No one uses it except viewer:
TBR=bsalomon@google.com
Bug: skia:
Change-Id: I460cc07c3de6d36e63826f57d359faf1facf5ab3
Reviewed-on: https://skia-review.googlesource.com/18524
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-06-05 12:46:04 +00:00
|
|
|
SkMatrix fLocalM, fGlobalM, fPreTouchM;
|
2011-03-16 12:10:02 +00:00
|
|
|
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
|