michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkTouchGesture_DEFINED michael@0: #define SkTouchGesture_DEFINED michael@0: michael@0: #include "SkTDArray.h" michael@0: #include "SkMatrix.h" michael@0: michael@0: struct SkFlingState { michael@0: SkFlingState() : fActive(false) {} michael@0: michael@0: bool isActive() const { return fActive; } michael@0: void stop() { fActive = false; } michael@0: michael@0: void reset(float sx, float sy); michael@0: bool evaluateMatrix(SkMatrix* matrix); michael@0: michael@0: private: michael@0: SkPoint fDirection; michael@0: SkScalar fSpeed0; michael@0: double fTime0; michael@0: bool fActive; michael@0: }; michael@0: michael@0: class SkTouchGesture { michael@0: public: michael@0: SkTouchGesture(); michael@0: ~SkTouchGesture(); michael@0: michael@0: void touchBegin(void* owner, float x, float y); michael@0: void touchMoved(void* owner, float x, float y); michael@0: void touchEnd(void* owner); michael@0: void reset(); michael@0: michael@0: bool isActive() { return fFlinger.isActive(); } michael@0: void stop() { fFlinger.stop(); } michael@0: michael@0: const SkMatrix& localM(); michael@0: const SkMatrix& globalM() const { return fGlobalM; } michael@0: michael@0: private: michael@0: enum State { michael@0: kEmpty_State, michael@0: kTranslate_State, michael@0: kZoom_State, michael@0: }; michael@0: michael@0: struct Rec { michael@0: void* fOwner; michael@0: float fStartX, fStartY; michael@0: float fPrevX, fPrevY; michael@0: float fLastX, fLastY; michael@0: SkMSec fPrevT, fLastT; michael@0: }; michael@0: SkTDArray fTouches; michael@0: michael@0: State fState; michael@0: SkMatrix fLocalM, fGlobalM; michael@0: SkFlingState fFlinger; michael@0: SkMSec fLastUpT; michael@0: SkPoint fLastUpP; michael@0: michael@0: michael@0: void flushLocalM(); michael@0: int findRec(void* owner) const; michael@0: void appendNewRec(void* owner, float x, float y); michael@0: float computePinch(const Rec&, const Rec&); michael@0: float limitTotalZoom(float scale) const; michael@0: bool handleDblTap(float, float); michael@0: }; michael@0: michael@0: #endif