|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Pinch touch gesture recognizer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef C_AKNTOUCHGESTUREFWPINCHRECOGNIZER_H |
|
19 #define C_AKNTOUCHGESTUREFWPINCHRECOGNIZER_H |
|
20 |
|
21 #include "akntouchgesturefwbaserecognizer.h" |
|
22 |
|
23 namespace AknTouchGestureFw { |
|
24 |
|
25 |
|
26 /** |
|
27 * Pinch touch gesture recognizer. |
|
28 * |
|
29 * @lib akntouchgesturefw |
|
30 * @since S60 v5.2 |
|
31 */ |
|
32 NONSHARABLE_CLASS( CAknTouchGestureFwPinchRecognizer ) |
|
33 : public CAknTouchGestureFwBaseRecognizer |
|
34 { |
|
35 |
|
36 public: |
|
37 |
|
38 /** |
|
39 * Two-phased constructor. |
|
40 * |
|
41 * @param aEngine The gesture recognition engine. |
|
42 */ |
|
43 static CAknTouchGestureFwPinchRecognizer* NewL( |
|
44 CAknTouchGestureFwRecognitionEngine& aEngine ); |
|
45 |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * |
|
49 * @param aEngine The gesture recognition engine. |
|
50 */ |
|
51 static CAknTouchGestureFwPinchRecognizer* NewLC( |
|
52 CAknTouchGestureFwRecognitionEngine& aEngine ); |
|
53 |
|
54 /** |
|
55 * Destructor. |
|
56 */ |
|
57 virtual ~CAknTouchGestureFwPinchRecognizer(); |
|
58 |
|
59 public: // From base class CAknTouchGestureFwBaseRecognizer. |
|
60 |
|
61 /** |
|
62 * Returns the recognizer gesture group. |
|
63 * |
|
64 * @return @c EAknTouchGestureFwGroupPinch |
|
65 */ |
|
66 TAknTouchGestureFwGroup GestureGroup() const; |
|
67 |
|
68 /** |
|
69 * Cancels the gesture recognition. |
|
70 */ |
|
71 void CancelRecognizing(); |
|
72 |
|
73 /** |
|
74 * Handles single pointer event. |
|
75 * |
|
76 * @param aPointerData Pointer event related data. |
|
77 */ |
|
78 void HandleSinglePointerEventL( const TPointerEventData& aPointerData ); |
|
79 |
|
80 /** |
|
81 * Handles multi pointer event. |
|
82 * |
|
83 * @param aPointerData Pointer event related data. |
|
84 * @param aFirstPointerPosition First pointer position. |
|
85 * @param aSecondPointerPosition Second pointer position. |
|
86 */ |
|
87 void HandleMultiPointerEventL( const TPointerEventData& aPointerData, |
|
88 const TPoint& aFirstPointerPosition, |
|
89 const TPoint& aSecondPointerPosition ); |
|
90 |
|
91 private: |
|
92 |
|
93 /** |
|
94 * C++ constructor. |
|
95 * |
|
96 * @param aEngine The gesture recognition engine. |
|
97 */ |
|
98 CAknTouchGestureFwPinchRecognizer( |
|
99 CAknTouchGestureFwRecognitionEngine& aEngine ); |
|
100 |
|
101 /** |
|
102 * Resets recognizer's state. |
|
103 */ |
|
104 void Reset(); |
|
105 |
|
106 /** |
|
107 * Starts multi-touch recognition. |
|
108 * |
|
109 * @param aFirstPointerPos Position of first pointer. |
|
110 * @param aSecondPointerPos Position of second pointer. |
|
111 */ |
|
112 void StartMultiRecognizing( |
|
113 const TPoint& aFirstPointerPos, |
|
114 const TPoint& aSecondPointerPos ); |
|
115 |
|
116 /** |
|
117 * Handles multi-touch recognition cycle. |
|
118 * Called for every drag event when one pointer is down. |
|
119 * |
|
120 * @param aEventTime Time of pointer event. |
|
121 * @param aFirstPointerPos New position of first pointer. |
|
122 * @param aSecondPointerPos New position of second pointer. |
|
123 */ |
|
124 void MultiRecognizeL( |
|
125 const TTime& aEventTime, |
|
126 const TPoint& aFirstPointerPos, |
|
127 const TPoint& aSecondPointerPos ); |
|
128 |
|
129 /** |
|
130 * Completes multi touch recognition. |
|
131 * |
|
132 * @param aEventTime Time of pointer event. |
|
133 */ |
|
134 void CompleteMultiRecognizingL( |
|
135 const TTime& aEventTime ); |
|
136 |
|
137 /** |
|
138 * Asks engine to send pinch event to observer. |
|
139 * |
|
140 * @param aGestureState Pinch gesture state. |
|
141 * @param aMovementDelta delta movement. |
|
142 */ |
|
143 void SendPinchEventL( |
|
144 TAknTouchGestureFwState aGestureState, |
|
145 TInt aMovementDelta ); |
|
146 |
|
147 /** |
|
148 * Returns pinch initial threshold. |
|
149 * |
|
150 * @return Pinch initial threshold. |
|
151 */ |
|
152 TInt PinchInitialThreshold() const; |
|
153 |
|
154 /** |
|
155 * Returns pinch movement threshold. |
|
156 * |
|
157 * @return Pinch movement threshold. |
|
158 */ |
|
159 TInt PinchMovementThreshold() const; |
|
160 |
|
161 /** |
|
162 * Returns pinch direction change sensitivity. |
|
163 * |
|
164 * @return pinch direction change sensitivity. |
|
165 */ |
|
166 TInt PinchDirectionChangeSensitivity() const; |
|
167 |
|
168 /** |
|
169 * Returns pinch direction reset sensitivity. |
|
170 * |
|
171 * @return pinch direction reset sensitivity. |
|
172 */ |
|
173 TInt PinchDirectionResetSensitivity() const; |
|
174 |
|
175 /** |
|
176 * Returns pinch dimension threshold. |
|
177 * |
|
178 * @return pinch dimension threshold. |
|
179 */ |
|
180 TInt PinchDimensionThreshold() const; |
|
181 |
|
182 /** |
|
183 * Returns pinch maximum confirmation duration. |
|
184 * |
|
185 * @return pinch maximum confirmation duration. |
|
186 */ |
|
187 TInt PinchMaximumConfirmationDuration() const; |
|
188 |
|
189 /** |
|
190 * Calculates bounding rect so that both aPoint1 and aPoint2 are inside |
|
191 * the rectangle. |
|
192 * |
|
193 * @param aPoint1 First position. |
|
194 * @param aPoint2 Second position. |
|
195 * @return Bounding rect. |
|
196 */ |
|
197 static TRect CalculateBoundingRect( |
|
198 const TPoint& aPoint1, |
|
199 const TPoint& aPoint2 ); |
|
200 |
|
201 /** |
|
202 * Snaps aValue to aReference if they are sufficiently close |
|
203 * (defined by aMargin). |
|
204 * |
|
205 * @param aValue Value to be checked. |
|
206 * @param aReference Reference value. |
|
207 * @param aMargin Margin (applied to all directions). |
|
208 */ |
|
209 static void NormalizeValue( TInt& aValue, TInt aReference, TInt aMargin ); |
|
210 |
|
211 /** |
|
212 * Calculates movement value from width & height delta. |
|
213 * |
|
214 * @param aWidthDelta Width delta. |
|
215 * @param aHeightDelta Height delta. |
|
216 * @return movement value, 0 if no movement. |
|
217 */ |
|
218 static TInt CalculateMovement( TInt aWidthDelta, TInt aHeightDelta ); |
|
219 |
|
220 /** |
|
221 * Checks duration threshold. |
|
222 * @param aEventTime Current pointer event time. |
|
223 * @return ETrue if ok, EFalse otherwise. |
|
224 */ |
|
225 TBool CheckDurationThreshold( const TTime& aEventTime ) const; |
|
226 |
|
227 private: // data |
|
228 |
|
229 /** |
|
230 * Boolean flag to indicate whether pinch gesture has been detected. |
|
231 */ |
|
232 TBool iPinchDetected; |
|
233 |
|
234 /** |
|
235 * Current bounding rectangle for pinch. |
|
236 */ |
|
237 TRect iPinchRect; |
|
238 |
|
239 /** |
|
240 * Direction tracer for width. |
|
241 */ |
|
242 TDirectionTracer iPinchWidthTracer; |
|
243 |
|
244 /** |
|
245 * Direction tracer for height. |
|
246 */ |
|
247 TDirectionTracer iPinchHeightTracer; |
|
248 |
|
249 /** |
|
250 * Pinch width direction tracer reset counter. |
|
251 * If height changes repeatedly without any width changes, |
|
252 * then width direction tracer is reset. |
|
253 */ |
|
254 TInt iResetPinchWidthTracer; |
|
255 |
|
256 /** |
|
257 * Pinch height direction tracer reset counter. |
|
258 * If width changes repeatedly without any height changes, |
|
259 * then height direction tracer is reset. |
|
260 */ |
|
261 TInt iResetPinchHeightTracer; |
|
262 |
|
263 /** |
|
264 * Time (from event) when iStoredWidthDelta & iStoredHeightDelta |
|
265 * were updated. |
|
266 */ |
|
267 TTime iStoredTime; |
|
268 |
|
269 /** |
|
270 * Stored width delta value. |
|
271 */ |
|
272 TInt iStoredWidthDelta; |
|
273 |
|
274 /** |
|
275 * Stored height delta value. |
|
276 */ |
|
277 TInt iStoredHeightDelta; |
|
278 |
|
279 /** |
|
280 * ETrue if continuous feedback ongoing. |
|
281 */ |
|
282 TBool iContinuousFeedback; |
|
283 |
|
284 }; |
|
285 |
|
286 } // namespace AknTouchGestureFw |
|
287 |
|
288 #endif // C_AKNTOUCHGESTUREFWPINCHRECOGNIZER_H |