|
1 /* |
|
2 * Copyright (c) 2008-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 the License "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: Gesture class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef _GESTURE_H_ |
|
20 #define _GESTURE_H_ |
|
21 |
|
22 #include <e32base.h> |
|
23 |
|
24 #include "rt_gestureobserver.h" |
|
25 #include "gesturerecogniser.h" |
|
26 #include "pointarray.h" |
|
27 |
|
28 namespace RT_GestureHelper |
|
29 { |
|
30 |
|
31 |
|
32 enum TEventState |
|
33 { |
|
34 ENoEvent = 0, |
|
35 ETouchDown, |
|
36 ETouchUp, |
|
37 EMove, |
|
38 ELongTouchDown |
|
39 }; |
|
40 |
|
41 /** |
|
42 * TGesture represents the gesture that the user has made. |
|
43 * Implements MGestureEvent interface to allow clients to |
|
44 * inspect the gesture |
|
45 */ |
|
46 NONSHARABLE_CLASS( CGesture ) : public CBase |
|
47 { |
|
48 public: |
|
49 /** destructor */ |
|
50 ~CGesture(); |
|
51 |
|
52 /** |
|
53 * @return a new gesture that will have only the first point |
|
54 * of this gesture. Can be used to create gesture's a "start" event |
|
55 * after some other points have been received. |
|
56 */ |
|
57 CGesture* AsStartEventLC() const; |
|
58 |
|
59 /** |
|
60 * Sets the gesture as empty. resets timers to receive points |
|
61 * immediately |
|
62 */ |
|
63 void Reset(); |
|
64 |
|
65 /** @return ETrue if the gesture has no points */ |
|
66 TBool IsEmpty() const; |
|
67 |
|
68 /** |
|
69 * Add a point to the sequence of points that forms the gesture |
|
70 * Call Reset() just before adding the first point |
|
71 * @param aPoint the point to add |
|
72 * @return error code |
|
73 */ |
|
74 TInt AddPoint( const TPoint& aPoint, const TTime& eventtime); |
|
75 |
|
76 /** Set the visual of this gesture. Should be called when gesture starts */ |
|
77 |
|
78 /** @return ETrue if the point is very near the holding point */ |
|
79 TBool IsNearHoldingPoint( const TPoint& aPoint ) const; |
|
80 /** Set the latest point as the holding point */ |
|
81 void SetHoldingPoint(); |
|
82 /** @return ETrue if aPoint is the same as point added last */ |
|
83 TBool IsLatestPoint( const TPoint& aPoint ) const; |
|
84 |
|
85 /** |
|
86 * After call, Code(...) will return appropriate holding gesture code. |
|
87 */ |
|
88 void StartHolding(); |
|
89 /** |
|
90 * After call, Code(...) will return a "hold released" gesture code when |
|
91 * the gesture is completed. Meanwhile, code will be drag. |
|
92 */ |
|
93 void ContinueHolding(); |
|
94 /** Set as stylus released */ |
|
95 void SetReleased(); |
|
96 /** Set the gesture as complete. Gesture is completed at pointer up */ |
|
97 void SetComplete(); |
|
98 /** After call, Code(...) will return a "cancelled" gesture code */ |
|
99 void SetCancelled(); |
|
100 |
|
101 /** force returning a code as double tap when gesture is complete */ |
|
102 void SetDoubleTap(); |
|
103 |
|
104 /** |
|
105 * @return Whether the current gesture is a tap (and hence not a swipe) |
|
106 * Does not consider holding or other state information (such as |
|
107 * whether the gesture was just started or is dragging). |
|
108 * Results are based purely on the current stream of points. |
|
109 */ |
|
110 TBool IsTap() const; |
|
111 |
|
112 void SetLongTap(TBool aLongTap); |
|
113 |
|
114 // From MGestureEvent |
|
115 TTime TimeOfLastEntry() const; |
|
116 inline TGestureCode PreviousGestureCode() { return iPrevGestureCode; }; |
|
117 TGestureCode Code( TAxis aRelevantAxis ); |
|
118 TBool IsHolding() const; |
|
119 TPoint StartPos() const; |
|
120 TPoint CurrentPos() const; |
|
121 TRealPoint Speed() const; |
|
122 TRealPoint SpeedPercent( const TRect& aEdges ) const; |
|
123 TPoint Distance() const; |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 private: |
|
129 /** @return elapsed time between the latest and previous points */ |
|
130 inline TTimeIntervalMicroSeconds32 TimeFromPreviousPoint() const; |
|
131 |
|
132 /** @return elapsed time between the latest and first points */ |
|
133 inline TTimeIntervalMicroSeconds32 TimeFromStart() const; |
|
134 |
|
135 /** @return ETrue if user has stopped moving the stylus before lifting it */ |
|
136 inline TBool IsMovementStopped() const; |
|
137 |
|
138 /** @return aOffset'th last entry in the list of points */ |
|
139 inline const TPointEntry& NthLastEntry( TInt aOffset ) const; |
|
140 |
|
141 /** @return previous point (may not be exactly the point before last) */ |
|
142 inline const TPointEntry& PreviousEntry() const; |
|
143 |
|
144 /** @return position of point received just before the latest point */ |
|
145 inline TPoint PreviousPos() const; |
|
146 |
|
147 |
|
148 |
|
149 TBool IsFlick() const; |
|
150 private: |
|
151 /// sequence of points that make up the gesture. own. |
|
152 RArray< TPointEntry > iPoints; |
|
153 /// index in iPoints of the point in which user started holding |
|
154 TInt iHoldingPointIndex; |
|
155 |
|
156 /// the different states that indicate whether user has made a holding gesture |
|
157 enum THoldingState |
|
158 { |
|
159 ENotHolding = 0, // before holding activated (i.e., holding not activated) |
|
160 EHoldStarting, // holding activated just now (lasts just one callback round) |
|
161 EHolding // holding activated earlier |
|
162 }; |
|
163 |
|
164 /// state that indicates is user has held the pointer down in one position |
|
165 /// for long time to indicate a holding gesture |
|
166 THoldingState iHoldingState; |
|
167 |
|
168 /// Whether the gesture completion code will be forcefully overridden to be double tap, |
|
169 /// regardless of what the points are |
|
170 TBool iIsDoubleTap; |
|
171 |
|
172 enum TCompletionState |
|
173 { |
|
174 // Note: implementation assumes this order of enums |
|
175 ENotComplete = 0, |
|
176 ECancelled, |
|
177 EComplete, |
|
178 EReleased |
|
179 }; |
|
180 /// gesture only becomes complete when user lifts the pointer |
|
181 TCompletionState iState; |
|
182 |
|
183 /// time when the stylus was lifted. |
|
184 TTime iCompletionTime; |
|
185 |
|
186 /// visual relevant to this gesture. null if not known. |
|
187 |
|
188 TGestureCode iPrevGestureCode; |
|
189 |
|
190 TBool iIsLongTap; |
|
191 TBool iIsStopFlick; |
|
192 }; |
|
193 |
|
194 } // namespace GestureHelper |
|
195 |
|
196 #endif // _GESTURE_H_ |