startupservices/startupanimation/sanimctrl/src/sanimctrl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007 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 CSAnimCtrl class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sanimctrl.h"
       
    20 #include "sanimengine.h"
       
    21 
       
    22 #include "trace.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CSAnimCtrl::NewL
       
    28 //
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CSAnimCtrl* CSAnimCtrl::NewL(
       
    32     const TRect& aRect,
       
    33     const CCoeControl& aContainer )
       
    34     {
       
    35     FUNC_LOG;
       
    36 
       
    37     CSAnimCtrl* self = new( ELeave ) CSAnimCtrl;
       
    38     CleanupStack::PushL( self );
       
    39     self->BaseConstructL( aRect, aContainer );
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CSAnimCtrl::~CSAnimCtrl
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CSAnimCtrl::~CSAnimCtrl()
       
    51     {
       
    52     FUNC_LOG;
       
    53 
       
    54     delete iEngine;
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CSAnimCtrl::Load
       
    60 //
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CSAnimCtrl::Load(
       
    64     const TDesC& aImageFileName,
       
    65     const TTimeIntervalMicroSeconds32& aFrameDelay,
       
    66     const TBool aScalingEnabled,
       
    67     const TInt aAnimRepeatCount,
       
    68     const TDesC& aToneFileName,
       
    69     const TInt aVolume,
       
    70     const TTimeIntervalMicroSeconds& aVolumeRamp,
       
    71     const TInt aToneRepeatCount,
       
    72     TRequestStatus& aStatus )
       
    73     {
       
    74     FUNC_LOG;
       
    75 
       
    76     TDisplayMode dispMode = EColor16M;
       
    77     CGraphicsDevice* device = SystemGc().Device();
       
    78 	if ( device )
       
    79 	    {
       
    80 	    dispMode = device->DisplayMode();
       
    81 	    }
       
    82 
       
    83     TInt errorCode = iEngine->SetImageProperties(
       
    84         aImageFileName,
       
    85         dispMode,
       
    86         Size(),
       
    87         aFrameDelay,
       
    88         aScalingEnabled,
       
    89         aAnimRepeatCount );
       
    90     ERROR( errorCode, "Failed to set image properties" );
       
    91 
       
    92     errorCode = iEngine->SetToneProperties(
       
    93         aToneFileName,
       
    94         aVolume,
       
    95         aVolumeRamp,
       
    96         aToneRepeatCount );
       
    97     ERROR( errorCode, "Failed to set tone properties" );
       
    98 
       
    99     iEngine->Load( aStatus );
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CSAnimCtrl::Start
       
   105 //
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CSAnimCtrl::Start( TRequestStatus& aStatus )
       
   109     {
       
   110     FUNC_LOG;
       
   111 
       
   112     iBackgroundColour = iEngine->BackroundColour();
       
   113     iEngine->Start( aStatus );
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CSAnimCtrl::Cancel
       
   119 //
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CSAnimCtrl::Cancel()
       
   123     {
       
   124     FUNC_LOG;
       
   125 
       
   126     Clear();
       
   127     iEngine->Cancel();
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CSAnimCtrl::Clear
       
   133 //
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CSAnimCtrl::Clear()
       
   137     {
       
   138     FUNC_LOG;
       
   139 
       
   140     iBackgroundColour = TRgb();
       
   141     iImage = NULL;
       
   142     iMask = NULL;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CSAnimCtrl::CountComponentControls
       
   148 //
       
   149 // ---------------------------------------------------------------------------
       
   150 TInt CSAnimCtrl::CountComponentControls() const
       
   151     {
       
   152     return 0;
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSAnimCtrl::ComponentControl
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 CCoeControl* CSAnimCtrl::ComponentControl( TInt /*aIndex*/ ) const
       
   161     {
       
   162     return NULL;
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CSAnimCtrl::Draw
       
   168 //
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 void CSAnimCtrl::Draw( const TRect& /*aRect*/ ) const
       
   172     {
       
   173     FUNC_LOG;
       
   174 
       
   175 	CWindowGc& gc = SystemGc();
       
   176 
       
   177     TRect rect = Rect();
       
   178     gc.Clear( rect );
       
   179     gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   180     gc.SetBrushColor( iBackgroundColour );
       
   181     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   182     gc.Clear();
       
   183 
       
   184     TPoint pos = rect.iTl;
       
   185     TSize imgSize( 0, 0 );
       
   186     if ( iImage )
       
   187         {
       
   188         imgSize = iImage->SizeInPixels();
       
   189         }
       
   190 
       
   191     pos.iX += ( rect.Width() - imgSize.iWidth ) / 2;
       
   192     pos.iY += ( rect.Height() - imgSize.iHeight ) / 2;
       
   193 
       
   194     if ( iImage && iMask )
       
   195         {
       
   196         INFO_2( "Frame size: %d, %d", imgSize.iWidth, imgSize.iHeight );
       
   197         INFO_2( "Mask size: %d, %d", iMask->SizeInPixels().iWidth, iMask->SizeInPixels().iHeight );
       
   198         INFO_2( "Position: %d, %d", pos.iX, pos.iY );
       
   199 
       
   200         gc.BitBltMasked( pos, iImage, imgSize, iMask, EFalse );
       
   201 	    }
       
   202     else if ( iImage )
       
   203         {
       
   204         INFO_2( "Frame size: %d, %d", imgSize.iWidth, imgSize.iHeight );
       
   205         INFO_2( "Position: %d, %d", pos.iX, pos.iY );
       
   206 
       
   207     	gc.BitBlt( pos, iImage );
       
   208 	    }
       
   209 	else
       
   210 	    {
       
   211         INFO( "No frame or mask" );
       
   212 	    }
       
   213     }
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CSAnimCtrl::UpdateScreen
       
   218 //
       
   219 // ---------------------------------------------------------
       
   220 //
       
   221 void CSAnimCtrl::UpdateScreen(
       
   222     const CFbsBitmap& aFrame,
       
   223     const CFbsBitmap& aMask )
       
   224     {
       
   225     FUNC_LOG;
       
   226 
       
   227     iImage = &aFrame;
       
   228     iMask = &aMask;
       
   229     DrawNow();
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CSAnimCtrl::UpdateScreen
       
   235 //
       
   236 // ---------------------------------------------------------
       
   237 //
       
   238 void CSAnimCtrl::UpdateScreen( const CFbsBitmap& aFrame )
       
   239     {
       
   240     FUNC_LOG;
       
   241 
       
   242     iImage = &aFrame;
       
   243     iMask = NULL;
       
   244     DrawNow();
       
   245     }
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CSAnimCtrl::CSAnimCtrl
       
   250 //
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 EXPORT_C CSAnimCtrl::CSAnimCtrl()
       
   254   : iEngine( NULL ),
       
   255     iImage( NULL ),
       
   256     iMask( NULL )
       
   257     {
       
   258     FUNC_LOG;
       
   259     }
       
   260 
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CSAnimCtrl::BaseConstructL
       
   264 //
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CSAnimCtrl::BaseConstructL(
       
   268     const TRect& aRect,
       
   269     const CCoeControl& aContainer )
       
   270     {
       
   271     FUNC_LOG;
       
   272 
       
   273     iEngine = CSAnimEngine::NewL( iCoeEnv->FsSession(), *this );
       
   274 
       
   275     SetContainerWindowL( aContainer );
       
   276     SetRect( aRect );
       
   277     ActivateL();
       
   278     }