uiacceltk/hitchcock/coretoolkit/src/HuiImageVisual.cpp
changeset 0 15bf7259bb7c
child 50 1801340c26a2
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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:   Implementation of CHuiImageVisual. CHuiImageVisual is a visual
       
    15 *                that is able to display images.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include "uiacceltk/HuiImageVisual.h"  // Class definition
       
    22 #include "uiacceltk/HuiStatic.h"
       
    23 #include "HuiRenderPlugin.h"
       
    24 #include "uiacceltk/HuiDrawing.h"
       
    25 #include "uiacceltk/HuiControl.h"
       
    26 #include "uiacceltk/HuiUtil.h"
       
    27 #include "uiacceltk/huifixmath.h"
       
    28 #include "HuiMatrixStack.h"
       
    29 
       
    30 #include "uiacceltk/huidropshadow.h"
       
    31 #include "uiacceltk/HuiDisplay.h"
       
    32 
       
    33 #include "HuiRosterImpl.h"
       
    34 
       
    35 
       
    36 EXPORT_C CHuiImageVisual* CHuiImageVisual::AddNewL(CHuiControl& aOwnerControl,
       
    37                                                    CHuiLayout* aParentLayout)
       
    38     {
       
    39     CHuiImageVisual* image = static_cast<CHuiImageVisual*>(
       
    40         aOwnerControl.AppendVisualL(EHuiVisualTypeImage, aParentLayout));
       
    41     return image;
       
    42     }
       
    43 
       
    44 
       
    45 CHuiImageVisual::CHuiImageVisual(MHuiVisualOwner& aOwner)
       
    46         : CHuiVisual(aOwner), iScaleMode(EScaleFit),
       
    47           iStretchMode(CHuiGc::EStretchVertical), iColor(KRgbWhite),
       
    48           iScale(1.f),iOffset(.5f,.5f),iDropShadow(0)
       
    49     {
       
    50     iSecondaryAlpha.SetStyle(EHuiTimedValueStyleLinear);
       
    51     }
       
    52 
       
    53 
       
    54 void CHuiImageVisual::ConstructL()
       
    55     {
       
    56     CHuiVisual::ConstructL();
       
    57     }
       
    58 
       
    59 
       
    60 CHuiImageVisual::~CHuiImageVisual()
       
    61     {
       
    62     }
       
    63 
       
    64 
       
    65 EXPORT_C void CHuiImageVisual::SetScaleMode(TScaleMode aScaleMode)
       
    66     {
       
    67     iScaleMode = aScaleMode;
       
    68     SetChanged();
       
    69     }
       
    70 
       
    71 
       
    72 EXPORT_C void CHuiImageVisual::SetStretch(TInt aTop, TInt aBottom)
       
    73     {
       
    74     iTopStretch = aTop;
       
    75     iBottomStretch = aBottom;
       
    76     SetChanged();
       
    77     }
       
    78 
       
    79 
       
    80 EXPORT_C void CHuiImageVisual::SetStretchMode(CHuiGc::TStretchMode aStretchMode)
       
    81     {
       
    82     iStretchMode = aStretchMode;
       
    83     SetChanged();
       
    84     }
       
    85 
       
    86 // deprecated
       
    87 EXPORT_C void CHuiImageVisual::SetDropShadow(TInt aShadowDistance)
       
    88     {
       
    89     SetDropShadow(THuiXYMetric(aShadowDistance));
       
    90     }
       
    91     
       
    92 EXPORT_C void CHuiImageVisual::SetDropShadow(const THuiMetric& aShadowDistance)
       
    93 	{
       
    94     SetDropShadow(THuiXYMetric(aShadowDistance));
       
    95 	}
       
    96 
       
    97 EXPORT_C void CHuiImageVisual::SetDropShadow(const THuiXYMetric& aShadowDistance)
       
    98 	{
       
    99     iDropShadow = aShadowDistance;
       
   100     SetChanged();	
       
   101     
       
   102     if(!HuiUtil::RealCompare(iDropShadow.iX.iMagnitude,0.f) || !HuiUtil::RealCompare(iDropShadow.iY.iMagnitude,0.f))
       
   103         {
       
   104         TRAP_IGNORE( EnableDropShadowL( ETrue ) );
       
   105         }
       
   106     else
       
   107         {
       
   108         TRAP_IGNORE( EnableDropShadowL( EFalse ) );
       
   109         }
       
   110 
       
   111 	}
       
   112 
       
   113 
       
   114 EXPORT_C void CHuiImageVisual::SetImage(const THuiImage& aImage)
       
   115     {
       
   116     iImage = aImage;
       
   117     SetChanged();
       
   118     }
       
   119 
       
   120 
       
   121 EXPORT_C void CHuiImageVisual::SetSecondaryImage(const THuiImage& aImage)
       
   122     {
       
   123     iSecondaryImage = aImage;
       
   124     SetChanged();
       
   125     }
       
   126 
       
   127 
       
   128 EXPORT_C const THuiImage& CHuiImageVisual::Image() const
       
   129     {
       
   130     return iImage;
       
   131     }
       
   132 
       
   133 
       
   134 EXPORT_C void CHuiImageVisual::SetColor(const TRgb& aColor)
       
   135     {
       
   136     iColor = aColor;
       
   137     SetChanged();
       
   138     }
       
   139 
       
   140 
       
   141 EXPORT_C void CHuiImageVisual::SetColorMode(TColorMode aColorMode, TReal32 aParam) __SOFTFP
       
   142     {
       
   143     iColorMode = aColorMode;
       
   144     iColorParam = aParam;
       
   145     SetChanged();
       
   146     }
       
   147 
       
   148 TBool CHuiImageVisual::PrepareDrawL()
       
   149     {
       
   150 	if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent)
       
   151 	   	{
       
   152 	    // This is used only as external content visual. Return now if we are not currently drawing
       
   153 	    // external content.
       
   154 	   	if (!Display() || !Display()->RosterImpl().IsDrawingExternalContent())
       
   155 	   		{
       
   156 			return ETrue;
       
   157 	   		}
       
   158 	   	}
       
   159 
       
   160     if ( iImage.HasTexture() )
       
   161         {   
       
   162         CHuiDropShadow* shadowHandler = DropShadowHandler();
       
   163         if ( shadowHandler && shadowHandler->IsShadowVisible() )
       
   164             {
       
   165             CHuiTexture* shadowTextureSource = shadowHandler->ShadowedTextureInstance( *iImage.ImageTexture() );
       
   166             if ( shadowTextureSource )
       
   167                 {        
       
   168                 const TInt requestedBlurredSize = HUI_ROUND_FLOAT_TO_INT( 2*DropShadowHandler()->iRadius.Now() );
       
   169                 shadowTextureSource->CreateShadowTextureL( requestedBlurredSize, EHuiTextureShadowStyleIcon );
       
   170                 }
       
   171             }
       
   172         }
       
   173     return ETrue;       
       
   174     }
       
   175 
       
   176 void CHuiImageVisual::DrawSelf(CHuiGc& aGc, const TRect& /*aDisplayRect*/) const
       
   177     {
       
   178     TReal32 effectiveOpacity = EffectiveOpacity();
       
   179 
       
   180     THuiRealRect content = DisplayRect();
       
   181     content.Shrink(PaddingInPixels());
       
   182 
       
   183     if(!iImage.HasTexture() || effectiveOpacity <= 0)
       
   184         {        
       
   185         aGc.NotifyImagePreferredSize(iImage, content);
       
   186         return;
       
   187         }
       
   188 
       
   189     if(content.Width() <= 0 || content.Height() <= 0)
       
   190         {
       
   191         // Too small to see.
       
   192         return;
       
   193         }
       
   194 
       
   195     aGc.Enable(CHuiGc::EFeatureBlending);
       
   196 
       
   197     TReal32 turnAngle = iTurnAngle.Now();
       
   198     TReal32 xOffset = 0;
       
   199     TReal32 yOffset = 0;
       
   200 
       
   201     TReal32 scale = HuiUtil::CalculateScaleFactorFromScaleMode(
       
   202                 content.Size(),
       
   203                 iImage.Texture().Size(),
       
   204                 iScaleMode,
       
   205                 iScale.Now() );
       
   206 
       
   207     // Determine offset.
       
   208     TSize imageSize = iImage.Texture().Size();
       
   209     TReal32 scaled = scale * imageSize.iWidth;
       
   210     if(scaled > content.Width())
       
   211         {
       
   212         xOffset = (scaled - content.Width()) * (iOffset.iX.Now() - 0.5f);
       
   213         }
       
   214     scaled = scale * imageSize.iHeight;
       
   215     if(scaled > content.Height())
       
   216         {
       
   217         yOffset = (scaled - content.Height()) * (iOffset.iY.Now() - 0.5f);
       
   218         }
       
   219 
       
   220     if(turnAngle != 0 || scale != 1)
       
   221         {
       
   222         /** @todo  GC must provide some support for transformations. */
       
   223         aGc.Push(EHuiGcMatrixModel);
       
   224 
       
   225         // Rotate around the midpoint of the visual.
       
   226         THuiRealPoint mid = content.Center();
       
   227 
       
   228         aGc.Translate(EHuiGcMatrixModel, mid.iX - xOffset, mid.iY - yOffset, 0.f);
       
   229         if(turnAngle != 0)
       
   230             {
       
   231             aGc.Rotate(EHuiGcMatrixModel, turnAngle, 0.f, 0.f, -1.f);
       
   232             }
       
   233         if(scale != 1)
       
   234             {
       
   235             aGc.Scale(EHuiGcMatrixModel, scale, scale, 1.f);
       
   236             }
       
   237         aGc.Translate(EHuiGcMatrixModel, -mid.iX, -mid.iY, 0.f);
       
   238         }
       
   239 
       
   240     // Use the appropriate alignment in the graphics context.
       
   241     if(iScaleMode == EScaleFit)
       
   242         {
       
   243         aGc.SetAlign(EHuiAlignHLeft, EHuiAlignVTop);
       
   244         }
       
   245     else
       
   246         {
       
   247         aGc.SetAlign(EHuiAlignHCenter, EHuiAlignVCenter);
       
   248         }
       
   249    
       
   250     // draw drop shadow
       
   251     CHuiDropShadow* shadowHandler = DropShadowHandler();
       
   252     if ( shadowHandler && iImage.HasTexture() )
       
   253         {
       
   254         CHuiTexture* shadowTextureSource = shadowHandler->ShadowedTextureInstance( *iImage.ImageTexture() );
       
   255         if ( iImage.ImageTexture() &&
       
   256              shadowTextureSource &&
       
   257              shadowHandler->IsShadowVisible() )
       
   258             {
       
   259             const TInt requestedBlurredSize = HUI_ROUND_FLOAT_TO_INT( 2*DropShadowHandler()->iRadius.Now() );
       
   260             
       
   261             THuiTextureHandle shadow;
       
   262             TBool haveShadowTexture = shadowTextureSource->GetShadowTexture( shadow,requestedBlurredSize );
       
   263 
       
   264             if ( haveShadowTexture )
       
   265                 {
       
   266                 THuiImage shadowImage( shadow );
       
   267                 const THuiRealRect shadowDrawingRect = shadowHandler->ShadowDrawingRealRect( 
       
   268                     content.iTl,
       
   269                     content.Size(),
       
   270                     shadow.Size(),
       
   271                     *this );
       
   272                 
       
   273                 // set drawing parameters
       
   274                 aGc.SetPenAlpha(TInt(effectiveOpacity * shadowHandler->iOpacity.Now()*255.f));
       
   275                 aGc.SetPenColor(shadowHandler->Color());
       
   276                 const THuiQuality oldQuality = aGc.Quality(); // store the original quality
       
   277                 aGc.SetQuality(EHuiQualityFast); // draw always with 'fast'
       
   278                 
       
   279                 if(iScaleMode == EScaleFit)
       
   280                     {
       
   281                     aGc.DrawImage(shadowImage, shadowDrawingRect.iTl, shadowDrawingRect.Size() );
       
   282                     }
       
   283                 else
       
   284                     {
       
   285                     THuiRealSize relativeShadowTextureSize = iImage.Texture().Size();
       
   286                     relativeShadowTextureSize.iWidth *= ((TReal32)shadowDrawingRect.Width())/((TReal32)content.Size().iWidth);
       
   287                     relativeShadowTextureSize.iHeight *= ((TReal32)shadowDrawingRect.Height())/((TReal32)content.Size().iHeight);
       
   288 
       
   289                     aGc.DrawImage(
       
   290                         shadowImage, 
       
   291                         relativeShadowTextureSize,
       
   292                         THuiRealRect( shadowDrawingRect.iTl, shadowDrawingRect.Size() ));
       
   293                        
       
   294                     }
       
   295                     
       
   296                 aGc.SetQuality(oldQuality); // restore quality
       
   297                 }
       
   298             }
       
   299         }
       
   300         
       
   301     // Actual color of the image.
       
   302     aGc.SetPenAlpha(TInt(effectiveOpacity * 255));
       
   303     aGc.SetPenColor(iColor);
       
   304 
       
   305     // Apply special color mode.
       
   306     if(iColorMode == EColorDimmed)
       
   307         {
       
   308         aGc.Enable(CHuiGc::EFeatureFog);
       
   309         aGc.SetDimmingFog(iColor, iColorParam);
       
   310         }
       
   311 
       
   312     if(iTopStretch || iBottomStretch)
       
   313         {
       
   314         aGc.DrawStretchImage(iStretchMode, iImage, content,
       
   315                              iTopStretch, iBottomStretch);
       
   316         }
       
   317     else
       
   318         {
       
   319         if(aGc.TextureUnits() >= 2 &&
       
   320            CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowTextureModeInterpolate) &&
       
   321            iImage.HasTexture() && iSecondaryImage.HasTexture() &&
       
   322            (iImage.SegmentCount() == iSecondaryImage.SegmentCount() && 
       
   323            (iImage.Texture().Size() == iSecondaryImage.Texture().Size() || iImage.SegmentCount() == 1)))
       
   324             {
       
   325             // Can use multitexturing to interpolate.
       
   326             aGc.SetTextureUnits(2);
       
   327             aGc.Enable(CHuiGc::EFeatureTexturing);
       
   328             aGc.SetTextureMode(CHuiGc::ETextureModeInterpolate,
       
   329                                iSecondaryAlpha.Now());
       
   330             aGc.SetPenAlpha(TInt(effectiveOpacity * 255));
       
   331 
       
   332             if(iScaleMode == EScaleFit)
       
   333                 {
       
   334                 // Scale both images to the content rectangle.
       
   335                 aGc.DrawImages(iImage, iSecondaryImage,
       
   336                                content.iTl, content.Size());
       
   337                 }
       
   338             else
       
   339                 {
       
   340                 // Draw both images by taking the size of the first one.
       
   341                 aGc.DrawImages(iImage, iSecondaryImage,
       
   342                                iImage.Texture().Size(), content);
       
   343                 }
       
   344 
       
   345             aGc.SetTextureUnits(1);
       
   346             aGc.SetTextureMode(CHuiGc::ETextureModeNormal);
       
   347             }
       
   348         else
       
   349             {
       
   350             // Must draw using two passes.
       
   351             TInt primaryAlpha = 0;
       
   352             TInt secondaryAlpha = 0;
       
   353             GetDualAlpha(effectiveOpacity, iSecondaryAlpha.Now(),
       
   354                          primaryAlpha, secondaryAlpha);
       
   355 
       
   356             // Draw both the primary and the secondary images.
       
   357             if(primaryAlpha > 0)
       
   358                 {
       
   359                 aGc.SetPenAlpha(primaryAlpha);
       
   360                 if(iScaleMode == EScaleFit)
       
   361                     {
       
   362                     aGc.DrawImage(iImage, content.iTl, content.Size());
       
   363                     }
       
   364                 else
       
   365                     {
       
   366                     aGc.DrawImage(iImage, content);
       
   367                     }
       
   368                 }
       
   369 
       
   370             if(secondaryAlpha > 0 && iSecondaryImage.HasTexture())
       
   371                 {
       
   372                 aGc.SetPenAlpha(secondaryAlpha);
       
   373                 if(iScaleMode == EScaleFit)
       
   374                     {
       
   375                     aGc.DrawImage(iSecondaryImage, content.iTl, content.Size());
       
   376                     }
       
   377                 else
       
   378                     {
       
   379                     aGc.DrawImage(iSecondaryImage, iImage.Texture().Size(), content);
       
   380                     }
       
   381                 }
       
   382             else
       
   383                 {
       
   384                 // Notify preferred size even if image is not drawn (yet)
       
   385                 aGc.NotifyImagePreferredSize(iSecondaryImage, content);                    
       
   386                 }
       
   387             }
       
   388         }
       
   389 
       
   390     // Disable special color modes.
       
   391     if(iColorMode == EColorDimmed)
       
   392         {
       
   393         aGc.Disable(CHuiGc::EFeatureFog);
       
   394         }
       
   395 
       
   396     // Restore original transformation.
       
   397     if(turnAngle != 0 || scale != 1)
       
   398         {
       
   399         aGc.Pop(EHuiGcMatrixModel);
       
   400         }
       
   401     }
       
   402 
       
   403 
       
   404 TBool CHuiImageVisual::Changed() const
       
   405     {
       
   406     if(CHuiVisual::Changed())
       
   407         {
       
   408         return ETrue;
       
   409         }
       
   410         
       
   411 	if(iImage.Changed())
       
   412 		{
       
   413 		return ETrue;
       
   414 		}
       
   415 		        
       
   416     return (iTurnAngle.Changed() || iOffset.Changed() || iScale.Changed() ||
       
   417             iSecondaryAlpha.Changed());
       
   418     }
       
   419 
       
   420 
       
   421 void CHuiImageVisual::ClearChanged()
       
   422     {
       
   423     CHuiVisual::ClearChanged();
       
   424     iImage.ClearChanged();
       
   425     iTurnAngle.ClearChanged();
       
   426     iOffset.ClearChanged();
       
   427     iScale.ClearChanged();
       
   428     iSecondaryAlpha.ClearChanged();
       
   429     }
       
   430 
       
   431 void DoRotateRect(THuiRealRect& aRect, TReal32 aAngle)
       
   432     {
       
   433     // Transform dirty rect and enlarge it if rotated.    
       
   434     THuiRealRect transformed(aRect);
       
   435     
       
   436     THuiRealPoint coords[4];
       
   437     coords[0].iX = transformed.iTl.iX;
       
   438     coords[0].iY = transformed.iTl.iY;
       
   439     coords[1].iX = transformed.iBr.iX;
       
   440     coords[1].iY = transformed.iTl.iY;
       
   441     coords[2].iX = transformed.iBr.iX;
       
   442     coords[2].iY = transformed.iBr.iY;
       
   443     coords[3].iX = transformed.iTl.iX;
       
   444     coords[3].iY = transformed.iBr.iY;
       
   445     
       
   446 
       
   447     TInt radians = HuiFixMath::FixMul(HuiFixMath::FloatToFix(aAngle),KFixPi)/180;
       
   448     if (aAngle < 0)
       
   449         {
       
   450         radians = -radians;
       
   451         }
       
   452 
       
   453     TInt sin = HuiFixMath::FixSin(radians);
       
   454     TInt cos = HuiFixMath::FixCos(radians);
       
   455         
       
   456         
       
   457     CHuiMatrixStack::TMatrix rotation;
       
   458     rotation.iMatrix[0] = HuiFixMath::FixToFloat(cos);
       
   459     rotation.iMatrix[1] = HuiFixMath::FixToFloat(sin);
       
   460     rotation.iMatrix[3] = HuiFixMath::FixToFloat(-sin);
       
   461     rotation.iMatrix[4] = HuiFixMath::FixToFloat(cos);
       
   462     rotation.iMatrix[8] = 1.0f;
       
   463     rotation.iIsIdentity = EFalse;
       
   464 
       
   465     for (TInt count = 0; count < 4; count++)
       
   466         {
       
   467         rotation.Multiply(coords[count]);
       
   468         }
       
   469 
       
   470     // rotate only if there is really rotation, not mirroring
       
   471     
       
   472     if ( !HuiUtil::RealCompare(coords[2].iY, coords[3].iY) )
       
   473         {
       
   474         // rotation has been applied
       
   475         THuiRealPoint minPoint = coords[0];
       
   476         THuiRealPoint maxPoint = coords[0];
       
   477         for (TInt count = 1; count < 4; count++)
       
   478             {
       
   479             if (coords[count].iX < minPoint.iX)
       
   480                 {
       
   481                 minPoint.iX = coords[count].iX;
       
   482                 }
       
   483             if (coords[count].iY < minPoint.iY)
       
   484                 {
       
   485                 minPoint.iY = coords[count].iY;
       
   486                 }
       
   487             if (coords[count].iX > maxPoint.iX)
       
   488                 {
       
   489                 maxPoint.iX = coords[count].iX;
       
   490                 }
       
   491             if (coords[count].iY > maxPoint.iY)
       
   492                 {
       
   493                 maxPoint.iY = coords[count].iY;
       
   494                 }
       
   495             }
       
   496 				
       
   497         transformed.iTl = minPoint;
       
   498         transformed.iBr = maxPoint;
       
   499         }
       
   500     else
       
   501         {
       
   502         transformed.iTl = coords[0];
       
   503         transformed.iBr = coords[2];            
       
   504         }    
       
   505         
       
   506     aRect = transformed;
       
   507     }
       
   508 
       
   509 
       
   510 void CHuiImageVisual::ExpandRectWithContent(TRect& aRect) const
       
   511     {
       
   512     if(!Clipping())
       
   513         {
       
   514         if( iImage.HasTexture() )
       
   515             {
       
   516             TSize imageSize = iImage.Texture().Size(); 
       
   517 
       
   518             // Handle scale mode
       
   519             if (iScaleMode == EScaleNormal && 
       
   520                  ( imageSize.iWidth > aRect.Width() || imageSize.iHeight > aRect.Height()))
       
   521                 {
       
   522                 const TInt growX = Max( 0, ((imageSize.iWidth - aRect.Width()) + 1) / 2 );
       
   523                 const TInt growY = Max( 0, ((imageSize.iHeight - aRect.Height()) + 1) / 2 );
       
   524                 aRect.Grow( growX, growY );
       
   525                 }
       
   526             else if (iScaleMode == EScaleFitWidth)
       
   527                 {
       
   528                 TReal32 scale = HuiUtil::CalculateScaleFactorFromScaleMode(
       
   529                     aRect.Size(),
       
   530                     imageSize,
       
   531                     iScaleMode,
       
   532                     1.f );
       
   533                 TInt scaled = (TReal32)imageSize.iHeight*scale+0.5f;
       
   534                 if (scaled > aRect.Height())
       
   535                     {
       
   536                     aRect.Grow(0,(((scaled-aRect.Height()) +1)/2));
       
   537                     }
       
   538                 }
       
   539             else if (iScaleMode == EScaleFitHeight)
       
   540                 {
       
   541                 TReal32 scale = HuiUtil::CalculateScaleFactorFromScaleMode(
       
   542                     aRect.Size(),
       
   543                     imageSize,
       
   544                     iScaleMode,
       
   545                     1.f );
       
   546                 TInt scaled = (TReal32)imageSize.iWidth*scale+0.5f;
       
   547                 if (scaled > aRect.Width())
       
   548                     {
       
   549                     aRect.Grow((((scaled-aRect.Width()) +1)/2),0);                    
       
   550                     }
       
   551                 }
       
   552             else if (iScaleMode == EScaleCover || iScaleMode == EScaleFitInside)
       
   553                 {
       
   554                 TReal32 scale = HuiUtil::CalculateScaleFactorFromScaleMode(
       
   555                     aRect.Size(),
       
   556                     imageSize,
       
   557                     iScaleMode,
       
   558                     1.f );
       
   559                 TInt scaledW = (TReal32)imageSize.iWidth*scale+0.5f;
       
   560                 TInt scaledH = (TReal32)imageSize.iHeight*scale+0.5f;
       
   561 
       
   562                 if (scaledW > aRect.Width())
       
   563                     {
       
   564                     aRect.Grow((((scaledW-aRect.Width()) +1)/2),0);                    
       
   565                     }
       
   566                 if (scaledH > aRect.Height())
       
   567                     {
       
   568                     aRect.Grow(0,(((scaledH-aRect.Height()) +1)/2));
       
   569                     }
       
   570                 }
       
   571             else
       
   572                 {
       
   573                 // For PC-lint
       
   574                 }
       
   575             }
       
   576                
       
   577         // Calculate scaled rect.
       
   578         // aRect and scaled rect has same center position. 
       
   579         TRect adjusted;
       
   580         TReal32 scale = iScale.Now();
       
   581         TReal32 offsetX = TReal32(aRect.Width()) * scale / 2.f;
       
   582         TReal32 offsetY = TReal32(aRect.Height()) * scale / 2.f;
       
   583 
       
   584         adjusted.iTl.iX = HUI_ROUND_FLOAT_TO_INT((aRect.iTl.iX + aRect.Width()/2.f) - offsetX);
       
   585         adjusted.iTl.iY = HUI_ROUND_FLOAT_TO_INT((aRect.iTl.iY + aRect.Height()/2.f) - offsetY);
       
   586         adjusted.iBr.iX = HUI_ROUND_FLOAT_TO_INT((aRect.iBr.iX - aRect.Width()/2.f) + offsetX);
       
   587         adjusted.iBr.iY = HUI_ROUND_FLOAT_TO_INT((aRect.iBr.iY - aRect.Height()/2.f) + offsetY);
       
   588 
       
   589         // aRect must not become smaller.
       
   590         aRect.BoundingRect( adjusted );
       
   591         
       
   592         // calculate drop shadow
       
   593         CHuiDropShadow* shadowHandler = DropShadowHandler();
       
   594         if ( iImage.HasTexture() &&
       
   595             shadowHandler &&
       
   596             shadowHandler->IsShadowVisible() )
       
   597             {
       
   598             CHuiTexture* shadowTextureSource = shadowHandler->ShadowedTextureInstance( *iImage.ImageTexture() );
       
   599             if ( shadowTextureSource )
       
   600                 {
       
   601                     
       
   602                 const TInt requestedBlurredSize = HUI_ROUND_FLOAT_TO_INT( 2*shadowHandler->iRadius.Now() );
       
   603                 
       
   604                 THuiTextureHandle shadow;
       
   605                 TBool haveShadowTexture = shadowTextureSource->GetShadowTexture( shadow,requestedBlurredSize );
       
   606                 
       
   607                 if ( haveShadowTexture )
       
   608                     {
       
   609                     const TRect shadowRect = shadowHandler->ShadowDrawingTRect( 
       
   610                         aRect.iTl,
       
   611                         aRect.Size(),
       
   612                         shadow.Size(),
       
   613                         *this );
       
   614                          
       
   615                     // aRect must not become smaller.
       
   616                     aRect.BoundingRect( shadowRect );
       
   617                     }
       
   618                 }
       
   619             }
       
   620 
       
   621         // add the turn angle effect
       
   622         if ( iImage.HasTexture() && iTurnAngle.Now() )
       
   623             {
       
   624             // Take turn angle into accout by rotating aRect.
       
   625             THuiRealRect rotated( THuiRealPoint(0.f,0.f), aRect.Size() );
       
   626             rotated.Move( -rotated.Center().iX, -rotated.Center().iY );
       
   627             DoRotateRect( rotated, iTurnAngle.Now() );
       
   628             TSize rotatedSize = rotated.Size();
       
   629             // Size rounds down, compensate by increasing by one.
       
   630             rotatedSize.iWidth++;
       
   631             rotatedSize.iHeight++;
       
   632             
       
   633             // Define rotatedRect: same center point as aRect, different size
       
   634             TRect rotatedRect( rotatedSize );
       
   635             rotatedRect.Move( 
       
   636                 aRect.Center() - 
       
   637                 TPoint( ( rotatedSize.iWidth + 1 )/2, ( rotatedSize.iHeight + 1 )/2 ) );
       
   638             rotatedRect.iBr += TPoint( 1, 1 ); // two possible center
       
   639             
       
   640             // aRect must not become smaller.
       
   641             aRect.BoundingRect( rotatedRect );
       
   642             }
       
   643         
       
   644         // Apparently, there is two pixel error in above 
       
   645         // (occurs already before scaling, fit width/fit height cases).
       
   646         aRect.Grow( 2, 2 );
       
   647         }
       
   648 
       
   649     CHuiVisual::ExpandRectWithContent(aRect);
       
   650     }