00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "AnimExample.h"
00031
00032 CAnimationAppView::CAnimationAppView()
00033 {
00034 }
00035
00036 CAnimationAppView* CAnimationAppView::NewL(const TRect& aRect)
00037 {
00038 CAnimationAppView* self = new(ELeave) CAnimationAppView();
00039 CleanupStack::PushL(self);
00040 self->ConstructL(aRect);
00041 CleanupStack::Pop();
00042 return self;
00043 }
00044
00045 CAnimationAppView::~CAnimationAppView()
00046 {
00047 delete iAnimTestText;
00048 delete iSpriteAnim;
00049 delete iBasicAnim;
00050
00051 if( iSpriteAnimMover )
00052 {
00053 iSpriteAnimMover->Cancel();
00054 delete iSpriteAnimMover;
00055 }
00056
00057 if( iBasicAnimMover )
00058 {
00059 iBasicAnimMover->Cancel();
00060 delete iBasicAnimMover;
00061 }
00062 }
00063
00064
00065 void CAnimationAppView::ConstructL( const TRect& aRect )
00066 {
00067
00068
00069 iAnimTestText = iEikonEnv->AllocReadResourceL( R_EXAMPLE_TEXT_BASICANIM );
00070
00071
00072 CreateWindowL();
00073
00074
00075 SetRect(aRect);
00076
00077
00078 ActivateL();
00079 }
00080
00081
00082 void CAnimationAppView::ProduceSpriteAnimL()
00083 {
00084
00085
00086 CICLAnimationDataProvider* spriteDataProvider = new (ELeave)CICLAnimationDataProvider;
00087 CleanupStack::PushL( spriteDataProvider );
00088 spriteDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00089 CleanupStack::Pop( spriteDataProvider );
00090
00091 iSpriteAnim = CSpriteAnimation::NewL( spriteDataProvider,TPoint(KAnimExSpritePositionX, KAnimExSpritePositionY), iEikonEnv->WsSession(), Window() );
00092
00093 TAnimationConfig config;
00094 config.iFlags = TAnimationConfig::ELoop;
00095 config.iData = -1;
00096
00097 iSpriteAnim->Start( config );
00098 }
00099
00100 void CAnimationAppView::ProduceBasicAnimL()
00101 {
00102
00103 TAnimationConfig config;
00104 config.iFlags = TAnimationConfig::ELoop;
00105 config.iData = -1;
00106
00107
00108 CICLAnimationDataProvider* basicDataProvider = new (ELeave)CICLAnimationDataProvider;
00109 CleanupStack::PushL( basicDataProvider );
00110 basicDataProvider->SetFileL( iEikonEnv->FsSession(), KAnimExStopWatch() );
00111
00112 CleanupStack::Pop( basicDataProvider );
00113
00114 iBasicAnim = CBasicAnimation::NewL( basicDataProvider,TPoint( KAnimExBasicPositionX, KAnimExBasicPositionY ), iEikonEnv->WsSession(), Window() );
00115
00116 iBasicAnim->Start( config );
00117 }
00118
00119 void CAnimationAppView::MoveAnimsL()
00120 {
00121
00122 if( iSpriteAnimMover )
00123 {
00124 iSpriteAnimMover->Cancel();
00125 delete iSpriteAnimMover;
00126 iSpriteAnimMover = NULL;
00127 }
00128
00129 iSpriteAnimMover = new (ELeave) CSpriteAnimMover( EPriorityNormal, KspriteInterval, iSpriteAnim );
00130
00131
00132 if( iBasicAnimMover )
00133 {
00134 iBasicAnimMover->Cancel();
00135 delete iBasicAnimMover;
00136 iBasicAnimMover = NULL;
00137 }
00138
00139 iBasicAnimMover = new (ELeave) CBasicAnimMover( EPriorityNormal, KBasicInterval, iBasicAnim );
00140
00141 }
00142
00143 void CAnimationAppView::DoSpriteAnimOperationL( TAnimOperation aOperation )
00144 {
00145
00146 if( !iSpriteAnim )
00147 {
00148 iEikonEnv->InfoMsg( _L("Not Initialised") );
00149 return;
00150 }
00151
00152 switch( aOperation )
00153 {
00154
00155 case EAnimPause:
00156 iSpriteAnim->Pause();
00157 break;
00158
00159 case EAnimResume:
00160 iSpriteAnim->Resume();
00161 break;
00162
00163 case EAnimStop:
00164 iSpriteAnim->Stop();
00165 break;
00166
00167 default:
00168 break;
00169
00170 }
00171
00172 }
00173
00174
00175 void CAnimationAppView::DoBasicAnimOperationL( TAnimOperation aOperation )
00176 {
00177
00178 if( !iBasicAnim )
00179 {
00180 iEikonEnv->InfoMsg( _L("Not Initialised") );
00181 return;
00182 }
00183
00184 switch( aOperation )
00185 {
00186 case EAnimPause:
00187 iBasicAnim->Pause();
00188 break;
00189
00190 case EAnimResume:
00191 iBasicAnim->Resume();
00192 break;
00193
00194 case EAnimStop:
00195 iBasicAnim->Stop();
00196 break;
00197
00198 default:
00199 break;
00200 }
00201
00202 }
00203
00204
00205
00206
00207
00208 void CAnimationAppView::ResetSpriteAnimAndMover()
00209 {
00210
00211 if( iSpriteAnimMover )
00212 {
00213 iSpriteAnimMover->Cancel();
00214 delete iSpriteAnimMover;
00215 iSpriteAnimMover = NULL;
00216 }
00217
00218 if( iSpriteAnim )
00219 {
00220 iSpriteAnim->Stop();
00221 delete iSpriteAnim;
00222 iSpriteAnim = NULL;
00223 }
00224 }
00225
00226 void CAnimationAppView::ResetBasicAnimAndMover()
00227 {
00228 if( iBasicAnimMover )
00229 {
00230 iBasicAnimMover->Cancel();
00231 delete iBasicAnimMover;
00232 iBasicAnimMover = NULL;
00233 }
00234
00235 if( iBasicAnim )
00236 {
00237 iBasicAnim->Stop();
00238 delete iBasicAnim;
00239 iBasicAnim = NULL;
00240
00241 Window().Invalidate();
00242 }
00243
00244 }
00245
00246
00247
00248 void CAnimationAppView::Draw(const TRect& ) const
00249 {
00250
00251
00252 CWindowGc& gc = SystemGc();
00253
00254
00255 TRect drawRect = Rect();
00256
00257
00258 const CFont* fontUsed;
00259
00260
00261 gc.Clear();
00262
00263
00264 fontUsed = iEikonEnv->TitleFont();
00265 gc.UseFont( fontUsed );
00266
00267
00268 TInt baselineOffset=( drawRect.Height() - fontUsed->HeightInPixels() );
00269 gc.DrawText( *iAnimTestText,drawRect,0 + fontUsed->HeightInPixels(),CGraphicsContext::ECenter, 0 );
00270
00271 gc.DrawText( KAnimExBasicLabel, drawRect, baselineOffset - KBasicOffset, CGraphicsContext::ECenter, 0 );
00272
00273
00274
00275 if( iBasicAnim )
00276 {
00277 iBasicAnim->Draw( gc );
00278 }
00279
00280 gc.DrawText( KAnimExSpriteLabel, drawRect, baselineOffset - KSpriteOffset, CGraphicsContext::ELeft, 0 );
00281
00282
00283 gc.DiscardFont();
00284 }
00285
00286
00287
00288