|
1 /* |
|
2 * Copyright (c) 2004 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <bitdev.h> |
|
21 #include <eikenv.h> |
|
22 #include <eikspane.h> |
|
23 #include <AknUtils.h> |
|
24 #include <AknsDrawUtils.h> |
|
25 |
|
26 #include "AknIndicatorFader.h" |
|
27 #include "AknIndicatorContainer.h" |
|
28 #include "AknIndicator.h" |
|
29 |
|
30 |
|
31 // LOCAL CONSTANTS AND MACROS |
|
32 |
|
33 // MODULE DATA STRUCTURES |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CAknIndicatorFader::CAknIndicatorFader |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CAknIndicatorFader::CAknIndicatorFader(TSize aSize) |
|
44 { |
|
45 iSize = aSize; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CAknIndicatorFader::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CAknIndicatorFader::ConstructL() |
|
54 { |
|
55 iFadedBitmap = new (ELeave) CFbsBitmap(); |
|
56 iFadedBitmap->Create(iSize, EGray256); |
|
57 |
|
58 iFadingBitmap = new (ELeave) CFbsBitmap(); |
|
59 iFadingBitmap->Create(iSize, EGray256); |
|
60 |
|
61 iInvertingBitmap = new (ELeave) CFbsBitmap(); |
|
62 iInvertingBitmap->Create(iSize, EGray2); |
|
63 |
|
64 iInvertedBitmap = new (ELeave) CFbsBitmap(); |
|
65 iInvertedBitmap->Create(iSize, EGray2); |
|
66 |
|
67 InitializeL(); |
|
68 |
|
69 SetActiveFadeEffect(EEffectNone); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CAknIndicatorFader::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CAknIndicatorFader* CAknIndicatorFader::NewL(TSize aSize) |
|
78 { |
|
79 CAknIndicatorFader* self = |
|
80 new (ELeave) CAknIndicatorFader(aSize); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop(); // self |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CAknIndicatorFader::~CAknIndicatorFader() |
|
92 { |
|
93 delete iFadedBitmap; |
|
94 delete iFaderDevice; |
|
95 delete iFaderGc; |
|
96 |
|
97 delete iFadingBitmap; |
|
98 delete iFadingDevice; |
|
99 delete iFadingGc; |
|
100 |
|
101 delete iInvertingBitmap; |
|
102 delete iInvertingDevice; |
|
103 delete iInvertingGc; |
|
104 |
|
105 delete iInvertedBitmap; |
|
106 delete iInvertedDevice; |
|
107 delete iInvertedGc; |
|
108 |
|
109 } |
|
110 |
|
111 CFbsBitmap* CAknIndicatorFader::FadeMask(CFbsBitmap* aOriginalMask) const |
|
112 { |
|
113 if (aOriginalMask && |
|
114 iActiveEffect != EEffectNone && |
|
115 Initialized()) |
|
116 { |
|
117 CFbsBitmap* usedMask = aOriginalMask; |
|
118 TDisplayMode displayMode = aOriginalMask->DisplayMode(); |
|
119 TSize size = aOriginalMask->SizeInPixels(); |
|
120 TRect rect = TRect(0,0,size.iWidth, size.iHeight); |
|
121 TRgb rgbValue = 0x00000000; |
|
122 |
|
123 // If given mask is hardmask, it must inverted. |
|
124 if (displayMode == EGray2) |
|
125 { |
|
126 // clear the area first |
|
127 iInvertedGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
128 iInvertedGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
129 iInvertedGc->SetBrushColor(KRgbWhite); |
|
130 iInvertedGc->DrawRect(TRect(TPoint(0,0), iSize)); |
|
131 |
|
132 iInvertedGc->BitBltMasked(TPoint(0,0), |
|
133 iInvertingBitmap, |
|
134 rect, |
|
135 aOriginalMask, |
|
136 EFalse); |
|
137 usedMask = iInvertedBitmap; |
|
138 } |
|
139 |
|
140 rgbValue = 0x00000000; |
|
141 for (TInt x=0; x < iSize.iWidth; x++) |
|
142 { |
|
143 iFaderGc->SetPenColor(TRgb(rgbValue)); |
|
144 iFaderGc->DrawLine(TPoint(x,0), TPoint(x,iSize.iHeight)); |
|
145 } |
|
146 |
|
147 iFaderGc->BitBltMasked(TPoint(0,0), |
|
148 iFadingBitmap, |
|
149 rect, |
|
150 usedMask, |
|
151 EFalse); |
|
152 |
|
153 return iFadedBitmap; |
|
154 } |
|
155 else |
|
156 { |
|
157 return aOriginalMask; |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 |
|
163 void CAknIndicatorFader::SetActiveFadeEffect(TInt aActiveEffect) |
|
164 { |
|
165 if (aActiveEffect == iActiveEffect) |
|
166 return; |
|
167 |
|
168 iActiveEffect = aActiveEffect; |
|
169 CreateEffect(aActiveEffect); |
|
170 } |
|
171 |
|
172 |
|
173 void CAknIndicatorFader::CreateEffect(TInt aEffect) |
|
174 { |
|
175 if (!Initialized()) |
|
176 return; |
|
177 |
|
178 switch (aEffect) |
|
179 { |
|
180 case EEffectFadeToLeft: |
|
181 { |
|
182 TInt KStartValue = 30; |
|
183 TInt KEndValue = 90; |
|
184 |
|
185 TInt KMaxFadeSteps = KEndValue - KStartValue; |
|
186 TInt usedFadeStep = 0; |
|
187 |
|
188 if (iSize.iWidth < KMaxFadeSteps && |
|
189 iSize.iWidth != 0) |
|
190 { |
|
191 usedFadeStep = KMaxFadeSteps/iSize.iWidth; |
|
192 } |
|
193 else |
|
194 { |
|
195 usedFadeStep = iSize.iWidth/KMaxFadeSteps; |
|
196 } |
|
197 |
|
198 TRgb rgb; |
|
199 rgb.SetRed(KStartValue); |
|
200 rgb.SetGreen(KStartValue); |
|
201 rgb.SetBlue(KStartValue); |
|
202 |
|
203 for (TInt x=0; x < iSize.iWidth;x++) |
|
204 { |
|
205 iFadingGc->SetPenColor(rgb); |
|
206 iFadingGc->DrawLine(TPoint(x,0), TPoint(x,iSize.iHeight)); |
|
207 rgb.SetRed(rgb.Red() + usedFadeStep); |
|
208 rgb.SetGreen(rgb.Green() + usedFadeStep); |
|
209 rgb.SetBlue(rgb.Blue() + usedFadeStep); |
|
210 } |
|
211 |
|
212 break; |
|
213 } |
|
214 |
|
215 case EEffectFadeToRight: |
|
216 { |
|
217 TInt KStartValue = 30; |
|
218 TInt KEndValue = 90; |
|
219 |
|
220 TInt KMaxFadeSteps = KEndValue - KStartValue; |
|
221 TInt usedFadeStep = 0; |
|
222 |
|
223 if (iSize.iWidth < KMaxFadeSteps && |
|
224 iSize.iWidth != 0) |
|
225 { |
|
226 usedFadeStep = KMaxFadeSteps/iSize.iWidth; |
|
227 } |
|
228 else |
|
229 { |
|
230 usedFadeStep = iSize.iWidth/KMaxFadeSteps; |
|
231 } |
|
232 |
|
233 TRgb rgb; |
|
234 rgb.SetRed(KStartValue); |
|
235 rgb.SetGreen(KStartValue); |
|
236 rgb.SetBlue(KStartValue); |
|
237 |
|
238 for (TInt x=iSize.iWidth - 1; x >= 0;x--) |
|
239 { |
|
240 iFadingGc->SetPenColor(rgb); |
|
241 iFadingGc->DrawLine(TPoint(x,0), TPoint(x,iSize.iHeight)); |
|
242 rgb.SetRed(rgb.Red() + usedFadeStep); |
|
243 rgb.SetGreen(rgb.Green() + usedFadeStep); |
|
244 rgb.SetBlue(rgb.Blue() + usedFadeStep); |
|
245 } |
|
246 break; |
|
247 } |
|
248 case EEffectNone: |
|
249 default: |
|
250 { |
|
251 break; |
|
252 } |
|
253 } |
|
254 |
|
255 } |
|
256 |
|
257 |
|
258 void CAknIndicatorFader::SetActiveFadeSize(TSize aSize) |
|
259 { |
|
260 if (aSize == iSize) |
|
261 return; |
|
262 |
|
263 iSize = aSize; |
|
264 TRAP_IGNORE(InitializeL()); |
|
265 CreateEffect(iActiveEffect); |
|
266 } |
|
267 |
|
268 void CAknIndicatorFader::InitializeL() |
|
269 { |
|
270 iFadedBitmap->Resize(iSize); |
|
271 iFadingBitmap->Resize(iSize); |
|
272 iInvertingBitmap->Resize(iSize); |
|
273 iInvertedBitmap->Resize(iSize); |
|
274 |
|
275 delete iFaderDevice; |
|
276 iFaderDevice = NULL; |
|
277 delete iFaderGc; |
|
278 iFaderGc = NULL; |
|
279 iFaderDevice = CFbsBitmapDevice::NewL( iFadedBitmap ); |
|
280 iFaderDevice->CreateContext( iFaderGc ); |
|
281 |
|
282 delete iFadingDevice; |
|
283 iFadingDevice = NULL; |
|
284 delete iFadingGc; |
|
285 iFadingGc = NULL; |
|
286 iFadingDevice = CFbsBitmapDevice::NewL( iFadingBitmap ); |
|
287 iFadingDevice->CreateContext( iFadingGc ); |
|
288 |
|
289 delete iInvertingDevice; |
|
290 iInvertingDevice = NULL; |
|
291 delete iInvertingGc; |
|
292 iInvertingGc = NULL; |
|
293 iInvertingDevice = CFbsBitmapDevice::NewL( iInvertingBitmap ); |
|
294 iInvertingDevice->CreateContext( iInvertingGc ); |
|
295 |
|
296 delete iInvertedDevice; |
|
297 iInvertedDevice = NULL; |
|
298 delete iInvertedGc; |
|
299 iInvertedGc = NULL; |
|
300 iInvertedDevice = CFbsBitmapDevice::NewL( iInvertedBitmap ); |
|
301 iInvertedDevice->CreateContext( iInvertedGc ); |
|
302 |
|
303 if (Initialized()) |
|
304 { |
|
305 iFadingGc->SetPenColor(KRgbGray); |
|
306 iFadingGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
307 iFadingGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
308 |
|
309 iInvertingGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
310 iInvertingGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
311 iInvertingGc->SetBrushColor(KRgbBlack); |
|
312 iInvertingGc->DrawRect(TRect(TPoint(0,0), iSize)); |
|
313 } |
|
314 } |
|
315 |
|
316 TBool CAknIndicatorFader::Initialized() const |
|
317 { |
|
318 if (iFadedBitmap && |
|
319 iFaderDevice && |
|
320 iFaderGc && |
|
321 iFadingBitmap && |
|
322 iFadingDevice && |
|
323 iFadingGc && |
|
324 iInvertingBitmap && |
|
325 iInvertingDevice && |
|
326 iInvertingGc && |
|
327 iInvertedBitmap && |
|
328 iInvertedDevice && |
|
329 iInvertedGc) |
|
330 { |
|
331 return ETrue; |
|
332 } |
|
333 else |
|
334 { |
|
335 return EFalse; |
|
336 } |
|
337 } |