uifw/ganes/src/HgVgLabel.cpp
branchRCL_3
changeset 56 d48ab3b357f1
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
       
     1 /*
       
     2 * Copyright (c) 2009 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "HgVgLabel.h"
       
    21 #include "HgVgHelper.h"
       
    22 #include "HgVgDrawBuffer.h"
       
    23 #include "HgDrawUtils.h"
       
    24 
       
    25 #include <ganes.mbg>
       
    26 #include <AknIconUtils.h>
       
    27 #include <avkon.mbg>
       
    28 #include <AknsDrawUtils.h>
       
    29 #include <touchfeedback.h>
       
    30 #include <gulicon.h>
       
    31 #include <AknUtils.h>
       
    32 #include <layoutmetadata.cdl.h>
       
    33 #include <AknLayout2ScalableDef.h>
       
    34 #include <e32math.h>
       
    35 #include <gulcolor.h>
       
    36 
       
    37 #include <AknsDrawUtils.h>
       
    38 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 // -----------------------------------------------------------------------------
       
    42 // CHgVgTitleRenderer::NewL()
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CHgVgLabel* CHgVgLabel::NewL(const TRect& aRect, const TDesC& aText)
       
    47     {
       
    48     CHgVgLabel* self = new ( ELeave ) CHgVgLabel(aRect);
       
    49     CleanupStack::PushL (self );
       
    50     self->ConstructL(aText);
       
    51     CleanupStack::Pop ( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CHgVgTitleRenderer::ConstructL()
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CHgVgLabel::ConstructL (const TDesC& aText)
       
    61     {
       
    62     iText = aText.AllocL();
       
    63     
       
    64     iTextRenderer = CHgVgDrawBuffer::NewL(iRect.Size(), EGray256);
       
    65         
       
    66     iTextImage = vgCreateImage(VG_A_8, 
       
    67             iRect.Width(), iRect.Height(), 
       
    68             VG_IMAGE_QUALITY_NONANTIALIASED);
       
    69     
       
    70     if (iTextImage == VG_INVALID_HANDLE)
       
    71         {
       
    72         User::Leave(KErrNoMemory);
       
    73         }
       
    74         
       
    75     // get text color from skin
       
    76     if ( AknsUtils::AvkonSkinEnabled() )
       
    77         {
       
    78         // this does not modify color unless it gets a correct one
       
    79         // no real need to check errors
       
    80         AknsUtils::GetCachedColor( 
       
    81                 AknsUtils::SkinInstance(),
       
    82                 iTextColor,
       
    83                 KAknsIIDQsnTextColors,
       
    84                 EAknsCIQsnTextColorsCG6 );
       
    85         }
       
    86     
       
    87     if (iTextColor.Red() < 128)
       
    88         {
       
    89         iShadowColor = KRgbWhite;
       
    90         }
       
    91     else
       
    92         {
       
    93         iShadowColor = KRgbBlack;
       
    94         }
       
    95         
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CHgVgTitleRenderer::CHgVgTitleRenderer()
       
   100 // C++ default constructor can NOT contain any code, that might leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CHgVgLabel::CHgVgLabel(const TRect& aRect) : 
       
   104 iRect(aRect),
       
   105 iTextColor(KRgbDarkGray),
       
   106 iShadowColor(KRgbBlack),
       
   107 iDirty(ETrue)
       
   108     {
       
   109     
       
   110     }
       
   111         
       
   112 // -----------------------------------------------------------------------------
       
   113 // CHgVgTitleRenderer::~CHgVgTitleRenderer()
       
   114 // Destructor.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CHgVgLabel::~CHgVgLabel ( )
       
   118     {
       
   119     delete iText;
       
   120     delete iTextRenderer;    
       
   121     // then parent
       
   122     vgDestroyImage(iTextImage);
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CHgVgLabel::SetText()
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CHgVgLabel::SetTextL(const TDesC& aText)
       
   130     {
       
   131     if (aText != *iText)
       
   132         {
       
   133         delete iText;
       
   134         iText = 0;
       
   135         iText = aText.AllocL();
       
   136         iDirty = ETrue;
       
   137         }
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CHgVgLabel::Draw()
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CHgVgLabel::Draw(const TRect& aWindowRect, TReal aAlpha)
       
   145     {
       
   146     if (iDirty)
       
   147         {
       
   148         Update();
       
   149         iDirty = EFalse;
       
   150         }
       
   151     
       
   152     TRgb color = iTextColor;
       
   153     color.SetAlpha(255.0f * aAlpha);
       
   154     TRgb shadowColor = iShadowColor;
       
   155     shadowColor.SetAlpha(255.0f * aAlpha);
       
   156 
       
   157     //HgVgHelper::DrawImageColorized(iTextImage, shadowColor, iRect.iTl+TPoint(1,1), aWindowRect);    
       
   158     HgVgHelper::DrawImageColorized(iTextImage, color, iRect.iTl, aWindowRect, EFalse, iLandscape);    
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CHgVgLabel::Update()
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CHgVgLabel::Update()
       
   166     {
       
   167     iTextRenderer->Clear(iRect.Size(), KRgbBlack);
       
   168 /*    iTextRenderer->Gc().SetPenColor(KRgbWhite);    
       
   169         
       
   170     iTextRenderer->Gc().UseFont(iFont);
       
   171     iTextRenderer->Gc().DrawText(*iText, TPoint(
       
   172             iRect.Width() / 2 - iFont->TextWidthInPixels(*iText) / 2, 
       
   173             iFont->HeightInPixels()));
       
   174 */
       
   175     TAknLayoutText text;
       
   176             
       
   177     text.LayoutText(iParentRect, iLayout);
       
   178     text.DrawText(iTextRenderer->Gc(), *iText, ETrue, KRgbWhite);
       
   179     
       
   180     iTextRenderer->GetDrawBufferToVgImage(TRect(TPoint(0,0), iRect.Size()), 
       
   181             TPoint(0, 0), iTextImage, VG_A_8);    
       
   182     }
       
   183 
       
   184 
       
   185 void CHgVgLabel::SetLayout(const TAknTextComponentLayout& aLayout, const TRect& aParentRect)
       
   186     {
       
   187     iLayout = aLayout;
       
   188     iLayout.Sett(0);
       
   189     iLayout.Setl(0);
       
   190     iParentRect = aParentRect;
       
   191     }
       
   192 
       
   193 void CHgVgLabel::DrawEmptyText(const TRect& aClientRect, const TDesC& aText)
       
   194     {
       
   195     iTextRenderer->Clear(iRect.Size(), KRgbBlack);
       
   196     DrawEmptyListImpl_real(aClientRect, iTextRenderer->Gc(), aText, KRgbWhite);
       
   197     iTextRenderer->GetDrawBufferToVgImage(TRect(TPoint(0,0), iRect.Size()), 
       
   198             TPoint(0, 0), iTextImage, VG_A_8);
       
   199     iDirty = EFalse;
       
   200     Draw(aClientRect, 1.0f);
       
   201     }
       
   202 
       
   203 void CHgVgLabel::EnableLandscapeRendering(TBool enabled)
       
   204 {
       
   205     iLandscape = enabled;
       
   206 }
       
   207 
       
   208 
       
   209 // End of File