76 }; |
72 }; |
77 |
73 |
78 /** |
74 /** |
79 * a gesture event |
75 * a gesture event |
80 */ |
76 */ |
81 class MGestureEvent |
77 |
|
78 enum TAxis |
82 { |
79 { |
83 public: |
80 EAxisBoth, |
84 /** X and Y axes, or both */ |
81 EAxisHorizontal, |
85 enum TAxis |
82 EAxisVertical |
86 { |
83 }; |
87 EAxisBoth, |
|
88 EAxisHorizontal, |
|
89 EAxisVertical |
|
90 }; |
|
91 |
84 |
92 public: |
85 |
93 /** |
86 class TGestureEvent |
94 * @param aRelevantAxis indicates whether only x, y or both coordinates |
87 { |
95 * should be considered when determining the code. For example, |
88 public: |
96 * if client specifies EAxisVertical as relevant axis, a swipe |
89 inline TGestureCode Code( TAxis /*aRelevantAxis*/ ) const { return iCode; }; |
97 * to left and slightly up would result in an "swipe up" code, |
90 inline TBool IsHolding() const { return iIsHolding; }; |
98 * and not "swipe left" code. If client specifies EAxisHorizontal |
91 inline TPoint StartPos() const { return iStartPos; }; |
99 * or EAxisBoth, "swipe left" code is returned. |
92 inline TPoint CurrentPos() const { return iCurrPos; }; |
100 * @return gesture code |
93 inline TRealPoint Speed() const { return iSpeed; }; |
101 */ |
94 inline TRealPoint SpeedPercent ( const TRect& /*aEdges*/ ) const { return iSpeedPercent; }; |
102 virtual TGestureCode Code( TAxis aRelevantAxis ) /* const */ = 0; |
95 inline TPoint Distance() const { return iDistance; }; |
103 |
96 |
104 /** |
97 inline void SetCurrentPos(TPoint aPos) { iCurrPos = aPos; }; |
105 * @return ETrue if user has activated holding |
98 inline void SetStartPos(TPoint aPos) {iStartPos = aPos; }; |
106 * (by keeping stylus in the same position for longer time) |
99 inline void SetCode(TGestureCode aCode) {iCode = aCode; }; |
107 * EFalse if holding has not been activated |
100 inline void SetSpeed(TRealPoint aSpeed) { iSpeed = aSpeed; }; |
108 */ |
101 inline void SetDistance(TPoint aDistance) { iDistance = aDistance; }; |
109 virtual TBool IsHolding() const = 0; |
102 inline void SetSpeedPercent(TRealPoint aSpeedPercent) { iSpeedPercent = aSpeedPercent; }; |
110 |
103 |
111 /** |
104 inline void SetIsHolding(TBool aIsHolding) { iIsHolding = aIsHolding; }; |
112 * @return position where gesture started, i.e., where stulys |
|
113 * was pressed down |
|
114 */ |
|
115 virtual TPoint StartPos() const = 0; |
|
116 |
105 |
117 /** |
106 private: |
118 * @return current position of the stylus |
107 TGestureCode iCode; |
119 */ |
108 TBool iIsHolding; |
120 virtual TPoint CurrentPos() const = 0; |
109 TPoint iStartPos; |
121 |
110 TPoint iCurrPos; |
122 /** |
111 TRealPoint iSpeed; |
123 * @return speed of a swipe. unit is pixels per second. |
112 TRealPoint iSpeedPercent; |
124 */ |
113 TPoint iDistance; |
125 virtual TRealPoint Speed() const = 0; |
114 }; |
126 |
115 |
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 |
116 |
154 /** |
117 /** |
155 * Observer that will be notified when user makes gestures |
118 * Observer that will be notified when user makes gestures |
156 */ |
119 */ |
157 class MGestureObserver |
120 class MGestureObserver |
159 public: |
122 public: |
160 /** |
123 /** |
161 * Handle the gesture event |
124 * Handle the gesture event |
162 * @param aEvent event describing the gesture |
125 * @param aEvent event describing the gesture |
163 */ |
126 */ |
164 virtual void HandleGestureL( const MGestureEvent& aEvent ) = 0; |
127 virtual void HandleGestureL( const TGestureEvent& aEvent ) = 0; |
165 }; |
128 }; |
166 |
129 |
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 // ---------------------------------------------------------------------------- |
130 // ---------------------------------------------------------------------------- |
181 // Default constructor for real point |
131 // Default constructor for real point |
182 // ---------------------------------------------------------------------------- |
132 // ---------------------------------------------------------------------------- |
183 // |
133 // |
184 inline TRealPoint::TRealPoint() |
134 inline TRealPoint::TRealPoint() |