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: RT Gesture helper interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef _RT_GESTUREOBSERVER_H_ |
|
20 #define _RT_GESTUREOBSERVER_H_ |
|
21 |
|
22 #include <e32std.h> |
|
23 |
|
24 class CAlfControl; |
|
25 class CAlfVisual; |
|
26 |
|
27 namespace RT_GestureHelper |
|
28 { |
|
29 |
|
30 /// flag that indicates gesture code is a holding code |
|
31 /// clients should use MGestureEvent::IsHolding |
|
32 const TInt EFlagHold = 0x10000000; |
|
33 |
|
34 enum TGestureCode |
|
35 { |
|
36 // states |
|
37 EGestureStart = 0x00000001, // gesture just started (user pressed stylus down) |
|
38 EGestureDrag = 0x00000002, // user moved stylus (may be holding or not holding) |
|
39 EGestureReleased = 0x00000003, // user lifted stylus while user was holding |
|
40 // gestures |
|
41 EGestureUnknown = 0x00000005, // gesture was not recognised |
|
42 // these codes are sent when user lifts stylus (if holding not started) |
|
43 EGestureTap = 0x00000006, |
|
44 EGestureDoubleTap = 0x00000007, // only if double tap is enabled |
|
45 // (via CGestureHelper::SetDoubleTapEnabled or |
|
46 // CGestureControl::SetDoubleTapEnabled) |
|
47 EGestureSwipeLeft = 0x00000008, |
|
48 EGestureSwipeRight = 0x00000009, |
|
49 EGestureSwipeUp = 0x0000000A, |
|
50 EGestureSwipeDown = 0x0000000B, |
|
51 |
|
52 EGestureFlick = 0x0000000C, |
|
53 EGestureLongTap = 0x0000000D, |
|
54 EGestureDrop = 0x0000000E, |
|
55 |
|
56 // these codes are sent when user initiates holding by keeping stylus in |
|
57 // same place for a longer duration |
|
58 EGestureHoldLeft = EGestureSwipeLeft | EFlagHold, |
|
59 EGestureHoldRight = EGestureSwipeRight | EFlagHold, |
|
60 EGestureHoldUp = EGestureSwipeUp | EFlagHold, |
|
61 EGestureHoldDown = EGestureSwipeDown | EFlagHold |
|
62 }; |
|
63 |
|
64 /** |
|
65 * Point of float accuracy |
|
66 */ |
|
67 NONSHARABLE_STRUCT( TRealPoint ) |
|
68 { |
|
69 inline TRealPoint(); |
|
70 inline TRealPoint( const TRealPoint& aPoint ); |
|
71 inline TRealPoint( TReal aX, TReal aY ); |
|
72 inline TBool operator==( const TRealPoint& aPoint ) const; |
|
73 |
|
74 TReal32 iX; |
|
75 TReal32 iY; |
|
76 }; |
|
77 |
|
78 /** |
|
79 * a gesture event |
|
80 */ |
|
81 class MGestureEvent |
|
82 { |
|
83 public: |
|
84 /** X and Y axes, or both */ |
|
85 enum TAxis |
|
86 { |
|
87 EAxisBoth, |
|
88 EAxisHorizontal, |
|
89 EAxisVertical |
|
90 }; |
|
91 |
|
92 public: |
|
93 /** |
|
94 * @param aRelevantAxis indicates whether only x, y or both coordinates |
|
95 * should be considered when determining the code. For example, |
|
96 * if client specifies EAxisVertical as relevant axis, a swipe |
|
97 * to left and slightly up would result in an "swipe up" code, |
|
98 * and not "swipe left" code. If client specifies EAxisHorizontal |
|
99 * or EAxisBoth, "swipe left" code is returned. |
|
100 * @return gesture code |
|
101 */ |
|
102 virtual TGestureCode Code( TAxis aRelevantAxis ) /* const */ = 0; |
|
103 |
|
104 /** |
|
105 * @return ETrue if user has activated holding |
|
106 * (by keeping stylus in the same position for longer time) |
|
107 * EFalse if holding has not been activated |
|
108 */ |
|
109 virtual TBool IsHolding() const = 0; |
|
110 |
|
111 /** |
|
112 * @return position where gesture started, i.e., where stulys |
|
113 * was pressed down |
|
114 */ |
|
115 virtual TPoint StartPos() const = 0; |
|
116 |
|
117 /** |
|
118 * @return current position of the stylus |
|
119 */ |
|
120 virtual TPoint CurrentPos() const = 0; |
|
121 |
|
122 /** |
|
123 * @return speed of a swipe. unit is pixels per second. |
|
124 */ |
|
125 virtual TRealPoint Speed() const = 0; |
|
126 |
|
127 /** |
|
128 * Abstracts the algorithm to calculate speed during swipe and hold. This |
|
129 * algorithm (currently) assumes that max speed is achieved at the edges of an |
|
130 * area. |
|
131 * @param aEdges represents the coordinates of the rectange on which speed is |
|
132 * calculated. Speed will reach maximum if stylus is on the edge |
|
133 * or beyond the rect. In practise, the value should match the |
|
134 * area of the layout that contains the scrollable visuals. |
|
135 * For example, if the control area is the whole screen, the |
|
136 * rect should be the screen rect. |
|
137 * @returns the speed as a percentage between -100% and 100% |
|
138 */ |
|
139 virtual TRealPoint SpeedPercent( const TRect& aEdges ) const = 0; |
|
140 |
|
141 /** |
|
142 * @return Length of gesture from starting position |
|
143 * (start pos - current pos) |
|
144 */ |
|
145 virtual TPoint Distance() const = 0; |
|
146 |
|
147 /** |
|
148 * @return visual on which the gesture started |
|
149 * NULL if not known (e.g., AVKON-based client |
|
150 */ |
|
151 virtual CAlfVisual* Visual() const = 0; |
|
152 }; |
|
153 |
|
154 /** |
|
155 * Observer that will be notified when user makes gestures |
|
156 */ |
|
157 class MGestureObserver |
|
158 { |
|
159 public: |
|
160 /** |
|
161 * Handle the gesture event |
|
162 * @param aEvent event describing the gesture |
|
163 */ |
|
164 virtual void HandleGestureL( const MGestureEvent& aEvent ) = 0; |
|
165 }; |
|
166 |
|
167 /** |
|
168 * static class for finding a visual from a visual tree |
|
169 */ |
|
170 class HitTest |
|
171 { |
|
172 public: |
|
173 /** |
|
174 * @return the leaf-most visual is under aPos, or NULL if not found |
|
175 */ |
|
176 IMPORT_C static CAlfVisual* VisualByCoordinates( const CAlfControl& aControl, |
|
177 const TPoint& aPos ); |
|
178 }; |
|
179 |
|
180 // ---------------------------------------------------------------------------- |
|
181 // Default constructor for real point |
|
182 // ---------------------------------------------------------------------------- |
|
183 // |
|
184 inline TRealPoint::TRealPoint() |
|
185 : iX( 0 ), iY( 0 ) |
|
186 { |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // Copy constructor for real point |
|
191 // ---------------------------------------------------------------------------- |
|
192 // |
|
193 inline TRealPoint::TRealPoint( const TRealPoint& aPoint ) |
|
194 : iX( aPoint.iX ), iY( aPoint.iY ) |
|
195 { |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // Copy constructor for real point |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 inline TRealPoint::TRealPoint( TReal aX, TReal aY ) |
|
203 : iX( aX ), iY( aY ) |
|
204 { |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // Default constructor for real point |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 inline TBool TRealPoint::operator==( const TRealPoint& aPoint ) const |
|
212 { |
|
213 return iX == aPoint.iX && iY == aPoint.iY; |
|
214 } |
|
215 |
|
216 |
|
217 } // namespace RT_GestureHelper |
|
218 |
|
219 #endif // _RT_GESTUREOBSERVER_H_ |
|