gfx/skia/trunk/include/views/SkTouchGesture.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/views/SkTouchGesture.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +#ifndef SkTouchGesture_DEFINED
    1.12 +#define SkTouchGesture_DEFINED
    1.13 +
    1.14 +#include "SkTDArray.h"
    1.15 +#include "SkMatrix.h"
    1.16 +
    1.17 +struct SkFlingState {
    1.18 +    SkFlingState() : fActive(false) {}
    1.19 +
    1.20 +    bool isActive() const { return fActive; }
    1.21 +    void stop() { fActive = false; }
    1.22 +
    1.23 +    void reset(float sx, float sy);
    1.24 +    bool evaluateMatrix(SkMatrix* matrix);
    1.25 +
    1.26 +private:
    1.27 +    SkPoint     fDirection;
    1.28 +    SkScalar    fSpeed0;
    1.29 +    double      fTime0;
    1.30 +    bool        fActive;
    1.31 +};
    1.32 +
    1.33 +class SkTouchGesture {
    1.34 +public:
    1.35 +    SkTouchGesture();
    1.36 +    ~SkTouchGesture();
    1.37 +
    1.38 +    void touchBegin(void* owner, float x, float y);
    1.39 +    void touchMoved(void* owner, float x, float y);
    1.40 +    void touchEnd(void* owner);
    1.41 +    void reset();
    1.42 +
    1.43 +    bool isActive() { return fFlinger.isActive(); }
    1.44 +    void stop() { fFlinger.stop(); }
    1.45 +
    1.46 +    const SkMatrix& localM();
    1.47 +    const SkMatrix& globalM() const { return fGlobalM; }
    1.48 +
    1.49 +private:
    1.50 +    enum State {
    1.51 +        kEmpty_State,
    1.52 +        kTranslate_State,
    1.53 +        kZoom_State,
    1.54 +    };
    1.55 +
    1.56 +    struct Rec {
    1.57 +        void*   fOwner;
    1.58 +        float   fStartX, fStartY;
    1.59 +        float   fPrevX, fPrevY;
    1.60 +        float   fLastX, fLastY;
    1.61 +        SkMSec  fPrevT, fLastT;
    1.62 +    };
    1.63 +    SkTDArray<Rec> fTouches;
    1.64 +
    1.65 +    State           fState;
    1.66 +    SkMatrix        fLocalM, fGlobalM;
    1.67 +    SkFlingState    fFlinger;
    1.68 +    SkMSec          fLastUpT;
    1.69 +    SkPoint         fLastUpP;
    1.70 +
    1.71 +
    1.72 +    void flushLocalM();
    1.73 +    int findRec(void* owner) const;
    1.74 +    void appendNewRec(void* owner, float x, float y);
    1.75 +    float computePinch(const Rec&, const Rec&);
    1.76 +    float limitTotalZoom(float scale) const;
    1.77 +    bool handleDblTap(float, float);
    1.78 +};
    1.79 +
    1.80 +#endif

mercurial