|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE |
|
21 #include <aknview.h> |
|
22 #include <aknlists.h> |
|
23 #include <barsread.h> |
|
24 #include <akniconarray.h> |
|
25 #include <gulicon.h> |
|
26 #include <aknutils.h> |
|
27 |
|
28 #include "ColorSelectionGrid.h" |
|
29 #include "ResolutionUtil.h" |
|
30 |
|
31 const TInt KColorGridRows = 8; |
|
32 const TInt KColorGridCols = 14; |
|
33 |
|
34 const TInt KStandardGridSizeWidth = 12; |
|
35 const TInt KStandardGridSizeHeight = 12; |
|
36 const TInt KQVGAGridSizeWidth = 15; |
|
37 const TInt KQVGAGridSizeHeight = 15; |
|
38 const TInt KDoubleGridSizeWidth = 24; |
|
39 const TInt KDoubleGridSizeHeight = 24; |
|
40 const TInt KHVGAGridSizeWidth = 20; |
|
41 const TInt KHVGAGridSizeHeight = 20; |
|
42 const TInt KVGAGridSizeWidth = 31; |
|
43 const TInt KVGAGridSizeHeight = 26; |
|
44 const TInt KQHDGridSizeWidth = 22; |
|
45 const TInt KQHDGridSizeHeight = 22; |
|
46 |
|
47 const TInt KStandardIconSizeWidth = 9; |
|
48 const TInt KStandardIconSizeHeight = 9; |
|
49 const TInt KQVGAIconSizeWidth = 11; |
|
50 const TInt KQVGAIconSizeHeight = 11; |
|
51 const TInt KDoubleIconSizeWidth = 18; |
|
52 const TInt KDoubleIconSizeHeight = 18; |
|
53 const TInt KHVGAIconSizeWidth = 15; |
|
54 const TInt KHVGAIconSizeHeight = 15; |
|
55 const TInt KVGAIconSizeWidth = 26; |
|
56 const TInt KVGAIconSizeHeight = 22; |
|
57 const TInt KQHDIconSizeWidth = 17; |
|
58 const TInt KQHDIconSizeHeight = 17; |
|
59 |
|
60 |
|
61 |
|
62 //============================================================================= |
|
63 EXPORT_C CColorSelectionGrid::CColorSelectionGrid () |
|
64 : CAknGrid () |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 //============================================================================= |
|
70 EXPORT_C CColorSelectionGrid::~CColorSelectionGrid () |
|
71 { |
|
72 |
|
73 } |
|
74 |
|
75 //============================================================================= |
|
76 EXPORT_C void CColorSelectionGrid::ConstructL ( |
|
77 const CCoeControl * aParent, |
|
78 TInt aFlags |
|
79 ) |
|
80 { |
|
81 // Construct base instance |
|
82 CAknGrid::ConstructL (aParent, aFlags); |
|
83 |
|
84 // Get the screen mode from the Resolution Util |
|
85 TInt screenMode = CResolutionUtil::Self()->GetScreenMode(); |
|
86 |
|
87 switch (screenMode) |
|
88 { |
|
89 |
|
90 case CResolutionUtil::EDouble: |
|
91 case CResolutionUtil::EDoubleFullScreen: |
|
92 case CResolutionUtil::EDoubleLandscape: |
|
93 case CResolutionUtil::EDoubleLandscapeFullScreen: |
|
94 { |
|
95 iGridSize.SetSize( |
|
96 KDoubleGridSizeWidth, |
|
97 KDoubleGridSizeHeight); |
|
98 |
|
99 iIconSize.SetSize( |
|
100 KDoubleIconSizeWidth, |
|
101 KDoubleIconSizeHeight); |
|
102 break; |
|
103 |
|
104 } |
|
105 // QVGA |
|
106 case CResolutionUtil::EQVGA: |
|
107 case CResolutionUtil::EQVGAFullScreen: |
|
108 case CResolutionUtil::EQVGALandscape: |
|
109 case CResolutionUtil::EQVGALandscapeFullScreen: |
|
110 { |
|
111 iGridSize.SetSize( |
|
112 KQVGAGridSizeWidth, |
|
113 KQVGAGridSizeHeight); |
|
114 |
|
115 iIconSize.SetSize( |
|
116 KQVGAIconSizeWidth, |
|
117 KQVGAIconSizeHeight); |
|
118 |
|
119 break; |
|
120 } |
|
121 // HVGA |
|
122 case CResolutionUtil::EHVGA: |
|
123 case CResolutionUtil::EHVGAFullScreen: |
|
124 case CResolutionUtil::EHVGALandscape: |
|
125 case CResolutionUtil::EHVGALandscapeFullScreen: |
|
126 { |
|
127 iGridSize.SetSize( |
|
128 KHVGAGridSizeWidth, |
|
129 KHVGAGridSizeHeight); |
|
130 |
|
131 iIconSize.SetSize( |
|
132 KHVGAIconSizeWidth, |
|
133 KHVGAIconSizeHeight); |
|
134 |
|
135 break; |
|
136 } |
|
137 // VGA |
|
138 case CResolutionUtil::EVGA: |
|
139 case CResolutionUtil::EVGAFullScreen: |
|
140 case CResolutionUtil::EVGALandscape: |
|
141 case CResolutionUtil::EVGALandscapeFullScreen: |
|
142 { |
|
143 iGridSize.SetSize( |
|
144 KVGAGridSizeWidth, |
|
145 KVGAGridSizeHeight); |
|
146 |
|
147 iIconSize.SetSize( |
|
148 KVGAIconSizeWidth, |
|
149 KVGAIconSizeHeight); |
|
150 |
|
151 break; |
|
152 } |
|
153 // QHD |
|
154 case CResolutionUtil::EQHD: |
|
155 case CResolutionUtil::EQHDFullScreen: |
|
156 case CResolutionUtil::EQHDLandscape: |
|
157 case CResolutionUtil::EQHDLandscapeFullScreen: |
|
158 { |
|
159 iGridSize.SetSize( |
|
160 KQHDGridSizeWidth, |
|
161 KQHDGridSizeHeight); |
|
162 |
|
163 iIconSize.SetSize( |
|
164 KQHDIconSizeWidth, |
|
165 KQHDIconSizeHeight); |
|
166 |
|
167 break; |
|
168 } |
|
169 default: |
|
170 { |
|
171 iGridSize.SetSize( |
|
172 KStandardGridSizeWidth, |
|
173 KStandardGridSizeHeight); |
|
174 |
|
175 iIconSize.SetSize( |
|
176 KStandardIconSizeWidth, |
|
177 KStandardIconSizeHeight); |
|
178 |
|
179 break; |
|
180 } |
|
181 } |
|
182 // Set grid layout |
|
183 SetLayoutL ( |
|
184 EFalse, |
|
185 ETrue, |
|
186 ETrue, |
|
187 KColorGridCols, |
|
188 KColorGridRows, |
|
189 iGridSize); |
|
190 |
|
191 // Set scroll bar invisible |
|
192 ScrollBarFrame()-> |
|
193 SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
194 CEikScrollBarFrame::EOff ); |
|
195 |
|
196 SetPrimaryScrollingType (CAknGridView::EScrollStops); |
|
197 SetSecondaryScrollingType (CAknGridView::EScrollStops); |
|
198 |
|
199 SetCurrentDataIndex (0); |
|
200 |
|
201 // Set up the icons |
|
202 SetupGridIconsL (); |
|
203 |
|
204 // Draw the grid |
|
205 SizeChanged(); |
|
206 } |
|
207 |
|
208 //============================================================================= |
|
209 EXPORT_C void CColorSelectionGrid::SizeChanged() |
|
210 { |
|
211 CAknGrid::SizeChanged(); |
|
212 SetupGrid(); |
|
213 } |
|
214 |
|
215 //============================================================================= |
|
216 void CColorSelectionGrid::SetupGridIconsL () |
|
217 { |
|
218 // Create icon array |
|
219 CArrayPtr<CGulIcon>* icons = |
|
220 new (ELeave) CAknIconArray (KColorGridRows * KColorGridCols); |
|
221 CleanupStack::PushL(icons); |
|
222 |
|
223 // Get reference to grid item text array |
|
224 MDesCArray * array = Model()->ItemTextArray(); |
|
225 CDesCArray * cArray = static_cast<CDesCArray *>(array); |
|
226 |
|
227 // Create icon bitmaps and add them to the array |
|
228 TInt index = 0; |
|
229 for (TInt i = 0; i < KColorGridRows; ++i) |
|
230 { |
|
231 for (TInt j = 0; j < KColorGridCols; ++j) |
|
232 { |
|
233 // Create grid item bitmap |
|
234 CFbsBitmap * bitmap = new (ELeave) CFbsBitmap; |
|
235 CleanupStack::PushL( bitmap ); |
|
236 User::LeaveIfError (bitmap->Create (iIconSize, EColor64K) ); |
|
237 |
|
238 // Compute color for bitmap |
|
239 TRgb color (255, 255, 255); |
|
240 if (j == 0) |
|
241 { |
|
242 color = HSLtoRGB (0.0, 0.0, i * (1.0 / 7.0)); |
|
243 |
|
244 } |
|
245 else |
|
246 { |
|
247 color = HSLtoRGB (i * (360.0 / 8.0), 1.0, j * (1.0 / 14.0)); |
|
248 } |
|
249 |
|
250 // Fill the bitmap with the correct color |
|
251 TUint16 color_64k = (TUint16) |
|
252 (0 | |
|
253 (((TUint8)color.Red() >> 3) << 11) | |
|
254 (((TUint8)color.Green() >> 2) << 5) | |
|
255 ((TUint8)color.Blue() >> 3)); |
|
256 |
|
257 bitmap->LockHeapLC(); |
|
258 TUint16 * pd = (TUint16 *)bitmap->DataAddress(); |
|
259 TSize size = bitmap->SizeInPixels(); |
|
260 TInt w = (bitmap->ScanLineLength(size.iWidth, EColor64K) >> 1) * size.iHeight; |
|
261 for (TInt k = w; k != 0; --k) |
|
262 { |
|
263 *pd++ = color_64k; |
|
264 } |
|
265 CleanupStack::PopAndDestroy(); // LockHeapLC() |
|
266 |
|
267 // Add item to the grid |
|
268 icons->AppendL ( CGulIcon::NewL (bitmap, 0) ); |
|
269 |
|
270 CleanupStack::Pop(); // bitmap |
|
271 |
|
272 // Create grid item text |
|
273 TBuf<256> buf; |
|
274 buf.AppendNum (index); |
|
275 buf.Append(KAknStripTabs); |
|
276 buf.AppendNum ((TInt)color.Value()); |
|
277 cArray->AppendL (buf); |
|
278 ++index; |
|
279 } |
|
280 } |
|
281 CleanupStack::Pop(icons); // icons |
|
282 |
|
283 // Set icons to the grid |
|
284 ItemDrawer()->FormattedCellData()->SetIconArray(icons); |
|
285 |
|
286 // Handle item addition |
|
287 HandleItemAdditionL(); |
|
288 } |
|
289 |
|
290 //============================================================================= |
|
291 void CColorSelectionGrid::SetupGrid () |
|
292 { |
|
293 // Setup text foreground and background colours to default |
|
294 AknListBoxLayouts::SetupStandardGrid (*this); |
|
295 |
|
296 // Get local copies of data we will need |
|
297 CFormattedCellListBoxItemDrawer * itemDrawer = this->ItemDrawer(); |
|
298 TInt cell_w = ColumnWidth(); |
|
299 TInt cell_h = ItemHeight(); |
|
300 |
|
301 // Set up graphics sub-cells |
|
302 AknListBoxLayouts::SetupFormGfxCell ( |
|
303 *this, // the grid |
|
304 itemDrawer, // the grid's drawer |
|
305 0, // index of the graphic within item strings |
|
306 0, // left position |
|
307 0, // top position |
|
308 0, // right - unused |
|
309 0, // bottom - unused |
|
310 cell_w , // width of graphic |
|
311 cell_h, // height of graphic |
|
312 TPoint (0, 0), // start position |
|
313 TPoint (cell_w, cell_h) // end position |
|
314 ); |
|
315 } |
|
316 |
|
317 //============================================================================= |
|
318 TRgb CColorSelectionGrid::HSLtoRGB ( |
|
319 const TReal aH, |
|
320 const TReal aS, |
|
321 const TReal aL |
|
322 ) const |
|
323 { |
|
324 TRgb rgb; |
|
325 |
|
326 if (aS == 0.0) |
|
327 { |
|
328 rgb.SetRed ((TInt)(aL * 255.0)); |
|
329 rgb.SetGreen((TInt)(aL * 255.0)); |
|
330 rgb.SetBlue((TInt)(aL * 255.0)); |
|
331 } |
|
332 else |
|
333 { |
|
334 TReal rm1, rm2; |
|
335 if (aL <= 0.5) |
|
336 { |
|
337 rm2 = aL + aL * aS; |
|
338 } |
|
339 else |
|
340 { |
|
341 rm2 = aL + aS - aL * aS; |
|
342 } |
|
343 rm1 = 2.0 * aL - rm2; |
|
344 |
|
345 rgb.SetRed (ToRGB (rm1, rm2, aH + 120.0)); |
|
346 rgb.SetGreen (ToRGB (rm1, rm2, aH)); |
|
347 rgb.SetBlue (ToRGB (rm1, rm2, aH - 120.0)); |
|
348 } |
|
349 |
|
350 return rgb; |
|
351 } |
|
352 |
|
353 //============================================================================= |
|
354 TInt CColorSelectionGrid::ToRGB ( |
|
355 TReal aRM1, |
|
356 TReal aRM2, |
|
357 TReal aRH |
|
358 ) const |
|
359 { |
|
360 if (aRH > 360.0) |
|
361 { |
|
362 aRH -= 360.0; |
|
363 } |
|
364 else if (aRH < 0.0) |
|
365 { |
|
366 aRH += 360.0; |
|
367 } |
|
368 |
|
369 if (aRH < 60.0) |
|
370 { |
|
371 aRM1 = aRM1 + (aRM2 - aRM1) * aRH / 60.0; |
|
372 } |
|
373 else if (aRH < 180.0) |
|
374 { |
|
375 aRM1 = aRM2; |
|
376 } |
|
377 else if (aRH < 240.0) |
|
378 { |
|
379 aRM1 = aRM1 + (aRM2 - aRM1) * (240.0f - aRH) / 60.0; |
|
380 } |
|
381 return (TInt)(aRM1 * 255.0); |
|
382 } |
|
383 |
|
384 // End of File |