Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / pan-gesture-detector-base.h
1 #ifndef __DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H__
2 #define __DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/input/common/gesture-detector.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 class Core;
35 struct TouchEvent;
36 struct PanGestureRequest;
37 }
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 class EnvironmentOptions;
46
47 /**
48  * When given a set of touch events, this detector attempts to determine if a pan gesture has taken place.
49  */
50 class PanGestureDetectorBase : public GestureDetector
51 {
52 public:
53
54   /**
55    * Virtual destructor.
56    */
57   virtual ~PanGestureDetectorBase();
58
59 public:
60
61   /**
62    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
63    */
64   virtual void SendEvent(const Integration::TouchEvent& event);
65
66   /**
67    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
68    */
69   virtual void Update(const Integration::GestureRequest& request);
70
71 protected:
72
73   /**
74    * Constructor
75    * @param[in]  screenSize  The size of the screen.
76    * @param[in]  request     The details of the request.
77    */
78   PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions* environmentOptions);
79
80 private:
81
82   /**
83    * Emits the pan gesture event (performs some smoothing operation).
84    * @param[in]  state         The state of the pan.
85    * @param[in]  currentEvent  The latest touch event.
86    */
87   void SendPan(Gesture::State state, const Integration::TouchEvent& currentEvent);
88
89   /**
90    * Emits the pan gesture event to the core.
91    * @param[in] gesture The pan gesture event.
92    */
93   virtual void EmitPan(const Integration::PanGestureEvent gesture) = 0;
94
95 private:
96
97   /**
98    * Internal state machine.
99    */
100   enum State
101   {
102     Clear,    ///< No gesture detected.
103     Possible, ///< The current touch event data suggests that a gesture is possible.
104     Started,  ///< A gesture has been detected.
105     Finished, ///< A previously started pan gesture has finished.
106     Failed,   ///< Current touch event data suggests a pan gesture is not possible.
107   };
108
109   State mState; ///< The current state of the detector.
110   std::vector<Integration::TouchEvent> mTouchEvents;     ///< A container of all touch events after an initial down event.
111
112   Vector2 mPrimaryTouchDownLocation;    ///< The initial touch down point.
113   Vector2 mThresholdAdjustmentPerFrame; ///< The adjustment per frame at the start of a slow pan.
114   Vector2 mPreviousPosition;            ///< The previous position.
115
116   unsigned int mThresholdAdjustmentsRemaining; ///< No. of threshold adjustments still to apply (for a slow-pan).
117   unsigned int mThresholdTotalAdjustments;     ///< The total number of adjustments required.
118
119   unsigned long mPrimaryTouchDownTime;  ///< The initial touch down time.
120   unsigned int mMinimumTouchesRequired; ///< The minimum touches required before a pan should be emitted.
121   unsigned int mMaximumTouchesRequired; ///< The maximum touches after which a pan should not be emitted.
122
123   unsigned int mMinimumDistanceSquared; ///< The minimum distance squared before pan should start.
124   unsigned int mMinimumMotionEvents;    ///< The minimum motion events before pan should start.
125   unsigned int mMotionEvents;           ///< The motion events received so far (before pan is emitted).
126 };
127
128 } // namespace Adaptor
129
130 } // namespace Internal
131
132 } // namespace Dali
133
134 #endif // __DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H__