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: Active Palette Base plugin class* |
|
15 */ |
|
16 |
|
17 |
|
18 /** |
|
19 * @file CActivePalettePluginBase.cpp |
|
20 * Active Palette Base plugin class |
|
21 */ |
|
22 |
|
23 // INCLUDE FILES |
|
24 |
|
25 #include "CActivePalettePluginBase.h" |
|
26 #include "ActivePalette2Logger.h" |
|
27 |
|
28 #include "ActivePalette2Utils.h" |
|
29 |
|
30 #include <fbs.h> |
|
31 #include <bitstd.h> |
|
32 |
|
33 #include "ActivePalette2Cfg.h" |
|
34 |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 const TInt KAnimPhase1 = 0; |
|
39 const TInt KAnimPhase2 = 1; |
|
40 const TInt KAnimPhaseMax = KAnimPhase2; |
|
41 const TInt KAnimNofPhases = 2; |
|
42 |
|
43 const TInt KAnimDeviatinFactorMul = 1; |
|
44 const TInt KAnimDeviatinFactorDiv = 5; |
|
45 |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CAnimationHelper::CAnimationHelper() |
|
51 // C++ constructor |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CAnimationHelper::CAnimationHelper() |
|
55 { |
|
56 // empty |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAnimationHelper::ConstructL() |
|
61 // 2nd phase construction |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CAnimationHelper::ConstructL(const TSize aSize, const TBool aMaskNeeded) |
|
65 { |
|
66 ActivePalette2Utils::CreateDrawingObjectsL(aSize,&iFrame,&iFrameDevice,&iFrameGc); |
|
67 if (aMaskNeeded) |
|
68 { |
|
69 ActivePalette2Utils::CreateDrawingObjectsL(EGray256, |
|
70 aSize,&iFrameMask,&iFrameMaskDevice,&iFrameMaskGc); |
|
71 } |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CAnimationHelper::~CAnimationHelper() |
|
76 // Destructor |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CAnimationHelper::~CAnimationHelper() |
|
80 { |
|
81 // DeleteDrawingObjects checks passed pointers to ensure they are not null |
|
82 ActivePalette2Utils::DeleteDrawingObjects(&iFrame,&iFrameDevice,&iFrameGc); |
|
83 ActivePalette2Utils::DeleteDrawingObjects(&iFrameMask,&iFrameMaskDevice,&iFrameMaskGc); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CAnimationHelper::NewL() |
|
88 // Symbian 2 phase construction |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CAnimationHelper * CAnimationHelper::NewL(const TSize aSize, const TBool aMaskNeeded) |
|
92 { |
|
93 CAnimationHelper * self = new (ELeave) CAnimationHelper(); |
|
94 |
|
95 CleanupStack::PushL(self); |
|
96 self->ConstructL(aSize, aMaskNeeded); |
|
97 CleanupStack::Pop(self); |
|
98 |
|
99 return self; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // NActivePalettePluginFactory::TPluginCreationParams::PluginObserver() |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C MActivePalettePluginObserver& NActivePalettePluginFactory::TPluginCreationParams::PluginObserver(void) const |
|
107 { |
|
108 return iObserver; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // NActivePalettePluginFactory::TPluginCreationParams::Dimensions(void) |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C TSize NActivePalettePluginFactory::TPluginCreationParams::Dimensions(void) const |
|
116 { |
|
117 return iDimensions; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // NActivePalettePluginFactory::TPluginCreationParams::TPluginCreationParams() |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C NActivePalettePluginFactory::TPluginCreationParams::TPluginCreationParams(MActivePalettePluginObserver & aObserver, |
|
125 const TSize& aDimensions) |
|
126 : iObserver(aObserver), |
|
127 iDimensions(aDimensions) |
|
128 { |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CActivePalettePluginBase::CActivePalettePluginBase() |
|
133 // C++ constructor |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C CActivePalettePluginBase::CActivePalettePluginBase(const NActivePalettePluginFactory::TPluginCreationParams & aCreationParams) |
|
137 : iPluginObserver(aCreationParams.PluginObserver()) |
|
138 { |
|
139 LOGTEXT( _L( "CActivePalettePluginBase::CActivePalettePluginBase" ) ); |
|
140 PluginObserver().NotifyPluginCreated(this); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CActivePalettePluginBase::~CActivePalettePluginBase() |
|
145 // Destructor |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C CActivePalettePluginBase::~CActivePalettePluginBase(void) |
|
149 { |
|
150 LOGTEXT( _L( "CActivePalettePluginBase::~CActivePalettePluginBase" ) ); |
|
151 CBase::Delete(iAnimationHelper); |
|
152 iAnimationHelper = NULL; |
|
153 PluginObserver().NotifyPluginDestroyed(this); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CActivePalettePluginBase::ConstructL() |
|
158 // 2nd phase constructor |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C void CActivePalettePluginBase::ConstructL(const NActivePalettePluginFactory::TPluginCreationParams& /*aCreationParams*/, |
|
162 const TDesC8 & /*aCustomDataDes*/, |
|
163 const TInt /*aCustomDataInt*/) |
|
164 { |
|
165 LOGTEXT( _L( "CActivePalettePluginBase::ConstructL" ) ); |
|
166 // empty |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CActivePalettePluginBase::Shutdown() |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CActivePalettePluginBase::Shutdown(void) |
|
174 { |
|
175 LOGTEXT( _L( "CActivePalettePluginBase::Shutdown" ) ); |
|
176 // empty |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CActivePalettePluginBase::HandleMessageL() |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C void CActivePalettePluginBase::HandleMessageL(const TInt aMessageID, |
|
184 const TDesC8& /*aDataDes*/, |
|
185 const TInt /*aDataInt*/) |
|
186 { |
|
187 LOGTEXT1( _L( "CActivePalettePluginBase::HandleMessageL, message ID: %d" ), aMessageID ); |
|
188 // empty |
|
189 if (aMessageID) |
|
190 { |
|
191 // no compiler warning |
|
192 } |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CActivePalettePluginBase::PrepareAniFramesL() |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C void CActivePalettePluginBase::PrepareAniFramesL(const TInt aAniType, |
|
200 TPluginAnimationInfo& aAniInfo, |
|
201 const TPluginAnimationInfo& aDefaultAniInfo, |
|
202 const CFbsBitmap& aItemIcon, |
|
203 const CFbsBitmap* aItemIconMask) |
|
204 { |
|
205 LOGTEXT1( _L( "CActivePalettePluginBase::PrepareAniFramesL, AniType ID: %d" ), aAniType); |
|
206 |
|
207 // use default animation info |
|
208 aAniInfo = aDefaultAniInfo; |
|
209 |
|
210 // create data for icon and mask frames |
|
211 iAnimationHelper = CAnimationHelper::NewL(aDefaultAniInfo.iFrameSize, |
|
212 (NULL != aItemIconMask)); |
|
213 |
|
214 if (aAniType) |
|
215 { |
|
216 // no compiler warning |
|
217 } |
|
218 if (aItemIcon.Handle()) |
|
219 { |
|
220 // no compiler warning |
|
221 } |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CActivePalettePluginBase::ReleaseAniFrames() |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C void CActivePalettePluginBase::ReleaseAniFrames(const TInt aAniType) |
|
229 { |
|
230 LOGTEXT1( _L( "CActivePalettePluginBase::ReleaseAniFrames, AniType ID: %d" ), aAniType); |
|
231 |
|
232 CBase::Delete(iAnimationHelper); |
|
233 iAnimationHelper = NULL; |
|
234 |
|
235 if (aAniType) |
|
236 { |
|
237 // no compiler warning |
|
238 } |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CActivePalettePluginBase::ProduceAniFrame( |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C void CActivePalettePluginBase::ProduceAniFrame( |
|
246 TInt aAniType, |
|
247 TInt aFrameNo, |
|
248 const TPluginAnimationInfo& aAniInfo, |
|
249 const CFbsBitmap& aItemIcon, |
|
250 const CFbsBitmap* aItemIconMask, |
|
251 CFbsBitmap** aFrame, |
|
252 CFbsBitmap** aFrameMask, |
|
253 TBool& aOwnershipTransferForFrame, |
|
254 TBool& aOwnershipTransferForMask) |
|
255 { |
|
256 LOGTEXT2( |
|
257 _L( "CActivePalettePluginBase::ProduceAniFrame, AniType ID: %d, frame no : %d" ), |
|
258 aAniType, |
|
259 aFrameNo); |
|
260 |
|
261 CAnimationHelper* ani = static_cast<CAnimationHelper*>(iAnimationHelper); |
|
262 |
|
263 aOwnershipTransferForFrame = EFalse; |
|
264 aOwnershipTransferForMask = EFalse; |
|
265 |
|
266 *aFrame = ani->iFrame; |
|
267 *aFrameMask = ani->iFrameMask; |
|
268 |
|
269 // empty mask, transparent |
|
270 if (NULL != ani->iFrameMaskGc) |
|
271 { |
|
272 ani->iFrameMaskGc->Reset(); |
|
273 ani->iFrameMaskGc->SetBrushColor(KRgbBlack); |
|
274 ani->iFrameMaskGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
275 ani->iFrameMaskGc->Clear(); |
|
276 } |
|
277 |
|
278 // empty frame |
|
279 ani->iFrameGc->Reset(); |
|
280 ani->iFrameGc->SetBrushColor(KRgbWhite); |
|
281 ani->iFrameGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
282 ani->iFrameGc->Clear(); |
|
283 |
|
284 // ani frame |
|
285 TInt phase = Min(KAnimPhaseMax, |
|
286 KAnimNofPhases * aFrameNo / aAniInfo.iNofFrames); |
|
287 |
|
288 TInt inPhaseMax = aAniInfo.iNofFrames / KAnimNofPhases; |
|
289 |
|
290 TInt inPhaseOfs = Min(inPhaseMax, aFrameNo - (phase * KAnimPhaseMax)); |
|
291 |
|
292 TInt lenX = aAniInfo.iFrameSize.iWidth; |
|
293 TInt lenY = aAniInfo.iFrameSize.iHeight; |
|
294 |
|
295 TInt devX = lenX * KAnimDeviatinFactorMul / KAnimDeviatinFactorDiv; |
|
296 TInt devY = lenY * KAnimDeviatinFactorMul / KAnimDeviatinFactorDiv; |
|
297 |
|
298 TInt szx(0); |
|
299 TInt szy(0); |
|
300 |
|
301 TInt addX = devX * inPhaseOfs / inPhaseMax; |
|
302 TInt addY = devY * inPhaseOfs / inPhaseMax; |
|
303 |
|
304 switch (phase) |
|
305 { |
|
306 case KAnimPhase1: |
|
307 szx = lenX - addX; |
|
308 szy = lenY - addY; |
|
309 break; |
|
310 |
|
311 case KAnimPhase2: |
|
312 default: |
|
313 szx = lenX - devX + addX; |
|
314 szy = lenY - devY + addY; |
|
315 break; |
|
316 } |
|
317 |
|
318 TRect frameRect(TPoint( (lenX - szx) / 2, (lenY - szy) / 2), |
|
319 TSize(szx, szy)); |
|
320 TRect iconRect(TPoint(0,0), aItemIcon.SizeInPixels()); |
|
321 |
|
322 if (NULL != aItemIconMask && NULL != ani->iFrameMaskGc) |
|
323 { |
|
324 ani->iFrameMaskGc->DrawBitmap(frameRect,aItemIconMask,iconRect); |
|
325 } |
|
326 |
|
327 ani->iFrameGc->DrawBitmap(frameRect,&aItemIcon,iconRect); |
|
328 |
|
329 if (aAniType) |
|
330 { |
|
331 // no compiler warning |
|
332 } |
|
333 } |
|
334 |
|
335 // End of File |
|