00001 /* 00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions are met: 00006 00007 * Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, 00010 this list of conditions and the following disclaimer in the documentation 00011 and/or other materials provided with the distribution. 00012 * Neither the name of Nokia Corporation nor the names of its contributors 00013 may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 Description: 00028 */ 00029 #include <eiklabel.h> 00030 #include <eikenv.h> 00031 00032 #include "AnimationContainer.h" 00033 00034 #include <aknutils.h> 00035 00036 00037 const TInt KFrameReadInterval = 200000; 00038 00039 /* 00040 ----------------------------------------------------------------------------- 00041 ----------------------------------------------------------------------------- 00042 */ 00043 CAnimationContainer* CAnimationContainer::NewL( const TRect& aRect, const TDesC& aFileName) 00044 { 00045 CAnimationContainer* self = CAnimationContainer::NewLC( aRect,aFileName); 00046 CleanupStack::Pop( self ); 00047 return self; 00048 } 00049 /* 00050 ----------------------------------------------------------------------------- 00051 ----------------------------------------------------------------------------- 00052 */ 00053 CAnimationContainer* CAnimationContainer::NewLC( const TRect& aRect, const TDesC& aFileName) 00054 { 00055 CAnimationContainer* self = new ( ELeave ) CAnimationContainer; 00056 CleanupStack::PushL( self ); 00057 self->ConstructL( aRect,aFileName); 00058 return self; 00059 } 00060 /* 00061 ----------------------------------------------------------------------------- 00062 ----------------------------------------------------------------------------- 00063 */ 00064 CAnimationContainer::~CAnimationContainer() 00065 { 00066 if (iFrameReadTimer) 00067 { 00068 iFrameReadTimer->Cancel(); 00069 } 00070 00071 delete iFrameReadTimer; 00072 00073 delete iAniFrame_Reader; 00074 delete iBitmap; 00075 delete iBitmapDevice; 00076 delete iGraphicsContext; 00077 } 00078 /* 00079 ----------------------------------------------------------------------------- 00080 ----------------------------------------------------------------------------- 00081 */ 00082 void CAnimationContainer::ConstructL( const TRect& aRect, const TDesC& aFileName) 00083 { 00084 CreateWindowL(); 00085 00086 SetRect( aRect ); 00087 00088 // construct the animation frame reader 00089 iAniFrame_Reader = CAniFrame_Reader::NewL(*this,aFileName); 00090 00091 // get the actual size of the animation frame 00092 TSize imgSiz = iAniFrame_Reader->AniFrameSizeL(); 00093 00094 // if we got the size, then there are frames, and we can start 00095 if(imgSiz.iWidth > 0 00096 && imgSiz.iHeight> 0) 00097 { 00098 // construct the bitmap for drawing the animation frames 00099 // use the actual size of the animation frames 00100 iBitmap = new(ELeave)CFbsBitmap(); 00101 iBitmap->Create(imgSiz,EColor16M); 00102 00103 // constrct the graphics device & context for drawing 00104 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap); 00105 User::LeaveIfError(iBitmapDevice->CreateContext(iGraphicsContext)); 00106 00107 // read the first animation frame 00108 iAniFrame_Reader->NextImageL(); 00109 } 00110 00111 ActivateL(); 00112 } 00113 /* 00114 ------------------------------------------------------------------------------- 00115 iFrameReadTimer calls this function periodically to tell us to show the next frame 00116 ------------------------------------------------------------------------------- 00117 */ 00118 TInt CAnimationContainer::DoReadNextFrameL(TAny* aPtr) 00119 { 00120 CAnimationContainer* self = static_cast<CAnimationContainer*>(aPtr); 00121 00122 if(self->iAniFrame_Reader)// check that the reader has been constructed 00123 { // and read the next frame 00124 self->iAniFrame_Reader->NextImageL(); 00125 } 00126 00127 return KErrNone; 00128 } 00129 /* 00130 ----------------------------------------------------------------------------- 00131 iAniFrame_Reader, uses this function to give use the frame we asked it to read 00132 so we can draw it to teh bitmap for showing into the screen 00133 ----------------------------------------------------------------------------- 00134 */ 00135 void CAnimationContainer::AppendFrameL(CFbsBitmap& aImage,CFbsBitmap& aMask,TRect aArea, TBool aReDraw) 00136 { 00137 if(iGraphicsContext)// make sure we have the context constructed 00138 { 00139 // check the size of the image for drawing 00140 TSize imgSiz(aImage.SizeInPixels()); 00141 00142 if(aReDraw) 00143 {// if its complete re-draw, we do not need to use the mask 00144 iGraphicsContext->DrawBitmap(TRect(0,0,imgSiz.iWidth,imgSiz.iHeight),&aImage); 00145 } 00146 else 00147 { // othervise we need to check the position 00148 // and use the mask to draw the frame on top of the old bitmap image 00149 iGraphicsContext->DrawBitmapMasked(aArea,&aImage,TRect(0,0,imgSiz.iWidth,imgSiz.iHeight),&aMask,EFalse); 00150 } 00151 } 00152 00153 if(!iFrameReadTimer) 00154 { // if it is first time we did this, we'll start the periodic timer 00155 iFrameReadTimer = CPeriodic::NewL(CActive::EPriorityHigh); 00156 iFrameReadTimer->Start(KFrameReadInterval, KFrameReadInterval, TCallBack(DoReadNextFrameL, this)); 00157 } 00158 00159 DrawNow(); 00160 } 00161 /* 00162 ----------------------------------------------------------------------------- 00163 normal Draw funtion for CCoeControl, which is used to draw to the screen 00164 ----------------------------------------------------------------------------- 00165 */ 00166 void CAnimationContainer::Draw( const TRect& /*aRect*/ ) const 00167 { 00168 CWindowGc& gc = SystemGc(); 00169 00170 if(iBitmap)// Check that we have the bitmap constructed 00171 { 00172 if(iBitmap->Handle())// and it has valid bitmap 00173 { 00174 // just draw it to fill the whole container screen 00175 // so not caring about the scaling issues in here. 00176 gc.DrawBitmap(Rect(),iBitmap); 00177 } 00178 } 00179 00180 } 00181 00182 /* 00183 ----------------------------------------------------------------------------- 00184 used for informinging about resource changes, 00185 in S60 one usage is to know when the layout of the screen has been changed 00186 ----------------------------------------------------------------------------- 00187 */ 00188 void CAnimationContainer::HandleResourceChange(TInt aType) 00189 { 00190 if ( aType==KEikDynamicLayoutVariantSwitch )// layout change event 00191 { // get new main panel rect and set it 00192 TRect rect; 00193 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); 00194 SetRect(rect); 00195 } 00196 00197 // forward events for CCoeControl's base class handler 00198 CCoeControl::HandleResourceChange(aType); 00199 } 00200 00201 00202 00203 // End of File