|
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: Image visual |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alf/alfimagevisual.h" |
|
21 #include "alf/alfcontrol.h" |
|
22 #include "alf/alfenv.h" |
|
23 #include "alfclient.h" |
|
24 #include "alf/alfimage.h" |
|
25 #include "alf/alfgencomponent.h" |
|
26 #include "alf/alftexture.h" |
|
27 #include "alf/alfconstants.h" |
|
28 #include "alflogger.h" |
|
29 #include "alf/alfimageloaderutil.h" |
|
30 #include "alfskinnableimage.h" |
|
31 #include "alf/alfdropshadow.h" |
|
32 |
|
33 #include <uiacceltk/HuiUtil.h> |
|
34 |
|
35 // ======== LOCAL FUNCTIONS ======== |
|
36 #define FLOAT_COMPARE(a, b) (Abs(a-b)<0.0001f) |
|
37 |
|
38 // Private data. |
|
39 struct CAlfImageVisual::TImageVisualPrivateData |
|
40 { |
|
41 CAlfSkinnableImage* iImage; |
|
42 CAlfSkinnableImage* iSecondaryImage; |
|
43 CAlfImageVisual::TScaleMode iScaleMode; |
|
44 }; |
|
45 |
|
46 // ======== MEMBER FUNCTIONS ======== |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // ?description_if_needed |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C CAlfImageVisual::CAlfImageVisual() |
|
53 { |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // ?description_if_needed |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void CAlfImageVisual::ConstructL(CAlfControl& aOwner) |
|
62 { |
|
63 CAlfVisual::ConstructL(aOwner); |
|
64 iImageVisualData = new (ELeave) TImageVisualPrivateData; |
|
65 iImageVisualData->iImage = NULL; |
|
66 iImageVisualData->iSecondaryImage = NULL; |
|
67 |
|
68 iImageVisualData->iImage = new (ELeave) CAlfSkinnableImage(&aOwner.Env()); |
|
69 iImageVisualData->iSecondaryImage = new (ELeave) CAlfSkinnableImage(&aOwner.Env()); |
|
70 iImageVisualData->iScaleMode = EScaleFit; |
|
71 } |
|
72 |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // ?description_if_needed |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CAlfImageVisual::~CAlfImageVisual() |
|
79 { |
|
80 if (iImageVisualData) |
|
81 { |
|
82 delete iImageVisualData->iImage; |
|
83 iImageVisualData->iImage = NULL, |
|
84 |
|
85 delete iImageVisualData->iSecondaryImage; |
|
86 iImageVisualData->iSecondaryImage = NULL; |
|
87 } |
|
88 |
|
89 delete iImageVisualData; |
|
90 iImageVisualData = NULL; |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // ?implementation_description |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CAlfImageVisual* CAlfImageVisual::AddNewL( |
|
99 CAlfControl& aOwnerControl, |
|
100 CAlfLayout* aParentLayout) |
|
101 { |
|
102 CAlfImageVisual* image = STATIC_CAST(CAlfImageVisual*, |
|
103 aOwnerControl.AppendVisualL(EAlfVisualTypeImage, aParentLayout)); |
|
104 return image; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Sets scale mode. |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C void CAlfImageVisual::SetScaleMode(CAlfImageVisual::TScaleMode aScaleMode) |
|
112 { |
|
113 TPckgC<CAlfImageVisual::TScaleMode> buf(aScaleMode); |
|
114 |
|
115 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetScaleMode, buf); |
|
116 |
|
117 if ( err ) |
|
118 { |
|
119 __ALFLOGSTRING1( "CAlfImageVisual::SetScaleMode ignore error %d", err ) |
|
120 } |
|
121 else |
|
122 { |
|
123 iImageVisualData->iScaleMode = aScaleMode; |
|
124 } |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Gets scale mode. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C CAlfImageVisual::TScaleMode CAlfImageVisual::ScaleMode() |
|
132 { |
|
133 CAlfImageVisual::TScaleMode ret = EScaleFit; |
|
134 if( iImageVisualData ) |
|
135 { |
|
136 ret = iImageVisualData->iScaleMode; |
|
137 } |
|
138 else |
|
139 { |
|
140 __ALFLOGSTRING( "CAlfImageVisual::ScaleMode Ignore ScaleMode iImageVisualData is NULL" ) |
|
141 } |
|
142 return ret; |
|
143 } |
|
144 // --------------------------------------------------------------------------- |
|
145 // Sets image. |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C void CAlfImageVisual::SetImage(const TAlfImage& aImage) |
|
149 { |
|
150 iImageVisualData->iImage->SetImage(aImage); // This texturizes skin graphics if needed |
|
151 |
|
152 TAlfImageParams params(iImageVisualData->iImage->Image()); |
|
153 |
|
154 TPckgC<TAlfImageParams> buf(params); |
|
155 |
|
156 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetImage, buf); |
|
157 |
|
158 if ( err ) |
|
159 { |
|
160 __ALFLOGSTRING1( "CAlfImageVisual::SetImage ignore error %d", err ) |
|
161 } |
|
162 |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Sets secondary image. |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 EXPORT_C void CAlfImageVisual::SetSecondaryImage(const TAlfImage& aImage) |
|
170 { |
|
171 iImageVisualData->iSecondaryImage->SetImage(aImage); // This texturizes skin graphics if needed |
|
172 |
|
173 TAlfImageParams params(iImageVisualData->iSecondaryImage->Image()); |
|
174 |
|
175 TPckgC<TAlfImageParams> buf(params); |
|
176 |
|
177 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetSecondaryImage, buf); |
|
178 |
|
179 if ( err ) |
|
180 { |
|
181 __ALFLOGSTRING1( "CAlfImageVisual::SetSecondaryImage ignore error %d", err ) |
|
182 } |
|
183 |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Sets secondary image alpha value. |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 EXPORT_C void CAlfImageVisual::SetSecondaryAlpha(const TAlfTimedValue& aAlpha) |
|
191 { |
|
192 TPckgC<TAlfTimedValue> alphaPckg(aAlpha); |
|
193 |
|
194 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetSecondaryAlpha, alphaPckg ); |
|
195 |
|
196 if ( err ) |
|
197 { |
|
198 __ALFLOGSTRING1( "CAlfImageVisual::SetSecondaryAlpha ignore error %d", err ) |
|
199 } |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Gets image. |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C const TAlfImage& CAlfImageVisual::Image() const |
|
207 { |
|
208 return iImageVisualData->iImage->Image(); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // Gets secondary image. |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C const TAlfImage& CAlfImageVisual::SecondaryImage() const |
|
216 { |
|
217 return iImageVisualData->iSecondaryImage->Image(); |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // Sets color. |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C void CAlfImageVisual::SetColor(const TRgb& aColor) |
|
225 { |
|
226 TPckgC<TRgb> buf(aColor); |
|
227 |
|
228 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetColor, buf ); |
|
229 |
|
230 if ( err ) |
|
231 { |
|
232 __ALFLOGSTRING1( "CAlfImageVisual::SetColor ignore error %d", err ) |
|
233 } |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // Sets colormode. |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 EXPORT_C void CAlfImageVisual::SetColorMode(CAlfImageVisual::TColorMode aColorMode, |
|
241 TReal32 aParam) __SOFTFP |
|
242 { |
|
243 TIntTReal params(aColorMode, aParam); |
|
244 TPckg<TIntTReal> buf(params); |
|
245 |
|
246 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetColorMode, buf ); |
|
247 |
|
248 if ( err ) |
|
249 { |
|
250 __ALFLOGSTRING1( "CAlfImageVisual::SetColorMode ignore error %d", err ) |
|
251 } |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Sets stretch. |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 EXPORT_C void CAlfImageVisual::SetStretch(TInt aTop, TInt aBottom) |
|
259 { |
|
260 TInt2 params(aTop, aBottom); |
|
261 TPckg<TInt2> buf(params); |
|
262 |
|
263 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetStretch, buf ); |
|
264 |
|
265 if ( err ) |
|
266 { |
|
267 __ALFLOGSTRING1( "CAlfImageVisual::SetStretch ignore error %d", err ) |
|
268 } |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // Sets stretchmode. |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C void CAlfImageVisual::SetStretchMode(CAlfGc::TStretchMode aStretchMode) |
|
276 { |
|
277 TPckg<CAlfGc::TStretchMode> buf(aStretchMode); |
|
278 |
|
279 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetStretchMode, buf ); |
|
280 |
|
281 if ( err ) |
|
282 { |
|
283 __ALFLOGSTRING1( "CAlfImageVisual::SetStretchMode ignore error %d", err ) |
|
284 } |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // Sets drop shadow. (deprecated) |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 EXPORT_C void CAlfImageVisual::SetDropShadow(TInt aShadowDistance) |
|
292 { |
|
293 if ( aShadowDistance == 0 ) |
|
294 { |
|
295 TRAP_IGNORE( EnableDropShadowL(EFalse) ); |
|
296 return; |
|
297 } |
|
298 |
|
299 TRAPD( err, EnableDropShadowL() ); |
|
300 |
|
301 if ( err ) |
|
302 { |
|
303 __ALFLOGSTRING1( "CAlfImageVisual::SetDropShadow ignore error %d", err ) |
|
304 return; |
|
305 } |
|
306 |
|
307 DropShadowHandler()->SetOffset( TAlfTimedPoint( aShadowDistance, aShadowDistance ) ); |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // Sets drop shadow. |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 EXPORT_C void CAlfImageVisual::SetDropShadow(const TAlfMetric& aShadowDistance) |
|
315 { |
|
316 SetDropShadow(TAlfXYMetric(aShadowDistance)); |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // Sets drop shadow. |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 EXPORT_C void CAlfImageVisual::SetDropShadow(const TAlfXYMetric& aShadowDistance) |
|
324 { |
|
325 if ( FLOAT_COMPARE(aShadowDistance.iX.iMagnitude, 0.f ) && |
|
326 FLOAT_COMPARE(aShadowDistance.iY.iMagnitude, 0.f ) ) |
|
327 { |
|
328 TRAP_IGNORE( EnableDropShadowL(EFalse) ); |
|
329 return; |
|
330 } |
|
331 |
|
332 TRAPD( err, EnableDropShadowL() ); |
|
333 |
|
334 if ( err ) |
|
335 { |
|
336 __ALFLOGSTRING1( "CAlfImageVisual::SetDropShadow ignore error %d", err ) |
|
337 return; |
|
338 } |
|
339 |
|
340 DropShadowHandler()->SetOffset( |
|
341 TAlfTimedPoint( aShadowDistance.iX.iMagnitude,aShadowDistance.iY.iMagnitude ), |
|
342 aShadowDistance.iX.iUnit ); // assume that the unit for x and y are the same |
|
343 } |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 EXPORT_C void CAlfImageVisual::SetTurnAngle(const TAlfTimedValue& aAngle) |
|
350 { |
|
351 TPckgC<TAlfTimedValue> pckg(aAngle); |
|
352 |
|
353 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetTurnAngle, pckg ); |
|
354 |
|
355 if ( err ) |
|
356 { |
|
357 __ALFLOGSTRING1( "CAlfImageVisual::SetTurnAngle ignore error %d", err ) |
|
358 } |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C void CAlfImageVisual::SetScale(const TAlfTimedValue& aScale) |
|
366 { |
|
367 TPckgC<TAlfTimedValue> pckg(aScale); |
|
368 |
|
369 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetScale, pckg ); |
|
370 |
|
371 if ( err ) |
|
372 { |
|
373 __ALFLOGSTRING1( "CAlfImageVisual::SetScale ignore error %d", err ) |
|
374 } |
|
375 } |
|
376 |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 EXPORT_C void CAlfImageVisual::SetOffset(const TAlfTimedPoint& aOffset) |
|
383 { |
|
384 TPckgC<TAlfTimedPoint> pckg(aOffset); |
|
385 |
|
386 TInt err = Comms()->DoCmdNoReply(EAlfImageVisualSetOffset, pckg ); |
|
387 |
|
388 if ( err ) |
|
389 { |
|
390 __ALFLOGSTRING1( "CAlfImageVisual::SetOffset ignore error %d", err ) |
|
391 } |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C TAlfTimedValue CAlfImageVisual::SecondaryAlpha() |
|
399 { |
|
400 TAlfTimedValue value; |
|
401 TPckg<TAlfTimedValue> buf(value); |
|
402 TInt err = Comms()->DoSynchronousCmd( EAlfImageVisualSecondaryAlpha, |
|
403 KNullDesC8, |
|
404 buf); |
|
405 |
|
406 if (err) |
|
407 { |
|
408 __ALFLOGSTRING1( "CAlfImageVisual::SecondaryAlpha panic error %d", err ) |
|
409 USER_INVARIANT(); |
|
410 } |
|
411 |
|
412 return value; |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C TAlfTimedValue CAlfImageVisual::TurnAngle() |
|
420 { |
|
421 TAlfTimedValue value; |
|
422 TPckg<TAlfTimedValue> buf(value); |
|
423 TInt err = Comms()->DoSynchronousCmd( EAlfImageVisualTurnAngle, |
|
424 KNullDesC8, |
|
425 buf); |
|
426 |
|
427 if (err) |
|
428 { |
|
429 __ALFLOGSTRING1( "CAlfImageVisual::TurnAngle panic error %d", err ) |
|
430 USER_INVARIANT(); |
|
431 } |
|
432 |
|
433 return value; |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 EXPORT_C TAlfTimedValue CAlfImageVisual::Scale() |
|
441 { |
|
442 TAlfTimedValue value; |
|
443 TPckg<TAlfTimedValue> buf(value); |
|
444 TInt err = Comms()->DoSynchronousCmd( EAlfImageVisualScale, |
|
445 KNullDesC8, |
|
446 buf); |
|
447 |
|
448 if (err) |
|
449 { |
|
450 __ALFLOGSTRING1( "CAlfImageVisual::Scale panic error %d", err ) |
|
451 USER_INVARIANT(); |
|
452 } |
|
453 |
|
454 return value; |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 EXPORT_C TAlfTimedPoint CAlfImageVisual::Offset() |
|
462 { |
|
463 TAlfTimedPoint value; |
|
464 TPckg<TAlfTimedPoint> buf(value); |
|
465 TInt err = Comms()->DoSynchronousCmd( EAlfImageVisualOffset, |
|
466 KNullDesC8, |
|
467 buf); |
|
468 |
|
469 if (err) |
|
470 { |
|
471 __ALFLOGSTRING1( "CAlfImageVisual::Offset panic error %d", err ) |
|
472 USER_INVARIANT(); |
|
473 } |
|
474 |
|
475 return value; |
|
476 } |
|
477 |
|
478 // --------------------------------------------------------------------------- |
|
479 // Place holder from CAlfVisual |
|
480 // --------------------------------------------------------------------------- |
|
481 // |
|
482 EXPORT_C void CAlfImageVisual::RemoveAndDestroyAllD() |
|
483 { |
|
484 CAlfVisual::RemoveAndDestroyAllD(); |
|
485 } |
|
486 |
|
487 // --------------------------------------------------------------------------- |
|
488 // Place holder from CAlfVisual |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 EXPORT_C void CAlfImageVisual::UpdateChildrenLayout(TInt aTransitionTime ) |
|
492 { |
|
493 CAlfVisual::UpdateChildrenLayout( aTransitionTime ); |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------------------------- |
|
497 // Place holder from CAlfVisual |
|
498 // --------------------------------------------------------------------------- |
|
499 // |
|
500 EXPORT_C CAlfVisual* CAlfImageVisual::FindTag(const TDesC8& aTag) |
|
501 { |
|
502 return CAlfVisual::FindTag( aTag ); |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------- |
|
506 // Place holder from CAlfVisual |
|
507 // --------------------------------------------------------------------------- |
|
508 // |
|
509 EXPORT_C void CAlfImageVisual::DoRemoveAndDestroyAllD() |
|
510 { |
|
511 CAlfVisual::DoRemoveAndDestroyAllD(); |
|
512 } |
|
513 |
|
514 // --------------------------------------------------------------------------- |
|
515 // future proofing |
|
516 // --------------------------------------------------------------------------- |
|
517 // |
|
518 EXPORT_C void CAlfImageVisual::PropertyOwnerExtension(const TUid& aExtensionUid, TAny** aExtensionParams) |
|
519 { |
|
520 CAlfVisual::PropertyOwnerExtension(aExtensionUid,aExtensionParams); |
|
521 } |
|
522 |