uifw/ganes/src/HgVgLetterPopup.cpp
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     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 "HgVgLetterPopup.h"
       
    21 #include "HgVgDrawBuffer.h"
       
    22 #include "HgVgHelper.h"
       
    23 #include <VG/vgu.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 
       
    27 
       
    28 
       
    29 const VGfloat KLetterStripColor[] = { 0.2f, 0.2f, 0.2f, 0.8f };
       
    30 const VGfloat KLetterStripCurviness(10);
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 // -----------------------------------------------------------------------------
       
    35 // CHgVgPopup::NewL()
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CHgVgPopup* CHgVgPopup::NewL( const TRect& aRect, const CFont* aFont )
       
    40     {
       
    41     CHgVgPopup* self = new ( ELeave ) CHgVgPopup( aRect, aFont );
       
    42     CleanupStack::PushL (self );
       
    43     self->ConstructL( );
       
    44     CleanupStack::Pop ( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CHgVgPopup::ConstructL()
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CHgVgPopup::ConstructL (  )
       
    54     {
       
    55     iPrevText = ((TDesC)KNullDesC).AllocL();
       
    56 
       
    57     iDrawBuffer = CHgVgDrawBuffer::NewL(iRect.Size(), EGray2);
       
    58 
       
    59     iDrawBuffer->Gc().UseFont(iFont);
       
    60     iDrawBuffer->Gc().SetPenColor(KRgbWhite);
       
    61     iDrawBuffer->Gc().SetBrushColor(KRgbBlack);
       
    62     
       
    63     // Create VG Image to use
       
    64     iLetterImage = vgCreateImage(VG_A_1, 
       
    65             iRect.Width(), iRect.Height(), 
       
    66             VG_IMAGE_QUALITY_NONANTIALIASED);
       
    67 
       
    68     VGErrorCode error = vgGetError();
       
    69     
       
    70     if (iLetterImage == VG_INVALID_HANDLE || error == VG_OUT_OF_MEMORY_ERROR)
       
    71         {
       
    72         User::Leave(KErrNoMemory);
       
    73         }
       
    74         
       
    75     iLetterBgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 
       
    76             1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL);
       
    77             
       
    78     vguRoundRect(iLetterBgPath, 0, 0, iRect.Width(), 
       
    79             iRect.Height(), KLetterStripCurviness, KLetterStripCurviness);
       
    80     
       
    81     iLetterBgPaint = vgCreatePaint();
       
    82     
       
    83     vgSetParameteri(iLetterBgPaint, VG_PAINT_TYPE, 
       
    84         VG_PAINT_TYPE_COLOR);
       
    85     
       
    86     vgSetParameterfv(iLetterBgPaint, VG_PAINT_COLOR, 4, KLetterStripColor);
       
    87     
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CHgVgPopup::CHgVgPopup()
       
    92 // C++ default constructor can NOT contain any code, that might leave.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CHgVgPopup::CHgVgPopup( const TRect& aRect, const CFont* aFont) :
       
    96 iRect(aRect),
       
    97 iFont(aFont)
       
    98     {
       
    99 
       
   100 
       
   101     }
       
   102         
       
   103 // -----------------------------------------------------------------------------
       
   104 // CHgVgPopup::~CHgVgLetterStrip()
       
   105 // Destructor.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CHgVgPopup::~CHgVgPopup ( )
       
   109     {
       
   110 
       
   111     delete iDrawBuffer;
       
   112 
       
   113     delete iPrevText;
       
   114     
       
   115     vgDestroyImage(iLetterImage);
       
   116     
       
   117     vgDestroyPath(iLetterBgPath);    
       
   118     vgDestroyPaint(iLetterBgPaint);
       
   119     
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CHgVgPopup::SetLetter()
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CHgVgPopup::SetTextL(const TDesC& aText)
       
   127     {
       
   128     User::LeaveIfNull(iPrevText);
       
   129     if (*iPrevText != aText)
       
   130         {
       
   131         delete iPrevText;
       
   132         iPrevText = 0;
       
   133         iPrevText = aText.AllocL();
       
   134         iDrawBuffer->Clear(iRect.Size(), KRgbBlack);
       
   135         
       
   136         TAknLayoutText layout;
       
   137         layout.LayoutText(iParentRect, iTextLayout);
       
   138         layout.DrawText(iDrawBuffer->Gc(), aText, ETrue, KRgbWhite);
       
   139         
       
   140 /*        TInt width = iFont->TextWidthInPixels(aText);
       
   141         TInt height = iFont->HeightInPixels();
       
   142         TPoint pos(iRect.Width() / 2 - width / 2, 
       
   143                 iRect.Height() / 2 + height / 2);
       
   144         iDrawBuffer->DrawText(aText, iFont, KRgbWhite, pos);*/
       
   145         iDrawBuffer->GetDrawBufferToVgImage(iRect.Size(), TPoint(0,0), iLetterImage, VG_A_1);
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CHgVgPopup::SetTexts()
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CHgVgPopup::SetTexts(const TDesC& aText1, const TDesC& aText2)
       
   154     {
       
   155     iDrawBuffer->Clear(iRect.Size(), KRgbBlack);
       
   156     TInt w1 = iFont->TextWidthInPixels(aText1);
       
   157     TInt w2 = iFont->TextWidthInPixels(aText2);
       
   158     TInt height = iFont->HeightInPixels();
       
   159     TPoint pos(iRect.Width() / 2 - w1 / 2, iRect.Height() / 2);
       
   160     iDrawBuffer->Gc().DrawText(aText1, pos);
       
   161     pos.iY += height;
       
   162     pos.iX = iRect.Width() / 2 - w2 / 2;
       
   163     iDrawBuffer->Gc().DrawText(aText2, pos);
       
   164     iDrawBuffer->GetDrawBufferToVgImage(iRect.Size(), TPoint(0,0), iLetterImage, VG_A_1);    
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CHgVgPopup::Draw()
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CHgVgPopup::Draw(const TRect& aWindowRect, TReal aAlpha) 
       
   172     {
       
   173     
       
   174     VGfloat w = iRect.Width();
       
   175     VGfloat h = iRect.Height();
       
   176     
       
   177     TRgb color;
       
   178     AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), 
       
   179             color, 
       
   180             KAknsIIDQsnTextColors, 
       
   181             EAknsCIQsnTextColorsCG6 );
       
   182     
       
   183     TRgb bgColor(KRgbWhite);
       
   184     if (color.Blue() > 128)
       
   185         {
       
   186         bgColor = KRgbBlack;
       
   187         }
       
   188 
       
   189     // draw background     
       
   190     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
       
   191     vgLoadIdentity();
       
   192     
       
   193     vgTranslate(iRect.iTl.iX, (aWindowRect.Height() - iRect.iBr.iY));
       
   194 
       
   195     VGfloat bgv[4];
       
   196     bgv[0] = (VGfloat)bgColor.Red() / 255.0f;
       
   197     bgv[1] = (VGfloat)bgColor.Green() / 255.0f;
       
   198     bgv[2] = (VGfloat)bgColor.Blue() / 255.0f;    
       
   199     bgv[3] = aAlpha;
       
   200     vgSetParameterfv(iLetterBgPaint, VG_PAINT_COLOR, 4, bgv);
       
   201     
       
   202     vgSetPaint(iLetterBgPaint, VG_FILL_PATH);
       
   203     vgDrawPath(iLetterBgPath, VG_FILL_PATH);
       
   204 
       
   205     // draw letter
       
   206     color.SetAlpha(aAlpha * 255.0f);
       
   207     HgVgHelper::DrawImageColorized(iLetterImage, 
       
   208             color, iRect.iTl, aWindowRect, EFalse);
       
   209     }
       
   210 
       
   211 void CHgVgPopup::SetLayouts(const TAknWindowComponentLayout& aPopupLayout, 
       
   212         const TAknTextComponentLayout& aTextLayout, const TRect& aParentRect)
       
   213     {
       
   214     iPopupLayout = aPopupLayout;
       
   215     iTextLayout = aTextLayout;
       
   216     iTextLayout.Setl(0);
       
   217     iTextLayout.Sett(0);
       
   218     iParentRect = aParentRect;
       
   219     }
       
   220 
       
   221 
       
   222 // End of File