|
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: Juha Kauppinen, Mika Hokkanen |
|
13 * |
|
14 * Description: Photo Browser |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef GESTURE_H |
|
19 #define GESTURE_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <w32std.h> |
|
25 |
|
26 #undef CURSOR_SIMULATION |
|
27 |
|
28 const TInt KDefaultThresholdOfTapPixels = 25; |
|
29 const TInt KDefaultThresholdOfCursorPixels = 0; // Any movement is cursor movement |
|
30 const TInt KDefaultStationaryTime = 100000; // 100ms |
|
31 const TInt KDefaultLongTapTime = 400000; // 300ms = 200ms + stationary (100ms) |
|
32 const TInt KDefaultMonitoringTime = 200000; // 200ms |
|
33 const TInt KDefaultSafetyTime = 200000; // 200ms |
|
34 const TInt KDefaultValidityTimeOfFlick = 300000; // recent 300ms drag to be checked |
|
35 |
|
36 enum { |
|
37 EGestureNone = 0x0000, |
|
38 EGestureStationary = 0x0001, // Send on moved event when user hasn't moved finger |
|
39 EGestureDrag = 0x0002, |
|
40 EGestureTap = 0x0004, |
|
41 EGestureLongTapping = 0x0008, |
|
42 EGestureLongTap = 0x0010, |
|
43 EGestureCursor = 0x0100, |
|
44 // sub-type for cursor simuation |
|
45 EGestureUp = 0x1000, |
|
46 EGestureDown = 0x2000, |
|
47 EGestureLeft = 0x4000, |
|
48 EGestureRight = 0x8000, |
|
49 // 1st gesture type is stored in high 16 bits |
|
50 EGestureDragged = EGestureDrag << 16, |
|
51 EGestureTapped = EGestureTap << 16, |
|
52 EGestureLongTapped = EGestureLongTap << 16 |
|
53 }; |
|
54 // Gestures can be combination |
|
55 typedef TUint32 TGestureType; |
|
56 |
|
57 #define IS_GESTURE_NONE(t) ((t) == (EGestureNone)) |
|
58 #define IS_GESTURE_DRAG(t) ((t) & (EGestureDrag)) |
|
59 #define IS_GESTURE_STATIONARY(t) ((t) & (EGestureStationary)) |
|
60 #define IS_GESTURE_CURSORSIMULATION(t) ((t) & ((EGestureUp | EGestureDown | EGestureLeft | EGestureRight))) |
|
61 #define IS_GESTURE_TAP(t) ((t) & (EGestureTap)) |
|
62 #define IS_GESTURE_TAPPED(t) ((t) & (EGestureTapped)) |
|
63 #define IS_GESTURE_LONGTAPPING(t) ((t) & (EGestureLongTapping)) |
|
64 #define IS_GESTURE_LONGTAP(t) ((t) & (EGestureLongTap)) |
|
65 #define IS_GESTURE_DRAGGED(t) ((t) & (EGestureDragged)) |
|
66 #define IS_GESTURE_SINGLETAP(t) (IS_GESTURE_TAP(t) && !IS_GESTURE_TAPPED(t)) |
|
67 #define IS_GESTURE_DOUBLETAP(t) (IS_GESTURE_TAP(t) && IS_GESTURE_TAPPED(t)) |
|
68 #define IS_GESTURE_TAPnDRAG(t) (IS_GESTURE_CURSORSIMULATION(t) && IS_GESTURE_TAPPED(t)) |
|
69 |
|
70 enum { |
|
71 EGestureModeNone = 0x00, |
|
72 EGestureModeCursorEmulation = 0x01, // gives cursor movements when beyond threshold |
|
73 EGestureModeSingleCursorEmulation = 0x02, // gives singles cursor movement on each touch |
|
74 EGestureModeDrag = 0x04, // |
|
75 EGestureModeTap = 0x08, |
|
76 EGestureModeTapAndDrag = 0x10, |
|
77 EGestureModeDrawCircle = 0x20 |
|
78 }; |
|
79 |
|
80 // CLASS DECLARATION |
|
81 |
|
82 class MGestureCallBack |
|
83 { |
|
84 public: |
|
85 /** |
|
86 * Callback method. Get's called when touch gesture started (when user touches). |
|
87 * @param aPos Point where touch happens |
|
88 * @param aType Gesture type bit flag (move_right/left/up/down or tap) |
|
89 */ |
|
90 |
|
91 // Called when user touches screen |
|
92 virtual void HandleGestureBeganL(const TPoint& aPos ) = 0; |
|
93 |
|
94 // Called when user is dragging |
|
95 // Drag event comes with movement delta from previous event (EGestureDrag) |
|
96 // Drag event comes with touched position (EGestureUp/Down/Left/Right) |
|
97 // when it exceeds defined threshold |
|
98 virtual void HandleGestureMovedL(const TPoint& aPos, |
|
99 const TGestureType aType) = 0; |
|
100 |
|
101 // Called when user releases screen |
|
102 // Movement within defined last moment is given in aPos. (pixels/250ms by default) |
|
103 virtual void HandleGestureEndedL(const TPoint& aPos, |
|
104 const TGestureType aType) = 0; |
|
105 }; |
|
106 |
|
107 /** |
|
108 * CGesture |
|
109 * |
|
110 */ |
|
111 class CGesture : public CTimer |
|
112 { |
|
113 public: |
|
114 // Constructors and destructor |
|
115 |
|
116 /** |
|
117 * Destructor. |
|
118 */ |
|
119 ~CGesture(); |
|
120 |
|
121 /** |
|
122 * Two-phased constructor. |
|
123 */ |
|
124 static CGesture* NewL(MGestureCallBack* aOwner); |
|
125 |
|
126 /** |
|
127 * Two-phased constructor. |
|
128 */ |
|
129 static CGesture* NewLC(MGestureCallBack* aOwner); |
|
130 |
|
131 private: |
|
132 |
|
133 /** |
|
134 * Constructor for performing 1st stage construction |
|
135 */ |
|
136 CGesture(MGestureCallBack* aOwner); |
|
137 |
|
138 /** |
|
139 * EPOC default constructor for performing 2nd stage construction |
|
140 */ |
|
141 void ConstructL(); |
|
142 |
|
143 public: // New functions |
|
144 |
|
145 IMPORT_C void PointerEventL(const TPointerEvent& aEvent); |
|
146 IMPORT_C void SetThresholdOfTap(const TInt aPixels); |
|
147 IMPORT_C void SetThresholdOfCursor(const TInt aPixels); |
|
148 IMPORT_C void SetStationaryTime(const TInt aMicroseconds); |
|
149 IMPORT_C void SetLongTapTime(const TInt aMicroSeconds); |
|
150 IMPORT_C void SetMonitoringTime(const TInt aMicroseconds); |
|
151 IMPORT_C void SetSafetyTime(const TInt aMicroseconds); |
|
152 |
|
153 private: |
|
154 |
|
155 enum TGestureState |
|
156 { |
|
157 EWaiting, // Waiting for first touch |
|
158 EBegan, // Touch down. Gesture started (or second gesture) |
|
159 EStationary, // Gesture is stationary |
|
160 ETravelling, // Dragging beyond threshold |
|
161 EMonitoring, // Monitoring second gesture |
|
162 EEnded // Touch operation ended. Wait to avoid mis touch |
|
163 }; |
|
164 |
|
165 /** |
|
166 * Just check if the movement exceeds thoreshold |
|
167 */ |
|
168 TBool IsMovementWithinThreshold(const TPoint aDelta, const TInt aThreshold); |
|
169 |
|
170 /** |
|
171 * Map touch movement to 8-directions if volume of movement exceeds threshold |
|
172 * Also check if movement is faster than threshold |
|
173 */ |
|
174 TGestureType CheckMovement(const TPoint aPointPrevious, const TPoint aPointCurrent, const TBool aSkipThresholdCheck=EFalse); |
|
175 |
|
176 /** |
|
177 * Maps touch movements in last defines time, aValidityTime, to 8-directions |
|
178 * Movements are recorded in iDragPoints and iDragTicks (RArray of TPoint and TInt) |
|
179 */ |
|
180 TGestureType CheckFlick(const TInt aValidityTime, TPoint& aVector); |
|
181 |
|
182 /** |
|
183 * Active object callback. Used for timer |
|
184 */ |
|
185 void RunL(); |
|
186 |
|
187 private: // Data |
|
188 |
|
189 /** |
|
190 * Current state of Gesture |
|
191 */ |
|
192 TGestureState iState; |
|
193 |
|
194 /** |
|
195 * Pointer to owner |
|
196 */ |
|
197 MGestureCallBack* iOwner; |
|
198 |
|
199 /** |
|
200 * Pointer event received from owner. |
|
201 */ |
|
202 TPointerEvent iPointerEvent; |
|
203 |
|
204 /** |
|
205 * Point records |
|
206 */ |
|
207 TPoint iPointBegan; // point where user touched down |
|
208 TPoint iPointFirstBegan; // point where user touched down in 1st gesture |
|
209 TPoint iPointLastCursor; // point where last cursor simulation event occured |
|
210 TPoint iPointPreviousEvent; // last point where avkon informed on drag |
|
211 |
|
212 /** |
|
213 * Remembers gesture in 1st gesture |
|
214 */ |
|
215 TGestureType iFirstGesture; |
|
216 |
|
217 /** |
|
218 * Thresholds in Pixels |
|
219 */ |
|
220 TInt iThresholdOfTap; // movement stays within this pixels |
|
221 TInt iThresholdOfCursor; // cursor simulation occurs when exceeding threshold |
|
222 |
|
223 /** |
|
224 * Thresholds in Micro seconds |
|
225 */ |
|
226 TInt iStationaryTime; // UP should occur within the time for Tap |
|
227 TInt iLongTapTime; // for long tap |
|
228 TInt iMonitoringTime; // for 2nd gesture. Notify gesture end if expires |
|
229 TInt iSafetyTime; // Ignores gesture after Ended to avoid mis-touch |
|
230 |
|
231 /** |
|
232 * Drag points and the tick time for flick |
|
233 */ |
|
234 RArray<TPoint> iDragPoints; |
|
235 RArray<TInt> iDragTicks; |
|
236 }; |
|
237 |
|
238 #endif // GESTURE_H |