|
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: Class to store physics related data in forms. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "aknformphysics.h" |
|
22 #include <aknphysics.h> |
|
23 #include <coecntrl.h> |
|
24 #include <coemain.h> |
|
25 #include <eikdpage.h> |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CAknFormPhysics::CAknFormPhysics |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CAknFormPhysics::CAknFormPhysics( CEikDialogPage& aParent, |
|
35 CAknRecordingGc& aRecordingGc ) : iParent( aParent ), |
|
36 iRecordingGc( aRecordingGc ) |
|
37 { |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CAknFormPhysics::ConstructL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CAknFormPhysics::ConstructL() |
|
46 { |
|
47 iPhysics = CAknPhysics::NewL( *this, &iParent ); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CAknFormPhysics::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CAknFormPhysics* CAknFormPhysics::NewL( CEikDialogPage& aParent, |
|
56 CAknRecordingGc& aRecordingGc ) |
|
57 { |
|
58 CAknFormPhysics* self = new ( ELeave ) CAknFormPhysics( aParent, |
|
59 aRecordingGc ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CAknFormPhysics::~CAknFormPhysics |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CAknFormPhysics::~CAknFormPhysics() |
|
72 { |
|
73 delete iPhysics; |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CAknFormPhysics::InitPhysicsL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CAknFormPhysics::InitPhysicsL( const TSize& aWorldSize, |
|
82 const TSize& aViewSize, const TPoint& aViewCenter ) |
|
83 { |
|
84 iPhysics->InitPhysicsL( aWorldSize, aViewSize, EFalse ); |
|
85 iViewCenter = aViewCenter; |
|
86 iWorldSize = aWorldSize; |
|
87 iViewSize = aViewSize; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CAknFormPhysics::Stop |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CAknFormPhysics::Stop() |
|
96 { |
|
97 iPhysics->StopPhysics(); |
|
98 iPhysics->ResetFriction(); |
|
99 } |
|
100 |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CAknFormPhysics::StartFlick |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 TBool CAknFormPhysics::StartFlick( const TPoint& aLength, |
|
107 const TTime& aStartTime ) |
|
108 { |
|
109 if ( PhysicsAllowed() ) |
|
110 { |
|
111 TPoint drag( aLength ); |
|
112 if ( iPhysics->StartPhysics( drag, aStartTime ) ) |
|
113 { |
|
114 // reset benchmark variables |
|
115 iStartTime.HomeTime(); |
|
116 iFrameCount = 0; |
|
117 return ETrue; |
|
118 } |
|
119 } |
|
120 |
|
121 PhysicEmulationEnded(); |
|
122 return EFalse; |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CAknFormPhysics::HighlightDelay |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CAknFormPhysics::HighlightDelay() const |
|
131 { |
|
132 return iPhysics->HighlightTimeout(); |
|
133 } |
|
134 |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CAknFormPhysics::DragThreshold |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CAknFormPhysics::DragThreshold() const |
|
141 { |
|
142 return iPhysics->DragThreshold(); |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CAknFormPhysics::WorldSize |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 TSize CAknFormPhysics::ViewSize() const |
|
151 { |
|
152 return iViewSize; |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CAknFormPhysics::SetPanningPosition |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CAknFormPhysics::SetPanningPosition( const TPoint& aDelta ) |
|
161 { |
|
162 if ( PhysicsAllowed() && iPhysics ) |
|
163 { |
|
164 iPhysics->RegisterPanningPosition( aDelta ); |
|
165 } |
|
166 } |
|
167 |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CAknFormPhysics::ViewPositionChanged |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CAknFormPhysics::ViewPositionChanged( const TPoint& aNewPosition, |
|
174 TBool aDrawNow, |
|
175 TUint /*aFlags*/ ) |
|
176 { |
|
177 if ( !PhysicsAllowed() ) |
|
178 { |
|
179 return; |
|
180 } |
|
181 TInt fps = 0; |
|
182 iViewCenter = aNewPosition; |
|
183 |
|
184 // benchmark / debug part |
|
185 if ( iFrameCount != -1 ) |
|
186 { |
|
187 ++iFrameCount; |
|
188 TTime now; |
|
189 now.HomeTime(); |
|
190 |
|
191 TInt64 duration = now.MicroSecondsFrom( iStartTime ).Int64(); |
|
192 |
|
193 if ( duration > 0 ) |
|
194 { |
|
195 fps = iFrameCount * 1000000 / duration; |
|
196 } |
|
197 } |
|
198 |
|
199 TBuf<128> msg; |
|
200 msg.Format( _L( "%dfps" ), fps ); |
|
201 |
|
202 iParent.ScrollCacheByPixels( iViewCenter.iY, msg, aDrawNow ); |
|
203 } |
|
204 |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CAknFormPhysics::PhysicEmulationEnded |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CAknFormPhysics::PhysicEmulationEnded() |
|
211 { |
|
212 iParent.Synchronize(); |
|
213 iFrameCount = -1; |
|
214 } |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CAknFormPhysics::ViewPosition |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 TPoint CAknFormPhysics::ViewPosition() const |
|
222 { |
|
223 return iViewCenter; |
|
224 } |
|
225 |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // CAknFormPhysics::CanBeStopped |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 TBool CAknFormPhysics::CanBeStopped() const |
|
232 { |
|
233 return iPhysics->OngoingPhysicsAction() != |
|
234 CAknPhysics::EAknPhysicsActionBouncing; |
|
235 } |
|
236 |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // CAknFormPhysics::OngoingPhysicsAction |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 TInt CAknFormPhysics::OngoingPhysicsAction() const |
|
243 { |
|
244 return iPhysics->OngoingPhysicsAction(); |
|
245 } |
|
246 |
|
247 /// --------------------------------------------------------------------------- |
|
248 // CAknFormPhysics::ViewTopY |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CAknFormPhysics::ViewTopY() const |
|
252 { |
|
253 return iViewCenter.iY - iParent.Size().iHeight / 2; |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CAknFormPhysics::ViewDistance |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CAknFormPhysics::ViewCenterDistance() const |
|
262 { |
|
263 return iParent.Size().iHeight / 2; |
|
264 } |
|
265 |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CAknFormPhysics::SetViewCenter |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CAknFormPhysics::SetViewCenter( const TPoint& aPosition ) |
|
272 { |
|
273 iViewCenter = aPosition; |
|
274 } |
|
275 |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CAknFormPhysics::ViewCenter |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 TPoint CAknFormPhysics::ViewCenter() const |
|
282 { |
|
283 return iViewCenter; |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CAknFormPhysics::PhysicsAllowed |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 TBool CAknFormPhysics::PhysicsAllowed() const |
|
292 { |
|
293 return ETrue; |
|
294 } |