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 "Animation_Control.h" 00033 00034 00035 #include <aknutils.h> 00036 00037 00038 const TInt KFrameReadInterval = 200000; 00039 00040 /* 00041 ----------------------------------------------------------------------------- 00042 ----------------------------------------------------------------------------- 00043 */ 00044 CAnimationControl* CAnimationControl::NewL(CCoeControl& aContainer,const TRect& aRect, const TDesC& aFileName) 00045 { 00046 CAnimationControl* self = CAnimationControl::NewLC(aContainer,aRect,aFileName); 00047 CleanupStack::Pop( self ); 00048 return self; 00049 } 00050 /* 00051 ----------------------------------------------------------------------------- 00052 ----------------------------------------------------------------------------- 00053 */ 00054 CAnimationControl* CAnimationControl::NewLC(CCoeControl& aContainer,const TRect& aRect, const TDesC& aFileName) 00055 { 00056 CAnimationControl* self = new ( ELeave ) CAnimationControl; 00057 CleanupStack::PushL( self ); 00058 self->ConstructL(aContainer,aRect,aFileName); 00059 return self; 00060 } 00061 /* 00062 ----------------------------------------------------------------------------- 00063 ----------------------------------------------------------------------------- 00064 */ 00065 CAnimationControl::~CAnimationControl() 00066 { 00067 if (iFrameReadTimer) 00068 { 00069 iFrameReadTimer->Cancel(); 00070 } 00071 00072 delete iFrameReadTimer; 00073 00074 delete iAniFrame_Reader; 00075 delete iBitmap; 00076 delete iBitmapDevice; 00077 delete iGraphicsContext; 00078 } 00079 /* 00080 ----------------------------------------------------------------------------- 00081 ----------------------------------------------------------------------------- 00082 */ 00083 void CAnimationControl::ConstructL(CCoeControl& aContainer,const TRect& aRect, const TDesC& aFileName) 00084 { 00085 SetContainerWindowL(aContainer); 00086 00087 SetRect( aRect ); 00088 00089 // construct the animation frame reader 00090 iAniFrame_Reader = CAniFrame_Reader::NewL(*this,aFileName); 00091 00092 // get the actual size of the animation frame 00093 TSize imgSiz = iAniFrame_Reader->AniFrameSizeL(); 00094 00095 // if we got the size, then there are frames, and we can start 00096 if(imgSiz.iWidth > 0 00097 && imgSiz.iHeight> 0) 00098 { 00099 // construct the bitmap for drawing the animation frames 00100 // use the actual size of the animation frames 00101 iBitmap = new(ELeave)CFbsBitmap(); 00102 iBitmap->Create(imgSiz,EColor16M); 00103 00104 // constrct the graphics device & context for drawing 00105 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap); 00106 User::LeaveIfError(iBitmapDevice->CreateContext(iGraphicsContext)); 00107 00108 // read the first animation frame 00109 iAniFrame_Reader->NextImageL(); 00110 } 00111 00112 ActivateL(); 00113 } 00114 /* 00115 ------------------------------------------------------------------------------- 00116 iFrameReadTimer calls this function periodically to tell us to show the next frame 00117 ------------------------------------------------------------------------------- 00118 */ 00119 TInt CAnimationControl::DoReadNextFrameL(TAny* aPtr) 00120 { 00121 CAnimationControl* self = static_cast<CAnimationControl*>(aPtr); 00122 00123 if(self->iAniFrame_Reader)// check that the reader has been constructed 00124 { // and read the next frame 00125 self->iAniFrame_Reader->NextImageL(); 00126 } 00127 00128 return KErrNone; 00129 } 00130 /* 00131 ----------------------------------------------------------------------------- 00132 iAniFrame_Reader, uses this function to give use the frame we asked it to read 00133 so we can draw it to teh bitmap for showing into the screen 00134 ----------------------------------------------------------------------------- 00135 */ 00136 void CAnimationControl::AppendFrameL(CFbsBitmap& aImage,CFbsBitmap& aMask,TRect aArea, TBool aReDraw) 00137 { 00138 if(iGraphicsContext)// make sure we have the context constructed 00139 { 00140 // check the size of the image for drawing 00141 TSize imgSiz(aImage.SizeInPixels()); 00142 00143 if(aReDraw) 00144 {// if its complete re-draw, we do not need to use the mask 00145 iGraphicsContext->DrawBitmap(TRect(0,0,imgSiz.iWidth,imgSiz.iHeight),&aImage); 00146 } 00147 else 00148 { // othervise we need to check the position 00149 // and use the mask to draw the frame on top of the old bitmap image 00150 iGraphicsContext->DrawBitmapMasked(aArea,&aImage,TRect(0,0,imgSiz.iWidth,imgSiz.iHeight),&aMask,EFalse); 00151 } 00152 } 00153 00154 if(!iFrameReadTimer) 00155 { // if it is first time we did this, we'll start the periodic timer 00156 iFrameReadTimer = CPeriodic::NewL(CActive::EPriorityHigh); 00157 iFrameReadTimer->Start(KFrameReadInterval, KFrameReadInterval, TCallBack(DoReadNextFrameL, this)); 00158 } 00159 00160 DrawNow(); 00161 } 00162 /* 00163 ----------------------------------------------------------------------------- 00164 normal Draw funtion for CCoeControl, which is used to draw to the screen 00165 ----------------------------------------------------------------------------- 00166 */ 00167 void CAnimationControl::Draw( const TRect& /*aRect*/ ) const 00168 { 00169 CWindowGc& gc = SystemGc(); 00170 00171 if(iBitmap)// Check that we have the bitmap constructed 00172 { 00173 if(iBitmap->Handle())// and it has valid bitmap 00174 { 00175 // just draw it to fill the whole container screen 00176 // so not caring about the scaling issues in here. 00177 gc.DrawBitmap(Rect(),iBitmap); 00178 } 00179 } 00180 } 00181 00182 // End of File