1 #ifndef __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__
2 #define __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
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>
25 namespace Dali DALI_IMPORT_API
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).
38 * The created TouchEvent can then be sent to the Dali Core as indicated by the GetNextTouchEvent()
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.
47 class TouchEventCombiner
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.
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.
65 TouchEventCombiner( unsigned long minMotionTime, float minMotionXDistance, float minMotionYDistance );
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.
73 TouchEventCombiner( unsigned long minMotionTime, Vector2 minMotionDistance );
76 * Non virtual destructor
78 ~TouchEventCombiner();
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.
86 * @note If the thresholds set have not been passed, then false is returned and the TouchEvent should not be sent
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.
93 * @return true if the point is beyond the different thresholds set thus, should be sent to core, false otherwise.
95 bool GetNextTouchEvent( const TouchPoint& point, unsigned long time, TouchEvent& touchEvent );
98 * Sets the minimum time (in ms) that should occur between motion events.
99 * @param[in] minTime Minimum time between motion events.
101 void SetMinimumMotionTimeThreshold( unsigned long minTime );
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.
108 void SetMinimumMotionDistanceThreshold( float minDistance );
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.
117 void SetMinimumMotionDistanceThreshold( float minXDistance, float minYDistance );
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.
125 void SetMinimumMotionDistanceThreshold( Vector2 minDistance );
128 * Retrieves the minimum motion time threshold.
129 * @return the minimum time threshold.
131 unsigned long GetMinimumMotionTimeThreshold() const;
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.
137 Vector2 GetMinimumMotionDistanceThreshold() const;
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.
149 typedef std::vector< PointInfo > PointInfoContainer;
150 PointInfoContainer mPressedPoints; ///< A container of point and time.
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.
156 } // namespace Integration
160 #endif // __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__