|
1 /* |
|
2 * Copyright (c) 2008-2008 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: Implementation of member functions of |
|
15 * AlfExAnalogDialerControl. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <coemain.h> |
|
22 |
|
23 // Visuals |
|
24 #include <alf/alfgridlayout.h> |
|
25 #include <alf/alftextvisual.h> |
|
26 #include <alf/alfimagevisual.h> |
|
27 #include <alf/alflinevisual.h> |
|
28 |
|
29 // Layouts |
|
30 #include <alf/alfdecklayout.h> |
|
31 #include <alf/alfcurvepath.h> |
|
32 #include <alf/alfcurvepathlayout.h> |
|
33 |
|
34 // Brushes |
|
35 #include <alf/alfborderbrush.h> |
|
36 #include <alf/alfbrusharray.h> |
|
37 #include <alf/alfimagebrush.h> |
|
38 #include <alf/alfimage.h> |
|
39 #include <alf/alfshadowborderbrush.h> |
|
40 #include <alf/alfgradientbrush.h> |
|
41 |
|
42 // Unsorted |
|
43 #include <aknutils.h> |
|
44 #include <alf/alftransformation.h> |
|
45 #include <alf/alfevent.h> |
|
46 #include <alf/alfdisplay.h> |
|
47 #include <alf/alfenv.h> |
|
48 #include <alf/alfmappingfunctions.h> |
|
49 #include <alf/alfroster.h> |
|
50 |
|
51 #include <e32math.h> |
|
52 |
|
53 #include "alfexanalogdialercontrol.h" |
|
54 #include "alfexanalogdialerfeedback.h" |
|
55 |
|
56 // Image names |
|
57 _LIT(KImageAnalogDialerBackground, "background.png"); |
|
58 _LIT(KImageAnalogDialerNumbers, "numbers.png"); |
|
59 _LIT(KImageAnalogDialerPlate, "plate.png"); |
|
60 _LIT(KImageAnalogDialerStopper, "stopper.png"); |
|
61 |
|
62 #define RADTODEG(Rad) ((180.0 * Rad) / KPi) |
|
63 |
|
64 // font color |
|
65 const TRgb KFontColor = TRgb(192,192,192); |
|
66 |
|
67 // dimension of grid |
|
68 const TInt KDimensionsOfGrid = 2; |
|
69 |
|
70 // Tags for visuals which have always same appearance. |
|
71 // TTagAnalogDialerVisual is used for indexing |
|
72 const char* KTagArray[] = |
|
73 { |
|
74 "root-layout", |
|
75 "display-deck", |
|
76 "display-visual", |
|
77 "plate-deck", |
|
78 "numbers-visual", |
|
79 "plate-visaul", |
|
80 "stopper-visual" |
|
81 }; |
|
82 |
|
83 // Dimensions of grid. iLayoutMode is used for indexing |
|
84 const TInt KRowsAndColumnsOfGrid[][KDimensionsOfGrid] = |
|
85 { |
|
86 { 1, 2 }, // columns, rows |
|
87 { 2, 1 } |
|
88 }; |
|
89 |
|
90 // Template for displaying number |
|
91 _LIT(KNumberDisplayTemplate, "%d"); |
|
92 |
|
93 // Radius of Clear area of plate. Per cents from radius of plate. |
|
94 const TInt KPlateClearRadius = 25; |
|
95 |
|
96 // Unit speed of returning plate to idle position. Degrees per second. |
|
97 const TInt KPlateReturnSpeed = 65; |
|
98 |
|
99 // As dragging events occur very often, redrawing plate is optimised that |
|
100 // it is not drawn after every dragging event. |
|
101 // Plate is redrawn when angle of the plate has changed KPlateDraggingDelta clockwise. |
|
102 const TInt KPlateDraggingDelta = 2; |
|
103 |
|
104 // position of stopper in degrees. Angle is 43 clockwise down from the X-axis |
|
105 const TInt KStopperAngle = 360-43; |
|
106 |
|
107 // angle of arch on which numbers (or holes) are distributed |
|
108 const TInt KPlateNumbersDistributionAngle = 290; |
|
109 |
|
110 // minimum rotation of plate that a number becomes selected. If plate has been dialed |
|
111 // less than or equal to KPlateMinimumRotateAngle degrees, number is not selected. |
|
112 const TInt KPlateMinimumRotateAngle=43; |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // NewL |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 CAlfExAnalogDialerControl* CAlfExAnalogDialerControl::NewL(CAlfEnv& aEnv) |
|
119 { |
|
120 CAlfExAnalogDialerControl* self = CAlfExAnalogDialerControl::NewLC(aEnv); |
|
121 CleanupStack::Pop(self); |
|
122 return self; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // NewLC |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 CAlfExAnalogDialerControl* CAlfExAnalogDialerControl::NewLC(CAlfEnv& aEnv) |
|
130 { |
|
131 CAlfExAnalogDialerControl* self = new (ELeave) CAlfExAnalogDialerControl(); |
|
132 CleanupStack::PushL(self); |
|
133 self->ConstructL(aEnv); |
|
134 return self; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // ~CAlfExAnalogDialerControl |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 CAlfExAnalogDialerControl::~CAlfExAnalogDialerControl() |
|
142 { |
|
143 // Remove observer is still there |
|
144 if (iFlags & EAnalogDialerControlFlagLongTapRegistered) |
|
145 { |
|
146 Display()->Roster().RemovePointerEventObserver(EAlfPointerEventReportLongTap, *this); |
|
147 } |
|
148 Env().CancelCommands(this); |
|
149 delete iFeedback; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CAlfExAnalogDialerControl |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 CAlfExAnalogDialerControl::CAlfExAnalogDialerControl() |
|
157 : CAlfControl() |
|
158 { |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // ConstructL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CAlfExAnalogDialerControl::ConstructL(CAlfEnv& aEnv) |
|
166 { |
|
167 CAlfControl::ConstructL(aEnv); |
|
168 // Id cannot be be set in constructor. Id is needed in appui to retrieve control from control group |
|
169 SetId(KAlfExAnalogDialerControlId); |
|
170 |
|
171 // resolve layout: portrait or landscape |
|
172 iLayoutMode = ResolveLayout(iSquareSide, iLongerSide); |
|
173 |
|
174 // setup visuals accroding to layout |
|
175 (iLayoutMode == ELayoutAnalogDialerPortrait) ? SetupPortraitModeL() : SetupLandscapeModeL(); |
|
176 |
|
177 // set up vibra system |
|
178 iFeedback = CAlfExAnalogDialerFeedback::NewL(); |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // Creates layouts and visual for portrait layout |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CAlfExAnalogDialerControl::SetupPortraitModeL() |
|
188 { |
|
189 // Setup grid (root layout) |
|
190 AddGridLayoutL(); |
|
191 |
|
192 // from top to bottom 1) display pane 2) dialer |
|
193 AddDisplayPaneL(); |
|
194 AddDialerL(); |
|
195 |
|
196 //AddEffectLayout(); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // Creates layouts and visual for portrait layout |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CAlfExAnalogDialerControl::SetupLandscapeModeL() |
|
204 { |
|
205 // Setup grid (root layout) |
|
206 AddGridLayoutL(); |
|
207 |
|
208 // from left to right 1) dialer 2) display pane |
|
209 AddDialerL(); |
|
210 AddDisplayPaneL(); |
|
211 |
|
212 //AddEffectLayout(); |
|
213 } |
|
214 |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // Creates grid layout or modify existing one after layout change |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void CAlfExAnalogDialerControl::AddGridLayoutL() |
|
221 { |
|
222 if (!iRootLayout) |
|
223 { |
|
224 // Fresh start of the application. Create a grid layout to act as the root layout visual. |
|
225 iRootLayout = CAlfGridLayout::AddNewL(*this, |
|
226 KRowsAndColumnsOfGrid[iLayoutMode][EAlfGridColumn], |
|
227 KRowsAndColumnsOfGrid[iLayoutMode][EAlfGridRow]); |
|
228 // Tag is not really needed, because root layout assigned to member variable |
|
229 iRootLayout->SetTagL(_L8(KTagArray[ETagAnalogDialerRootLayout])); |
|
230 |
|
231 // Brushed must enabled before they can be used |
|
232 iRootLayout->EnableBrushesL(); |
|
233 |
|
234 // Background image is implemented using image brush |
|
235 CAlfTexture& backgroundTexture = Env().TextureManager().LoadTextureL( |
|
236 KImageAnalogDialerBackground, |
|
237 EAlfTextureFlagDefault, |
|
238 KAlfAutoGeneratedTextureId); |
|
239 // Default scale mode CAlfImageVisual::EScaleFit is OK |
|
240 CAlfImageBrush* brush = CAlfImageBrush::NewLC(Env(), TAlfImage(backgroundTexture)); |
|
241 |
|
242 // sets background image behind the visual |
|
243 brush->SetLayer(EAlfBrushLayerBackground); |
|
244 |
|
245 // Append brush to the layout and transfer its ownership to the visual. |
|
246 iRootLayout->Brushes()->AppendL(brush, EAlfHasOwnership); |
|
247 CleanupStack::Pop(brush); |
|
248 } |
|
249 else |
|
250 { |
|
251 // Layout change has taken place. Modify dimensions and weights |
|
252 // Reset current dimension |
|
253 for(TInt i=0; i<KDimensionsOfGrid; i++) |
|
254 { |
|
255 // resetting non existing weights causes Leave |
|
256 TRAP_IGNORE(iRootLayout->RemoveWeightL(EAlfGridColumn, i)); |
|
257 TRAP_IGNORE(iRootLayout->RemoveWeightL(EAlfGridRow, i)); |
|
258 } |
|
259 // now set up new dimension |
|
260 iRootLayout->SetColumnsL(KRowsAndColumnsOfGrid[iLayoutMode][EAlfGridColumn]); |
|
261 iRootLayout->SetRowsL(KRowsAndColumnsOfGrid[iLayoutMode][EAlfGridRow]); |
|
262 } |
|
263 |
|
264 // Sets weights of grid |
|
265 SetWeightsOfGridL(*iRootLayout, |
|
266 iLayoutMode, |
|
267 iSquareSide, |
|
268 iLongerSide, |
|
269 iPlateTopOffset); |
|
270 |
|
271 // Set the padding of the root layout |
|
272 |
|
273 // TODO: Padding disabled for now. This seems to mess the angle calculations as we the calculations do not consider |
|
274 // the effect of padding. |
|
275 |
|
276 /* |
|
277 TRect displayRect = Env().PrimaryDisplay().VisibleArea(); |
|
278 TInt pad = displayRect.Height(); |
|
279 if ( iLayoutMode == ELayoutAnalogDialerLandscape ) |
|
280 { |
|
281 pad = displayRect.Width(); |
|
282 } |
|
283 layout->SetInnerPadding(TPoint( |
|
284 pad * KPaddingExtents[iLayoutMode][EAlfGridColumn], |
|
285 pad * KPaddingExtents[iLayoutMode][EAlfGridRow])); |
|
286 layout->SetPadding(pad * KPaddingPercentage);*/ |
|
287 } |
|
288 |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // Adds content into display pane of the application |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void CAlfExAnalogDialerControl::AddDisplayPaneL() |
|
295 { |
|
296 CAlfDeckLayout* displayDeck = CAlfDeckLayout::AddNewL(*this, iRootLayout); |
|
297 displayDeck->SetTagL(_L8( KTagArray[ETagAnalogDialerDisplayDeck])); |
|
298 |
|
299 // Add TextVisual number display |
|
300 iDisplayPane = CAlfTextVisual::AddNewL(*this, displayDeck ); |
|
301 // Tag is not really needed |
|
302 iDisplayPane->SetTagL(_L8( KTagArray[ETagAnalogDialerDisplayVisual])); |
|
303 iDisplayPane->SetAlign(EAlfAlignHRight, EAlfAlignVCenter); |
|
304 |
|
305 /*iDisplayPane->SetFlag(EAlfVisualFlagManualLayout); |
|
306 |
|
307 // Decoration |
|
308 if (iLayoutMode == ELayoutAnalogDialerPortrait) |
|
309 { |
|
310 iDisplayPane->SetCenteredPosAndSize(TPoint(180,100),TSize(300,50)); |
|
311 } |
|
312 else |
|
313 { |
|
314 iDisplayPane->SetCenteredPosAndSize(TPoint(150,180),TSize(200,300)); |
|
315 }*/ |
|
316 iDisplayPane->SetStyle(EAlfTextStyleTitle); |
|
317 iDisplayPane->SetColor(KFontColor); |
|
318 |
|
319 |
|
320 // Enable brushed for borders etc |
|
321 iDisplayPane->EnableBrushesL(); |
|
322 |
|
323 // Display rectangular |
|
324 CAlfShadowBorderBrush* brush = CAlfShadowBorderBrush::NewLC(Env(),6); |
|
325 brush->SetOpacity(.25f); |
|
326 |
|
327 // Append brush to the visual and transfer its ownership to the visual. |
|
328 iDisplayPane->Brushes()->AppendL(brush, EAlfHasOwnership); |
|
329 CleanupStack::Pop(brush); |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------------------------- |
|
333 // Adds content into dialer pane of the application |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 void CAlfExAnalogDialerControl::AddDialerL() |
|
337 { |
|
338 // Dialer consists of three images on top of each other. Deck is needed to manage them |
|
339 // Parent layout is grid |
|
340 CAlfDeckLayout* dialerDeck = CAlfDeckLayout::AddNewL(*this, iRootLayout); |
|
341 dialerDeck->SetTagL(_L8(KTagArray[ETagAnalogDialerPlateDeck])); |
|
342 |
|
343 // Load images: |
|
344 // 1) Image with the numbers |
|
345 CAlfTexture& numbersTexture = Env().TextureManager().LoadTextureL( KImageAnalogDialerNumbers, |
|
346 EAlfTextureFlagDefault, |
|
347 KAlfAutoGeneratedTextureId); |
|
348 |
|
349 // Parent layout is deck |
|
350 CAlfImageVisual* numbers = CAlfImageVisual::AddNewL(*this,dialerDeck); |
|
351 // Default scale mode CAlfImageVisual::EScaleFit is OK |
|
352 // attach texture to image visual |
|
353 numbers->SetImage(TAlfImage(numbersTexture)); |
|
354 |
|
355 // 2) plate with holes |
|
356 CAlfTexture& plateTexture = Env().TextureManager().LoadTextureL( KImageAnalogDialerPlate, |
|
357 EAlfTextureFlagDefault, |
|
358 KAlfAutoGeneratedTextureId); |
|
359 // Parent layout is deck |
|
360 iPlate = CAlfImageVisual::AddNewL(*this,dialerDeck); |
|
361 // Default scale mode CAlfImageVisual::EScaleFit is OK |
|
362 iPlate->SetImage(TAlfImage(plateTexture)); |
|
363 |
|
364 // 2) stopper |
|
365 CAlfTexture& stopper = Env().TextureManager().LoadTextureL( KImageAnalogDialerStopper, |
|
366 EAlfTextureFlagDefault, |
|
367 KAlfAutoGeneratedTextureId); |
|
368 // Parent layout is deck |
|
369 iStopper = CAlfImageVisual::AddNewL(*this,dialerDeck); |
|
370 // Default scale mode CAlfImageVisual::EScaleFit is OK |
|
371 iStopper->SetImage(TAlfImage(stopper)); |
|
372 |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // Events from framework |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 TBool CAlfExAnalogDialerControl::OfferEventL(const TAlfEvent& aEvent) |
|
380 { |
|
381 // Ignore other events except pointer events |
|
382 if (aEvent.IsPointerEvent() && aEvent.PointerDown()) |
|
383 { |
|
384 return HandlePointerDownEventL(aEvent); |
|
385 } |
|
386 |
|
387 else if(aEvent.IsPointerEvent() && aEvent.PointerEvent().iType == TPointerEvent::EDrag ) |
|
388 { |
|
389 return HandleDraggingEventL(aEvent); |
|
390 } |
|
391 |
|
392 else if(aEvent.IsPointerEvent() && aEvent.PointerUp()) |
|
393 { |
|
394 return HandlePointerUpEventL(aEvent); |
|
395 } |
|
396 |
|
397 else if(aEvent.IsPointerEvent() && aEvent.PointerLongTap()) |
|
398 { |
|
399 return HandlePointerLongTapEventL(aEvent); |
|
400 } |
|
401 |
|
402 return EFalse; |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // Handles pointer down events |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 TBool CAlfExAnalogDialerControl::HandlePointerDownEventL(const TAlfEvent& aEvent) |
|
410 { |
|
411 // Topmost image i.e. stopper image visual gets the pointer event |
|
412 CAlfVisual* onVisual = aEvent.Visual(); |
|
413 if (onVisual == iStopper) |
|
414 { |
|
415 // Is plate rotating starting? |
|
416 if (IsPointerEventFollowingNumbersArcPath(aEvent)) |
|
417 { |
|
418 ResetDraggingData(); |
|
419 |
|
420 // Plate rotation is starting |
|
421 // Register to receive dragging events |
|
422 Display()->Roster().AddPointerEventObserver(EAlfPointerEventReportDrag, *this); |
|
423 |
|
424 // Dragging has started |
|
425 iFlags |= EAnalogDialerControlDragging; |
|
426 } |
|
427 // Is clear key pressed? |
|
428 else if (IsPointerEventOnClearKey(aEvent)) |
|
429 { |
|
430 ResetClearKeyData(); |
|
431 |
|
432 if (!(iFlags & EAnalogDialerControlFlagLongTapRegistered)) |
|
433 { |
|
434 // Clear key handling needs long tap events |
|
435 // Register for long tap events |
|
436 Display()->Roster().AddPointerEventObserver(EAlfPointerEventReportLongTap, *this); |
|
437 iFlags |= EAnalogDialerControlFlagLongTapRegistered; |
|
438 } |
|
439 // Clear key event has started |
|
440 iFlags |= EAnalogDialerControlClearKeyEvent; |
|
441 } |
|
442 } |
|
443 return ETrue; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // Handles dragging events |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 TBool CAlfExAnalogDialerControl::HandleDraggingEventL(const TAlfEvent& aEvent) |
|
451 { |
|
452 if (iFlags & EAnalogDialerControlDragging) |
|
453 { |
|
454 TPoint plateCentricPoint; |
|
455 ConvertEventToPlateCentricPosition(aEvent, |
|
456 iPlateTopOffset, |
|
457 iSquareSide, |
|
458 plateCentricPoint); |
|
459 TInt plateRadius = iSquareSide / 2; |
|
460 if (!IsPointerEventOnArcPath(plateCentricPoint, |
|
461 plateRadius, |
|
462 plateRadius * KPlateClearRadius / 100)) |
|
463 { |
|
464 FinishDragging(); |
|
465 } |
|
466 else |
|
467 { |
|
468 // Pointer event is following path |
|
469 // Get angle of pointer event and do further calculation based on it |
|
470 TInt degrees = Angle(plateCentricPoint.iX, plateCentricPoint.iY); |
|
471 |
|
472 // Save the angle of first dragging pointer event. |
|
473 // It is used to resolve selected number. |
|
474 if (iDraggingData.iInitialAngle == 0) |
|
475 { |
|
476 iDraggingData.iInitialAngle = degrees; |
|
477 iDraggingData.iPreviousAngle = degrees; |
|
478 } |
|
479 |
|
480 // As dragging events occur very often, redrawing plate is optimised that |
|
481 // it is not drawn after every dragging event. Change of KPlateDraggingDelta degrees |
|
482 // is needed until plate is redrawn. |
|
483 if ( degrees >= iDraggingData.iPreviousAngle + KPlateDraggingDelta |
|
484 || degrees <= iDraggingData.iPreviousAngle - KPlateDraggingDelta) |
|
485 { |
|
486 ResolveXAxisCrossing(degrees); |
|
487 iDraggingData.iPreviousAngle = degrees; |
|
488 |
|
489 if ( iDraggingData.iIsClockWiseOverZeroReached |
|
490 && degrees < KStopperAngle) |
|
491 { |
|
492 if (iDraggingData.iStopperReached) |
|
493 { |
|
494 // do not redraw as plate cannot rotate more |
|
495 return ETrue; |
|
496 } |
|
497 // stopper has been reached |
|
498 iDraggingData.iStopperReached = ETrue; |
|
499 } |
|
500 else if ( !iDraggingData.iIsClockWiseOverZeroReached |
|
501 && degrees > iDraggingData.iInitialAngle) |
|
502 { |
|
503 // Rotation counter clockwise to the left of idle position is asked |
|
504 // Plate does not rotate counterclockwise to the left of idle position |
|
505 return ETrue; |
|
506 } |
|
507 else if (iDraggingData.iStopperReached) |
|
508 { |
|
509 // user has dragged 360 degrees and is dragging now between idle and stopper position |
|
510 return ETrue; |
|
511 } |
|
512 else |
|
513 { |
|
514 // rotating when angle is between idle and stopper position |
|
515 iDraggingData.iStopperReached = EFalse; |
|
516 } |
|
517 //DebugDraggingData(degrees); |
|
518 RotatePlate( *iPlate, |
|
519 iDraggingData.iInitialAngle, |
|
520 degrees, |
|
521 iDraggingData.iIsClockWiseOverZeroReached); |
|
522 } |
|
523 // else - delta of rotation has not reached KPlateDraggingDelta |
|
524 } |
|
525 } |
|
526 // else - it is permitted that clear key event is dragged outside clear key area. What matters is where |
|
527 // the pointer event up takes place |
|
528 return ETrue; |
|
529 } |
|
530 |
|
531 // --------------------------------------------------------------------------- |
|
532 // Handle pointer up event |
|
533 // --------------------------------------------------------------------------- |
|
534 // |
|
535 TBool CAlfExAnalogDialerControl::HandlePointerUpEventL(const TAlfEvent& aEvent) |
|
536 { |
|
537 if (iFlags & EAnalogDialerControlDragging) |
|
538 { |
|
539 // Plate rotating has ended. Process result. |
|
540 FinishDragging(); |
|
541 } |
|
542 else if (iFlags & EAnalogDialerControlClearKeyEvent) |
|
543 { |
|
544 // clear key event has ended |
|
545 if (IsPointerEventOnClearKey(aEvent)) |
|
546 { |
|
547 ClearNumberDisplay(iFlags&EAnalogDialerControlFlagLongTapPressed); |
|
548 } |
|
549 // else - lifting pointer outside Clear key area cancels clearing number |
|
550 ResetClearKeyData(); |
|
551 } |
|
552 return ETrue; |
|
553 } |
|
554 |
|
555 // --------------------------------------------------------------------------- |
|
556 // Handle long tap event |
|
557 // --------------------------------------------------------------------------- |
|
558 // |
|
559 TBool CAlfExAnalogDialerControl::HandlePointerLongTapEventL(const TAlfEvent& /*aEvent*/) |
|
560 { |
|
561 if (iFlags & EAnalogDialerControlClearKeyEvent) |
|
562 { |
|
563 iFlags |= EAnalogDialerControlFlagLongTapPressed; |
|
564 } |
|
565 return ETrue; |
|
566 } |
|
567 |
|
568 // --------------------------------------------------------------------------- |
|
569 // AddNumberToDisplayPaneL |
|
570 // --------------------------------------------------------------------------- |
|
571 // |
|
572 void CAlfExAnalogDialerControl::AddNumberToDisplayPaneL(TInt aNumber) |
|
573 { |
|
574 if ( aNumber > 9 ) |
|
575 { |
|
576 return; |
|
577 } |
|
578 TBuf<8> number; |
|
579 |
|
580 // aNumber is 0...9 |
|
581 // Second parameter: number 10 must be changed to 0 |
|
582 number.Format(KNumberDisplayTemplate, (aNumber+1)%10); |
|
583 if (iDisplayNumber.Length() + number.Length() <= KNumberDisplayBufferLength) |
|
584 { |
|
585 iDisplayNumber.Append(number); |
|
586 iDisplayPane->SetTextL(iDisplayNumber); |
|
587 } |
|
588 } |
|
589 |
|
590 |
|
591 // --------------------------------------------------------------------------- |
|
592 // SwitchLayoutL |
|
593 // --------------------------------------------------------------------------- |
|
594 // |
|
595 void CAlfExAnalogDialerControl::SwitchLayoutL() |
|
596 { |
|
597 // Get access to first leafs (visuals) of grid layout |
|
598 CAlfVisual* displayDeck = FindTag(_L8( KTagArray[ETagAnalogDialerDisplayDeck])); |
|
599 CAlfVisual* dialerDeck = FindTag(_L8( KTagArray[ETagAnalogDialerPlateDeck])); |
|
600 |
|
601 if (displayDeck && dialerDeck) |
|
602 { |
|
603 // remove visuals from grid layout |
|
604 iRootLayout->Remove(displayDeck); |
|
605 iRootLayout->Remove(dialerDeck); |
|
606 |
|
607 // resolve new layout |
|
608 iLayoutMode = ResolveLayout(iSquareSide, |
|
609 iLongerSide); |
|
610 |
|
611 // modify grid layout |
|
612 AddGridLayoutL(); |
|
613 |
|
614 // put visuals back to layout |
|
615 if (iLayoutMode == ELayoutAnalogDialerPortrait) |
|
616 { |
|
617 User::LeaveIfError(iRootLayout->Append(displayDeck)); |
|
618 User::LeaveIfError(iRootLayout->Append(dialerDeck)); |
|
619 } |
|
620 else |
|
621 { |
|
622 User::LeaveIfError(iRootLayout->Append(dialerDeck)); |
|
623 User::LeaveIfError(iRootLayout->Append(displayDeck)); |
|
624 } |
|
625 |
|
626 // Notify Alf about layout change |
|
627 Env().NotifyLayoutChangedL(); |
|
628 } |
|
629 // else - better not to do anything |
|
630 |
|
631 iFeedback->Start(); |
|
632 |
|
633 // expose new root layout |
|
634 /*TAlfTimedValue opacity(0.0f); |
|
635 opacity.SetTarget(255, 500); |
|
636 iRootLayout->SetOpacity(opacity); */ |
|
637 |
|
638 } |
|
639 |
|
640 // --------------------------------------------------------------------------- |
|
641 // Hides the visual |
|
642 // --------------------------------------------------------------------------- |
|
643 // |
|
644 void CAlfExAnalogDialerControl::PrepareForLayoutSwitchL() |
|
645 { |
|
646 /*CAlfVisual* layout = FindTag(_L8(KTagArray[ETagAnalogDialerRootLayout])); |
|
647 if ( layout ) |
|
648 { |
|
649 TAlfTimedValue opacity(1.0f); |
|
650 opacity.SetTarget( 0.0f, 500); |
|
651 layout->SetOpacity(opacity); |
|
652 } |
|
653 iFeedback->Start(); |
|
654 User::After(500000);*/ |
|
655 } |
|
656 |
|
657 |
|
658 // --------------------------------------------------------------------------- |
|
659 // Resolves current layout. |
|
660 // --------------------------------------------------------------------------- |
|
661 // |
|
662 CAlfExAnalogDialerControl::TLayoutMode CAlfExAnalogDialerControl::ResolveLayout( |
|
663 TInt& aShorterSide, |
|
664 TInt& aLongerSide) const |
|
665 { |
|
666 // Resolve whether application is now running in portrait or landscape mode |
|
667 // Function must also return the shorter extent of the application |
|
668 // to be used as side length of the square of dialer plate. |
|
669 // Longer side is returned also to be used in grid weights. |
|
670 TLayoutMode layoutMode = ELayoutAnalogDialerPortrait; |
|
671 TRect displayRect = Env().PrimaryDisplay().VisibleArea(); |
|
672 TInt height = displayRect.Height(); |
|
673 TInt width = displayRect.Width(); |
|
674 if (width > height) |
|
675 { |
|
676 layoutMode = ELayoutAnalogDialerLandscape; |
|
677 aShorterSide = height; |
|
678 aLongerSide = width; |
|
679 } |
|
680 else |
|
681 { |
|
682 // default mode is OK |
|
683 aShorterSide = width; |
|
684 aLongerSide = height; |
|
685 } |
|
686 return layoutMode; |
|
687 } |
|
688 |
|
689 // --------------------------------------------------------------------------- |
|
690 // ResolveXAxisCrossing |
|
691 // --------------------------------------------------------------------------- |
|
692 // |
|
693 void CAlfExAnalogDialerControl::ResolveXAxisCrossing(TInt aAngle) |
|
694 { |
|
695 // Delta of angle change, which indicates X-axis crossing |
|
696 const TInt KXAxisCrossingAngleDelta = 300; |
|
697 |
|
698 TInt degreesDelta = aAngle - iDraggingData.iPreviousAngle; |
|
699 // switch from 0 to 359? |
|
700 if (degreesDelta > KXAxisCrossingAngleDelta) |
|
701 { |
|
702 iDraggingData.iIsClockWiseOverZeroReached = ETrue; |
|
703 } |
|
704 // switch from 359 to 0? |
|
705 else if ( iDraggingData.iIsClockWiseOverZeroReached |
|
706 && degreesDelta < (-KXAxisCrossingAngleDelta)) |
|
707 { |
|
708 iDraggingData.iIsClockWiseOverZeroReached = EFalse; |
|
709 } |
|
710 } |
|
711 |
|
712 |
|
713 // --------------------------------------------------------------------------- |
|
714 // Calculate angle of triangle, when adjacent and opposite sides are known |
|
715 // --------------------------------------------------------------------------- |
|
716 // |
|
717 TInt CAlfExAnalogDialerControl::Angle(TReal32 aAdjacent, TReal32 aOpposite) |
|
718 { |
|
719 if (aAdjacent == 0) |
|
720 { |
|
721 aAdjacent = 0.01; |
|
722 } |
|
723 |
|
724 if (aOpposite == 0) |
|
725 { |
|
726 aOpposite = 0.01; |
|
727 } |
|
728 |
|
729 TReal angle; |
|
730 Math::ATan(angle, Abs(aOpposite / aAdjacent)); |
|
731 |
|
732 if (aAdjacent < 0 && aOpposite > 0) |
|
733 { |
|
734 angle = KPi - angle; |
|
735 } |
|
736 else if (aAdjacent < 0 && aOpposite < 0) |
|
737 { |
|
738 angle = KPi + angle; |
|
739 } |
|
740 else if (aAdjacent > 0 && aOpposite < 0) |
|
741 { |
|
742 angle = 2* KPi - angle; |
|
743 } |
|
744 return RADTODEG(angle); |
|
745 } |
|
746 |
|
747 // --------------------------------------------------------------------------- |
|
748 // Calculate hypotenuse of triangle when length of adjacent and opposite sides are known |
|
749 // --------------------------------------------------------------------------- |
|
750 // |
|
751 TInt CAlfExAnalogDialerControl::Hypotenuse(const TPoint& aPosition) |
|
752 { |
|
753 TInt sideLength = aPosition.iX * aPosition.iX; |
|
754 TInt oppositeLength = aPosition.iY * aPosition.iY; |
|
755 |
|
756 TReal hypotenuse; |
|
757 Math::Sqrt(hypotenuse, sideLength + oppositeLength); |
|
758 return hypotenuse; |
|
759 } |
|
760 |
|
761 |
|
762 // --------------------------------------------------------------------------- |
|
763 // Order of function calls fix the layout of grid in portrait and landscape modes. |
|
764 // --------------------------------------------------------------------------- |
|
765 // |
|
766 void CAlfExAnalogDialerControl::SetWeightsOfGridL( CAlfGridLayout& aGridLayout, |
|
767 TLayoutMode aLayout, |
|
768 TInt aSquareSide, |
|
769 TInt aLongerSide, |
|
770 TInt& aPlateTop) |
|
771 { |
|
772 // Set up a variable for default value. |
|
773 RArray<TInt> weightsDefault; |
|
774 User::LeaveIfError(weightsDefault.Append(1)); |
|
775 |
|
776 // sets weights of grid. Use pizels of application window size to get exact adjustment of pane sizes |
|
777 RArray<TInt> weights; |
|
778 if (aLayout == ELayoutAnalogDialerPortrait) |
|
779 { |
|
780 // top: display; take rest what dialer plate leaves for number display |
|
781 User::LeaveIfError(weights.Append(aLongerSide-aSquareSide)); |
|
782 |
|
783 // bottom: dialer, which must be square |
|
784 User::LeaveIfError(weights.Append(aSquareSide)); |
|
785 aGridLayout.SetRowsL(weights); |
|
786 |
|
787 // default weight for dimension, which is 1. Needed, because weights are reset |
|
788 aGridLayout.SetColumnsL(weightsDefault); |
|
789 |
|
790 // Offset to the plate in Y-dimension is height of number display |
|
791 aPlateTop = aLongerSide-aSquareSide; |
|
792 } |
|
793 else |
|
794 { |
|
795 // left: dialer, which must be square |
|
796 User::LeaveIfError(weights.Append(aSquareSide)); |
|
797 // right: display; take rest what dialer plate leaves for number display |
|
798 User::LeaveIfError(weights.Append(aLongerSide-aSquareSide)); |
|
799 |
|
800 // default weight for dimension, which is 1. Needed, because weights are reset |
|
801 aGridLayout.SetRowsL(weightsDefault); |
|
802 aGridLayout.SetColumnsL(weights); |
|
803 |
|
804 aPlateTop = 0; |
|
805 } |
|
806 weights.Close(); |
|
807 weightsDefault.Close(); |
|
808 } |
|
809 |
|
810 |
|
811 // --------------------------------------------------------------------------- |
|
812 // ConvertEventToPlateCentricPosition |
|
813 // --------------------------------------------------------------------------- |
|
814 // |
|
815 void CAlfExAnalogDialerControl::ConvertEventToPlateCentricPosition( |
|
816 const TAlfEvent& aEvent, |
|
817 TInt aPlateTopOffset, |
|
818 TInt aSquareSide, |
|
819 TPoint& aPlateCentricPoint) |
|
820 { |
|
821 // event position is converted in a such way that centre position of the plate is (0,0) |
|
822 // iY: value is negative, if position is below the centre position |
|
823 // iY: value is position, if position is above the centre position |
|
824 // iX: value is negative, if position is to the left the centre position |
|
825 // iX: value is position, if position is to the right of the centre position |
|
826 |
|
827 // aSquare side is length of whole square side |
|
828 const TInt plateCentreY = aPlateTopOffset + aSquareSide / 2; |
|
829 aPlateCentricPoint.iX = aEvent.PointerEvent().iParentPosition.iX - aSquareSide / 2; |
|
830 aPlateCentricPoint.iY = plateCentreY - aEvent.PointerEvent().iParentPosition.iY ; |
|
831 } |
|
832 |
|
833 |
|
834 // --------------------------------------------------------------------------- |
|
835 // Checks whether pointer event occurred between outer and inner radius |
|
836 // --------------------------------------------------------------------------- |
|
837 // |
|
838 TBool CAlfExAnalogDialerControl::IsPointerEventOnArcPath( TPoint& aPlateCentricPoint, |
|
839 TInt aOuterRadius, |
|
840 TInt aInnerRadius) |
|
841 { |
|
842 // Checks whether position is along a path, which is between radii. |
|
843 // Event may be exactly on distance of radii |
|
844 TBool ret = ETrue; |
|
845 TInt distanceFromPlateCentre = Hypotenuse(aPlateCentricPoint); |
|
846 if (distanceFromPlateCentre > aOuterRadius || distanceFromPlateCentre < aInnerRadius) |
|
847 { |
|
848 ret = EFalse; |
|
849 } |
|
850 return ret; |
|
851 } |
|
852 |
|
853 // --------------------------------------------------------------------------- |
|
854 // Dragging has finished. Resets dragging data |
|
855 // --------------------------------------------------------------------------- |
|
856 // |
|
857 void CAlfExAnalogDialerControl::ResetDraggingData() |
|
858 { |
|
859 iFlags &= (~EAnalogDialerControlDragging); |
|
860 iDraggingData.iInitialAngle = 0; |
|
861 iDraggingData.iPreviousAngle = 0; |
|
862 iDraggingData.iIsClockWiseOverZeroReached = EFalse; |
|
863 iDraggingData.iStopperReached=EFalse; |
|
864 } |
|
865 |
|
866 // --------------------------------------------------------------------------- |
|
867 // Clear key event has finished. Resets dragging data |
|
868 // --------------------------------------------------------------------------- |
|
869 // |
|
870 void CAlfExAnalogDialerControl::ResetClearKeyData() |
|
871 { |
|
872 iFlags &= (~EAnalogDialerControlClearKeyEvent); |
|
873 iFlags &= (~EAnalogDialerControlFlagLongTapPressed); |
|
874 } |
|
875 |
|
876 |
|
877 // --------------------------------------------------------------------------- |
|
878 // Turns plate back to idle position i.e. counter clokcwise |
|
879 // --------------------------------------------------------------------------- |
|
880 // |
|
881 void CAlfExAnalogDialerControl::RotatePlateToIdlePosition(CAlfImageVisual& aImage) |
|
882 { |
|
883 // Rotate the image. This has immediate effect. |
|
884 TAlfTimedValue tValue; |
|
885 tValue.SetTargetWithSpeed(0, // position zero |
|
886 KPlateReturnSpeed); |
|
887 aImage.SetTurnAngle(tValue); |
|
888 } |
|
889 |
|
890 |
|
891 // --------------------------------------------------------------------------- |
|
892 // Rotates image clockwise |
|
893 // --------------------------------------------------------------------------- |
|
894 // |
|
895 void CAlfExAnalogDialerControl::RotatePlate( |
|
896 CAlfImageVisual& aImage, |
|
897 TInt aInitialAngle, |
|
898 TInt aTargetAngle, |
|
899 TBool aIsClockWiseOverZeroReached) |
|
900 { |
|
901 // When rotates clockwise, rotation angle is negative |
|
902 TInt rotateDelta = aTargetAngle-aInitialAngle; |
|
903 if (aIsClockWiseOverZeroReached) |
|
904 { |
|
905 // Angle is big value (near to 360), which cannot be used as such |
|
906 // Convert it to negative value |
|
907 rotateDelta = (aTargetAngle-360)-aInitialAngle; |
|
908 } |
|
909 //RDebug::Printf("***AnalogDialer rotateDelta : %d",rotateDelta); |
|
910 TAlfTimedValue tValue(rotateDelta); |
|
911 aImage.SetTurnAngle(tValue); |
|
912 } |
|
913 |
|
914 // --------------------------------------------------------------------------- |
|
915 // Returns selected number based on rotated angle of plate |
|
916 // --------------------------------------------------------------------------- |
|
917 // |
|
918 TInt CAlfExAnalogDialerControl::DialedNumber( TInt aInitialAngle, |
|
919 TInt aCurrentAngle) const |
|
920 { |
|
921 // Default value when dragging event has not crossed zero-angle X-axis |
|
922 TInt deltaAngle = aCurrentAngle-aInitialAngle; |
|
923 |
|
924 // aCurrentAngle must be an angle derived directly from ConvertEventToPlateCentricPosition |
|
925 // aCurrentAngle is really current pointer position. KStopper value must be used instead |
|
926 if (iDraggingData.iIsClockWiseOverZeroReached) |
|
927 { |
|
928 deltaAngle = aInitialAngle+(360-KStopperAngle); |
|
929 } |
|
930 |
|
931 // Subtract required minimun angle. |
|
932 deltaAngle = Abs(deltaAngle)-KPlateMinimumRotateAngle; |
|
933 if (deltaAngle<0) |
|
934 { |
|
935 // plate has not been rotated enough to select any number |
|
936 return KErrNotFound; |
|
937 } |
|
938 |
|
939 // TODO. These values could be made constant to use plate with other number systems as decimal |
|
940 // e.g. binary, or hexadecimal |
|
941 // Finally calculate dialed number based on rotated angle |
|
942 TInt angleOfANumber(KPlateNumbersDistributionAngle/10); |
|
943 TInt dialedNumber = deltaAngle/angleOfANumber; |
|
944 if (dialedNumber > 9) |
|
945 { |
|
946 dialedNumber = 9; |
|
947 } |
|
948 return dialedNumber; |
|
949 } |
|
950 |
|
951 |
|
952 // --------------------------------------------------------------------------- |
|
953 // Checks whether pointer is on path allowed for plate rotation |
|
954 // The path is between edges of plate and clear key area |
|
955 // --------------------------------------------------------------------------- |
|
956 // |
|
957 TBool CAlfExAnalogDialerControl::IsPointerEventFollowingNumbersArcPath( const TAlfEvent& aEvent ) const |
|
958 { |
|
959 TPoint plateCentricPoint; |
|
960 ConvertEventToPlateCentricPosition(aEvent, |
|
961 iPlateTopOffset, |
|
962 iSquareSide, |
|
963 plateCentricPoint); |
|
964 // Third parameter: Radius of clear area belongs to clear area. Eliminate it. |
|
965 TInt plateRadius = iSquareSide / 2; |
|
966 if ( IsPointerEventOnArcPath( plateCentricPoint, |
|
967 plateRadius, |
|
968 (plateRadius*KPlateClearRadius/100)+1)) |
|
969 { |
|
970 return ETrue; |
|
971 } |
|
972 return EFalse; |
|
973 } |
|
974 |
|
975 // --------------------------------------------------------------------------- |
|
976 // Checks whether pointer is on area of clear key |
|
977 // --------------------------------------------------------------------------- |
|
978 // |
|
979 TBool CAlfExAnalogDialerControl::IsPointerEventOnClearKey( const TAlfEvent& aEvent ) const |
|
980 { |
|
981 TPoint plateCentricPoint; |
|
982 ConvertEventToPlateCentricPosition(aEvent, |
|
983 iPlateTopOffset, |
|
984 iSquareSide, |
|
985 plateCentricPoint); |
|
986 TInt plateRadius = iSquareSide / 2; |
|
987 // Third parameter: The 'bull eye' of the plate |
|
988 if ( IsPointerEventOnArcPath( plateCentricPoint, |
|
989 plateRadius*KPlateClearRadius/100, |
|
990 0)) |
|
991 { |
|
992 return ETrue; |
|
993 } |
|
994 return EFalse; |
|
995 } |
|
996 |
|
997 |
|
998 // --------------------------------------------------------------------------- |
|
999 // Performs actions needed when dragging is finished |
|
1000 // --------------------------------------------------------------------------- |
|
1001 // |
|
1002 void CAlfExAnalogDialerControl::FinishDragging() |
|
1003 { |
|
1004 // Dragging has finished |
|
1005 // Remove pointer dragging observer, which will gain us performance |
|
1006 Display()->Roster().RemovePointerEventObserver( EAlfPointerEventReportDrag,*this ); |
|
1007 DialedNumberToDisplay( iDraggingData.iInitialAngle, |
|
1008 iDraggingData.iPreviousAngle); |
|
1009 RotatePlateToIdlePosition(*iPlate); |
|
1010 ResetDraggingData(); |
|
1011 } |
|
1012 |
|
1013 // --------------------------------------------------------------------------- |
|
1014 // Puts dialed number into number display |
|
1015 // --------------------------------------------------------------------------- |
|
1016 // |
|
1017 void CAlfExAnalogDialerControl::DialedNumberToDisplay( TInt aInitialAngle, |
|
1018 TInt aCurrentAngle ) |
|
1019 { |
|
1020 TInt dialedNumber = DialedNumber(aInitialAngle, aCurrentAngle); |
|
1021 // Filter KErrNotFound out |
|
1022 if (dialedNumber>=0) |
|
1023 { |
|
1024 TRAP_IGNORE(AddNumberToDisplayPaneL( dialedNumber )); |
|
1025 } |
|
1026 } |
|
1027 |
|
1028 // --------------------------------------------------------------------------- |
|
1029 // Clear number display either wholly or last number |
|
1030 // --------------------------------------------------------------------------- |
|
1031 // |
|
1032 void CAlfExAnalogDialerControl::ClearNumberDisplay(TBool aClearWholeDisplay) |
|
1033 { |
|
1034 TInt lengthNumber = iDisplayNumber.Length(); |
|
1035 if (lengthNumber == 0) |
|
1036 { |
|
1037 // nothing to clear |
|
1038 return; |
|
1039 } |
|
1040 |
|
1041 if (aClearWholeDisplay) |
|
1042 { |
|
1043 // clear whole buf |
|
1044 iDisplayNumber.Zero(); |
|
1045 } |
|
1046 else |
|
1047 { |
|
1048 // delete one number |
|
1049 iDisplayNumber.Delete(lengthNumber-1,1); |
|
1050 } |
|
1051 // changed number to the screen |
|
1052 TRAP_IGNORE(iDisplayPane->SetTextL(iDisplayNumber)); |
|
1053 } |
|
1054 |
|
1055 |
|
1056 // --------------------------------------------------------------------------- |
|
1057 // |
|
1058 // --------------------------------------------------------------------------- |
|
1059 // |
|
1060 /*void CAlfExAnalogDialerControl::AddEffectLayout() |
|
1061 { |
|
1062 |
|
1063 }*/ |
|
1064 |
|
1065 |
|
1066 // --------------------------------------------------------------------------- |
|
1067 // Debugs dragging data + given angle |
|
1068 // --------------------------------------------------------------------------- |
|
1069 // |
|
1070 void CAlfExAnalogDialerControl::DebugDraggingData(TInt aAngle) |
|
1071 { |
|
1072 RDebug::Printf("\n***AnalogDialer:"); |
|
1073 RDebug::Printf("***AnalogDialer iFlags & EAnalogDialerControlDragging: %d",iFlags & EAnalogDialerControlDragging); |
|
1074 RDebug::Printf("***AnalogDialer iDraggingData.iInitialAngle: %d",iDraggingData.iInitialAngle); |
|
1075 RDebug::Printf("***AnalogDialer iDraggingData.iPreviousAngle: %d",iDraggingData.iPreviousAngle); |
|
1076 RDebug::Printf("***AnalogDialer iDraggingData.iIsClockWiseOverZeroReached: %d",iDraggingData.iIsClockWiseOverZeroReached); |
|
1077 RDebug::Printf("***AnalogDialer iDraggingData.iStopperReached: %d",iDraggingData.iStopperReached); |
|
1078 RDebug::Printf("***AnalogDialer aAngle: %d",aAngle); |
|
1079 RDebug::Printf("\n"); |
|
1080 } |
|
1081 |