|
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: Touch gesture framework utility functions. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef AKNTOUCHGESTUREFWUTILS_H |
|
19 #define AKNTOUCHGESTUREFWUTILS_H |
|
20 |
|
21 #include <e32math.h> |
|
22 #include <w32std.h> |
|
23 |
|
24 namespace AknTouchGestureFw { |
|
25 |
|
26 class MAknTouchGestureFwEvent; |
|
27 |
|
28 /** |
|
29 * Data structure to hold pointer event related data. |
|
30 */ |
|
31 NONSHARABLE_CLASS( TPointerEventData ) |
|
32 { |
|
33 |
|
34 public: |
|
35 |
|
36 /** |
|
37 * Constructor. |
|
38 * |
|
39 * @param aPointerEvent Pointer event from window server. |
|
40 * @param aPointerNumber Pointer number of the event. |
|
41 * @param aTimeStamp Time stamp of the event. |
|
42 * @param aSimulated @c ETrue if event is simulated. |
|
43 * @param aTargetedToControl @c ETrue if event is targeted to control. |
|
44 */ |
|
45 TPointerEventData( TPointerEvent& aPointerEvent, |
|
46 TInt aPointerNumber, |
|
47 const TTime& aTimeStamp, |
|
48 TBool aSimulated, |
|
49 TBool aTargetedToControl ); |
|
50 |
|
51 /** |
|
52 * Pointer event. |
|
53 */ |
|
54 TPointerEvent& iPointerEvent; |
|
55 |
|
56 /** |
|
57 * Pointer number. |
|
58 */ |
|
59 TInt iPointerNumber; |
|
60 |
|
61 /** |
|
62 * Pointer time stamp. |
|
63 */ |
|
64 TTime iTimeStamp; |
|
65 |
|
66 /** |
|
67 * Indicates wheter event is simulated. |
|
68 */ |
|
69 TBool iSimulated; |
|
70 |
|
71 /** |
|
72 * Indicates wheter event is targeted to control. |
|
73 */ |
|
74 TBool iTargetedToControl; |
|
75 }; |
|
76 |
|
77 |
|
78 /** |
|
79 * Represents a single point given at certain time. |
|
80 * |
|
81 */ |
|
82 NONSHARABLE_CLASS( TPointEntry ) |
|
83 { |
|
84 |
|
85 public: |
|
86 |
|
87 /** |
|
88 * C++ constructor. |
|
89 * |
|
90 * @param aPos Position of the point. |
|
91 * @param aTime Time of the point. |
|
92 */ |
|
93 TPointEntry( const TPoint& aPos, const TTime& aTime ); |
|
94 |
|
95 /** |
|
96 * Default C++ constructor. |
|
97 */ |
|
98 TPointEntry(); |
|
99 |
|
100 /** |
|
101 * Position. |
|
102 */ |
|
103 TPoint iPos; |
|
104 |
|
105 /** |
|
106 * Time. |
|
107 */ |
|
108 TTime iTime; |
|
109 |
|
110 }; |
|
111 |
|
112 |
|
113 /** |
|
114 * Vector class (math) |
|
115 */ |
|
116 NONSHARABLE_CLASS( TVector ) |
|
117 { |
|
118 |
|
119 public: |
|
120 |
|
121 /** |
|
122 * C++ constructor. |
|
123 * |
|
124 * @param aFrom Starting point of the vector. |
|
125 * @param aTo Ending point of the vector. |
|
126 */ |
|
127 TVector( const TPoint& aFrom, const TPoint& aTo ); |
|
128 |
|
129 /** |
|
130 * C++ constructor. |
|
131 * |
|
132 * @param aDeltaX X part of vector. |
|
133 * @param aDeltaY Y part of vector. |
|
134 */ |
|
135 TVector( TReal aDeltaX, TReal aDeltaY ); |
|
136 |
|
137 /** |
|
138 * Default C++ constructor. |
|
139 */ |
|
140 TVector(); |
|
141 |
|
142 /** |
|
143 * Angle of the vector |
|
144 * |
|
145 * @return Angle of the vector. |
|
146 */ |
|
147 TInt Angle() const; |
|
148 |
|
149 /** |
|
150 * Length of the vector |
|
151 * |
|
152 * @return Length of the vector. |
|
153 */ |
|
154 TReal Length() const; |
|
155 |
|
156 private: |
|
157 |
|
158 /** |
|
159 * Radians in degrees. |
|
160 * |
|
161 * @return Radians in degrees. |
|
162 */ |
|
163 static TInt Degrees( TReal aRadians ); |
|
164 |
|
165 public: |
|
166 |
|
167 /** |
|
168 * X coordinate that represent the vector. |
|
169 */ |
|
170 TReal iX; |
|
171 |
|
172 /** |
|
173 * Y coordinate that represent the vector. |
|
174 */ |
|
175 TReal iY; |
|
176 |
|
177 }; |
|
178 |
|
179 |
|
180 /** |
|
181 * Threshold area. |
|
182 */ |
|
183 NONSHARABLE_CLASS( TThresholdArea ) |
|
184 { |
|
185 |
|
186 public: |
|
187 |
|
188 /** |
|
189 * Constructor. |
|
190 */ |
|
191 TThresholdArea(); |
|
192 |
|
193 /** |
|
194 * Resets the threshold area. |
|
195 * After calling this method, this area becomes inactive. |
|
196 */ |
|
197 void Reset(); |
|
198 |
|
199 /** |
|
200 * Returns @c ETrue if threshold area is active. |
|
201 * |
|
202 * @return @c ETrue if active, @c EFalse otherwise. |
|
203 */ |
|
204 TBool IsActive() const; |
|
205 |
|
206 /** |
|
207 * Returns the initial position. |
|
208 * |
|
209 * @return Initial position. |
|
210 */ |
|
211 TPoint InitialPosition() const; |
|
212 |
|
213 /** |
|
214 * Starts threshold checking. |
|
215 * |
|
216 * @param aInitialPosition Initial position against which other |
|
217 * points are checked. |
|
218 */ |
|
219 void Start( const TPoint& aInitialPosition ); |
|
220 |
|
221 /** |
|
222 * Checks if @c aNewPosition is inside threshold area. |
|
223 * |
|
224 * @param aNewPosition New position. |
|
225 * @param aMargin Threshold margin. |
|
226 * |
|
227 * @return True if threshold is crossed, false otherwise. |
|
228 */ |
|
229 TBool Check( const TPoint& aNewPosition, TInt aMargin ) const; |
|
230 |
|
231 // C++ default copy constructor & assignment operator |
|
232 // are sufficient. |
|
233 |
|
234 private: |
|
235 |
|
236 /** |
|
237 * Initial position. |
|
238 */ |
|
239 TPoint iInitialPosition; |
|
240 |
|
241 /** |
|
242 * Boolean flag to indicate whether this area is active. |
|
243 */ |
|
244 TBool iActive; |
|
245 |
|
246 }; |
|
247 |
|
248 |
|
249 /** |
|
250 * Touch gesture framework utility class. |
|
251 * |
|
252 */ |
|
253 NONSHARABLE_CLASS( AknTouchGestureFwUtils ) |
|
254 { |
|
255 |
|
256 public: |
|
257 |
|
258 /** |
|
259 * Dumps pointer event (principal input to this component). |
|
260 * |
|
261 * @param aEvent Event to output. |
|
262 * @param aSimulated @c ETrue if simulated, @c EFalse if from HW. |
|
263 */ |
|
264 static void DumpPointerEvent( const TPointerEvent& aEvent, |
|
265 TBool aSimulated ); |
|
266 |
|
267 /** |
|
268 * Dumps gesture event (principal output from this component). |
|
269 * |
|
270 * @param aEvent Gesture event. |
|
271 */ |
|
272 static void DumpGestureEvent( MAknTouchGestureFwEvent& aEvent ); |
|
273 |
|
274 }; |
|
275 |
|
276 |
|
277 /** |
|
278 * Direction tracer for gestures. |
|
279 */ |
|
280 class TDirectionTracer |
|
281 { |
|
282 public: |
|
283 /** |
|
284 * Enumerates directions. |
|
285 */ |
|
286 enum TDirection |
|
287 { |
|
288 EDirectionNeutral = 0, |
|
289 EDirectionPositive = 1, |
|
290 EDirectionNegative = -1 |
|
291 }; |
|
292 |
|
293 public: |
|
294 |
|
295 /** |
|
296 * Constructor. |
|
297 */ |
|
298 TDirectionTracer(); |
|
299 |
|
300 /** |
|
301 * Resets back to initial constructed state. |
|
302 */ |
|
303 void Reset(); |
|
304 |
|
305 /** |
|
306 * Updates tracer with new value. |
|
307 * @param aDelta change. |
|
308 * @param aSensitivity sensitivity to direction changes. |
|
309 */ |
|
310 void Update( TInt aDelta, TInt aSensitivity ); |
|
311 |
|
312 /** |
|
313 * Checks if direction has changed. |
|
314 * @return true if changed. |
|
315 */ |
|
316 TBool IsDirectionChanged() const; |
|
317 |
|
318 /** |
|
319 * Returns current direction. |
|
320 * @return direction. |
|
321 */ |
|
322 TDirection Direction() const; |
|
323 |
|
324 // Default copy constructor & assignment operator are |
|
325 // sufficient. |
|
326 |
|
327 private: |
|
328 |
|
329 /** |
|
330 * Checks direction change. Helper method for Update. |
|
331 * |
|
332 * @param aDelta change in value. |
|
333 * @param aSensitivity sensitivity. |
|
334 * @param aCounter change counter. |
|
335 */ |
|
336 static TBool CheckDirectionChange( |
|
337 TInt aDelta, TInt aSensitivity, TInt& aCounter ); |
|
338 |
|
339 private: |
|
340 |
|
341 /** |
|
342 * Current direction. |
|
343 */ |
|
344 TDirection iDirection; |
|
345 |
|
346 /** |
|
347 * ETrue if direction changed. |
|
348 */ |
|
349 TBool iDirectionChanged; |
|
350 |
|
351 /** |
|
352 * Change direction. |
|
353 */ |
|
354 TDirection iChangeDirection; |
|
355 |
|
356 /** |
|
357 * Change counter. |
|
358 */ |
|
359 TInt iChangeCounter; |
|
360 |
|
361 }; |
|
362 |
|
363 } // namespace AknTouchGestureFw |
|
364 |
|
365 #endif // AKNTOUCHGESTUREFWUTILS_H |