|
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: AknPhysics drag event observer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <w32std.h> |
|
20 |
|
21 #include "aknphysicsdragobserver.h" |
|
22 #include "aknphysicsflicktracker.h" |
|
23 #include "aknphysicsparameterprovider.h" |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CAknPhysicsDragObserver::NewL |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CAknPhysicsDragObserver* CAknPhysicsDragObserver::NewL( |
|
32 CAknPhysicsParameterProvider* aProvider ) |
|
33 { |
|
34 CAknPhysicsDragObserver* self = |
|
35 CAknPhysicsDragObserver::NewLC( aProvider ); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CAknPhysicsDragObserver::NewLC |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CAknPhysicsDragObserver* CAknPhysicsDragObserver::NewLC( |
|
46 CAknPhysicsParameterProvider* aProvider ) |
|
47 { |
|
48 CAknPhysicsDragObserver* self |
|
49 = new ( ELeave ) CAknPhysicsDragObserver(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aProvider ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CAknPhysicsDragObserver::~CAknPhysicsDragObserver |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CAknPhysicsDragObserver::~CAknPhysicsDragObserver() |
|
61 { |
|
62 delete iVerticalTracker; |
|
63 delete iHorizontalTracker; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CAknPhysicsDragObserver::RegisterEventPosition |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CAknPhysicsDragObserver::RegisterEventPosition( |
|
72 const TPointerEvent* aEvent ) |
|
73 { |
|
74 if ( aEvent->iType == TPointerEvent::EButton1Down || |
|
75 ( !iPointerDown && aEvent->iType == TPointerEvent::EDrag ) ) |
|
76 { |
|
77 HandlePointerDownEvent( aEvent->iPosition ); |
|
78 iPointerDown = ETrue; |
|
79 } |
|
80 else if ( aEvent->iType == TPointerEvent::EDrag ) |
|
81 { |
|
82 HandlePointerDragEvent( aEvent->iPosition ); |
|
83 } |
|
84 else if ( aEvent->iType == TPointerEvent::EButton1Up ) |
|
85 { |
|
86 if ( iPointerDown ) |
|
87 { |
|
88 HandlePointerUpEvent( aEvent->iPosition ); |
|
89 } |
|
90 else |
|
91 { |
|
92 Reset(); |
|
93 } |
|
94 iPointerDown = EFalse; |
|
95 } |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CAknPhysicsDragObserver::ChangedDragDistance |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 TPoint CAknPhysicsDragObserver::ChangedDragDistance() const |
|
104 { |
|
105 TPoint dragDistance; |
|
106 dragDistance.iY = iVerticalTracker->FlickStartCoordinate() - iUpPosition.iY; |
|
107 dragDistance.iX = iHorizontalTracker->FlickStartCoordinate() - iUpPosition.iX; |
|
108 return dragDistance; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CAknPhysicsDragObserver::ChangedVerticalDragMoveTime |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CAknPhysicsDragObserver::ChangedVerticalDragMoveTime() const |
|
117 { |
|
118 if ( iVerticalTracker ) |
|
119 { |
|
120 return iVerticalTracker->FlickMoveTime(); |
|
121 } |
|
122 return 0; |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CAknPhysicsDragObserver::ChangedHorizontalDragMoveTime |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CAknPhysicsDragObserver::ChangedHorizontalDragMoveTime() const |
|
131 { |
|
132 if ( iHorizontalTracker ) |
|
133 { |
|
134 return iHorizontalTracker->FlickMoveTime(); |
|
135 } |
|
136 return 0; |
|
137 } |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CAknPhysicsDragObserver::DragChanged |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CAknPhysicsDragObserver::DragChanged() const |
|
145 { |
|
146 TBool changed( EFalse ); |
|
147 if ( iVerticalTracker ) |
|
148 { |
|
149 changed = iVerticalTracker->FlickStartCoordinate() != iDownPosition.iY; |
|
150 } |
|
151 if ( !changed && iHorizontalTracker ) |
|
152 { |
|
153 changed = iHorizontalTracker->FlickStartCoordinate() != iDownPosition.iX; |
|
154 } |
|
155 return changed; |
|
156 } |
|
157 |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CAknPhysicsDragObserver::CAknPhysicsDragObserver |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 CAknPhysicsDragObserver::CAknPhysicsDragObserver() |
|
164 { |
|
165 } |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CAknPhysicsDragObserver::ConstructL |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CAknPhysicsDragObserver::ConstructL( |
|
173 CAknPhysicsParameterProvider* aProvider ) |
|
174 { |
|
175 iVerticalTracker = CAknPhysicsFlickTracker::NewL( aProvider ); |
|
176 iHorizontalTracker = CAknPhysicsFlickTracker::NewL( aProvider ); |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CAknPhysicsDragObserver::HandlePointerDownEvent |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CAknPhysicsDragObserver::HandlePointerDownEvent( |
|
185 const TPoint& aPosition ) |
|
186 { |
|
187 iDownPosition = aPosition; |
|
188 iUpPosition = TPoint(); |
|
189 iVerticalTracker->InitTracker( aPosition.iY ); |
|
190 iHorizontalTracker->InitTracker( aPosition.iX ); |
|
191 } |
|
192 |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CAknPhysicsDragObserver::HandlePointerDragEvent |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CAknPhysicsDragObserver::HandlePointerDragEvent( |
|
199 const TPoint& aPosition ) |
|
200 { |
|
201 if ( iVerticalTracker ) |
|
202 { |
|
203 iVerticalTracker->DragChanged( aPosition.iY ); |
|
204 } |
|
205 if ( iHorizontalTracker ) |
|
206 { |
|
207 iHorizontalTracker->DragChanged( aPosition.iX ); |
|
208 } |
|
209 } |
|
210 |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CAknPhysicsDragObserver::HandlePointerUpEvent |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CAknPhysicsDragObserver::HandlePointerUpEvent( |
|
217 const TPoint& aPosition ) |
|
218 { |
|
219 HandlePointerDragEvent( aPosition ); |
|
220 iUpPosition = aPosition; |
|
221 } |
|
222 |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CAknPhysicsDragObserver::Reset |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 void CAknPhysicsDragObserver::Reset() |
|
229 { |
|
230 iDownPosition.SetXY( 0, 0 ); |
|
231 iUpPosition.SetXY( 0, 0 ); |
|
232 iVerticalTracker->InitTracker( 0 ); |
|
233 iHorizontalTracker->InitTracker( 0 ); |
|
234 } |
|
235 |