|
1 /* |
|
2 * Copyright (c) 2006-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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <uiacceltk/huigifanimationtexture.h> |
|
21 #include <uiacceltk/HuiStatic.h> |
|
22 #include <driveinfo.h> |
|
23 |
|
24 CHuiGifAnimationTexture::TAnimationState SetFlag(TInt aValue, TInt aFlag) |
|
25 { |
|
26 return CHuiGifAnimationTexture::TAnimationState(aValue|aFlag); |
|
27 } |
|
28 |
|
29 CHuiGifAnimationTexture::TAnimationState ClearFlag(TInt aValue, TInt aFlag) |
|
30 { |
|
31 return CHuiGifAnimationTexture::TAnimationState(aValue^aFlag); |
|
32 } |
|
33 |
|
34 |
|
35 EXPORT_C CHuiGifAnimationTexture* CHuiGifAnimationTexture::NewL(const TDesC& aFilename, |
|
36 CHuiTextureManager& aManager, |
|
37 TInt aID, |
|
38 THuiTextureUploadFlags aFlags) |
|
39 { |
|
40 CHuiGifAnimationTexture* self = new(ELeave) CHuiGifAnimationTexture(aManager,aFlags, aID); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(aFilename); |
|
43 CleanupStack::Pop(); // self |
|
44 return self; |
|
45 } |
|
46 |
|
47 EXPORT_C void CHuiGifAnimationTexture::Start() |
|
48 { |
|
49 iAnimationState = SetFlag(TInt(iAnimationState), TInt(ERunning)); |
|
50 if (iAnimationState&EStopped) |
|
51 { |
|
52 iAnimationState=ClearFlag(TInt(iAnimationState), TInt(EStopped)); |
|
53 } |
|
54 |
|
55 if (iTexture) |
|
56 { |
|
57 iTexture->SetTextureChanged(ETrue); |
|
58 } |
|
59 } |
|
60 |
|
61 EXPORT_C void CHuiGifAnimationTexture::Stop() |
|
62 { |
|
63 if (iAnimationState&ERunning) |
|
64 { |
|
65 iAnimationState=ClearFlag(TInt(iAnimationState), TInt(ERunning)); |
|
66 } |
|
67 iAnimationState = SetFlag(TInt(iAnimationState), TInt(EStopped)); |
|
68 } |
|
69 |
|
70 |
|
71 EXPORT_C void CHuiGifAnimationTexture::EnableAnimation(TBool aEnable) |
|
72 { |
|
73 if (aEnable) |
|
74 { |
|
75 iAnimationState = SetFlag(TInt(iAnimationState), TInt(EEnabled)); |
|
76 } |
|
77 else |
|
78 { |
|
79 iAnimationState = ClearFlag(TInt(iAnimationState), TInt(EEnabled)); |
|
80 } |
|
81 } |
|
82 |
|
83 EXPORT_C TInt CHuiGifAnimationTexture::Id() |
|
84 { |
|
85 return iId; |
|
86 } |
|
87 |
|
88 void CHuiGifAnimationTexture::AdvanceTime(TReal32 aElapsedTime) __SOFTFP |
|
89 { |
|
90 if (((iAnimationState & EInitializing) || (iFrameInterval == -1)) || (iAnimationState & EStopped) |
|
91 || !(iAnimationState & EEnabled)) |
|
92 { |
|
93 return; |
|
94 } |
|
95 |
|
96 iElapsedTime+=aElapsedTime; |
|
97 |
|
98 TReal32 time = (TReal(iFrameInterval))/1000000.0f; |
|
99 if (iElapsedTime >= time) |
|
100 { |
|
101 const TInt loadingTextureId = iCurrentTexture ? iTextureId1 : iTextureId2; |
|
102 if ( !iManager.IsLoaded( loadingTextureId ) ) |
|
103 { |
|
104 return; |
|
105 } |
|
106 |
|
107 iCurrentTexture^=1; |
|
108 |
|
109 if (iCurrentTexture) |
|
110 // use texture 2 |
|
111 { |
|
112 iTexture = iTexture2; |
|
113 TInt nextToLoad = iTexture2->iFrameNumber+1; |
|
114 if (nextToLoad >= iFrameCount) |
|
115 { |
|
116 nextToLoad = 0; |
|
117 } |
|
118 |
|
119 delete iTexture1; |
|
120 iTexture1 = 0; |
|
121 |
|
122 TRAP_IGNORE(iTexture1 = &iManager.LoadTextureL(*iFilename,EHuiTextureUploadFlagDefault, iTextureId1, nextToLoad)) |
|
123 } |
|
124 else |
|
125 // use texture 1 |
|
126 { |
|
127 iTexture = iTexture1; |
|
128 TInt nextToLoad = iTexture1->iFrameNumber+1; |
|
129 if (nextToLoad >= iFrameCount) |
|
130 { |
|
131 nextToLoad = 0; |
|
132 } |
|
133 |
|
134 delete iTexture2; |
|
135 iTexture2 = 0; |
|
136 |
|
137 TRAP_IGNORE(iTexture2 = &iManager.LoadTextureL(*iFilename,EHuiTextureUploadFlagDefault, iTextureId2, nextToLoad)) |
|
138 |
|
139 } |
|
140 iElapsedTime = 0.0f; |
|
141 |
|
142 } |
|
143 } |
|
144 |
|
145 |
|
146 void CHuiGifAnimationTexture::TextureLoadingCompleted(CHuiTexture& aTexture, |
|
147 TInt aTextureId, |
|
148 TInt /*aErrorCode*/) |
|
149 { |
|
150 if ((iAnimationState & EInitializing) && aTexture.iFrameCount > 1 && aTextureId == iTextureId1) |
|
151 { |
|
152 iTexture = iTexture1; |
|
153 TRAP_IGNORE(iTexture2 = &iManager.LoadTextureL(*iFilename,EHuiTextureUploadFlagDefault, iTextureId2, 1)) |
|
154 iFrameInterval = aTexture.iFrameInterval; |
|
155 iFrameCount = aTexture.iFrameCount; |
|
156 return; |
|
157 } |
|
158 if ((iAnimationState & EInitializing) && aTextureId == iTextureId2) |
|
159 { |
|
160 iAnimationState = SetFlag(TInt(iAnimationState),TInt(ERunning)); |
|
161 iAnimationState = ClearFlag(TInt(iAnimationState), TInt(EInitializing)); |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 CHuiGifAnimationTexture::CHuiGifAnimationTexture(CHuiTextureManager& aManager,THuiTextureUploadFlags aFlags,TInt aId) : |
|
167 CHuiAnimatedTexture(aManager), |
|
168 iTexture2(NULL), |
|
169 iCurrentTexture(0), |
|
170 iAnimationState(EInitializing), |
|
171 iFrameInterval(-1), |
|
172 iFrameCount(0), |
|
173 iFlags(aFlags), |
|
174 iId(aId) |
|
175 { |
|
176 } |
|
177 |
|
178 void CHuiGifAnimationTexture::ConstructL(const TDesC& aFilename) |
|
179 { |
|
180 CHuiAnimatedTexture::BaseConstructL(); |
|
181 iTextureId1 = CHuiStatic::GenerateId(); |
|
182 iTextureId2 = CHuiStatic::GenerateId(); |
|
183 |
|
184 // To load GIF animation, you should load textures in sequence - |
|
185 // previous state is needed. Thus, this group indicates that |
|
186 // previous state can be shared between these textures. |
|
187 RArray<TInt> groupIds; |
|
188 CleanupClosePushL( groupIds ); |
|
189 groupIds.AppendL( iTextureId1 ); |
|
190 groupIds.AppendL( iTextureId2 ); |
|
191 iAnimatedTextureGroupId = iManager.AddAnimatedTextureGroupL( groupIds ); |
|
192 CleanupStack::PopAndDestroy( &groupIds ); |
|
193 |
|
194 // Alf locks the file while drawing textures hence preventing any other operations on this file |
|
195 // so copy file to RAM and use that instead. |
|
196 TParse parse; |
|
197 parse.Set(aFilename, NULL, NULL); |
|
198 parse.NameAndExt(); |
|
199 |
|
200 TChar drive; |
|
201 User::LeaveIfError( DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRam, drive ) ); |
|
202 |
|
203 iFilename = HBufC::NewL(parse.NameAndExt().Size() + 4); |
|
204 TPtr ptr = iFilename->Des(); |
|
205 |
|
206 ptr.Append(drive); |
|
207 ptr.Append(_L(":\\")); |
|
208 ptr.Append(parse.NameAndExt()); |
|
209 |
|
210 RFs fs; |
|
211 User::LeaveIfError(fs.Connect()); |
|
212 |
|
213 CFileMan* fileman = CFileMan::NewL(fs); |
|
214 CleanupStack::PushL(fileman); |
|
215 TInt err = fileman->Copy(aFilename, iFilename->Des()); |
|
216 |
|
217 CleanupStack::PopAndDestroy(); |
|
218 |
|
219 if(err != KErrNone) |
|
220 { |
|
221 delete iFilename; |
|
222 iFilename = aFilename.AllocL(); |
|
223 } |
|
224 |
|
225 |
|
226 iTexture1 = &iManager.LoadTextureL( |
|
227 *iFilename,EHuiTextureUploadFlagDefault, iTextureId1, 0); |
|
228 iManager.iLoadObservers.AppendL(*this); |
|
229 |
|
230 iAnimationState = SetFlag(TInt(iAnimationState), TInt(EEnabled)); |
|
231 } |
|
232 |
|
233 EXPORT_C CHuiGifAnimationTexture::~CHuiGifAnimationTexture() |
|
234 { |
|
235 if ( iAnimatedTextureGroupId ) |
|
236 { |
|
237 iManager.RemoveAnimatedTextureGroup( iAnimatedTextureGroupId ); |
|
238 } |
|
239 iManager.iLoadObservers.RemoveIfFound(*this); |
|
240 |
|
241 delete iTexture1; |
|
242 delete iTexture2; |
|
243 |
|
244 iTexture = 0; |
|
245 |
|
246 RFs fs; |
|
247 TInt err = fs.Connect(); |
|
248 if(err == KErrNone) |
|
249 { |
|
250 CFileMan* fileman = 0; |
|
251 TRAP(err, fileman = CFileMan::NewL(fs)); |
|
252 if(err == KErrNone) |
|
253 { |
|
254 fileman->Delete(iFilename->Des()); |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 delete iFilename; |
|
260 } |
|
261 |
|
262 |