[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / integration-api / events / touch-event-combiner.h
1 #ifndef __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__
2 #define __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/events/touch-point.h>
23 #include <dali/public-api/math/vector2.h>
24
25 namespace Dali DALI_IMPORT_API
26 {
27
28 namespace Integration
29 {
30
31 struct TouchEvent;
32
33 /**
34  * Dali::Integration::TouchEventCombiner is a utility class, an instance of which, should be created
35  * upon initialisation.  It accepts single Point(s) containing information about a touch area and
36  * creates a TouchEvent combining the latest event's information with previous TouchPoint(s).
37  *
38  * The created TouchEvent can then be sent to the Dali Core as indicated by the GetNextTouchEvent()
39  * method.
40  *
41  * The TouchEventCombiner ensures that the following rules are also adhered to:
42  * - If two Down events are accidentally received, then the second one is ignored.
43  * - Motion events are not processed if a Down event does not precede it.
44  * - Motion event throttling is carried out to satisfy the minimum distance and time delta required.
45  * - If an interrupted event is received, then any stored Point history is cleared.
46  */
47 class TouchEventCombiner
48 {
49 public:
50
51   /**
52    * Default Constructor.
53    * @note The default minimum motion time is 1 ms between motion events and the default behaviour
54    *       is to throttle X and Y movement by 1.
55    */
56   TouchEventCombiner();
57
58   /**
59    * Construction with parameters.
60    * @param[in]  minMotionTime       The minimum time (in ms) that should occur between motion events.
61    * @param[in]  minMotionXDistance  The minimum distance a finger has to be moved between horizontal motion events.
62    * @param[in]  minMotionYDistance  The minimum distance a finger has to be moved between vertical motion events.
63    * @note Will assert if any of the parameters is negative.
64    */
65   TouchEventCombiner( unsigned long minMotionTime, float minMotionXDistance, float minMotionYDistance );
66
67   /**
68    * Construction with parameters.
69    * @param[in]  minMotionTime      The minimum time (in ms) that should occur between motion events.
70    * @param[in]  minMotionDistance  A Vector2 representing the minimum distance a finger has to be moved between horizontal and vertical motion events.
71    * @note Will assert if any of the parameters is negative.
72    */
73   TouchEventCombiner( unsigned long minMotionTime, Vector2 minMotionDistance );
74
75   /**
76    * Non virtual destructor
77    */
78   ~TouchEventCombiner();
79
80 public:
81
82   /**
83    * Allows the caller to pass in a point which is processed and the TouchEvent is appropriately filled with the new,
84    * and previously stored Point information.
85    *
86    * @note If the thresholds set have not been passed, then false is returned and the TouchEvent should not be sent
87    * to Dali Core.
88    *
89    * @param[in]   point         The new Point.
90    * @param[in]   time          The time the event occurred.
91    * @param[out]  touchEvent    This is populated with the correct Point(s) and time information.
92    *
93    * @return true if the point is beyond the different thresholds set thus, should be sent to core, false otherwise.
94    */
95   bool GetNextTouchEvent( const TouchPoint& point, unsigned long time, TouchEvent& touchEvent );
96
97   /**
98    * Sets the minimum time (in ms) that should occur between motion events.
99    * @param[in]  minTime  Minimum time between motion events.
100    */
101   void SetMinimumMotionTimeThreshold( unsigned long minTime );
102
103   /**
104    * Sets the minimum distance a finger has to be moved (both X and Y) between motion events.
105    * @param[in]  minDistance  The minimum distance between motion events.
106    * @note Will assert if parameter is negative.
107    */
108   void SetMinimumMotionDistanceThreshold( float minDistance );
109
110   /**
111    * Sets the minimum distance a finger has to be moved between motion events.
112    * @param[in]  minXDistance  The minimum X distance between motion events.
113    * @param[in]  minYDistance  The minimum Y distance between motion events.
114    * @note Use this method if the X and Y threshold required is different.
115    * @note Will assert if any of the parameters is negative.
116    */
117   void SetMinimumMotionDistanceThreshold( float minXDistance, float minYDistance );
118
119   /**
120    * Sets the minimum distance a finger has to be moved between motion events.
121    * @param[in]  minDistance  A Vector2 representing the minimum X and Y thresholds.
122    * @note Use this method if the X and Y threshold required is different.
123    * @note Will assert if any of the parameters is negative.
124    */
125   void SetMinimumMotionDistanceThreshold( Vector2 minDistance );
126
127   /**
128    * Retrieves the minimum motion time threshold.
129    * @return the minimum time threshold.
130    */
131   unsigned long GetMinimumMotionTimeThreshold() const;
132
133   /**
134    * Gets the minimum distance a finger has to be moved (both X and Y) between motion events.
135    * @return A Vector2 representing the x and y thresholds.
136    */
137   Vector2 GetMinimumMotionDistanceThreshold() const;
138
139   /**
140    * This resets any information contained by the TouchEventCombiner.
141    * This may be required if some platform event has occurred which makes it necessary to reset any
142    * TouchPoint information that the combiner may store.
143    */
144   void Reset();
145
146 private:
147
148   struct PointInfo;
149   typedef std::vector< PointInfo > PointInfoContainer;
150   PointInfoContainer mPressedPoints; ///< A container of point and time.
151
152   unsigned long mMinMotionTime; ///< The minimum time that should elapse before considering a new motion event.
153   Vector2 mMinMotionDistance; ///< The minimum distance in the X and Y direction before considering a new motion event.
154 };
155
156 } // namespace Integration
157
158 } // namespace Dali
159
160 #endif // __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__