skins/AknSkins/alsrc/AknsAlTimingModelRealTime.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Real-time timing model.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <AknsRlParameter.h>
       
    22 #include "AknsAlTimingModelRealTime.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CAknsAlTimingModelRealTime::CAknsAlTimingModelRealTime
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CAknsAlTimingModelRealTime::CAknsAlTimingModelRealTime():
       
    31     iDuration( 0 ),
       
    32     iTotalDuration( 0 ),
       
    33     iElapsedTime( 0 ),
       
    34     iRelative( 0 ),
       
    35     iWrap( EFalse )
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CAknsAlTimingModelRealTime::NewL
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CAknsAlTimingModelRealTime* CAknsAlTimingModelRealTime::NewL()
       
    44     {
       
    45     CAknsAlTimingModelRealTime* self = new(ELeave) CAknsAlTimingModelRealTime();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CAknsAlTimingModelRealTime::CAknsAlTimingModelRealTime
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CAknsAlTimingModelRealTime::~CAknsAlTimingModelRealTime()
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAknsAlTimingModelRealTime::Duration
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 TInt CAknsAlTimingModelRealTime::Duration() const
       
    62     {
       
    63     return iDuration;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CAknsAlTimingModelRealTime::TotalDuration
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 TInt CAknsAlTimingModelRealTime::TotalDuration() const
       
    71     {
       
    72     return iTotalDuration;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAknsAlTimingModelRealTime::Configure
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CAknsAlTimingModelRealTime::Configure( TInt aD, TInt aRC, TInt aRD, TBool aWrap )
       
    80     {
       
    81     iElapsedTime = 0;
       
    82     iWrap = aWrap;
       
    83     iRelative = 0;
       
    84 
       
    85     // Because we use fixed point arithmetic, duration and repeat duration
       
    86     // absolute value must be clamped.
       
    87     if( Defined( aRD ) && aRD > KAlMaxDurationVal )
       
    88         {
       
    89         aRD = KAlMaxDurationVal;
       
    90         }
       
    91 
       
    92     if( Defined( aD ) && aD > KAlMaxDurationVal )
       
    93         {
       
    94         aD = KAlMaxDurationVal;
       
    95         }
       
    96 
       
    97     // Determine duration and total duration
       
    98     if( Defined( aD ) ) // Cases from #6 to #14
       
    99         {
       
   100         // Duration is the same in all cases
       
   101         iDuration = aD;
       
   102 
       
   103         if( Infinite( aRC ) )
       
   104             {
       
   105             if( Undefined( aRD ) ) // #6
       
   106                 {
       
   107                 iTotalDuration = -1;
       
   108                 }
       
   109             else if( Defined( aRD ) ) // #7
       
   110                 {
       
   111                 iTotalDuration = aRD;
       
   112                 }
       
   113             else // aRD must be infinite, #8
       
   114                 {
       
   115                 iTotalDuration = -1;
       
   116                 }
       
   117             }
       
   118         else if( Undefined( aRC ) )
       
   119             {
       
   120             if( Undefined( aRD ) ) // #9
       
   121                 {
       
   122                 iTotalDuration = aD;
       
   123                 }
       
   124             else if( Defined( aRD ) ) // #10
       
   125                 {
       
   126                 iTotalDuration = aRD;
       
   127                 }
       
   128             else // aRD must be infinite, #11
       
   129                 {
       
   130                 iTotalDuration = -1;
       
   131                 }
       
   132             }
       
   133         else // aRC must be defined
       
   134             {
       
   135             if( Undefined( aRD ) ) // #12
       
   136                 {
       
   137                 iTotalDuration = aD * aRC;
       
   138                 }
       
   139             else if( Defined( aRD ) ) // #13
       
   140                 {
       
   141                 // total duration = MIN( D * RC, RD )
       
   142                 iTotalDuration = aD * aRC < aRD ? aD * aRC: aRD;
       
   143                 }
       
   144             else // aRD must be infinite, #14
       
   145                 {
       
   146                 iTotalDuration = aD * aRC;
       
   147                 }
       
   148             }
       
   149         }
       
   150     else if( Infinite( aD ) ) // Cases from #15 to #17
       
   151         {
       
   152         // Repeat count is ignored
       
   153 
       
   154         if( Defined( aRD ) ) // #15
       
   155             {
       
   156             iDuration      = aRD;
       
   157             iTotalDuration = aRD;
       
   158             }
       
   159         else // #16 and #17
       
   160             {
       
   161             // Undefined and infinite produce the same result
       
   162             iDuration      = -1;
       
   163             iTotalDuration = -1;
       
   164             }
       
   165         }
       
   166     else // Duration is undefined, cases from #1 to #5
       
   167         {
       
   168         // Cases, #4 and #5
       
   169         if( Undefined( aRD ) && !Infinite( aRC ) )
       
   170             {
       
   171             // These are basically impossible cases
       
   172             iDuration      = 0;
       
   173             iTotalDuration = 0;
       
   174             }
       
   175         // Case #1
       
   176         else if( Defined( aRD ) )
       
   177             {
       
   178             iDuration      = aRD;
       
   179             iTotalDuration = aRD;
       
   180             }
       
   181         else // Must be cases #2 and #3
       
   182             {
       
   183             iDuration      = -1;
       
   184             iTotalDuration = -1;
       
   185             }
       
   186          }
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CAknsAlTimingModelRealTime::SetParametersL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CAknsAlTimingModelRealTime::SetParametersL(
       
   194     MAknsRlParameterIterator& aParameters )
       
   195     {
       
   196     TInt duration = 0;
       
   197     TInt repeatCount = 0;
       
   198     TInt repeatDuration = 0;
       
   199     TBool wrap = EFalse;
       
   200 
       
   201     // Iterate over available parameters
       
   202     while( aParameters.HasNext() )
       
   203         {
       
   204         const TAknsRlParameterData* param = aParameters.NextL();
       
   205 
       
   206         if( param->iName->Compare( KAknsAlRealTimeDuration ) == 0 )
       
   207             {
       
   208             if( param->iType != EAknsRlParameterTypeNumber )
       
   209                 User::Leave( KErrArgument );
       
   210 
       
   211             duration = param->iNumber;
       
   212             }
       
   213         else if( param->iName->Compare( KAknsAlRealTimeRepeatCount ) == 0 )
       
   214             {
       
   215             if( param->iType != EAknsRlParameterTypeNumber )
       
   216                 User::Leave( KErrArgument );
       
   217 
       
   218             repeatCount = param->iNumber;
       
   219             }
       
   220         else if( param->iName->Compare( KAknsAlRealTimeRepeatDuration ) == 0 )
       
   221             {
       
   222             if( param->iType != EAknsRlParameterTypeNumber )
       
   223                 User::Leave( KErrArgument );
       
   224 
       
   225             repeatDuration = param->iNumber;
       
   226             }
       
   227         else if( param->iName->Compare( KAknsAlRealTimeWrap ) == 0 )
       
   228             {
       
   229             if( param->iType != EAknsRlParameterTypeNumber )
       
   230                 User::Leave( KErrArgument );
       
   231 
       
   232             wrap = ( param->iNumber != 0 ) ? ETrue: EFalse;
       
   233             }
       
   234         }
       
   235 
       
   236     // Configure the model
       
   237     Configure( duration, repeatCount, repeatDuration, wrap );
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CAknsAlTimingModelRealTime::Tick
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CAknsAlTimingModelRealTime::Tick( const TInt aDeltaTime )
       
   245     {
       
   246     iElapsedTime = iElapsedTime + aDeltaTime;
       
   247 
       
   248     // Cases #4 and #5 are the only ones that will produce undefined durations
       
   249     // in Configure. This kind of animation will never run properly
       
   250     if( Undefined( iDuration ) || Undefined( iTotalDuration ) )
       
   251         return;
       
   252 
       
   253     // Starting from here the durations are either defined or infinite
       
   254 
       
   255     // Check if the the total duration has been exceeded
       
   256     if( IsFinished() )
       
   257         return;
       
   258 
       
   259     // Relative value is undefined if duration is either undefined or infinite
       
   260     if( !Defined( iDuration ) ) // iDuration <= 0
       
   261         {
       
   262         iRelative = 0;
       
   263         }
       
   264     else // Duration is defined, relative value can be calculated
       
   265         {
       
   266         // Note: iDuration is always > 0 here
       
   267 
       
   268         // Elapsed time and duration always >= 0 -> conversion ok
       
   269         TUint32 durationPos = TUint32( iElapsedTime % iDuration ); //lint !e414 iDuration > 0
       
   270         TBool ascending = ETrue;
       
   271 
       
   272         // When wrapping, odd durations are descending, even ascending
       
   273         if( iWrap && ( iElapsedTime / iDuration ) % 2 ) //lint !e414 iDuration > 0 Remainder != 0
       
   274             ascending = EFalse;
       
   275 
       
   276         // TODO Allow longer durations -> promote results to 64bit integer
       
   277         // Calculate the relative value
       
   278         if( ascending )
       
   279             {
       
   280             iRelative = ( durationPos << 16 ) / TUint32( iDuration ); //lint !e414 iDuration > 0
       
   281             }
       
   282         else // Current range must be descending
       
   283             {
       
   284             iRelative = ( ( iDuration - durationPos ) << 16 ) / TUint32( iDuration ); //lint !e414 iDuration > 0
       
   285             }
       
   286         }
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CAknsAlTimingModelRealTime::Tick
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CAknsAlTimingModelRealTime::Tick( const TTime& /*aStamp*/ )
       
   294     {
       
   295     // Not supported
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CAknsAlTimingModelRealTime::RelativeValue
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TUint32 CAknsAlTimingModelRealTime::RelativeValue() const
       
   303     {
       
   304     return iRelative;
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CAknsAlTimingModelRealTime::IsFinished
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TBool CAknsAlTimingModelRealTime::IsFinished() const
       
   312     {
       
   313     if( Defined( iTotalDuration ) && iElapsedTime > iTotalDuration )
       
   314         {
       
   315         return ETrue;
       
   316         }
       
   317 
       
   318     return EFalse;
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CAknsAlTimingModelRealTime::Begin
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CAknsAlTimingModelRealTime::Begin()
       
   326     {
       
   327     iElapsedTime = 0;
       
   328     iRelative = 0;
       
   329     }
       
   330 
       
   331 // End of file