uifw/ganes/src/HgVgLabel.cpp
changeset 0 2f259fa3e83a
child 5 aabf2c525e0f
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 CFont* aFont, const TDesC& aText)
       
    47     {
       
    48     CHgVgLabel* self = new ( ELeave ) CHgVgLabel(aRect, aFont);
       
    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(), EGray2);
       
    65         
       
    66     iTextImage = vgCreateImage(VG_A_1, 
       
    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, const CFont* aFont) : 
       
   104 iRect(aRect),
       
   105 iFont(aFont),
       
   106 iTextColor(KRgbDarkGray),
       
   107 iShadowColor(KRgbBlack),
       
   108 iDirty(ETrue)
       
   109     {
       
   110     
       
   111     }
       
   112         
       
   113 // -----------------------------------------------------------------------------
       
   114 // CHgVgTitleRenderer::~CHgVgTitleRenderer()
       
   115 // Destructor.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CHgVgLabel::~CHgVgLabel ( )
       
   119     {
       
   120     delete iText;
       
   121     delete iTextRenderer;    
       
   122     // then parent
       
   123     vgDestroyImage(iTextImage);
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CHgVgLabel::SetText()
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CHgVgLabel::SetTextL(const TDesC& aText)
       
   131     {
       
   132     if (aText != *iText)
       
   133         {
       
   134         delete iText;
       
   135         iText = 0;
       
   136         iText = aText.AllocL();
       
   137         iDirty = ETrue;
       
   138         }
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CHgVgLabel::SetFont()
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CHgVgLabel::SetFont(const CFont* aFont)
       
   146     {
       
   147     if (aFont != iFont)
       
   148         {
       
   149         iFont = aFont;
       
   150         iDirty = ETrue;
       
   151         }
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CHgVgLabel::SetColor()
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CHgVgLabel::SetColor(const TRgb& aColor)
       
   159     {
       
   160     iTextColor = aColor;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CHgVgLabel::SetColor()
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CHgVgLabel::SetShadowColor(const TRgb& aColor)
       
   168     {
       
   169     iShadowColor = aColor;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CHgVgLabel::Draw()
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CHgVgLabel::Draw(const TRect& aWindowRect, TReal aAlpha)
       
   177     {
       
   178     if (iDirty)
       
   179         {
       
   180         Update();
       
   181         iDirty = EFalse;
       
   182         }
       
   183     
       
   184     TRgb color = iTextColor;
       
   185     color.SetAlpha(255.0f * aAlpha);
       
   186     TRgb shadowColor = iShadowColor;
       
   187     shadowColor.SetAlpha(255.0f * aAlpha);
       
   188 
       
   189     //HgVgHelper::DrawImageColorized(iTextImage, shadowColor, iRect.iTl+TPoint(1,1), aWindowRect);    
       
   190     HgVgHelper::DrawImageColorized(iTextImage, color, iRect.iTl, aWindowRect);    
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CHgVgLabel::Update()
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CHgVgLabel::Update()
       
   198     {
       
   199     iTextRenderer->Clear(iRect.Size(), KRgbBlack);
       
   200 /*    iTextRenderer->Gc().SetPenColor(KRgbWhite);    
       
   201         
       
   202     iTextRenderer->Gc().UseFont(iFont);
       
   203     iTextRenderer->Gc().DrawText(*iText, TPoint(
       
   204             iRect.Width() / 2 - iFont->TextWidthInPixels(*iText) / 2, 
       
   205             iFont->HeightInPixels()));
       
   206 */
       
   207     TAknLayoutText text;
       
   208             
       
   209     text.LayoutText(iParentRect, iLayout);
       
   210     text.DrawText(iTextRenderer->Gc(), *iText, ETrue, KRgbWhite);
       
   211     
       
   212     iTextRenderer->GetDrawBufferToVgImage(TRect(TPoint(0,0), iRect.Size()), 
       
   213             TPoint(0, 0), iTextImage, VG_A_1);    
       
   214     }
       
   215 
       
   216 
       
   217 void CHgVgLabel::SetLayout(const TAknTextComponentLayout& aLayout, const TRect& aParentRect)
       
   218     {
       
   219     iLayout = aLayout;
       
   220     iLayout.Sett(0);
       
   221     iLayout.Setl(0);
       
   222     iParentRect = aParentRect;
       
   223     }
       
   224 
       
   225 void CHgVgLabel::DrawEmptyText(const TRect& aClientRect, const TDesC& aText)
       
   226     {
       
   227     iTextRenderer->Clear(iRect.Size(), KRgbBlack);
       
   228     DrawEmptyListImpl_real(aClientRect, iTextRenderer->Gc(), aText, KRgbWhite);
       
   229     iTextRenderer->GetDrawBufferToVgImage(TRect(TPoint(0,0), iRect.Size()), 
       
   230             TPoint(0, 0), iTextImage, VG_A_1);
       
   231     iDirty = EFalse;
       
   232     Draw(aClientRect, 1.0f);
       
   233     }
       
   234 
       
   235 
       
   236 
       
   237 // End of File