exampleapps/alfexcalendar/src/alfexcalendardeckcontrol.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c)  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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <alf/alftextvisual.h>
       
    21 #include <alf/alfgridlayout.h>
       
    22 #include <alf/alfdecklayout.h>
       
    23 #include <alf/alfflowlayout.h>
       
    24 #include <alf/alfcurvepathlayout.h>
       
    25 #include <alf/alfcurvepath.h>
       
    26 #include <alf/alfevent.h>
       
    27 #include <alf/alfenv.h>
       
    28 #include <alf/alfdisplay.h>
       
    29 #include <alf/alflinevisual.h>
       
    30 #include <alf/alfimagevisual.h>
       
    31 #include <alf/alftransformation.h>
       
    32 #include <alf/alfcommand.h>
       
    33 
       
    34 #include "alfexcalendardeckcontrol.h"
       
    35 #include "alfexcalendarmonth.h"
       
    36 #include "alfexcalendarengine.h"
       
    37 
       
    38 _LIT( KImagePath, "c:\\data\\Images\\Pictures\\" );
       
    39 _LIT( KCalendar, "calendar.jpg" );
       
    40 
       
    41 const TInt KMonthViewTransitTime = 1500;
       
    42 const TInt KMonthViewRotationTime = 1500;
       
    43 const TInt KMonthViewScalingTime = 2500;
       
    44 const TInt KMonthViewOpacityTime = 2500;
       
    45 
       
    46 const TReal KUnitSize = 1.0f;
       
    47 const TReal KMonthXSf = 0.2f;
       
    48 const TReal KMonthYSf = 0.2f;
       
    49 
       
    50 // Custome events
       
    51 enum TCustomEvent
       
    52 {
       
    53     EMoveMonthToBack = 1,
       
    54     EMonthMovedToFront,
       
    55 
       
    56     ECustomEventInvalid
       
    57 };
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CAlfExCalendarDeckControl::NewLC
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CAlfExCalendarDeckControl* CAlfExCalendarDeckControl::NewLC(
       
    64     CAlfEnv& aEnv,
       
    65     CAlfExCalendarEngine& aCalendarEngine )
       
    66     {
       
    67     CAlfExCalendarDeckControl* self =
       
    68         new (ELeave) CAlfExCalendarDeckControl( aCalendarEngine, aEnv );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL( aEnv );
       
    71     return self;
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------
       
    75 // CAlfExCalendarDeckControl::CAlfExCalendarDeckControl
       
    76 // --------------------------------------------------------------------------
       
    77 //
       
    78 CAlfExCalendarDeckControl::CAlfExCalendarDeckControl(
       
    79         CAlfExCalendarEngine& aCalendarEngine,
       
    80         CAlfEnv& aEnv )
       
    81     : iFocusedMonth( (KMonthsVisible-1) ), iMonthView( EFalse ),
       
    82       iCalendarEngine( aCalendarEngine ), iEnv( aEnv ),
       
    83       iMonthAnimationStyle( EAnimationStyle1 ),
       
    84       iMonthTransitionState( ETransitionStateStopped )
       
    85     {
       
    86     }
       
    87 
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CAlfExCalendarDeckControl::ConstructL
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 void CAlfExCalendarDeckControl::ConstructL( CAlfEnv& aEnv )
       
    94     {
       
    95     CAlfControl::ConstructL( aEnv );
       
    96     
       
    97     /* // not using currently
       
    98     // Background image.
       
    99     iBackground = CAlfImageVisual::AddNewL(*this);
       
   100     Env().TextureManager().SetImagePathL( KImagePath );
       
   101     SetImageTexture( iBackground, KCalendar );
       
   102     */
       
   103 
       
   104     // Get display rectangle
       
   105     iDisplayRect = aEnv.PrimaryDisplay().VisibleArea();
       
   106 
       
   107     // create Deck Layout and add to CAlfExCalendarDeckControl
       
   108     // CAlfExCalendarDeckControl takes ownership of created layout
       
   109     iDeck = CAlfDeckLayout::AddNewL( *this );
       
   110 
       
   111     
       
   112     // Calendar logic here
       
   113     // we create only KMonthsVisible number (atleast 2 :))of CAlfExCalendarMonth instances
       
   114     // and only use those many, to show un-limited calendar months.
       
   115     // take the responsibility of updating CAlfExCalendarMonth instances 
       
   116     // when moving between the months.
       
   117     iSelectedTime.HomeTime();
       
   118     iCurrentMonthControlIndex = (KMonthsVisible - 1);
       
   119     
       
   120     TTime tmpTime = iSelectedTime - (TTimeIntervalMonths)( KMonthsVisible - 1 );
       
   121     for( TInt i = 0; i < KMonthsVisible; i++ )
       
   122         {
       
   123         iMonthControls[i] = CAlfExCalendarMonth::NewLC( iDeck, tmpTime.DateTime(), aEnv, *this );
       
   124         tmpTime += (TTimeIntervalMonths)1;
       
   125         CleanupStack::Pop();
       
   126         };
       
   127 
       
   128     // move Focus to current month
       
   129     iMonthControls[iCurrentMonthControlIndex]->MonthFocusedL();
       
   130     iMonthView = ETrue;
       
   131     }
       
   132 
       
   133 // --------------------------------------------------------------------------
       
   134 // CAlfExCalendarDeckControl::~CAlfExCalendarDeckControl
       
   135 // --------------------------------------------------------------------------
       
   136 //
       
   137 CAlfExCalendarDeckControl::~CAlfExCalendarDeckControl()
       
   138     {
       
   139     // delete all iMonthControls
       
   140     for (TInt i = 0; i < KMonthsVisible ; i++ )
       
   141         {
       
   142         delete iMonthControls[i];
       
   143         }
       
   144     }
       
   145 
       
   146 // --------------------------------------------------------------------------
       
   147 // CAlfExCalendarDeckControl::SetImageTexture
       
   148 // --------------------------------------------------------------------------
       
   149 //
       
   150 void CAlfExCalendarDeckControl::SetImageTexture(
       
   151     CAlfImageVisual* aImageVisual,
       
   152     const TDesC& aImageFileName )
       
   153     {
       
   154     
       
   155     TRAP_IGNORE(
       
   156             // creates texture from given aImageFileName
       
   157             CAlfTexture& texture =
       
   158                 Env().TextureManager().LoadTextureL(
       
   159                         aImageFileName,
       
   160                         EAlfTextureFlagDefault,
       
   161                         KAlfAutoGeneratedTextureId );
       
   162 
       
   163             aImageVisual->SetScaleMode( CAlfImageVisual::EScaleCover );
       
   164             
       
   165             // sets created texture to given aImageVisual
       
   166             aImageVisual->SetImage( TAlfImage( texture ) );
       
   167                         );
       
   168     
       
   169     }
       
   170 
       
   171 // --------------------------------------------------------------------------
       
   172 // CAlfExCalendarDeckControl::SetMonthView
       
   173 // --------------------------------------------------------------------------
       
   174 //
       
   175 void CAlfExCalendarDeckControl::SetMonthView( TBool aVal )
       
   176     {
       
   177     iMonthView = aVal;
       
   178     }
       
   179 
       
   180 // --------------------------------------------------------------------------
       
   181 // CAlfExCalendarDeckControl::CalendarEngine
       
   182 // --------------------------------------------------------------------------
       
   183 //
       
   184 CAlfExCalendarEngine& CAlfExCalendarDeckControl::CalendarEngine() const
       
   185     {
       
   186     return iCalendarEngine;
       
   187     }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CAlfExCalendarDeckControl::OfferEventL
       
   191 // --------------------------------------------------------------------------
       
   192 //
       
   193 TBool CAlfExCalendarDeckControl::OfferEventL(const TAlfEvent& aEvent )
       
   194 	{
       
   195     // DO NOT change the order of below aEvent checking
       
   196     
       
   197     // Pointer events are irrelevant for 3.2,
       
   198     // but caught here for 5.0 compatibility.
       
   199     if( aEvent.IsPointerEvent() )
       
   200         {
       
   201         return ETrue;
       
   202         }
       
   203 
       
   204     if( aEvent.IsCustomEvent() /* && iMonthTransitionState != ETransitionStateStopped */ )
       
   205         {
       
   206         switch( aEvent.CustomParameter() )
       
   207             {
       
   208             // month transition (animation)is completed. Handle custome events
       
   209             case EMoveMonthToBack:
       
   210                 iDeck->MoveVisualToBack( iDeck->Visual( iFocusedMonth ) );
       
   211                 iMonthTransitionState = ETransitionStateStopped;
       
   212                 iMonthControls[iCurrentMonthControlIndex]->MonthFocusedL();
       
   213                 iMonthView = ETrue;
       
   214                 return ETrue;
       
   215 
       
   216             case EMonthMovedToFront:
       
   217                 iMonthTransitionState = ETransitionStateStopped;
       
   218                 iMonthControls[iCurrentMonthControlIndex]->MonthFocusedL();
       
   219                 iMonthView = ETrue;
       
   220                 return ETrue;
       
   221             
       
   222             default:
       
   223                 break;                
       
   224             }
       
   225         }
       
   226 
       
   227     // Don't handle events while month transition
       
   228     if( iMonthTransitionState != ETransitionStateStopped )
       
   229         {
       
   230         return ETrue;
       
   231         }
       
   232     
       
   233     // If month view
       
   234     if( iMonthView )
       
   235         {
       
   236         TBool ret = iMonthControls[iCurrentMonthControlIndex]->OfferEventL( aEvent );
       
   237         
       
   238         // iMonthControls can change the iMonthView value. 
       
   239         // month might have been closed
       
   240         if( iMonthView )
       
   241             {
       
   242             return ret;
       
   243             }
       
   244         else
       
   245             {
       
   246             // dont return, continue event processing here
       
   247             }
       
   248         }
       
   249 
       
   250     if ( aEvent.Code() == EEventKey )
       
   251         {
       
   252         iMonthAnimationStyle = EAnimationStyle1;
       
   253         TInt code = aEvent.KeyEvent().iCode;
       
   254         switch( code )
       
   255             {
       
   256             case EKeyUpArrow:
       
   257                 iMonthAnimationStyle = EAnimationStyle2;
       
   258                 MoveToPrevMonthL();
       
   259                 return ETrue;
       
   260 
       
   261             case EKeyDownArrow:
       
   262                 iMonthAnimationStyle = EAnimationStyle2;
       
   263                 MoveToNextMonthL();
       
   264                 return ETrue;
       
   265             
       
   266             case EKeyLeftArrow:
       
   267                 MoveToPrevMonthL();
       
   268                 return ETrue;
       
   269 
       
   270             case EKeyRightArrow:
       
   271                 MoveToNextMonthL();
       
   272                 return ETrue;
       
   273 
       
   274             default:
       
   275                 break;
       
   276             }
       
   277         }
       
   278     return EFalse;
       
   279     }
       
   280 
       
   281 // --------------------------------------------------------------------------
       
   282 // CAlfExCalendarDeckControl::MoveToNextMonthL
       
   283 // --------------------------------------------------------------------------
       
   284 //
       
   285 void CAlfExCalendarDeckControl::MoveToNextMonthL()
       
   286     {
       
   287     // calls appropriate function according to animation style
       
   288     switch( iMonthAnimationStyle )
       
   289         {
       
   290         case EAnimationStyle1:
       
   291             MoveToNextMonthAnimation1L();
       
   292             break;
       
   293         case EAnimationStyle2:
       
   294             MoveToNextMonthAnimation2L();
       
   295             break;
       
   296         default:
       
   297             break;
       
   298         }
       
   299     }
       
   300 
       
   301 // --------------------------------------------------------------------------
       
   302 // CAlfExCalendarDeckControl::MoveToPrevMonthL
       
   303 // --------------------------------------------------------------------------
       
   304 //
       
   305 void CAlfExCalendarDeckControl::MoveToPrevMonthL()
       
   306     {
       
   307     // calls appropriate function according to animation style
       
   308     switch( iMonthAnimationStyle )
       
   309         {
       
   310         case EAnimationStyle1:
       
   311             MoveToPrevMonthAnimation1L();
       
   312             break;
       
   313         case EAnimationStyle2:
       
   314             MoveToPrevMonthAnimation2L();
       
   315             break;
       
   316         default:
       
   317             break;
       
   318         }
       
   319     }
       
   320 
       
   321 // --------------------------------------------------------------------------
       
   322 // CAlfExCalendarDeckControl::UpdateNextMonthL
       
   323 // --------------------------------------------------------------------------
       
   324 //
       
   325 void CAlfExCalendarDeckControl::UpdateNextMonthL()
       
   326     {
       
   327     // change time to next month
       
   328     iSelectedTime += (TTimeIntervalMonths)1;
       
   329     
       
   330     // set iCurrentMonthControlIndex value properly.
       
   331     // some logic here based on how many no of month layout we have
       
   332     iCurrentMonthControlIndex++;
       
   333     if( iCurrentMonthControlIndex == KMonthsVisible )
       
   334         {
       
   335         iCurrentMonthControlIndex = 0;
       
   336         }
       
   337     
       
   338     // now update the month layout according to iSelectedTime
       
   339     iMonthControls[iCurrentMonthControlIndex]->UpdateMonthL( iSelectedTime.DateTime() );    
       
   340     }
       
   341 
       
   342 // --------------------------------------------------------------------------
       
   343 // CAlfExCalendarDeckControl::UpdatePrevMonthL
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 void CAlfExCalendarDeckControl::UpdatePrevMonthL()
       
   347     {
       
   348     // change time to previous month
       
   349     iSelectedTime -= (TTimeIntervalMonths)1;
       
   350     
       
   351     // set iCurrentMonthControlIndex value properly.
       
   352     iCurrentMonthControlIndex--;
       
   353     if( iCurrentMonthControlIndex == -1 )
       
   354         {
       
   355         iCurrentMonthControlIndex = (KMonthsVisible-1);
       
   356         }
       
   357 
       
   358     // update the month layout according to iSelectedTime
       
   359     iMonthControls[iCurrentMonthControlIndex]->UpdateMonthL( iSelectedTime.DateTime() );    
       
   360     }
       
   361 
       
   362 // --------------------------------------------------------------------------
       
   363 // CAlfExCalendarDeckControl::MoveToNextMonthAnimation1L
       
   364 // --------------------------------------------------------------------------
       
   365 //
       
   366 void CAlfExCalendarDeckControl::MoveToNextMonthAnimation1L()
       
   367     {
       
   368     // updates the month layout which is at bottom of deck layout
       
   369     UpdateNextMonthL();
       
   370 
       
   371     // get the bottom most month to front of DECK layout
       
   372     iDeck->MoveVisualToFront( iDeck->Visual( 0 ) );
       
   373     
       
   374     // move this month to extreme right of display
       
   375     iDeck->Visual( iFocusedMonth ).SetPos( TPoint( iDisplayRect.Width(), 0 ), 0 );
       
   376     
       
   377     // now move this month to 0,0 position in KMonthViewTransitTime time
       
   378     iDeck->Visual( iFocusedMonth ).SetPos( TPoint( 0, 0 ), KMonthViewTransitTime );
       
   379     
       
   380     // with rotation transformation
       
   381     RotateVisualL( iDeck->Visual( iFocusedMonth ), 360, 0, KMonthViewRotationTime );
       
   382 
       
   383     // send custome event, handle EMonthMovedToFront in OfferEventL() after KMonthViewTransitTime
       
   384     Env().Send( TAlfCustomEventCommand( EMonthMovedToFront, this ), KMonthViewTransitTime );
       
   385     
       
   386     // change iMonthTransitionState state
       
   387     iMonthTransitionState = ETransitionStateMovingToNext;
       
   388     }
       
   389 
       
   390 // --------------------------------------------------------------------------
       
   391 // CAlfExCalendarDeckControl::MoveToPrevMonthAnimation1L
       
   392 // --------------------------------------------------------------------------
       
   393 //
       
   394 void CAlfExCalendarDeckControl::MoveToPrevMonthAnimation1L()
       
   395     {
       
   396     // updates the month layout which is just below the top of deck layout
       
   397     UpdatePrevMonthL();
       
   398 
       
   399     // move currently focused month to out of screen horizontally
       
   400     iDeck->Visual( iFocusedMonth ).SetPos( TPoint( iDisplayRect.Width(), 0 ), KMonthViewTransitTime );
       
   401     
       
   402     // with rotation transformation
       
   403     RotateVisualL( iDeck->Visual( iFocusedMonth ), 0, 360, KMonthViewRotationTime );
       
   404 
       
   405     // move month to back of DECK after KMonthViewTransitTime duration by sending custom event
       
   406     // custom event EMoveMonthToBack should be handled in OfferEventL()
       
   407     Env().Send( TAlfCustomEventCommand( EMoveMonthToBack, this ), KMonthViewTransitTime );
       
   408     
       
   409     // change iMonthTransitionState state
       
   410     iMonthTransitionState = ETransitionStateMovingToPrev;
       
   411     }
       
   412 
       
   413 // --------------------------------------------------------------------------
       
   414 // CAlfExCalendarDeckControl::MoveToNextMonthAnimation2L
       
   415 // --------------------------------------------------------------------------
       
   416 //
       
   417 void CAlfExCalendarDeckControl::MoveToNextMonthAnimation2L()
       
   418     {
       
   419     // updates the month layout which is at bottom of deck layout
       
   420     UpdateNextMonthL();
       
   421 
       
   422     // get the bottom most month to front of DECK
       
   423     iDeck->MoveVisualToFront( iDeck->Visual( 0 ) );
       
   424 
       
   425     // position it at bottom of display
       
   426     iDeck->Visual( iFocusedMonth ).SetPos( TPoint( 0, iDisplayRect.Height() ), 0 );
       
   427 
       
   428     // ans move it to 0,0 position (top left of display)
       
   429     iDeck->Visual( iFocusedMonth ).SetPos( TPoint( 0, 0 ), KMonthViewTransitTime );
       
   430 
       
   431     // send custom event and handle it in OfferEventL()
       
   432     Env().Send( TAlfCustomEventCommand( EMonthMovedToFront, this ), KMonthViewTransitTime );
       
   433 
       
   434     // change iMonthTransitionState state
       
   435     iMonthTransitionState = ETransitionStateMovingToNext;
       
   436     }
       
   437 
       
   438 // --------------------------------------------------------------------------
       
   439 // CAlfExCalendarDeckControl::MoveToPrevMonthAnimation2L
       
   440 // --------------------------------------------------------------------------
       
   441 //
       
   442 void CAlfExCalendarDeckControl::MoveToPrevMonthAnimation2L()
       
   443     {
       
   444     // updates the month layout which is just below (2nd one)
       
   445     // from the top of deck layout
       
   446     UpdatePrevMonthL();
       
   447 
       
   448     // move currently visible month (which is on top of layout)
       
   449     // to bottom of didplay
       
   450     iDeck->Visual( iFocusedMonth ).SetPos(
       
   451             TPoint( 0, iDisplayRect.Height() ), KMonthViewTransitTime );
       
   452 
       
   453     // then move month to back of DECK after KMonthViewTransitTime duration
       
   454     Env().Send(
       
   455             TAlfCustomEventCommand( EMoveMonthToBack, this ),
       
   456             KMonthViewTransitTime );
       
   457     
       
   458     // change iMonthTransitionState state
       
   459     iMonthTransitionState = ETransitionStateMovingToPrev;
       
   460     }
       
   461 
       
   462 // --------------------------------------------------------------------------
       
   463 // CAlfExCalendarDeckControl::ScaleVisualL
       
   464 // --------------------------------------------------------------------------
       
   465 //
       
   466 void CAlfExCalendarDeckControl::ScaleVisualL(
       
   467         CAlfVisual& aVisual,
       
   468         TReal aXSf,
       
   469         TReal aYSf,
       
   470         TInt aTime )
       
   471     {
       
   472     aVisual.EnableTransformationL();
       
   473     TAlfTimedValue xSc( KUnitSize );
       
   474     xSc.SetTarget( aXSf, aTime );
       
   475     TAlfTimedValue ySc( KUnitSize );
       
   476     ySc.SetTarget( aYSf, aTime );
       
   477     aVisual.Transformation().Scale( xSc, ySc );
       
   478     }
       
   479 
       
   480 // --------------------------------------------------------------------------
       
   481 // CAlfExCalendarDeckControl::RotateVisualL
       
   482 // --------------------------------------------------------------------------
       
   483 //
       
   484 void CAlfExCalendarDeckControl::RotateVisualL(
       
   485         CAlfVisual& aVisual,
       
   486         TReal aInitAngle,
       
   487         TReal aTargetAngle,
       
   488         TInt aTime )
       
   489     {
       
   490     aVisual.EnableTransformationL();
       
   491     TAlfTimedValue angle( aInitAngle );
       
   492     angle.SetTarget( aTargetAngle, aTime );
       
   493     aVisual.Transformation().Rotate( angle , 0.0, 0.0, 1.0 );
       
   494     }
       
   495 
       
   496 
       
   497 // --------------------------------------------------------------------------
       
   498 // CAlfExCalendarDeckControl::SetOpacity
       
   499 // --------------------------------------------------------------------------
       
   500 //
       
   501 void CAlfExCalendarDeckControl::SetOpacity(
       
   502     CAlfVisual& aVisual,
       
   503     TReal aInitValue,
       
   504     TReal aTargetValue,
       
   505     TInt aTime )
       
   506     {
       
   507     TAlfTimedValue opacity;
       
   508     opacity.SetValueNow( aInitValue );
       
   509     opacity.SetTarget( aTargetValue, aTime ); // in milliseconds
       
   510     aVisual.SetOpacity( opacity );
       
   511     }
       
   512 
       
   513 
       
   514 // end of file
       
   515