|
1 /* |
|
2 * Copyright (c) 2006-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: Implements CHuiVisual class. Visuals are graphical entities |
|
15 * visible on a display. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "uiacceltk/HuiVisual.h" // Class definition |
|
22 #include "uiacceltk/HuiLayout.h" |
|
23 #include "uiacceltk/HuiControl.h" |
|
24 #include "uiacceltk/HuiControlGroup.h" |
|
25 #include "uiacceltk/HuiEnv.h" |
|
26 #include "uiacceltk/HuiDisplay.h" |
|
27 #include "uiacceltk/HuiRoster.h" |
|
28 #include "uiacceltk/HuiTransformation.h" |
|
29 #include "uiacceltk/HuiDrawing.h" |
|
30 #include "HuiRenderPlugin.h" |
|
31 #include "uiacceltk/HuiUtil.h" |
|
32 #include "uiacceltk/HuiStatic.h" |
|
33 #include "uiacceltk/HuiProbe.h" |
|
34 #include "uiacceltk/huidropshadow.h" |
|
35 #include "HuiRosterImpl.h" |
|
36 #include "HuiFxEffect.h" |
|
37 #include "HuiFxEffectParser.h" |
|
38 #include "alflogger.h" |
|
39 #include "HuiCmdBufferBrush.h" |
|
40 #include "huicanvasrenderbuffer.h" |
|
41 |
|
42 struct CHuiVisual::THuiVisualPrivateData |
|
43 { |
|
44 public: // Functions |
|
45 // Constructor: initialize the data |
|
46 THuiVisualPrivateData() : iTacticons(), iDropShadow(NULL) |
|
47 { |
|
48 iEffect = NULL; |
|
49 iEffectParser = NULL; |
|
50 } |
|
51 |
|
52 // Destructor: destruct the data |
|
53 ~THuiVisualPrivateData() |
|
54 { |
|
55 iTacticons.Close(); |
|
56 delete iDropShadow; |
|
57 delete iEffectParser; |
|
58 delete iEffect; |
|
59 } |
|
60 |
|
61 // structs |
|
62 struct TTacticon |
|
63 { |
|
64 TInt iFeedbackType; |
|
65 TInt iEventType; |
|
66 }; |
|
67 |
|
68 // Data |
|
69 RArray<TTacticon> iTacticons; |
|
70 CHuiDropShadow* iDropShadow; |
|
71 TRect iPreviousDrawnTvOut; |
|
72 CHuiFxEffect* iEffect; |
|
73 CHuiFxEffectParser* iEffectParser; |
|
74 MHuiEffectable *iEffectable; |
|
75 CHuiCanvasRenderBuffer* iStoredRenderBuffer; |
|
76 TBool iStoredRenderBufferModificationsEnabled; |
|
77 TBool iFreezed; |
|
78 }; |
|
79 class CHuiEffectable : public CBase, public MHuiEffectable |
|
80 { |
|
81 public: // from MHuiEffectable |
|
82 CHuiEffectable(CHuiVisual *aVisual) : iVisual(aVisual) { } |
|
83 void EffectSetEffect(CHuiFxEffect* aEffect); |
|
84 TReal32 EffectOpacityTarget() const; |
|
85 void EffectSetOpacity(TReal32 aOpacity); |
|
86 void EffectDrawSelf( CHuiGc &aGc, const TRect & aDisplayRect) const; |
|
87 THuiRealRect EffectDisplayRect() const __SOFTFP; |
|
88 void SetLoadingEffect(TBool aLoading); |
|
89 void EffectSetSource( TBool aIsInput1 ); |
|
90 TBool EffectGetSource() const; |
|
91 |
|
92 private: |
|
93 CHuiVisual *iVisual; |
|
94 TBool iIsInput1; |
|
95 }; |
|
96 void CHuiEffectable::EffectSetEffect(CHuiFxEffect* aEffect) |
|
97 { |
|
98 iVisual->SetEffect(aEffect); |
|
99 } |
|
100 void CHuiEffectable::EffectSetSource( TBool aIsInput1 ) |
|
101 { |
|
102 iIsInput1 = aIsInput1; |
|
103 } |
|
104 TBool CHuiEffectable::EffectGetSource() const |
|
105 { |
|
106 return iIsInput1; |
|
107 } |
|
108 |
|
109 TReal32 CHuiEffectable::EffectOpacityTarget() const |
|
110 { |
|
111 return iVisual->iOpacity.Target(); |
|
112 } |
|
113 |
|
114 void CHuiEffectable::EffectSetOpacity(TReal32 aOpacity) |
|
115 { |
|
116 iVisual->iOpacity.Set( aOpacity ); |
|
117 } |
|
118 |
|
119 void CHuiEffectable::EffectDrawSelf( CHuiGc &aGc, const TRect & aDisplayRect) const |
|
120 { |
|
121 iVisual->DrawSelf(aGc, aDisplayRect); |
|
122 } |
|
123 |
|
124 THuiRealRect CHuiEffectable::EffectDisplayRect() const __SOFTFP |
|
125 { |
|
126 return iVisual->DisplayRect(); |
|
127 } |
|
128 |
|
129 void CHuiEffectable::SetLoadingEffect(TBool aLoading) |
|
130 { |
|
131 iVisual->SetLoadingEffect(aLoading); |
|
132 } |
|
133 |
|
134 |
|
135 /// Descriptor that is returned when the tag is queried and no tag has been |
|
136 /// been defined for a visual. |
|
137 _LIT8(KHuiVisualUndefinedTag, ""); |
|
138 |
|
139 EXPORT_C MHuiVisualOwner::~MHuiVisualOwner() |
|
140 { |
|
141 } |
|
142 |
|
143 EXPORT_C CHuiCanvasRenderBuffer *CHuiVisual::StoredRenderBuffer() const |
|
144 { |
|
145 return iVisualData->iStoredRenderBuffer; |
|
146 } |
|
147 EXPORT_C void CHuiVisual::SetStoredRenderBuffer(CHuiCanvasRenderBuffer *aRenderBuffer) |
|
148 { |
|
149 if (iVisualData->iStoredRenderBufferModificationsEnabled) |
|
150 { |
|
151 if (iVisualData->iStoredRenderBuffer) |
|
152 { |
|
153 iVisualData->iStoredRenderBuffer->UnInitialize(); |
|
154 } |
|
155 delete iVisualData->iStoredRenderBuffer; |
|
156 iVisualData->iStoredRenderBuffer = aRenderBuffer; |
|
157 } |
|
158 } |
|
159 EXPORT_C void CHuiVisual::SetStoredRenderBufferModificationsEnabled(TBool aEnabled) |
|
160 { |
|
161 iVisualData->iStoredRenderBufferModificationsEnabled = aEnabled; |
|
162 } |
|
163 |
|
164 EXPORT_C void CHuiVisual::SetFreezeState(TBool aEnabled) |
|
165 { |
|
166 iVisualData->iFreezed = aEnabled; |
|
167 } |
|
168 TBool CHuiVisual::Freezed() const |
|
169 { |
|
170 return iVisualData->iFreezed; |
|
171 } |
|
172 |
|
173 EXPORT_C CHuiVisual* CHuiVisual::AddNewL(CHuiControl& aOwnerControl, |
|
174 CHuiLayout* aParentLayout) |
|
175 { |
|
176 CHuiVisual* visual = STATIC_CAST(CHuiVisual*, |
|
177 aOwnerControl.AppendVisualL(EHuiVisualTypeVisual, aParentLayout)); |
|
178 return visual; |
|
179 } |
|
180 |
|
181 |
|
182 EXPORT_C CHuiVisual::CHuiVisual(MHuiVisualOwner& aOwner) |
|
183 : iOpacity(1.f), |
|
184 iOwner(&aOwner), |
|
185 // Set the maximum size to unlimited. |
|
186 iMaxSize(TSize(KMaxTInt, KMaxTInt)), |
|
187 iPadding(0), |
|
188 iDisplayRectFrameNumber(KMaxTUint), |
|
189 iDisplayRectTargetFrameNumber(KMaxTUint) |
|
190 { |
|
191 HUI_PROBE_ASSOCIATE_WITH_CURRENT_SESSION |
|
192 HUI_PROBE_REPORT_CONSTRUCTED |
|
193 iOpacity.SetStyle(EHuiTimedValueStyleLinear); |
|
194 } |
|
195 |
|
196 |
|
197 EXPORT_C void CHuiVisual::ConstructL() |
|
198 { |
|
199 iVisualData = new (ELeave) THuiVisualPrivateData; |
|
200 iVisualData->iEffectable = new CHuiEffectable(this); |
|
201 iVisualData->iStoredRenderBuffer = NULL; |
|
202 } |
|
203 |
|
204 |
|
205 EXPORT_C CHuiVisual::~CHuiVisual() |
|
206 { |
|
207 // Cancel scheduled commands for this visual. |
|
208 Env().CancelCommands(this); |
|
209 |
|
210 // Update previous dirty rect to relevant displays so that the visual can be erased |
|
211 if(Display()) |
|
212 { |
|
213 CHuiRoster& roster = Display()->Roster(); |
|
214 // Check if this roster is shared between several displays and add previous dirty to all |
|
215 // of them |
|
216 for(TInt i = 0; i < Env().Displays().Count(); ++i) |
|
217 { |
|
218 CHuiDisplay* display = &Env().Display(i); |
|
219 if (&(display->Roster()) == &roster) |
|
220 { |
|
221 const TRect& previousDirtyRect = display->IsDisplayTypeTvOut() ? iVisualData->iPreviousDrawnTvOut : iPreviousDrawn; |
|
222 TRect empty; |
|
223 display->CombineAndAddDirtyRegion(previousDirtyRect, empty); |
|
224 } |
|
225 } |
|
226 } |
|
227 |
|
228 // If this is a root-level visual, it must be hidden on the display. |
|
229 if(iDisplay) |
|
230 { |
|
231 iDisplay->Roster().HideVisual(this); |
|
232 } |
|
233 |
|
234 // If the visual is still attached to a layout, it is time to remove it. |
|
235 if(iLayout) |
|
236 { |
|
237 iLayout->Remove(this); |
|
238 } |
|
239 |
|
240 // If the visual is attached to some visual as external content visual, |
|
241 // remove the link from the parent visual |
|
242 if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent) |
|
243 { |
|
244 TRAP_IGNORE(CHuiStatic::Env().Display(0).RosterImpl().RemoveExternalContentVisualFromParentL(this)); |
|
245 } |
|
246 |
|
247 delete iBrushes; |
|
248 delete iTag; |
|
249 delete iTransform; |
|
250 delete iVisualData->iEffectable; |
|
251 if (iVisualData->iStoredRenderBuffer) |
|
252 { |
|
253 iVisualData->iStoredRenderBuffer->UnInitialize(); |
|
254 } |
|
255 delete iVisualData->iStoredRenderBuffer; |
|
256 delete iVisualData; |
|
257 |
|
258 iOwner = NULL; |
|
259 iDisplay = NULL; |
|
260 iLayout = NULL; |
|
261 |
|
262 HUI_PROBE_REPORT_DESTRUCTED |
|
263 } |
|
264 |
|
265 |
|
266 EXPORT_C void CHuiVisual::RemoveAndDestroyAllD() |
|
267 { |
|
268 ASSERT(iOwner != NULL); |
|
269 iOwner->VisualDestroyed(*this); |
|
270 delete this; |
|
271 } |
|
272 |
|
273 |
|
274 EXPORT_C CHuiLayout* CHuiVisual::Layout() const |
|
275 { |
|
276 return iLayout; |
|
277 } |
|
278 |
|
279 |
|
280 void CHuiVisual::SetLayout(CHuiLayout* aLayout) |
|
281 { |
|
282 iLayout = aLayout; |
|
283 } |
|
284 |
|
285 |
|
286 EXPORT_C CHuiEnv& CHuiVisual::Env() const |
|
287 { |
|
288 return Owner().Env(); |
|
289 } |
|
290 |
|
291 |
|
292 EXPORT_C CHuiSkin& CHuiVisual::Skin() const |
|
293 { |
|
294 return Owner().Env().Skin(); |
|
295 } |
|
296 |
|
297 |
|
298 EXPORT_C CHuiDisplay* CHuiVisual::Display() const |
|
299 { |
|
300 const CHuiVisual* iter = this; |
|
301 |
|
302 while(iter) |
|
303 { |
|
304 if(iter->iDisplay) |
|
305 { |
|
306 return iter->iDisplay; |
|
307 } |
|
308 iter = iter->Layout(); |
|
309 } |
|
310 |
|
311 // Not shown on any display. |
|
312 return NULL; |
|
313 } |
|
314 |
|
315 |
|
316 void CHuiVisual::SetDisplay(CHuiDisplay* aDisplay) |
|
317 { |
|
318 iDisplay = aDisplay; |
|
319 } |
|
320 |
|
321 |
|
322 EXPORT_C void CHuiVisual::SetFlag(THuiVisualFlags aFlag) |
|
323 { |
|
324 SetFlags(aFlag); |
|
325 } |
|
326 |
|
327 |
|
328 EXPORT_C void CHuiVisual::SetFlags(TInt aAnyFlags) |
|
329 { |
|
330 const TInt oldFlags = iFlags; |
|
331 iFlags |= aAnyFlags; |
|
332 |
|
333 if(!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllow3DProjection)) |
|
334 { |
|
335 // The rendering plugin does not support 3D projection. |
|
336 ClearFlag(EHuiVisualFlag3DProjection); |
|
337 } |
|
338 |
|
339 HandleFlagsChanged( oldFlags ); |
|
340 } |
|
341 |
|
342 |
|
343 EXPORT_C void CHuiVisual::ClearFlag(THuiVisualFlags aFlag) |
|
344 { |
|
345 ClearFlags( aFlag ); |
|
346 } |
|
347 |
|
348 |
|
349 EXPORT_C void CHuiVisual::ClearFlags(TInt aAnyFlags) |
|
350 { |
|
351 const TInt oldFlags = iFlags; |
|
352 iFlags &= ~aAnyFlags; |
|
353 |
|
354 HandleFlagsChanged( oldFlags ); |
|
355 } |
|
356 |
|
357 |
|
358 EXPORT_C MHuiVisualOwner& CHuiVisual::Owner() const |
|
359 { |
|
360 ASSERT(iOwner != NULL); |
|
361 return *iOwner; |
|
362 } |
|
363 |
|
364 |
|
365 EXPORT_C void CHuiVisual::SetOwner(MHuiVisualOwner& aOwner) |
|
366 { |
|
367 iOwner = &aOwner; |
|
368 } |
|
369 |
|
370 |
|
371 EXPORT_C TInt CHuiVisual::Count() const |
|
372 { |
|
373 return 0; |
|
374 } |
|
375 |
|
376 |
|
377 EXPORT_C CHuiVisual& CHuiVisual::Visual(TInt /*aIndex*/) const |
|
378 { |
|
379 USER_INVARIANT(); |
|
380 return *(CHuiVisual*)this; // never reached |
|
381 } |
|
382 |
|
383 |
|
384 EXPORT_C void CHuiVisual::SetOrigin(THuiVisualHOrigin aHoriz, THuiVisualVOrigin aVert) |
|
385 { |
|
386 ClearFlags(EHuiVisualFlagHOriginCenter | EHuiVisualFlagHOriginRight); |
|
387 switch(aHoriz) |
|
388 { |
|
389 case EHuiVisualHOriginCenter: |
|
390 SetFlag(EHuiVisualFlagHOriginCenter); |
|
391 break; |
|
392 |
|
393 case EHuiVisualHOriginRight: |
|
394 SetFlag(EHuiVisualFlagHOriginRight); |
|
395 break; |
|
396 |
|
397 default: |
|
398 break; |
|
399 } |
|
400 |
|
401 ClearFlags(EHuiVisualFlagVOriginCenter | EHuiVisualFlagVOriginBottom); |
|
402 switch(aVert) |
|
403 { |
|
404 case EHuiVisualVOriginCenter: |
|
405 SetFlag(EHuiVisualFlagVOriginCenter); |
|
406 break; |
|
407 |
|
408 case EHuiVisualVOriginBottom: |
|
409 SetFlag(EHuiVisualFlagVOriginBottom); |
|
410 break; |
|
411 |
|
412 default: |
|
413 break; |
|
414 } |
|
415 } |
|
416 |
|
417 |
|
418 EXPORT_C THuiVisualHOrigin CHuiVisual::HorizontalOrigin() const |
|
419 { |
|
420 if(iFlags & EHuiVisualFlagHOriginCenter) |
|
421 { |
|
422 return EHuiVisualHOriginCenter; |
|
423 } |
|
424 if(iFlags & EHuiVisualFlagHOriginRight) |
|
425 { |
|
426 return EHuiVisualHOriginRight; |
|
427 } |
|
428 return EHuiVisualHOriginLeft; |
|
429 } |
|
430 |
|
431 |
|
432 EXPORT_C THuiVisualVOrigin CHuiVisual::VerticalOrigin() const |
|
433 { |
|
434 if(iFlags & EHuiVisualFlagVOriginCenter) |
|
435 { |
|
436 return EHuiVisualVOriginCenter; |
|
437 } |
|
438 if(iFlags & EHuiVisualFlagVOriginBottom) |
|
439 { |
|
440 return EHuiVisualVOriginBottom; |
|
441 } |
|
442 return EHuiVisualVOriginTop; |
|
443 } |
|
444 |
|
445 |
|
446 EXPORT_C void CHuiVisual::AlignByOrigin(THuiRealPoint& aPointInPixels, TBool aUndo) const |
|
447 { |
|
448 TInt factor = (aUndo? -1 : 1); |
|
449 THuiRealPoint itemSize(0.f, 0.f); |
|
450 |
|
451 TInt horizOrig = HorizontalOrigin(); |
|
452 TInt vertOrig = VerticalOrigin(); |
|
453 |
|
454 // The position of the origin depends whether the coordinates are mirrored. |
|
455 if(LocalBaseUnit().iX.iMagnitude < 0) |
|
456 { |
|
457 if(horizOrig == EHuiVisualHOriginLeft) |
|
458 { |
|
459 horizOrig = EHuiVisualHOriginRight; |
|
460 } |
|
461 else if(horizOrig == EHuiVisualHOriginRight) |
|
462 { |
|
463 horizOrig = EHuiVisualHOriginLeft; |
|
464 } |
|
465 else |
|
466 { |
|
467 // For PC-lint |
|
468 } |
|
469 } |
|
470 if(LocalBaseUnit().iY.iMagnitude < 0) |
|
471 { |
|
472 if(vertOrig == EHuiVisualVOriginTop) |
|
473 { |
|
474 vertOrig = EHuiVisualVOriginBottom; |
|
475 } |
|
476 else if(vertOrig == EHuiVisualVOriginBottom) |
|
477 { |
|
478 vertOrig = EHuiVisualVOriginTop; |
|
479 } |
|
480 else |
|
481 { |
|
482 // For PC-lint |
|
483 } |
|
484 } |
|
485 |
|
486 if(horizOrig != EHuiVisualHOriginLeft || |
|
487 vertOrig != EHuiVisualVOriginTop) |
|
488 { |
|
489 // Need the size of the visual for aligning to non-top/left corner. |
|
490 itemSize = LocalPointInPixels(Size().RealNow()); |
|
491 } |
|
492 |
|
493 switch(horizOrig) |
|
494 { |
|
495 case EHuiVisualHOriginCenter: |
|
496 aPointInPixels.iX -= factor * itemSize.iX / 2.f; |
|
497 break; |
|
498 |
|
499 case EHuiVisualHOriginRight: |
|
500 aPointInPixels.iX -= factor * itemSize.iX; |
|
501 break; |
|
502 |
|
503 default: |
|
504 break; |
|
505 } |
|
506 |
|
507 switch(vertOrig) |
|
508 { |
|
509 case EHuiVisualVOriginCenter: |
|
510 aPointInPixels.iY -= factor * itemSize.iY / 2.f; |
|
511 break; |
|
512 |
|
513 case EHuiVisualVOriginBottom: |
|
514 aPointInPixels.iY -= factor * itemSize.iY; |
|
515 break; |
|
516 |
|
517 default: |
|
518 break; |
|
519 } |
|
520 } |
|
521 |
|
522 |
|
523 EXPORT_C const THuiTimedPoint& CHuiVisual::Pos() const |
|
524 { |
|
525 return iPos; |
|
526 } |
|
527 |
|
528 |
|
529 EXPORT_C const THuiTimedPoint& CHuiVisual::Size() const |
|
530 { |
|
531 return iSize; |
|
532 } |
|
533 |
|
534 |
|
535 EXPORT_C void CHuiVisual::SetPos(const THuiRealPoint& aPos, TInt aTransitionTime) |
|
536 { |
|
537 iPos.iX.Set(aPos.iX, aTransitionTime); |
|
538 iPos.iY.Set(aPos.iY, aTransitionTime); |
|
539 } |
|
540 |
|
541 |
|
542 EXPORT_C void CHuiVisual::SetSize(const THuiRealSize& aSize, TInt aTransitionTime) |
|
543 { |
|
544 iSize.iX.Set(aSize.iWidth < 0 ? aSize.iWidth *-1 : aSize.iWidth, aTransitionTime); |
|
545 iSize.iY.Set(aSize.iHeight < 0 ? aSize.iHeight *-1 : aSize.iHeight, aTransitionTime); |
|
546 } |
|
547 |
|
548 |
|
549 EXPORT_C void CHuiVisual::SetRect(const THuiRealRect& aRect, TInt aTransitionTime) |
|
550 { |
|
551 SetPos(aRect.iTl, aTransitionTime); |
|
552 SetSize(aRect.Size(), aTransitionTime); |
|
553 } |
|
554 |
|
555 |
|
556 // deprecated |
|
557 EXPORT_C void CHuiVisual::Move(const TPoint& aOffset, TInt aTransitionTime) |
|
558 { |
|
559 Move(PixelPointInLocal(THuiRealPoint(aOffset), EHuiReferenceStateNow), aTransitionTime); |
|
560 } |
|
561 |
|
562 |
|
563 EXPORT_C void CHuiVisual::Move(const THuiRealPoint& aOffset, TInt aTransitionTime) |
|
564 { |
|
565 iPos.iX.Set(iPos.iX.Target() + aOffset.iX, aTransitionTime); |
|
566 iPos.iY.Set(iPos.iY.Target() + aOffset.iY, aTransitionTime); |
|
567 } |
|
568 |
|
569 |
|
570 EXPORT_C void CHuiVisual::Mimic(const CHuiVisual& aVisual, TInt aTransitionTime) |
|
571 { |
|
572 SetPos(aVisual.iPos.RealTarget(), aTransitionTime); |
|
573 SetSize(aVisual.iSize.RealTarget().AsSize(), aTransitionTime); |
|
574 } |
|
575 |
|
576 |
|
577 // deprecated |
|
578 EXPORT_C void CHuiVisual::SetCenteredPosAndSize(const TPoint& aCenterPoint, |
|
579 const TSize& aSize, |
|
580 TInt aTransitionTime) |
|
581 { |
|
582 THuiRealPoint visualSize = PixelPointInLocal(THuiRealPoint(aSize.iWidth, aSize.iHeight), |
|
583 EHuiReferenceStateNow); |
|
584 SetCenteredPosAndSize(PixelPointInLocal(THuiRealPoint(aCenterPoint), EHuiReferenceStateNow), |
|
585 visualSize.AsSize(), aTransitionTime); |
|
586 } |
|
587 |
|
588 |
|
589 EXPORT_C void CHuiVisual::SetCenteredPosAndSize(const THuiRealPoint& aCenterPoint, |
|
590 const THuiRealSize& aSize, |
|
591 TInt aTransitionTime) |
|
592 { |
|
593 SetPos(THuiRealPoint(aCenterPoint.iX - aSize.iWidth/2, |
|
594 aCenterPoint.iY - aSize.iHeight/2), aTransitionTime); |
|
595 SetSize(aSize, aTransitionTime); |
|
596 } |
|
597 |
|
598 |
|
599 EXPORT_C void CHuiVisual::UpdateChildrenLayout(TInt /*aTransitionTime*/) |
|
600 { |
|
601 } |
|
602 |
|
603 |
|
604 void CHuiVisual::ReportLayoutUpdate() |
|
605 { |
|
606 // Notify owner, if requested. |
|
607 if(iFlags & EHuiVisualFlagLayoutUpdateNotification) |
|
608 { |
|
609 Owner().VisualLayoutUpdated(*this); |
|
610 } |
|
611 } |
|
612 |
|
613 // deprecated |
|
614 EXPORT_C void CHuiVisual::SetMinSize(const TSize& aMinSize) |
|
615 { |
|
616 THuiRealPoint minPoint = PixelPointInLocal(THuiRealPoint(aMinSize.iWidth, aMinSize.iHeight), |
|
617 EHuiReferenceStateNow); |
|
618 SetMinSize(minPoint.AsSize()); |
|
619 } |
|
620 |
|
621 EXPORT_C void CHuiVisual::SetMinSize(const THuiRealSize& aMinSize) |
|
622 { |
|
623 iMinSize = aMinSize; |
|
624 } |
|
625 |
|
626 // deprecated |
|
627 EXPORT_C TSize CHuiVisual::MinSize() const |
|
628 { |
|
629 THuiRealSize minSize = MinSizeInBaseUnits(); |
|
630 THuiRealPoint minPoint = LocalPointInPixels(THuiRealPoint(minSize.iWidth, minSize.iHeight), |
|
631 EHuiReferenceStateNow); |
|
632 // @todo: Should we round this value? |
|
633 return (TSize(minPoint.AsSize())); |
|
634 } |
|
635 |
|
636 EXPORT_C THuiRealSize CHuiVisual::MinSizeInBaseUnits() const __SOFTFP |
|
637 { |
|
638 return iMinSize; |
|
639 } |
|
640 |
|
641 |
|
642 // deprecated |
|
643 EXPORT_C void CHuiVisual::SetMaxSize(const TSize& aMaxSize) |
|
644 { |
|
645 THuiRealPoint maxPoint = PixelPointInLocal(THuiRealPoint(aMaxSize.iWidth, aMaxSize.iHeight), |
|
646 EHuiReferenceStateNow); |
|
647 SetMaxSize(maxPoint.AsSize()); |
|
648 } |
|
649 |
|
650 EXPORT_C void CHuiVisual::SetMaxSize(const THuiRealSize& aMaxSize) |
|
651 { |
|
652 iMaxSize = aMaxSize; |
|
653 } |
|
654 |
|
655 |
|
656 // deprecated |
|
657 EXPORT_C TSize CHuiVisual::MaxSize() const |
|
658 { |
|
659 THuiRealSize maxSize = MaxSizeInBaseUnits(); |
|
660 THuiRealPoint maxPoint = LocalPointInPixels(THuiRealPoint(maxSize.iWidth, maxSize.iHeight), |
|
661 EHuiReferenceStateNow); |
|
662 // @todo: Should we round this value? |
|
663 return (TSize(maxPoint.AsSize())); |
|
664 } |
|
665 |
|
666 EXPORT_C THuiRealSize CHuiVisual::MaxSizeInBaseUnits() const __SOFTFP |
|
667 { |
|
668 return iMaxSize; |
|
669 } |
|
670 |
|
671 |
|
672 EXPORT_C void CHuiVisual::SetClipping(TBool aClipping) |
|
673 { |
|
674 if(aClipping) |
|
675 { |
|
676 SetFlag(EHuiVisualFlagClipping); |
|
677 } |
|
678 else |
|
679 { |
|
680 ClearFlag(EHuiVisualFlagClipping); |
|
681 } |
|
682 } |
|
683 |
|
684 |
|
685 EXPORT_C TBool CHuiVisual::Clipping() const |
|
686 { |
|
687 return (iFlags & EHuiVisualFlagClipping) != 0; |
|
688 } |
|
689 |
|
690 |
|
691 EXPORT_C THuiRealRect CHuiVisual::DisplayRect() const __SOFTFP |
|
692 { |
|
693 // Recalculate and cache as necessary. |
|
694 TBool recalculationNeeded = ETrue; |
|
695 |
|
696 TUint frameno = 0; // CHuiStatic::FrameCount() is called before used |
|
697 const TBool calledDuringDraw = Env().CurrentDisplay() ? ETrue : EFalse; |
|
698 |
|
699 if ( calledDuringDraw ) // before the draw, the cache is not updated |
|
700 { |
|
701 frameno = CHuiStatic::FrameCount(); |
|
702 if ( frameno == iDisplayRectFrameNumber ) |
|
703 { |
|
704 recalculationNeeded = EFalse; |
|
705 } |
|
706 } |
|
707 |
|
708 if( recalculationNeeded ) |
|
709 { |
|
710 THuiRealRect rect(LocalToDisplay(Pos().RealNow()), |
|
711 LocalPointInPixels(Size().RealNow()).AsSize()); |
|
712 |
|
713 if (rect.iTl.iX > rect.iBr.iX) |
|
714 { |
|
715 TReal tempX = rect.iTl.iX; |
|
716 rect.iTl.iX = rect.iBr.iX; |
|
717 rect.iBr.iX = tempX; |
|
718 } |
|
719 |
|
720 if (rect.iTl.iY > rect.iBr.iY) |
|
721 { |
|
722 TReal tempY = rect.iTl.iY; |
|
723 rect.iTl.iY = rect.iBr.iY; |
|
724 rect.iBr.iY = tempY; |
|
725 } |
|
726 |
|
727 iDisplayRect = rect; |
|
728 |
|
729 if ( calledDuringDraw ) // update frame number only during draw |
|
730 { |
|
731 iDisplayRectFrameNumber = frameno; |
|
732 } |
|
733 } |
|
734 return iDisplayRect; |
|
735 } |
|
736 |
|
737 THuiRealRect CHuiVisual::CachedDisplayRect() const |
|
738 { |
|
739 return iDisplayRect; |
|
740 } |
|
741 |
|
742 |
|
743 EXPORT_C THuiRealRect CHuiVisual::DisplayRectTarget() const __SOFTFP |
|
744 { |
|
745 // Calculate effect display area if the visual has an attached effect |
|
746 // For OpenVG nothing is needed as the area is the final position, |
|
747 // not something that happens during transition. |
|
748 // Recalculate and cache as necessary. |
|
749 TBool recalculationNeeded = ETrue; |
|
750 |
|
751 TUint frameno = 0; // CHuiStatic::FrameCount() is called before used |
|
752 const TBool calledDuringDraw = Env().CurrentDisplay() ? ETrue : EFalse; |
|
753 |
|
754 if ( calledDuringDraw ) // before the draw, the cache is not updated |
|
755 { |
|
756 frameno = CHuiStatic::FrameCount(); |
|
757 if ( frameno == iDisplayRectTargetFrameNumber ) |
|
758 { |
|
759 recalculationNeeded = EFalse; |
|
760 } |
|
761 } |
|
762 |
|
763 if( recalculationNeeded ) |
|
764 { |
|
765 THuiRealRect rect(LocalToDisplay(Pos().RealTarget(), EHuiReferenceStateTarget), |
|
766 LocalPointInPixels(Size().RealTarget(), EHuiReferenceStateTarget).AsSize()); |
|
767 |
|
768 if (rect.iTl.iX > rect.iBr.iX) |
|
769 { |
|
770 TReal32 tempX = rect.iTl.iX; |
|
771 rect.iTl.iX = rect.iBr.iX; |
|
772 rect.iBr.iX = tempX; |
|
773 } |
|
774 |
|
775 if (rect.iTl.iY > rect.iBr.iY) |
|
776 { |
|
777 TReal32 tempY = rect.iTl.iY; |
|
778 rect.iTl.iY = rect.iBr.iY; |
|
779 rect.iBr.iY = tempY; |
|
780 } |
|
781 |
|
782 iDisplayRectTarget = rect; |
|
783 |
|
784 if ( calledDuringDraw ) // update frame number only during draw |
|
785 { |
|
786 iDisplayRectTargetFrameNumber = frameno; |
|
787 } |
|
788 } |
|
789 return iDisplayRectTarget; |
|
790 } |
|
791 |
|
792 |
|
793 EXPORT_C TReal32 CHuiVisual::EffectiveOpacity() const __SOFTFP |
|
794 { |
|
795 TReal32 opacity = iOpacity.Now(); |
|
796 |
|
797 // Controls in control groups (i.e., normally all controls) |
|
798 // get a common opacity from the group. |
|
799 if(Owner().ControlGroup()) |
|
800 { |
|
801 opacity *= Owner().ControlGroup()->iOpacity.Now(); |
|
802 } |
|
803 |
|
804 CHuiVisual* iter = Layout(); |
|
805 |
|
806 // Factor in all the opacities of the parent visuals. |
|
807 while(iter) |
|
808 { |
|
809 opacity *= iter->iOpacity.Now(); |
|
810 if(opacity <= 0) |
|
811 { |
|
812 // Fully transparent; |
|
813 return 0; |
|
814 } |
|
815 iter = iter->Layout(); |
|
816 } |
|
817 |
|
818 return opacity; |
|
819 } |
|
820 |
|
821 |
|
822 EXPORT_C TBool CHuiVisual::PrepareDrawL() |
|
823 { |
|
824 // The visual base class doesn't prepare anything. |
|
825 return ETrue; |
|
826 } |
|
827 |
|
828 |
|
829 EXPORT_C void CHuiVisual::Draw(CHuiGc& aGc) const |
|
830 { |
|
831 if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent) |
|
832 { |
|
833 // This is used only as external content visual. Return now if we are not currently drawing |
|
834 // external content. |
|
835 if (!Display() || !Display()->RosterImpl().IsDrawingExternalContent()) |
|
836 { |
|
837 return; |
|
838 } |
|
839 } |
|
840 |
|
841 TReal32 opacity = EffectiveOpacity(); |
|
842 if(opacity <= 0) |
|
843 { |
|
844 // The visual is invisible because it's fully transparent. |
|
845 return; |
|
846 } |
|
847 |
|
848 // This is the currently effective area on the display used |
|
849 // by the visual. |
|
850 THuiRealRect displayRect = DisplayRect(); |
|
851 |
|
852 EnterLocalProjection(aGc, ETrue, 0.f, &displayRect); |
|
853 |
|
854 // Apply local transformation. |
|
855 Transform(aGc, ETrue, &displayRect); |
|
856 |
|
857 // Draw background brushes (under the content). |
|
858 DrawBrushes(aGc, EHuiBrushLayerBackground); |
|
859 |
|
860 // Clip contents to visual rectangle. |
|
861 if(Clipping()) |
|
862 { |
|
863 // Visual content clipping is affected by transformation. |
|
864 aGc.PushClip(); |
|
865 aGc.Clip(displayRect); |
|
866 aGc.Enable(CHuiGc::EFeatureClipping); |
|
867 } |
|
868 if( iVisualData->iEffect ) |
|
869 { |
|
870 // Can we draw effect |
|
871 TBool canUseEffectDrawing = Effect() && !LoadingEffect(); |
|
872 |
|
873 // Flag to know what we did |
|
874 TBool didDrawEffect = EFalse; |
|
875 |
|
876 if (canUseEffectDrawing) |
|
877 { |
|
878 // Note that EHuiVisualFlagOpaqueHint improves performance a lot in cached effect drawing |
|
879 TBool transparent = !(Flags() & EHuiVisualFlagOpaqueHint); |
|
880 TBool refreshCache = Changed(); |
|
881 didDrawEffect = iVisualData->iEffect->CachedDraw(aGc, displayRect, refreshCache, !transparent); |
|
882 } |
|
883 |
|
884 if (!didDrawEffect) |
|
885 { |
|
886 // Draw the visual instead if the effect failed |
|
887 DrawSelf(aGc, displayRect); |
|
888 } |
|
889 else |
|
890 { |
|
891 // Effect was drawn, OpenGLES/OpenVG may be in different state than what Gc thinks so we restore it. |
|
892 aGc.RestoreState(); |
|
893 } |
|
894 } |
|
895 else if ( !LoadingEffect() ) |
|
896 { |
|
897 // Draw the visual itself. |
|
898 // But don't draw if we are just building the effect - |
|
899 // We may get a view of the visual with its default values though it may |
|
900 // want to start from size 0 or whatever |
|
901 DrawSelf(aGc, displayRect); |
|
902 } |
|
903 else |
|
904 { |
|
905 // just to keep codescanners and other stupid tools happy |
|
906 } |
|
907 |
|
908 if(Clipping()) |
|
909 { |
|
910 aGc.PopClip(); |
|
911 } |
|
912 |
|
913 // Draw foreground brushes (over the content). |
|
914 DrawBrushes(aGc, EHuiBrushLayerForeground); |
|
915 |
|
916 // Undo local transformation. |
|
917 Transform(aGc, EFalse); |
|
918 EnterLocalProjection(aGc, EFalse); |
|
919 |
|
920 } |
|
921 |
|
922 |
|
923 EXPORT_C void CHuiVisual::DrawBrushes(CHuiGc& aGc, THuiBrushLayer aLayer) const |
|
924 { |
|
925 if(iBrushes) |
|
926 { |
|
927 iBrushes->ActivateBrushGuide(this); |
|
928 iBrushes->Draw(aLayer, aGc, *this); |
|
929 iBrushes->ActivateBrushGuide(NULL); |
|
930 } |
|
931 } |
|
932 |
|
933 |
|
934 EXPORT_C void CHuiVisual::DrawSelf(CHuiGc& /*aGc*/, |
|
935 const TRect& /*aDisplayRect*/) const |
|
936 { |
|
937 // The visual base class doesn't draw a3nything. |
|
938 } |
|
939 |
|
940 |
|
941 EXPORT_C void CHuiVisual::BoxMetricToPixelRect(const THuiBoxMetric& aBox, |
|
942 THuiRealRect& aRectInPixels) const |
|
943 { |
|
944 aRectInPixels.iTl = MetricToPixels(THuiXYMetric(aBox.iLeft, aBox.iTop)); |
|
945 aRectInPixels.iBr = MetricToPixels(THuiXYMetric(aBox.iRight, aBox.iBottom)); |
|
946 } |
|
947 |
|
948 |
|
949 /*EXPORT_C void CHuiVisual::BoxMetricToLocalRect(const THuiBoxMetric& aBox, |
|
950 THuiRealRect& aLocalRect) const |
|
951 { |
|
952 THuiRealRect pixelRect; |
|
953 BoxMetricToPixelRect(aBox, pixelRect); |
|
954 aLocalRect.iTl = PixelPointInLocal(pixelRect.iTl); |
|
955 aLocalRect.iBr = PixelPointInLocal(pixelRect.iBr); |
|
956 }*/ |
|
957 |
|
958 |
|
959 EXPORT_C THuiRealPoint CHuiVisual::LocalPointInPixels(const THuiRealPoint& aLocalPoint) const __SOFTFP |
|
960 { |
|
961 return LocalPointInPixels(aLocalPoint, EHuiReferenceStateNow); |
|
962 } |
|
963 |
|
964 |
|
965 EXPORT_C THuiRealPoint CHuiVisual::PixelPointInLocal(const THuiRealPoint& aPixelPoint) const __SOFTFP |
|
966 { |
|
967 return PixelPointInLocal(aPixelPoint, EHuiReferenceStateNow); |
|
968 } |
|
969 |
|
970 |
|
971 THuiRealPoint CHuiVisual::PixelPointInUnits(const THuiRealPoint& aPixelPoint, |
|
972 const THuiXYMetric& aUnit, THuiReferenceState aReferenceState ) const __SOFTFP |
|
973 { |
|
974 THuiRealPoint result(0.f, 0.f); |
|
975 THuiXYMetric metric = aUnit; |
|
976 PixelsToMetric(aPixelPoint, metric, aReferenceState); // sets X and Y lengths |
|
977 |
|
978 if(aUnit.iX.iMagnitude != 0) |
|
979 { |
|
980 result.iX = metric.iX.iMagnitude / aUnit.iX.iMagnitude; |
|
981 } |
|
982 else |
|
983 { |
|
984 result.iX = 0; |
|
985 } |
|
986 |
|
987 if(aUnit.iY.iMagnitude != 0) |
|
988 { |
|
989 result.iY = metric.iY.iMagnitude / aUnit.iY.iMagnitude; |
|
990 } |
|
991 else |
|
992 { |
|
993 result.iY = 0; |
|
994 } |
|
995 |
|
996 return result; |
|
997 } |
|
998 |
|
999 EXPORT_C THuiRealPoint CHuiVisual::MetricReferenceInPixels(const THuiXYMetric& aMetric) const __SOFTFP |
|
1000 { |
|
1001 return MetricReferenceInPixels(aMetric, EHuiReferenceStateNow); |
|
1002 } |
|
1003 |
|
1004 |
|
1005 EXPORT_C THuiRealPoint CHuiVisual::MetricReferenceInPixels(const THuiXYMetric& aMetric, |
|
1006 THuiReferenceState aReferenceState) const __SOFTFP |
|
1007 { |
|
1008 THuiRealPoint refSizePx(0.f, 0.f); |
|
1009 |
|
1010 // if weights are used in this context, treat them as normalized units |
|
1011 TInt xUnit = (aMetric.iX.iUnit == EHuiUnitWeight) ? EHuiUnitNormalized : aMetric.iX.iUnit; |
|
1012 TInt yUnit = (aMetric.iY.iUnit == EHuiUnitWeight) ? EHuiUnitNormalized : aMetric.iY.iUnit; |
|
1013 |
|
1014 // For normalized units, the reference is the parent size in pixels. |
|
1015 if(xUnit == EHuiUnitNormalized || yUnit == EHuiUnitNormalized || |
|
1016 xUnit == EHuiUnitParentWidth || yUnit == EHuiUnitParentWidth || |
|
1017 xUnit == EHuiUnitParentHeight || yUnit == EHuiUnitParentHeight) |
|
1018 { |
|
1019 THuiRealPoint sizePx(0.f, 0.f); |
|
1020 |
|
1021 // Determine parent size in pixels. |
|
1022 if(iLayout) |
|
1023 { |
|
1024 // Recursive fun. We don't want to do this more than once. |
|
1025 // (LocalPointInPixels => MetricsToPixels => MetricReferenceInPixels) |
|
1026 sizePx = iLayout->LocalPointInPixels( |
|
1027 aReferenceState == EHuiReferenceStateTarget? iLayout->Size().RealTarget() : |
|
1028 iLayout->Size().RealNow(), aReferenceState); |
|
1029 } |
|
1030 else if(Display()) |
|
1031 { |
|
1032 // @todo Jaakko please code review this change! |
|
1033 // sizePx = Display()->Size().AsPoint(); |
|
1034 sizePx = Display()->VisibleArea().Size().AsPoint(); |
|
1035 } |
|
1036 else |
|
1037 { |
|
1038 // For PC-lint |
|
1039 } |
|
1040 |
|
1041 if(xUnit == EHuiUnitNormalized || xUnit == EHuiUnitParentWidth) |
|
1042 { |
|
1043 refSizePx.iX = sizePx.iX; |
|
1044 } |
|
1045 else if(xUnit == EHuiUnitParentHeight) |
|
1046 { |
|
1047 refSizePx.iX = sizePx.iY; |
|
1048 } |
|
1049 else |
|
1050 { |
|
1051 // For PC-lint |
|
1052 } |
|
1053 |
|
1054 if(yUnit == EHuiUnitNormalized || yUnit == EHuiUnitParentHeight) |
|
1055 { |
|
1056 refSizePx.iY = sizePx.iY; |
|
1057 } |
|
1058 else if(yUnit == EHuiUnitParentWidth) |
|
1059 { |
|
1060 refSizePx.iY = sizePx.iX; |
|
1061 } |
|
1062 else |
|
1063 { |
|
1064 // For PC-lint |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 // Display-relative units are always relative to the display where the visual is on. |
|
1069 if(xUnit == EHuiUnitRelativeToDisplay && Display()) |
|
1070 { |
|
1071 refSizePx.iX = Display()->VisibleArea().Width(); |
|
1072 } |
|
1073 if(yUnit == EHuiUnitRelativeToDisplay && Display()) |
|
1074 { |
|
1075 refSizePx.iY = Display()->VisibleArea().Height(); |
|
1076 } |
|
1077 |
|
1078 // For relative to my size units, the reference is the size of this visual in pixels. |
|
1079 if(xUnit == EHuiUnitRelativeToMySize || yUnit == EHuiUnitRelativeToMySize || |
|
1080 xUnit == EHuiUnitMyWidth || yUnit == EHuiUnitMyWidth || |
|
1081 xUnit == EHuiUnitMyHeight || yUnit == EHuiUnitMyHeight || |
|
1082 xUnit == EHuiUnitMyDimensionAverage || yUnit == EHuiUnitMyDimensionAverage) |
|
1083 { |
|
1084 THuiRealPoint sizePx(0.f, 0.f); |
|
1085 if(iLayout) |
|
1086 { |
|
1087 // Recursive fun. We don't want to do this more than once. |
|
1088 // (MetricsToPixels => MetricReferenceInPixels) |
|
1089 sizePx = iLayout->MetricToPixels(LocalBaseUnit().Abs() * |
|
1090 ((aReferenceState == EHuiReferenceStateTarget) ? iSize.RealTarget() : iSize.RealNow())); |
|
1091 } |
|
1092 else if(Display()) |
|
1093 { |
|
1094 sizePx = Display()->VisibleArea().Size().AsPoint(); |
|
1095 } |
|
1096 else |
|
1097 { |
|
1098 // For PC-lint |
|
1099 } |
|
1100 |
|
1101 if(xUnit == EHuiUnitRelativeToMySize || xUnit == EHuiUnitMyWidth) |
|
1102 { |
|
1103 refSizePx.iX = sizePx.iX; |
|
1104 } |
|
1105 else if(xUnit == EHuiUnitMyHeight) |
|
1106 { |
|
1107 refSizePx.iX = sizePx.iY; |
|
1108 } |
|
1109 else |
|
1110 { |
|
1111 // For PC-lint |
|
1112 } |
|
1113 |
|
1114 if(yUnit == EHuiUnitRelativeToMySize || yUnit == EHuiUnitMyHeight) |
|
1115 { |
|
1116 refSizePx.iY = sizePx.iY; |
|
1117 } |
|
1118 else if(yUnit == EHuiUnitMyWidth) |
|
1119 { |
|
1120 refSizePx.iY = sizePx.iX; |
|
1121 } |
|
1122 else |
|
1123 { |
|
1124 // For PC-lint |
|
1125 } |
|
1126 |
|
1127 if( xUnit == EHuiUnitMyDimensionAverage || |
|
1128 yUnit == EHuiUnitMyDimensionAverage ) |
|
1129 { |
|
1130 TReal32 average = (sizePx.iX + sizePx.iY) / 2; |
|
1131 if(xUnit == EHuiUnitMyDimensionAverage) |
|
1132 { |
|
1133 refSizePx.iX = average; |
|
1134 } |
|
1135 if(yUnit == EHuiUnitMyDimensionAverage) |
|
1136 { |
|
1137 refSizePx.iY = average; |
|
1138 } |
|
1139 } |
|
1140 } |
|
1141 |
|
1142 if(xUnit == EHuiUnitS60 && Display()) |
|
1143 { |
|
1144 refSizePx.iX = Display()->UnitValue(); |
|
1145 } |
|
1146 if(yUnit == EHuiUnitS60 && Display()) |
|
1147 { |
|
1148 refSizePx.iY = Display()->UnitValue(); |
|
1149 } |
|
1150 |
|
1151 return refSizePx; |
|
1152 } |
|
1153 |
|
1154 void CHuiVisual::ConvertMetricLengthToPixels( |
|
1155 TReal32& aResult, |
|
1156 const THuiMetric& aMetric, |
|
1157 TReal32 aReference) |
|
1158 { |
|
1159 switch(aMetric.iUnit) |
|
1160 { |
|
1161 case EHuiUnitPixel: |
|
1162 aResult = aMetric.iMagnitude; |
|
1163 break; |
|
1164 default: |
|
1165 aResult = aMetric.iMagnitude * aReference; |
|
1166 break; |
|
1167 } |
|
1168 } |
|
1169 |
|
1170 |
|
1171 void CHuiVisual::ConvertPixelsToMetricLength( |
|
1172 THuiMetric& aResult, |
|
1173 TReal32 aPixels, |
|
1174 TReal32 aReference) |
|
1175 { |
|
1176 switch(aResult.iUnit) |
|
1177 { |
|
1178 case EHuiUnitPixel: |
|
1179 aResult.iMagnitude = aPixels; |
|
1180 break; |
|
1181 |
|
1182 default: |
|
1183 if(aReference != 0) |
|
1184 { |
|
1185 aResult.iMagnitude = aPixels / aReference; |
|
1186 } |
|
1187 else |
|
1188 { |
|
1189 aResult.iMagnitude = 0; |
|
1190 } |
|
1191 break; |
|
1192 } |
|
1193 } |
|
1194 |
|
1195 EXPORT_C THuiRealPoint CHuiVisual::MetricToPixels(const THuiXYMetric& aMetric) const __SOFTFP |
|
1196 { |
|
1197 return MetricToPixels(aMetric,EHuiReferenceStateNow); |
|
1198 } |
|
1199 |
|
1200 |
|
1201 EXPORT_C THuiRealPoint CHuiVisual::MetricToPixels(const THuiXYMetric& aMetric, |
|
1202 THuiReferenceState aReferenceState) const __SOFTFP |
|
1203 { |
|
1204 THuiRealPoint refSizePx = MetricReferenceInPixels(aMetric, aReferenceState); |
|
1205 THuiRealPoint resultPx(0.f, 0.f); |
|
1206 |
|
1207 ConvertMetricLengthToPixels(resultPx.iX, aMetric.iX, refSizePx.iX); |
|
1208 ConvertMetricLengthToPixels(resultPx.iY, aMetric.iY, refSizePx.iY); |
|
1209 |
|
1210 return resultPx; |
|
1211 } |
|
1212 |
|
1213 EXPORT_C void CHuiVisual::PixelsToMetric(const THuiRealPoint& aPixels, THuiXYMetric& aMetric) const |
|
1214 { |
|
1215 PixelsToMetric(aPixels, aMetric, EHuiReferenceStateNow); |
|
1216 } |
|
1217 |
|
1218 |
|
1219 EXPORT_C void CHuiVisual::PixelsToMetric(const THuiRealPoint& aPixels, THuiXYMetric& aMetric, |
|
1220 THuiReferenceState aReferenceState) const |
|
1221 { |
|
1222 THuiRealPoint refSizePx = MetricReferenceInPixels(aMetric, aReferenceState); |
|
1223 |
|
1224 ConvertPixelsToMetricLength(aMetric.iX, aPixels.iX, refSizePx.iX); |
|
1225 ConvertPixelsToMetricLength(aMetric.iY, aPixels.iY, refSizePx.iY); |
|
1226 } |
|
1227 |
|
1228 |
|
1229 EXPORT_C THuiXYMetric CHuiVisual::LocalBaseUnit() const |
|
1230 { |
|
1231 if(iLayout) |
|
1232 { |
|
1233 return iLayout->BaseUnit(); |
|
1234 } |
|
1235 else |
|
1236 { |
|
1237 return THuiXYMetric(THuiMetric(1.f), THuiMetric(1.f)); |
|
1238 } |
|
1239 } |
|
1240 |
|
1241 |
|
1242 void CHuiVisual::ApplyMirroring(THuiRealPoint& aPixels, THuiReferenceState aReferenceState) const |
|
1243 { |
|
1244 THuiRealPoint refSizePx = MetricReferenceInPixels( |
|
1245 THuiXYMetric( THuiMetric(1.f, EHuiUnitNormalized), THuiMetric(1.f, EHuiUnitNormalized)), aReferenceState ); |
|
1246 |
|
1247 if(LocalBaseUnit().iX.iMagnitude < 0) |
|
1248 { |
|
1249 aPixels.iX = refSizePx.iX - aPixels.iX; |
|
1250 } |
|
1251 if(LocalBaseUnit().iY.iMagnitude < 0) |
|
1252 { |
|
1253 aPixels.iY = refSizePx.iY - aPixels.iY; |
|
1254 } |
|
1255 } |
|
1256 |
|
1257 |
|
1258 EXPORT_C TPoint CHuiVisual::LocalToDisplay(const TPoint& aPoint) const |
|
1259 { |
|
1260 return LocalToDisplay(THuiRealPoint(aPoint)); |
|
1261 } |
|
1262 |
|
1263 |
|
1264 EXPORT_C THuiRealPoint CHuiVisual::LocalToDisplay(const THuiRealPoint& aPoint) const __SOFTFP |
|
1265 { |
|
1266 return LocalToDisplay(aPoint, EHuiReferenceStateNow); |
|
1267 } |
|
1268 |
|
1269 THuiRealPoint CHuiVisual::LocalToDisplay(const THuiRealPoint& aPoint, |
|
1270 THuiReferenceState aReferenceState) const |
|
1271 { |
|
1272 THuiRealPoint pos = aPoint; |
|
1273 THuiRealPoint resultPx(0.f, 0.f); |
|
1274 |
|
1275 const CHuiVisual* iter = this; |
|
1276 while(iter) |
|
1277 { |
|
1278 // Add the scroll offset to the position in the local coordinate system. |
|
1279 if(iter->iLayout && iter->iLayout->Scrolling()) |
|
1280 { |
|
1281 pos -= (aReferenceState == EHuiReferenceStateNow ? iter->iLayout->ScrollOffset().RealNow() : iter->iLayout->ScrollOffset().RealTarget()); |
|
1282 } |
|
1283 |
|
1284 THuiRealPoint coordsPx = iter->LocalPointInPixels(pos); |
|
1285 iter->ApplyMirroring(coordsPx, aReferenceState); |
|
1286 iter->AlignByOrigin(coordsPx); |
|
1287 resultPx += coordsPx; |
|
1288 |
|
1289 // Move up in the tree. |
|
1290 iter = iter->iLayout; |
|
1291 if(iter) |
|
1292 { |
|
1293 pos = (aReferenceState == EHuiReferenceStateNow ? iter->Pos().RealNow() : iter->Pos().RealTarget()); |
|
1294 } |
|
1295 } |
|
1296 |
|
1297 return resultPx; |
|
1298 } |
|
1299 |
|
1300 |
|
1301 EXPORT_C TPoint CHuiVisual::DisplayToLocal(const TPoint& aPoint) const |
|
1302 { |
|
1303 return DisplayToLocal(THuiRealPoint(aPoint)); |
|
1304 } |
|
1305 |
|
1306 |
|
1307 EXPORT_C THuiRealPoint CHuiVisual::DisplayToLocal(const THuiRealPoint& aPointInPixels) const __SOFTFP |
|
1308 { |
|
1309 return DisplayToLocal(aPointInPixels, EHuiReferenceStateNow); |
|
1310 } |
|
1311 |
|
1312 THuiRealPoint CHuiVisual::DisplayToLocal(const THuiRealPoint& aPointInPixels, |
|
1313 THuiReferenceState aReferenceState) const |
|
1314 { |
|
1315 THuiRealPoint posPx = aPointInPixels; |
|
1316 |
|
1317 // Undo the effect of the parents. |
|
1318 CHuiLayout* ancestor = iLayout; |
|
1319 while(ancestor) |
|
1320 { |
|
1321 THuiRealPoint ancestorPos = (aReferenceState == EHuiReferenceStateNow ? ancestor->Pos().RealNow() : ancestor->Pos().RealTarget()); |
|
1322 if(ancestor->Scrolling()) |
|
1323 { |
|
1324 ancestorPos -= (aReferenceState == EHuiReferenceStateNow ? ancestor->ScrollOffset().RealNow() : ancestor->ScrollOffset().RealTarget()); |
|
1325 } |
|
1326 THuiRealPoint coordsPx = ancestor->LocalPointInPixels(ancestorPos); |
|
1327 ancestor->ApplyMirroring(coordsPx, aReferenceState); |
|
1328 ancestor->AlignByOrigin(coordsPx); |
|
1329 posPx -= coordsPx; |
|
1330 |
|
1331 // Move up in the tree. |
|
1332 ancestor = ancestor->iLayout; |
|
1333 } |
|
1334 |
|
1335 // Now we have the point as pixels in the local coordinate system. |
|
1336 AlignByOrigin(posPx, ETrue); // undo alignment |
|
1337 ApplyMirroring(posPx, aReferenceState); // undo mirroring |
|
1338 return PixelPointInLocal(posPx); |
|
1339 } |
|
1340 |
|
1341 |
|
1342 EXPORT_C void CHuiVisual::SetChanged() |
|
1343 { |
|
1344 if ( Display() ) |
|
1345 { |
|
1346 Owner().Env().ContinueRefresh(); |
|
1347 } |
|
1348 iFlags |= EHuiVisualChanged; |
|
1349 } |
|
1350 |
|
1351 |
|
1352 EXPORT_C TBool CHuiVisual::Changed() const |
|
1353 { |
|
1354 if(iFlags & EHuiVisualChanged) |
|
1355 { |
|
1356 return ETrue; |
|
1357 } |
|
1358 |
|
1359 if(iBrushes && iBrushes->Changed()) |
|
1360 { |
|
1361 return ETrue; |
|
1362 } |
|
1363 |
|
1364 if(iTransform && iTransform->Changed()) |
|
1365 { |
|
1366 return ETrue; |
|
1367 } |
|
1368 |
|
1369 if (iVisualData->iEffect && iVisualData->iEffect->Changed()) |
|
1370 { |
|
1371 return ETrue; |
|
1372 } |
|
1373 |
|
1374 if(Owner().ControlGroup() && Owner().ControlGroup()->iOpacity.Changed()) |
|
1375 { |
|
1376 return ETrue; |
|
1377 } |
|
1378 |
|
1379 if ( iVisualData->iDropShadow && iVisualData->iDropShadow->Changed() ) |
|
1380 { |
|
1381 return ETrue; |
|
1382 } |
|
1383 |
|
1384 return iPos.Changed() || iSize.Changed() || iOpacity.Changed(); |
|
1385 } |
|
1386 |
|
1387 |
|
1388 EXPORT_C void CHuiVisual::ClearChanged() |
|
1389 { |
|
1390 if (iFlags & EHuiVisualChanged) |
|
1391 { |
|
1392 HUI_DEBUGF1(_L("CHuiVisual::ClearChanged() - Clearing change flags of visual %x."), this); |
|
1393 } |
|
1394 iFlags &= ~EHuiVisualChanged; |
|
1395 |
|
1396 if(iBrushes) |
|
1397 { |
|
1398 iBrushes->ClearChanged(); |
|
1399 } |
|
1400 |
|
1401 if(iTransform) |
|
1402 { |
|
1403 iTransform->ClearChanged(); |
|
1404 } |
|
1405 |
|
1406 if ( iVisualData->iDropShadow ) |
|
1407 { |
|
1408 iVisualData->iDropShadow->ClearChanged(); |
|
1409 } |
|
1410 |
|
1411 iPos.ClearChanged(); |
|
1412 iSize.ClearChanged(); |
|
1413 iOpacity.ClearChanged(); |
|
1414 } |
|
1415 |
|
1416 |
|
1417 EXPORT_C void CHuiVisual::ReportChanged() |
|
1418 { |
|
1419 // Notify the display that the visual's area should be redrawn. |
|
1420 CHuiDisplay* display = NULL; |
|
1421 |
|
1422 // Select active display, fallback to own display. |
|
1423 // For scaled tv-out cloning the active display takes care of scaling direty areas too. |
|
1424 if (iOwner && iOwner->Env().CurrentDisplay()) |
|
1425 { |
|
1426 display = iOwner->Env().CurrentDisplay(); |
|
1427 } |
|
1428 else |
|
1429 { |
|
1430 display = Display(); |
|
1431 } |
|
1432 |
|
1433 if(display) |
|
1434 { |
|
1435 // If nothing has changed, then we don't need to notify anything. |
|
1436 // The change flags will be cleared after the frame has been fully drawn. |
|
1437 if(!Changed() && !ParentChanged()) |
|
1438 { |
|
1439 return; |
|
1440 } |
|
1441 |
|
1442 TRect dirty; |
|
1443 TBool transformedReport = EFalse; |
|
1444 |
|
1445 if(iTransform && /*!(Flags() & EHuiVisualFlagClipping) &&*/ |
|
1446 iTransform->NonIdentityCount() > 0) |
|
1447 { |
|
1448 __ASSERT_DEBUG( Display() != NULL, |
|
1449 THuiPanic::Panic(THuiPanic::EVisualHasNoDisplayDuringRefresh) ); |
|
1450 |
|
1451 if (display->UseTransformedDirtyRegions()) |
|
1452 { |
|
1453 // There is a transformation and display would like to handle transformed dirty |
|
1454 // rects...in practice this means that we are using bitgdi and in that case |
|
1455 // the transformations do not happen in 3D, so calculating transformed dirty |
|
1456 // rects might be possible. |
|
1457 // -> so we enable transfromation during dirty area reporting. |
|
1458 THuiRealRect displayRect = DisplayRect(); |
|
1459 EnterLocalProjection(*display->Gc(), ETrue, 0.f, &displayRect); |
|
1460 Transform(*display->Gc(), ETrue, &displayRect); |
|
1461 dirty = TRect(HUI_ROUND_FLOAT_TO_INT(displayRect.iTl.iX), HUI_ROUND_FLOAT_TO_INT(displayRect.iTl.iY), |
|
1462 HUI_ROUND_FLOAT_TO_INT(displayRect.iBr.iX), HUI_ROUND_FLOAT_TO_INT(displayRect.iBr.iY)); |
|
1463 ExpandRectWithContent(dirty); |
|
1464 transformedReport = ETrue; |
|
1465 } |
|
1466 else |
|
1467 { |
|
1468 // Display says it does not want to handle transformed dirty rects. |
|
1469 // There is a transformation and the visual is not clipped. We |
|
1470 // could try to calculate where the visual's content may end up, |
|
1471 // but in a 3D projection this may be too complicated to yield |
|
1472 // any benefits. We will just assume that the entire display |
|
1473 // needs redrawing. |
|
1474 dirty = TRect(TPoint(0, 0), Display()->VisibleArea().Size()); |
|
1475 } |
|
1476 |
|
1477 } |
|
1478 else |
|
1479 { |
|
1480 THuiRealRect displayRect = DisplayRect(); |
|
1481 dirty = TRect(HUI_ROUND_FLOAT_TO_INT(displayRect.iTl.iX), HUI_ROUND_FLOAT_TO_INT(displayRect.iTl.iY), |
|
1482 HUI_ROUND_FLOAT_TO_INT(displayRect.iBr.iX), HUI_ROUND_FLOAT_TO_INT(displayRect.iBr.iY)); |
|
1483 ExpandRectWithContent(dirty); |
|
1484 } |
|
1485 |
|
1486 TRect& previousDrawn = display->IsDisplayTypeTvOut() ? iVisualData->iPreviousDrawnTvOut : iPreviousDrawn; |
|
1487 |
|
1488 // CombineAndAddDirtyRegion modifies "dirty" param by transforming it. |
|
1489 // "previousDrawn" is supposed to be already transformed. |
|
1490 display->CombineAndAddDirtyRegion(previousDrawn, dirty); |
|
1491 |
|
1492 // Note that "previousDrawn" is a reference so it updates correct member data. |
|
1493 previousDrawn = dirty; |
|
1494 |
|
1495 if (transformedReport) |
|
1496 { |
|
1497 EnterLocalProjection(*display->Gc(), EFalse); |
|
1498 Transform(*display->Gc(), EFalse); |
|
1499 } |
|
1500 |
|
1501 } |
|
1502 } |
|
1503 |
|
1504 |
|
1505 EXPORT_C void CHuiVisual::EnterLocalProjection( |
|
1506 CHuiGc& aGc, TBool aApply, TReal32 /*aExtraOffset*/, |
|
1507 const THuiRealRect* aVisibleRect) const __SOFTFP |
|
1508 { |
|
1509 TReal32 depthOffset = iDepthOffset.Now(); |
|
1510 |
|
1511 if(aApply && depthOffset != 0) |
|
1512 { |
|
1513 aGc.Enable(CHuiGc::EFeatureDepthTest); |
|
1514 aGc.Push(EHuiGcMatrixModel); |
|
1515 aGc.Translate(EHuiGcMatrixModel, 0.f, 0.f, depthOffset); |
|
1516 } |
|
1517 |
|
1518 if(aApply && (iFlags & EHuiVisualFlag3DProjection)) |
|
1519 { |
|
1520 // Change to a 3D projection. |
|
1521 aGc.SetProjection(CHuiGc::EProjectionPerspective); |
|
1522 |
|
1523 if(aVisibleRect && (Flags() & EHuiVisualFlagLocalHorizon)) |
|
1524 { |
|
1525 aGc.SetFrustumOffset(aVisibleRect->Center()); |
|
1526 } |
|
1527 |
|
1528 if(iFlags & EHuiVisualFlagNoDepthOcclusion) |
|
1529 { |
|
1530 aGc.Disable(CHuiGc::EFeatureDepthTest); |
|
1531 } |
|
1532 else |
|
1533 { |
|
1534 aGc.Enable(CHuiGc::EFeatureDepthTest); |
|
1535 } |
|
1536 |
|
1537 if(iFlags & EHuiVisualFlagNoDepthUpdate) |
|
1538 { |
|
1539 aGc.Disable(CHuiGc::EFeatureDepthWrite); |
|
1540 } |
|
1541 else |
|
1542 { |
|
1543 aGc.Enable(CHuiGc::EFeatureDepthWrite); |
|
1544 } |
|
1545 } |
|
1546 |
|
1547 if(!aApply) |
|
1548 { |
|
1549 // Back to normal. |
|
1550 aGc.Disable(CHuiGc::EFeatureDepthTest); |
|
1551 aGc.Enable(CHuiGc::EFeatureDepthWrite); |
|
1552 } |
|
1553 |
|
1554 if(!aApply && (iFlags & EHuiVisualFlag3DProjection)) |
|
1555 { |
|
1556 // Back to 2D projection. |
|
1557 aGc.SetProjection(); |
|
1558 } |
|
1559 |
|
1560 if(!aApply && depthOffset != 0) |
|
1561 { |
|
1562 aGc.Pop(EHuiGcMatrixModel); |
|
1563 } |
|
1564 } |
|
1565 |
|
1566 |
|
1567 EXPORT_C void CHuiVisual::Transform(CHuiGc& aGc, TBool aApply, |
|
1568 const THuiRealRect* aVisibleRect) const |
|
1569 { |
|
1570 if(iTransform) |
|
1571 { |
|
1572 if(aApply) |
|
1573 { |
|
1574 THuiRealPoint center; |
|
1575 aGc.Push(EHuiGcMatrixModel); |
|
1576 if(aVisibleRect) |
|
1577 { |
|
1578 center.iX = aVisibleRect->iTl.iX + aVisibleRect->Width() * iTransform->OriginPoint().iX.Now(); |
|
1579 center.iY = aVisibleRect->iTl.iY + aVisibleRect->Height() * iTransform->OriginPoint().iY.Now(); |
|
1580 aGc.Translate(EHuiGcMatrixModel, center.iX, center.iY, 0.f); |
|
1581 } |
|
1582 iTransform->Execute(EHuiGcMatrixModel, aGc); |
|
1583 if(aVisibleRect) |
|
1584 { |
|
1585 aGc.Translate(EHuiGcMatrixModel, -center.iX, -center.iY, 0.f); |
|
1586 } |
|
1587 } |
|
1588 else |
|
1589 { |
|
1590 aGc.Pop(EHuiGcMatrixModel); |
|
1591 } |
|
1592 } |
|
1593 } |
|
1594 |
|
1595 |
|
1596 EXPORT_C void CHuiVisual::SetPadding(TInt aPadding) |
|
1597 { |
|
1598 iPadding = THuiBoxMetric(THuiXYMetric(aPadding, aPadding)); |
|
1599 SetChanged(); |
|
1600 } |
|
1601 |
|
1602 |
|
1603 EXPORT_C void CHuiVisual::SetPadding(const TPoint& aPadding) |
|
1604 { |
|
1605 iPadding = THuiBoxMetric(THuiXYMetric(aPadding.iX, aPadding.iY)); |
|
1606 SetChanged(); |
|
1607 } |
|
1608 |
|
1609 |
|
1610 EXPORT_C void CHuiVisual::SetPadding(const THuiBoxMetric& aPadding) |
|
1611 { |
|
1612 iPadding = aPadding; |
|
1613 SetChanged(); |
|
1614 } |
|
1615 |
|
1616 |
|
1617 EXPORT_C const THuiBoxMetric& CHuiVisual::Padding() const |
|
1618 { |
|
1619 return iPadding; |
|
1620 } |
|
1621 |
|
1622 EXPORT_C THuiRealRect CHuiVisual::PaddingInPixels() const __SOFTFP |
|
1623 { |
|
1624 return PaddingInPixels(EHuiReferenceStateNow); |
|
1625 } |
|
1626 |
|
1627 EXPORT_C THuiRealRect CHuiVisual::PaddingInPixels(THuiReferenceState aReferenceState) const __SOFTFP |
|
1628 { |
|
1629 THuiRealRect paddingInPixels; |
|
1630 BoxMetricToPixelRect(Padding(), paddingInPixels, aReferenceState); |
|
1631 return paddingInPixels; |
|
1632 } |
|
1633 |
|
1634 |
|
1635 EXPORT_C void CHuiVisual::MoveToFront(TInt aTransitionTime) |
|
1636 { |
|
1637 if(iLayout) |
|
1638 { |
|
1639 // Make this the last child of the parent layout. |
|
1640 iLayout->MoveVisualToFront(*this, aTransitionTime); |
|
1641 } |
|
1642 else if(Display()) |
|
1643 { |
|
1644 Display()->Roster().MoveVisualToFront(this); |
|
1645 } |
|
1646 else |
|
1647 { |
|
1648 // for PC lint |
|
1649 } |
|
1650 } |
|
1651 |
|
1652 |
|
1653 EXPORT_C void CHuiVisual::GetDualAlpha(TReal32 aOpacity, TReal32 aSecondary, |
|
1654 TInt& aPrimaryAlpha, TInt& aSecondaryAlpha) |
|
1655 { |
|
1656 // Default values. |
|
1657 aPrimaryAlpha = TInt(255 * aOpacity); |
|
1658 aSecondaryAlpha = 0; |
|
1659 |
|
1660 if(aSecondary < 1 && aOpacity < 1) |
|
1661 { |
|
1662 /** This reduces the artifact where the sharp image is clearly |
|
1663 visible during a transition even though secondary alpha |
|
1664 has a value near to one. Not completely perfect, though. */ |
|
1665 aPrimaryAlpha = TInt(255 * (aOpacity + aSecondary * .5 * (aOpacity - 1))); |
|
1666 |
|
1667 if(aPrimaryAlpha < 0) |
|
1668 { |
|
1669 aPrimaryAlpha = 0; |
|
1670 } |
|
1671 } |
|
1672 else if(aSecondary >= 1) |
|
1673 { |
|
1674 aPrimaryAlpha = 0; |
|
1675 } |
|
1676 else |
|
1677 { |
|
1678 // for PC lint |
|
1679 } |
|
1680 |
|
1681 if(aSecondary > 0) |
|
1682 { |
|
1683 aSecondaryAlpha = TInt(255 * aOpacity * aSecondary); |
|
1684 } |
|
1685 } |
|
1686 |
|
1687 |
|
1688 EXPORT_C CHuiTransformation& CHuiVisual::Transformation() |
|
1689 { |
|
1690 if(!iTransform) |
|
1691 { |
|
1692 THuiPanic::Panic(THuiPanic::EVisualTransformNotEnabled); |
|
1693 } |
|
1694 |
|
1695 return *iTransform; |
|
1696 } |
|
1697 |
|
1698 CHuiTransformation* CHuiVisual::Transformation() const |
|
1699 { |
|
1700 return iTransform; |
|
1701 } |
|
1702 |
|
1703 |
|
1704 EXPORT_C void CHuiVisual::EnableTransformationL(TBool aIsTransformed) |
|
1705 { |
|
1706 if(iTransform && !aIsTransformed) |
|
1707 { |
|
1708 // Disable scrolling. |
|
1709 delete iTransform; |
|
1710 iTransform = NULL; |
|
1711 } |
|
1712 else if(!iTransform && aIsTransformed) |
|
1713 { |
|
1714 // Enable scrolling. |
|
1715 iTransform = CHuiTransformation::NewL(); |
|
1716 } |
|
1717 else |
|
1718 { |
|
1719 // for PC lint |
|
1720 } |
|
1721 |
|
1722 } |
|
1723 |
|
1724 |
|
1725 EXPORT_C void CHuiVisual::DumpTree() const |
|
1726 { |
|
1727 TBuf<100> buf; |
|
1728 TBuf<100> className; |
|
1729 GetClassName(className); |
|
1730 GetInstanceName(buf); |
|
1731 buf.AppendFormat(_L(" [label=%S];"), &className); |
|
1732 CHuiStatic::Printf(buf); |
|
1733 } |
|
1734 |
|
1735 |
|
1736 EXPORT_C void CHuiVisual::GetInstanceName(TDes& aName) const |
|
1737 { |
|
1738 GetClassName(aName); |
|
1739 TUint addr = TUint(this); |
|
1740 aName.AppendFormat(_L("%u"), addr); |
|
1741 } |
|
1742 |
|
1743 |
|
1744 EXPORT_C void CHuiVisual::GetClassName(TDes& aName) const |
|
1745 { |
|
1746 aName = _L("CHuiVisual"); |
|
1747 } |
|
1748 |
|
1749 |
|
1750 EXPORT_C void CHuiVisual::EnableBrushesL(TBool aEnabled) |
|
1751 { |
|
1752 if(aEnabled && !iBrushes) |
|
1753 { |
|
1754 iBrushes = CHuiBrushArray::NewL(); |
|
1755 } |
|
1756 else if(!aEnabled && iBrushes) |
|
1757 { |
|
1758 if ( iBrushes->Count() ) |
|
1759 { |
|
1760 iFlags |= EHuiVisualChanged; |
|
1761 } |
|
1762 |
|
1763 delete iBrushes; |
|
1764 iBrushes = 0; |
|
1765 } |
|
1766 else |
|
1767 { |
|
1768 // for PC lint |
|
1769 } |
|
1770 } |
|
1771 |
|
1772 |
|
1773 EXPORT_C CHuiBrushArray* CHuiVisual::Brushes() |
|
1774 { |
|
1775 return iBrushes; |
|
1776 } |
|
1777 |
|
1778 |
|
1779 EXPORT_C void CHuiVisual::NotifySkinChangedL() |
|
1780 { |
|
1781 // Do nothing by default. |
|
1782 } |
|
1783 |
|
1784 |
|
1785 EXPORT_C void CHuiVisual::ExpandRectWithContent(TRect& aRect) const |
|
1786 { |
|
1787 if(iBrushes) |
|
1788 { |
|
1789 iBrushes->ActivateBrushGuide(this); |
|
1790 iBrushes->ExpandVisualRect(aRect); |
|
1791 iBrushes->ActivateBrushGuide(NULL); |
|
1792 } |
|
1793 /* |
|
1794 if (iVisualData->iEffect) |
|
1795 { |
|
1796 TRect visualArea; |
|
1797 iVisualData->iEffect->VisualArea(visualArea); |
|
1798 aRect.BoundingRect(visualArea); |
|
1799 } |
|
1800 */ |
|
1801 } |
|
1802 |
|
1803 |
|
1804 EXPORT_C void CHuiVisual::SetTagL(const TDesC8& aTag) |
|
1805 { |
|
1806 // ASSERT(!iTag); |
|
1807 if ( iTag ) |
|
1808 { |
|
1809 delete iTag; |
|
1810 iTag = NULL; |
|
1811 } |
|
1812 if ( aTag.Length() > 0 ) |
|
1813 { |
|
1814 iTag = aTag.AllocL(); |
|
1815 } |
|
1816 } |
|
1817 |
|
1818 |
|
1819 EXPORT_C const TDesC8& CHuiVisual::Tag() const |
|
1820 { |
|
1821 if(iTag) |
|
1822 { |
|
1823 return *iTag; |
|
1824 } |
|
1825 return KHuiVisualUndefinedTag; |
|
1826 } |
|
1827 |
|
1828 |
|
1829 EXPORT_C TBool CHuiVisual::IsTagged() const |
|
1830 { |
|
1831 return iTag != 0; |
|
1832 } |
|
1833 |
|
1834 |
|
1835 EXPORT_C CHuiVisual* CHuiVisual::FindTag(const TDesC8& aTag) |
|
1836 { |
|
1837 // Look for the tag in this visual's tag descriptor. |
|
1838 if(iTag && HuiUtil::TagMatches(*iTag, aTag)) |
|
1839 { |
|
1840 return this; |
|
1841 } |
|
1842 else |
|
1843 { |
|
1844 // Could not find it. |
|
1845 return NULL; |
|
1846 } |
|
1847 } |
|
1848 |
|
1849 EXPORT_C TReal32 CHuiVisual::BrushOpacity() const __SOFTFP |
|
1850 { |
|
1851 return EffectiveOpacity(); |
|
1852 } |
|
1853 |
|
1854 |
|
1855 EXPORT_C THuiRealRect CHuiVisual::BrushRect() const __SOFTFP |
|
1856 { |
|
1857 // Subclasses can override this to make content-dependent brush guides. |
|
1858 return DisplayRect(); |
|
1859 } |
|
1860 |
|
1861 |
|
1862 EXPORT_C CHuiSkin& CHuiVisual::BrushSkin() const |
|
1863 { |
|
1864 return Skin(); |
|
1865 } |
|
1866 |
|
1867 HUI_SESSION_OBJECT_IMPL_EXPORT(CHuiVisual, ETypeVisual) |
|
1868 |
|
1869 EXPORT_C void CHuiVisual::VisualExtension(const TUid& /*aExtensionUid*/, TAny** /*aExtensionParams*/) |
|
1870 { |
|
1871 } |
|
1872 |
|
1873 EXPORT_C void CHuiVisual::UpdateSiblingLayout(TInt aTransitionTime) |
|
1874 { |
|
1875 if(Layout() && !(Layout()->Flags() & EHuiVisualFlagFreezeLayout)) |
|
1876 { |
|
1877 Layout()->UpdateChildrenLayout(aTransitionTime); |
|
1878 } |
|
1879 } |
|
1880 |
|
1881 EXPORT_C void CHuiVisual::BoxMetricToPixelRect(const THuiBoxMetric& aBox, |
|
1882 THuiRealRect& aRectInPixels, |
|
1883 THuiReferenceState aReferenceState) const |
|
1884 { |
|
1885 aRectInPixels.iTl = MetricToPixels(THuiXYMetric(aBox.iLeft, aBox.iTop), aReferenceState); |
|
1886 aRectInPixels.iBr = MetricToPixels(THuiXYMetric(aBox.iRight, aBox.iBottom), aReferenceState); |
|
1887 } |
|
1888 |
|
1889 EXPORT_C THuiRealPoint CHuiVisual::LocalPointInPixels(const THuiRealPoint& aLocalPoint, |
|
1890 THuiReferenceState aReferenceState) const __SOFTFP |
|
1891 { |
|
1892 return MetricToPixels(LocalBaseUnit().Abs() * aLocalPoint, aReferenceState); |
|
1893 } |
|
1894 |
|
1895 EXPORT_C THuiRealPoint CHuiVisual::PixelPointInLocal(const THuiRealPoint& aPixelPoint, |
|
1896 THuiReferenceState aReferenceState) const __SOFTFP |
|
1897 { |
|
1898 return PixelPointInUnits(aPixelPoint, LocalBaseUnit().Abs(), aReferenceState); |
|
1899 } |
|
1900 |
|
1901 |
|
1902 TInt CHuiVisual::FindTacticon( TInt aEventType ) const |
|
1903 { |
|
1904 for ( TInt i = 0 ; i < iVisualData->iTacticons.Count() ; i++ ) |
|
1905 { |
|
1906 if ( iVisualData->iTacticons[i].iEventType == aEventType ) |
|
1907 { |
|
1908 return i; |
|
1909 } |
|
1910 } |
|
1911 return KErrNotFound; |
|
1912 } |
|
1913 |
|
1914 TInt CHuiVisual::TactileFeedback( TInt aEventType ) const |
|
1915 { |
|
1916 TInt returnType = KErrNotFound; |
|
1917 TInt index = FindTacticon( aEventType ); |
|
1918 |
|
1919 if ( index == KErrNotFound ) |
|
1920 { |
|
1921 // Try the layout |
|
1922 CHuiVisual* layoutToCheck = Layout(); |
|
1923 while ( layoutToCheck ) |
|
1924 { |
|
1925 index = layoutToCheck->FindTacticon( aEventType ); |
|
1926 if ( index != KErrNotFound ) |
|
1927 { |
|
1928 returnType = layoutToCheck->iVisualData->iTacticons[index].iFeedbackType; |
|
1929 break; |
|
1930 } |
|
1931 |
|
1932 layoutToCheck = layoutToCheck->Layout(); |
|
1933 } |
|
1934 } |
|
1935 else |
|
1936 { |
|
1937 returnType = iVisualData->iTacticons[index].iFeedbackType; |
|
1938 } |
|
1939 |
|
1940 return returnType; |
|
1941 } |
|
1942 |
|
1943 EXPORT_C void CHuiVisual::SetTactileFeedbackL( TInt aEventType, TInt aFeedbackType ) |
|
1944 { |
|
1945 if ( aFeedbackType < 0 || aEventType < 0 ) |
|
1946 { |
|
1947 User::Leave( KErrArgument ); |
|
1948 } |
|
1949 |
|
1950 // find if it exists already |
|
1951 const TInt index = FindTacticon( aEventType ); |
|
1952 |
|
1953 if ( index != KErrNotFound ) |
|
1954 { |
|
1955 iVisualData->iTacticons[index].iFeedbackType = aFeedbackType; |
|
1956 } |
|
1957 else |
|
1958 { |
|
1959 // Create new item |
|
1960 THuiVisualPrivateData::TTacticon newTacticon; |
|
1961 newTacticon.iEventType = aEventType; |
|
1962 newTacticon.iFeedbackType = aFeedbackType; |
|
1963 |
|
1964 iVisualData->iTacticons.AppendL( newTacticon ); |
|
1965 } |
|
1966 } |
|
1967 |
|
1968 EXPORT_C TBool CHuiVisual::HasTactileFeedback( TInt aEventType ) const |
|
1969 { |
|
1970 if ( aEventType == KHuiTactileFeedbackEventTypeNone ) |
|
1971 { |
|
1972 return iVisualData->iTacticons.Count(); |
|
1973 } |
|
1974 |
|
1975 const TInt index = FindTacticon( aEventType ); |
|
1976 return index != KErrNotFound; |
|
1977 } |
|
1978 |
|
1979 EXPORT_C void CHuiVisual::RemoveTactileFeedback( TInt aEventType ) |
|
1980 { |
|
1981 if ( aEventType == KHuiTactileFeedbackEventTypeNone ) |
|
1982 { |
|
1983 iVisualData->iTacticons.Reset(); |
|
1984 return; |
|
1985 } |
|
1986 |
|
1987 const TInt index = FindTacticon( aEventType ); |
|
1988 if ( index != KErrNotFound ) |
|
1989 { |
|
1990 iVisualData->iTacticons.Remove(index); |
|
1991 } |
|
1992 } |
|
1993 |
|
1994 |
|
1995 TBool CHuiVisual::IsTransformed() const |
|
1996 { |
|
1997 return iTransform != 0; |
|
1998 } |
|
1999 |
|
2000 TBool CHuiVisual::ParentChanged() const |
|
2001 { |
|
2002 // Check if parent has been changed in a way that requires me to report myself as changed |
|
2003 // This may be a performance issue because this function is called often. |
|
2004 const CHuiLayout* iter = Layout(); // start from parent |
|
2005 const CHuiLayout* parent = Layout(); // Immediate parent |
|
2006 |
|
2007 while(iter) |
|
2008 { |
|
2009 // Parent scrolling, we check this before clipping because otherwise |
|
2010 // iPreviousDrawn would not get updated for children correctly as it |
|
2011 // is nowdays only updated in ReportChanged() method (and no more in the draw). |
|
2012 // NOTE: Only immediate parent is checked for better performance (no need to |
|
2013 // check others ?) |
|
2014 // TBD: Should transformations be also checked before clipping ? |
|
2015 if (parent->Scrolling() && parent->ScrollOffset().Changed()) |
|
2016 { |
|
2017 return ETrue; |
|
2018 } |
|
2019 |
|
2020 // If the parent is clipped, there is no need to check any more. |
|
2021 // If the parent in this case has been changed, the parent rect is added |
|
2022 // into the dirty regions and will be drawn anyways. |
|
2023 if ( iter->Clipping() ) |
|
2024 { |
|
2025 return EFalse; |
|
2026 } |
|
2027 |
|
2028 |
|
2029 // Parent transformation affects dirty regions if visual is not clipped and outside parent |
|
2030 if(iter->IsTransformed() && iter->Transformation()->Changed()) |
|
2031 { |
|
2032 return ETrue; |
|
2033 } |
|
2034 // Parent opacity affects this visuals opacity if visual is not clipped and outside parent |
|
2035 if (iter->iOpacity.Changed()) |
|
2036 { |
|
2037 return ETrue; |
|
2038 } |
|
2039 |
|
2040 // Also position (and size) affects |
|
2041 if (iter->iPos.Changed() || iter->iSize.Changed()) |
|
2042 { |
|
2043 return ETrue; |
|
2044 } |
|
2045 |
|
2046 |
|
2047 iter = iter->Layout(); |
|
2048 } |
|
2049 return EFalse; |
|
2050 } |
|
2051 |
|
2052 void CHuiVisual::HandleFlagsChanged( TInt aOldFlags ) |
|
2053 { |
|
2054 // If clipping setting is changed, refresh automatically. |
|
2055 const TBool oldClipping = aOldFlags & EHuiVisualFlagClipping; |
|
2056 const TBool newClipping = iFlags & EHuiVisualFlagClipping; |
|
2057 if ( ( oldClipping && !newClipping ) || |
|
2058 ( !oldClipping && newClipping ) ) |
|
2059 { |
|
2060 SetChanged(); |
|
2061 } |
|
2062 } |
|
2063 |
|
2064 EXPORT_C void CHuiVisual::EnableDropShadowL( TBool aEnable ) |
|
2065 { |
|
2066 if ( aEnable && !iVisualData->iDropShadow ) |
|
2067 { |
|
2068 CHuiDropShadow* dropShadowHandler = new (ELeave) CHuiDropShadow; |
|
2069 CleanupStack::PushL( dropShadowHandler ); |
|
2070 dropShadowHandler->ConstructL(); |
|
2071 CleanupStack::Pop( dropShadowHandler ); |
|
2072 iVisualData->iDropShadow = dropShadowHandler; |
|
2073 SetChanged(); |
|
2074 } |
|
2075 else if ( !aEnable && iVisualData->iDropShadow ) |
|
2076 { |
|
2077 delete iVisualData->iDropShadow; |
|
2078 iVisualData->iDropShadow = NULL; |
|
2079 SetChanged(); |
|
2080 } |
|
2081 } |
|
2082 |
|
2083 EXPORT_C CHuiDropShadow* CHuiVisual::DropShadowHandler() const |
|
2084 { |
|
2085 return iVisualData->iDropShadow; |
|
2086 } |
|
2087 CHuiBrushArray* CHuiVisual::Brushes() const |
|
2088 { |
|
2089 return iBrushes; |
|
2090 } |
|
2091 |
|
2092 |
|
2093 EXPORT_C CHuiFxEffect* CHuiVisual::Effect() const |
|
2094 { |
|
2095 if (!iVisualData) |
|
2096 return NULL; |
|
2097 else |
|
2098 return iVisualData->iEffect; |
|
2099 } |
|
2100 |
|
2101 EXPORT_C MHuiEffectable *CHuiVisual::Effectable() const |
|
2102 { |
|
2103 if (!iVisualData) |
|
2104 return NULL; |
|
2105 else |
|
2106 return iVisualData->iEffectable; |
|
2107 } |
|
2108 |
|
2109 TBool CHuiVisual::IsDelayedEffectSource() const |
|
2110 { |
|
2111 if (!Effectable()) |
|
2112 return EFalse; |
|
2113 else |
|
2114 { |
|
2115 TBool b = Effectable()->EffectGetSource(); |
|
2116 if (!b) |
|
2117 { // if not found from this object, try the parent |
|
2118 CHuiLayout *l = Layout(); |
|
2119 if (l) |
|
2120 return Layout()->IsDelayedEffectSource(); |
|
2121 } |
|
2122 return b; |
|
2123 } |
|
2124 } |
|
2125 |
|
2126 EXPORT_C void CHuiVisual::SetEffect(CHuiFxEffect* aEffect) |
|
2127 { |
|
2128 SetFreezeState(EFalse); |
|
2129 |
|
2130 __ALFFXLOGSTRING1("CHuiVisual::SetEffect - : 0x%d ", aEffect ); |
|
2131 // If effect is replaced by a new effect, we don't want the effect end callback |
|
2132 // as it would end the new effect |
|
2133 if ( iVisualData->iEffect ) |
|
2134 { |
|
2135 #ifdef _ALF_FXLOGGING |
|
2136 if ( aEffect ) |
|
2137 { |
|
2138 __ALFFXLOGSTRING1("CHuiVisual::SetEffect - : Deleting previous 0x%x effect on this visual ", iVisualData->iEffect ); |
|
2139 } |
|
2140 #endif |
|
2141 iVisualData->iEffect->SetEffectEndObserver( NULL, 0 ); |
|
2142 } |
|
2143 delete iVisualData->iEffect; |
|
2144 iVisualData->iEffect = aEffect; |
|
2145 // The parser must now go |
|
2146 delete iVisualData->iEffectParser; |
|
2147 iVisualData->iEffectParser = NULL; // the parser just died |
|
2148 SetChanged(); |
|
2149 } |
|
2150 |
|
2151 void CHuiVisual::SetEffectParser( CHuiFxEffectParser* aEffectParser ) |
|
2152 { |
|
2153 delete iVisualData->iEffectParser; |
|
2154 iVisualData->iEffectParser = aEffectParser; |
|
2155 } |