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 Checkerboard Styler* |
|
15 */ |
|
16 |
|
17 |
|
18 /** |
|
19 * @file ActivePalette2CheckerboardStyler.cpp |
|
20 * Active Palette Checkerboard Styler |
|
21 */ |
|
22 |
|
23 #include "ActivePalette2Logger.h" |
|
24 #include "ActivePalette2CheckerboardStyler.h" |
|
25 #include "ActivePalette2Cfg.h" |
|
26 #include "ActivePalette2Utils.h" |
|
27 #include <activepalette2graphics.mbg> |
|
28 |
|
29 #include <bitstd.h> |
|
30 #include <gdi.h> |
|
31 #include <AknIconUtils.h> |
|
32 |
|
33 /// Returns whether supplied number is odd |
|
34 #define IS_ODD(num) ((num) & 1) |
|
35 |
|
36 // Lightness threshold for checking whether a pixel |
|
37 // should be considered 'white'. Lightness is defined as the sum of the |
|
38 // 8-bit red, green, and blue values. |
|
39 const TInt KLightnessThreshold = 0x80 * 3; |
|
40 |
|
41 // Threshold for determining if a pixel in a soft mask is considered |
|
42 // opaque or transparent. |
|
43 const TUint8 KMaskThreshold = 0x7f; |
|
44 |
|
45 // Color value for transparent pixel (ARGB format). |
|
46 const TUint32 KColorKey = 0xFF000000; |
|
47 |
|
48 // Color value for opaque pixel (ARGB format). |
|
49 const TUint32 KOpaqueColor = 0x00FFFFFF; |
|
50 |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CActivePalette2CheckerboardStyler::NewL() |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CActivePalette2CheckerboardStyler* CActivePalette2CheckerboardStyler::NewL() |
|
57 { |
|
58 CActivePalette2CheckerboardStyler* self = new (ELeave) CActivePalette2CheckerboardStyler(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); // this |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CActivePalette2CheckerboardStyler::ConstructL() |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CActivePalette2CheckerboardStyler::ConstructL() |
|
70 { |
|
71 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::ConstructL entered")); |
|
72 CActivePalette2Styler::ConstructL(); |
|
73 |
|
74 iAPTopSectionMask = new (ELeave) CFbsBitmap; |
|
75 iAPItemMaskA = new (ELeave) CFbsBitmap; |
|
76 iAPItemMaskB = new (ELeave) CFbsBitmap; |
|
77 iAPGapMaskA = new (ELeave) CFbsBitmap; |
|
78 iAPGapMaskB = new (ELeave) CFbsBitmap; |
|
79 iAPBottomSectionMaskA = new (ELeave) CFbsBitmap; |
|
80 iAPBottomSectionMaskB = new (ELeave) CFbsBitmap; |
|
81 |
|
82 // The order of calling these has an importance, to create the checkers correctly |
|
83 |
|
84 LoadAndScaleCheckerboardL( iAPTopSectionMask, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_top, EMbmActivepalette2graphicsQgn_graf_cam4_tb_top_mask, |
|
85 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::ETopSectionHeight) ) ); |
|
86 LoadAndScaleCheckerboardL( iAPItemMaskA, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_body, EMbmActivepalette2graphicsQgn_graf_cam4_tb_body_mask, |
|
87 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EItemHeight) ) ); |
|
88 LoadAndScaleCheckerboardL( iAPGapMaskA, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_gap, EMbmActivepalette2graphicsQgn_graf_cam4_tb_gap_mask, |
|
89 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EGapBetweenItems) ) ); |
|
90 LoadAndScaleCheckerboardL( iAPItemMaskB, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_body, EMbmActivepalette2graphicsQgn_graf_cam4_tb_body_mask, |
|
91 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EItemHeight) ) ); |
|
92 LoadAndScaleCheckerboardL( iAPGapMaskB, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_gap, EMbmActivepalette2graphicsQgn_graf_cam4_tb_gap_mask, |
|
93 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EGapBetweenItems) ) ); |
|
94 LoadAndScaleCheckerboardL( iAPBottomSectionMaskB, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_bottom, EMbmActivepalette2graphicsQgn_graf_cam4_tb_bottom_mask, |
|
95 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EBottomSectionHeight) ) ); |
|
96 LoadAndScaleCheckerboardL( iAPBottomSectionMaskA, NAP2Cfg::KUIGraphics, EMbmActivepalette2graphicsQgn_graf_cam4_tb_bottom, EMbmActivepalette2graphicsQgn_graf_cam4_tb_bottom_mask, |
|
97 TSize(ActivePalette2Utils::APDimension(ActivePalette2Utils::EPaletteWidth), ActivePalette2Utils::APDimension(ActivePalette2Utils::EBottomSectionHeight) ) ); |
|
98 |
|
99 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::ConstructL Left")); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CActivePalette2CheckerboardStyler::~CActivePalette2CheckerboardStyler() |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 CActivePalette2CheckerboardStyler::~CActivePalette2CheckerboardStyler() |
|
107 { |
|
108 delete iAPTopSectionMask; |
|
109 delete iAPItemMaskA; |
|
110 delete iAPItemMaskB; |
|
111 delete iAPGapMaskA; |
|
112 delete iAPGapMaskB; |
|
113 delete iAPBottomSectionMaskA; |
|
114 delete iAPBottomSectionMaskB; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CActivePalette2CheckerboardStyler::DrawItem() |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CActivePalette2CheckerboardStyler::DrawItem(TInt aScreenPos, CFbsBitmap* aIcon, CFbsBitmap* aMask, TInt aOffsetFrame, TInt aOffsetTotal) |
|
122 { |
|
123 TRect area(ItemRect(aScreenPos, aOffsetFrame, aOffsetTotal)); |
|
124 |
|
125 iDrawBufContext->SetClippingRect(iItemsRect); |
|
126 iDrawBufMaskContext->SetClippingRect(iItemsRect); |
|
127 |
|
128 if ( IS_ODD(aScreenPos) ) |
|
129 { |
|
130 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPItem, iAPItemMaskB, EFalse, EFalse); |
|
131 } |
|
132 else |
|
133 { |
|
134 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPItem, iAPItemMaskA, EFalse, EFalse); |
|
135 } |
|
136 |
|
137 BlitGraphic(area.iTl + TPoint(ActivePalette2Utils::APDimension(ActivePalette2Utils::EItemXOffset),0), iDrawBufContext, iDrawBufMaskContext, aIcon, aMask, ETrue, ETrue); |
|
138 |
|
139 iDrawBufMaskContext->CancelClippingRect(); |
|
140 iDrawBufContext->CancelClippingRect(); |
|
141 |
|
142 area.Intersection(iItemsRect); |
|
143 AddToDirtyRect( area ); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CActivePalette2CheckerboardStyler::DrawGap() |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CActivePalette2CheckerboardStyler::DrawGap(TInt aScreenPos, TInt aOffsetFrame, TInt aOffsetTotal) |
|
151 { |
|
152 TRect area(GapRect(aScreenPos, aOffsetFrame, aOffsetTotal)); |
|
153 |
|
154 iDrawBufContext->SetClippingRect(iItemsRect); |
|
155 iDrawBufMaskContext->SetClippingRect(iItemsRect); |
|
156 |
|
157 if ( IS_ODD(aScreenPos) ) |
|
158 { |
|
159 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPGap, iAPGapMaskB, EFalse, EFalse); |
|
160 } |
|
161 else |
|
162 { |
|
163 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPGap, iAPGapMaskA, EFalse, EFalse); |
|
164 } |
|
165 |
|
166 iDrawBufMaskContext->CancelClippingRect(); |
|
167 iDrawBufContext->CancelClippingRect(); |
|
168 |
|
169 area.Intersection(iItemsRect); |
|
170 AddToDirtyRect( area ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CActivePalette2CheckerboardStyler::AnimItem() |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CActivePalette2CheckerboardStyler::AnimItem(TInt aScreenPos, CFbsBitmap* aIcon, CFbsBitmap* aMask) |
|
178 { |
|
179 TRect area(ItemRect(aScreenPos)); |
|
180 area.iTl.iX = ActivePalette2Utils::APDimension(ActivePalette2Utils::EItemXOffset); |
|
181 area.SetWidth(ActivePalette2Utils::APDimension( ActivePalette2Utils::EItemWidth )); |
|
182 |
|
183 TRect clippingRect(TPoint(ActivePalette2Utils::APDimension(ActivePalette2Utils::EItemXOffset), 0), ActivePalette2Utils::APDimensionSize( ActivePalette2Utils::EItemSize ) ); |
|
184 |
|
185 iDrawBufContext->BitBlt(area.iTl, iAPItem, clippingRect); |
|
186 |
|
187 if ( IS_ODD(aScreenPos) ) |
|
188 { |
|
189 iDrawBufMaskContext->BitBlt(area.iTl, iAPItemMaskB, clippingRect); |
|
190 } |
|
191 else |
|
192 { |
|
193 iDrawBufMaskContext->BitBlt(area.iTl, iAPItemMaskA, clippingRect); |
|
194 } |
|
195 |
|
196 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, aIcon, aMask, ETrue, ETrue); |
|
197 |
|
198 AddToDirtyRect( area ); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CActivePalette2CheckerboardStyler::DrawTopScrollArrowSection() |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CActivePalette2CheckerboardStyler::DrawTopScrollArrowSection(TBool aShowArrow) |
|
206 { |
|
207 TRect area(TopSectionRect()); |
|
208 |
|
209 BlitGraphic(TPoint(0,0), iDrawBufContext, iDrawBufMaskContext, iAPTopSection, iAPTopSectionMask, EFalse, EFalse); |
|
210 |
|
211 if ( aShowArrow ) |
|
212 { |
|
213 CentreGraphic(area, iDrawBufContext, iDrawBufMaskContext, iScrollUpIcon, iScrollUpIconMask, ETrue, ETrue); |
|
214 } |
|
215 |
|
216 AddToDirtyRect( area ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CActivePalette2CheckerboardStyler::DrawBottomScrollArrowSection() |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CActivePalette2CheckerboardStyler::DrawBottomScrollArrowSection(TBool aShowArrow) |
|
224 { |
|
225 TRect area(BottomSectionRect()); |
|
226 |
|
227 if ( IS_ODD(iNumItems) ) |
|
228 { |
|
229 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPBottomSection, iAPBottomSectionMaskA, EFalse, EFalse); |
|
230 } |
|
231 else |
|
232 { |
|
233 BlitGraphic(area.iTl, iDrawBufContext, iDrawBufMaskContext, iAPBottomSection, iAPBottomSectionMaskB, EFalse, EFalse); |
|
234 } |
|
235 |
|
236 if ( aShowArrow ) |
|
237 { |
|
238 CentreGraphic(area, iDrawBufContext, iDrawBufMaskContext, iScrollDownIcon, iScrollDownIconMask, ETrue, ETrue); |
|
239 } |
|
240 |
|
241 AddToDirtyRect( area ); |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboard() |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboardL( |
|
250 CFbsBitmap* aTargetBitmap, |
|
251 const TDesC& aFileName, |
|
252 TInt32 aId, |
|
253 TInt32 aMaskId, |
|
254 TSize aSize ) |
|
255 { |
|
256 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboard entered")); |
|
257 CFbsBitmap* sourceIcon = NULL; |
|
258 CFbsBitmap* sourceIconMask = NULL; |
|
259 AknIconUtils::CreateIconLC(sourceIcon, sourceIconMask, aFileName, aId, aMaskId); |
|
260 AknIconUtils::SetSize(sourceIcon, aSize); |
|
261 AknIconUtils::SetSize(sourceIconMask, aSize); |
|
262 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboard svg icons loaded")); |
|
263 User::LeaveIfError( aTargetBitmap->Create( aSize, EColor16MA ) ); |
|
264 |
|
265 TSize bmpSize = aTargetBitmap->SizeInPixels(); |
|
266 TRgb rgbColor = KRgbBlack; |
|
267 TRgb rgbAlphaColor = KRgbBlack; |
|
268 |
|
269 HBufC8* lineBuf = HBufC8::NewLC( CFbsBitmap::ScanLineLength( bmpSize.iWidth, EColor16MA ) ); |
|
270 TPtr8 lineDes = lineBuf->Des(); |
|
271 HBufC8* maskBuf = HBufC8::NewLC( CFbsBitmap::ScanLineLength( bmpSize.iWidth, EGray256 ) ); |
|
272 TPtr8 maskDes = maskBuf->Des(); |
|
273 |
|
274 for (TInt y = 0; y < bmpSize.iHeight; y++) |
|
275 { |
|
276 sourceIcon->GetScanLine( |
|
277 lineDes, TPoint(0, y), bmpSize.iWidth, EColor16MA); |
|
278 sourceIconMask->GetScanLine( |
|
279 maskDes, TPoint(0, y), bmpSize.iWidth, EGray256); |
|
280 |
|
281 // EColor16MA is 4 bytes (32-bits) per pixel |
|
282 TUint32* linePtr = reinterpret_cast<TUint32*>( &lineDes[0] ); |
|
283 |
|
284 // EGray256 is 1 byte per pixel |
|
285 TUint8* maskPtr = reinterpret_cast<TUint8*>( &maskDes[0] ); |
|
286 |
|
287 for( TInt x = 0; x < bmpSize.iWidth; x++ ) |
|
288 { |
|
289 TUint32 color = linePtr[x]; |
|
290 TUint8 mask = maskPtr[x]; |
|
291 |
|
292 // Get the RGB values in order to check the lightness of the pixel |
|
293 // to determine whether to mask with the checkerboard pattern. |
|
294 TInt lightness = |
|
295 (color & 0xFF) + // blue |
|
296 ((color >> 8) & 0xFF) + // green |
|
297 ((color >> 16) & 0xFF); // red |
|
298 |
|
299 if ( mask < KMaskThreshold ) |
|
300 { |
|
301 // Transparent area. |
|
302 linePtr[x] = KColorKey; |
|
303 } |
|
304 else if ( lightness > KLightnessThreshold ) |
|
305 { |
|
306 // Semitransparent (dithered) area. |
|
307 // Make every second pixel transparent. |
|
308 if ( ( x + iLineCheckerCounter ) & 1 ) |
|
309 { |
|
310 linePtr[x] = KColorKey; |
|
311 } |
|
312 else |
|
313 { |
|
314 linePtr[x] = KOpaqueColor; |
|
315 } |
|
316 } |
|
317 else |
|
318 { |
|
319 // Fully opaque area |
|
320 linePtr[x] = KOpaqueColor; |
|
321 } |
|
322 } |
|
323 |
|
324 aTargetBitmap->SetScanLine(lineDes, y); |
|
325 iLineCheckerCounter++; |
|
326 } |
|
327 |
|
328 // end draw checkers |
|
329 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboard svg4")); |
|
330 |
|
331 CleanupStack::PopAndDestroy(maskBuf); |
|
332 CleanupStack::PopAndDestroy(lineBuf); |
|
333 CleanupStack::PopAndDestroy(2); // sourceIcon, sourceIconMask |
|
334 LOGTEXT( _L( "CActivePalette2CheckerboardStyler::LoadAndScaleCheckerboard left")); |
|
335 } |
|
336 |
|
337 |
|