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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/events/touch-point.h>
24 #include <dali/public-api/math/vector2.h>
26 namespace Dali DALI_IMPORT_API
35 * Dali::Integration::TouchEventCombiner is a utility class, an instance of which, should be created
36 * upon initialisation. It accepts single Point(s) containing information about a touch area and
37 * creates a TouchEvent combining the latest event's information with previous TouchPoint(s).
39 * The created TouchEvent can then be sent to the Dali Core as indicated by the GetNextTouchEvent()
42 * The TouchEventCombiner ensures that the following rules are also adhered to:
43 * - If two Down events are accidentally received, then the second one is ignored.
44 * - Motion events are not processed if a Down event does not precede it.
45 * - Motion event throttling is carried out to satisfy the minimum distance and time delta required.
46 * - If an interrupted event is received, then any stored Point history is cleared.
48 class TouchEventCombiner
53 * Default Constructor.
54 * @note The default minimum motion time is 1 ms between motion events and the default behaviour
55 * is to throttle X and Y movement by 1.
60 * Construction with parameters.
61 * @param[in] minMotionTime The minimum time (in ms) that should occur between motion events.
62 * @param[in] minMotionXDistance The minimum distance a finger has to be moved between horizontal motion events.
63 * @param[in] minMotionYDistance The minimum distance a finger has to be moved between vertical motion events.
64 * @note Will assert if any of the parameters is negative.
66 TouchEventCombiner( unsigned long minMotionTime, float minMotionXDistance, float minMotionYDistance );
69 * Construction with parameters.
70 * @param[in] minMotionTime The minimum time (in ms) that should occur between motion events.
71 * @param[in] minMotionDistance A Vector2 representing the minimum distance a finger has to be moved between horizontal and vertical motion events.
72 * @note Will assert if any of the parameters is negative.
74 TouchEventCombiner( unsigned long minMotionTime, Vector2 minMotionDistance );
77 * Non virtual destructor
79 ~TouchEventCombiner();
84 * Allows the caller to pass in a point which is processed and the TouchEvent is appropriately filled with the new,
85 * and previously stored Point information.
87 * @note If the thresholds set have not been passed, then false is returned and the TouchEvent should not be sent
90 * @param[in] point The new Point.
91 * @param[in] time The time the event occurred.
92 * @param[out] touchEvent This is populated with the correct Point(s) and time information.
94 * @return true if the point is beyond the different thresholds set thus, should be sent to core, false otherwise.
96 bool GetNextTouchEvent( const TouchPoint& point, unsigned long time, TouchEvent& touchEvent );
99 * Sets the minimum time (in ms) that should occur between motion events.
100 * @param[in] minTime Minimum time between motion events.
102 void SetMinimumMotionTimeThreshold( unsigned long minTime );
105 * Sets the minimum distance a finger has to be moved (both X and Y) between motion events.
106 * @param[in] minDistance The minimum distance between motion events.
107 * @note Will assert if parameter is negative.
109 void SetMinimumMotionDistanceThreshold( float minDistance );
112 * Sets the minimum distance a finger has to be moved between motion events.
113 * @param[in] minXDistance The minimum X distance between motion events.
114 * @param[in] minYDistance The minimum Y distance between motion events.
115 * @note Use this method if the X and Y threshold required is different.
116 * @note Will assert if any of the parameters is negative.
118 void SetMinimumMotionDistanceThreshold( float minXDistance, float minYDistance );
121 * Sets the minimum distance a finger has to be moved between motion events.
122 * @param[in] minDistance A Vector2 representing the minimum X and Y thresholds.
123 * @note Use this method if the X and Y threshold required is different.
124 * @note Will assert if any of the parameters is negative.
126 void SetMinimumMotionDistanceThreshold( Vector2 minDistance );
129 * Retrieves the minimum motion time threshold.
130 * @return the minimum time threshold.
132 unsigned long GetMinimumMotionTimeThreshold() const;
135 * Gets the minimum distance a finger has to be moved (both X and Y) between motion events.
136 * @return A Vector2 representing the x and y thresholds.
138 Vector2 GetMinimumMotionDistanceThreshold() const;
141 * This resets any information contained by the TouchEventCombiner.
142 * This may be required if some platform event has occurred which makes it necessary to reset any
143 * TouchPoint information that the combiner may store.
150 typedef std::vector< PointInfo > PointInfoContainer;
151 PointInfoContainer mPressedPoints; ///< A container of point and time.
153 unsigned long mMinMotionTime; ///< The minimum time that should elapse before considering a new motion event.
154 Vector2 mMinMotionDistance; ///< The minimum distance in the X and Y direction before considering a new motion event.
157 } // namespace Integration
161 #endif // __DALI_INTEGRATION_TOUCH_EVENT_COMBINER_H__