56
|
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(), EGray256);
|
|
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_8,
|
|
65 |
iRect.Width(), iRect.Height(),
|
|
66 |
VG_IMAGE_QUALITY_NONANTIALIASED);
|
|
67 |
|
|
68 |
if( iLetterImage == VG_INVALID_HANDLE )
|
|
69 |
{
|
|
70 |
User::Leave(KErrNoMemory);
|
|
71 |
}
|
|
72 |
|
|
73 |
iLetterBgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
|
|
74 |
1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL);
|
|
75 |
|
|
76 |
vguRoundRect(iLetterBgPath, 0, 0, iRect.Width(),
|
|
77 |
iRect.Height(), KLetterStripCurviness, KLetterStripCurviness);
|
|
78 |
|
|
79 |
iLetterBgPaint = vgCreatePaint();
|
|
80 |
|
|
81 |
vgSetParameteri(iLetterBgPaint, VG_PAINT_TYPE,
|
|
82 |
VG_PAINT_TYPE_COLOR);
|
|
83 |
|
|
84 |
vgSetParameterfv(iLetterBgPaint, VG_PAINT_COLOR, 4, KLetterStripColor);
|
|
85 |
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// CHgVgPopup::CHgVgPopup()
|
|
90 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
CHgVgPopup::CHgVgPopup( const TRect& aRect, const CFont* aFont) :
|
|
94 |
iRect(aRect),
|
|
95 |
iFont(aFont)
|
|
96 |
{
|
|
97 |
|
|
98 |
|
|
99 |
}
|
|
100 |
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
// CHgVgPopup::~CHgVgLetterStrip()
|
|
103 |
// Destructor.
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
CHgVgPopup::~CHgVgPopup ( )
|
|
107 |
{
|
|
108 |
|
|
109 |
delete iDrawBuffer;
|
|
110 |
|
|
111 |
delete iPrevText;
|
|
112 |
|
|
113 |
vgDestroyImage(iLetterImage);
|
|
114 |
|
|
115 |
vgDestroyPath(iLetterBgPath);
|
|
116 |
vgDestroyPaint(iLetterBgPaint);
|
|
117 |
|
|
118 |
}
|
|
119 |
|
|
120 |
// -----------------------------------------------------------------------------
|
|
121 |
// CHgVgPopup::SetLetter()
|
|
122 |
// -----------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
void CHgVgPopup::SetTextL(const TDesC& aText)
|
|
125 |
{
|
|
126 |
User::LeaveIfNull(iPrevText);
|
|
127 |
if (*iPrevText != aText)
|
|
128 |
{
|
|
129 |
delete iPrevText;
|
|
130 |
iPrevText = 0;
|
|
131 |
iPrevText = aText.AllocL();
|
|
132 |
iDrawBuffer->Clear(iRect.Size(), KRgbBlack);
|
|
133 |
|
|
134 |
TAknLayoutText layout;
|
|
135 |
layout.LayoutText( TRect(TPoint(0,0), iRect.Size()), iTextLayout);
|
|
136 |
layout.DrawText(iDrawBuffer->Gc(), aText, ETrue, KRgbWhite);
|
|
137 |
|
|
138 |
iDrawBuffer->GetDrawBufferToVgImage(TRect(TPoint(0,0), iRect.Size()), TPoint(0,0), iLetterImage, VG_A_8);
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
// CHgVgPopup::SetTexts()
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CHgVgPopup::SetTexts(const TDesC& aText1, const TDesC& aText2)
|
|
147 |
{
|
|
148 |
iDrawBuffer->Clear(iRect.Size(), KRgbBlack);
|
|
149 |
TInt w1 = iFont->TextWidthInPixels(aText1);
|
|
150 |
TInt w2 = iFont->TextWidthInPixels(aText2);
|
|
151 |
TInt height = iFont->HeightInPixels();
|
|
152 |
TPoint pos(iRect.Width() / 2 - w1 / 2, iRect.Height() / 2);
|
|
153 |
iDrawBuffer->Gc().DrawText(aText1, pos);
|
|
154 |
pos.iY += height;
|
|
155 |
pos.iX = iRect.Width() / 2 - w2 / 2;
|
|
156 |
iDrawBuffer->Gc().DrawText(aText2, pos);
|
|
157 |
iDrawBuffer->GetDrawBufferToVgImage(iRect.Size(), TPoint(0,0), iLetterImage, VG_A_8);
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
// CHgVgPopup::Draw()
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void CHgVgPopup::Draw(const TRect& aWindowRect, TReal aAlpha)
|
|
165 |
{
|
|
166 |
|
|
167 |
VGfloat w = iRect.Width();
|
|
168 |
VGfloat h = iRect.Height();
|
|
169 |
|
|
170 |
TRgb color;
|
|
171 |
AknsUtils::GetCachedColor(AknsUtils::SkinInstance(),
|
|
172 |
color,
|
|
173 |
KAknsIIDQsnTextColors,
|
|
174 |
EAknsCIQsnTextColorsCG6 );
|
|
175 |
|
|
176 |
TRgb bgColor(KRgbWhite);
|
|
177 |
if (color.Blue() > 128)
|
|
178 |
{
|
|
179 |
bgColor = KRgbBlack;
|
|
180 |
}
|
|
181 |
|
|
182 |
// draw background
|
|
183 |
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
|
|
184 |
vgLoadIdentity();
|
|
185 |
if (iLandscape)
|
|
186 |
{
|
|
187 |
vgTranslate(0.0f, 640.0f);
|
|
188 |
vgRotate(-90.0f);
|
|
189 |
}
|
|
190 |
|
|
191 |
vgTranslate(iRect.iTl.iX, (aWindowRect.Height() - iRect.iBr.iY));
|
|
192 |
|
|
193 |
VGfloat bgv[4];
|
|
194 |
bgv[0] = (VGfloat)bgColor.Red() / 255.0f;
|
|
195 |
bgv[1] = (VGfloat)bgColor.Green() / 255.0f;
|
|
196 |
bgv[2] = (VGfloat)bgColor.Blue() / 255.0f;
|
|
197 |
bgv[3] = aAlpha;
|
|
198 |
vgSetParameterfv(iLetterBgPaint, VG_PAINT_COLOR, 4, bgv);
|
|
199 |
|
|
200 |
vgSetPaint(iLetterBgPaint, VG_FILL_PATH);
|
|
201 |
vgDrawPath(iLetterBgPath, VG_FILL_PATH);
|
|
202 |
|
|
203 |
// draw letter
|
|
204 |
color.SetAlpha(aAlpha * 255.0f);
|
|
205 |
HgVgHelper::DrawImageColorized(iLetterImage,
|
|
206 |
color, iRect.iTl, aWindowRect, EFalse, iLandscape);
|
|
207 |
}
|
|
208 |
|
|
209 |
void CHgVgPopup::SetLayouts(const TAknWindowComponentLayout& aPopupLayout,
|
|
210 |
const TAknTextComponentLayout& aTextLayout, const TRect& aParentRect)
|
|
211 |
{
|
|
212 |
iPopupLayout = aPopupLayout;
|
|
213 |
iTextLayout = aTextLayout;
|
|
214 |
iTextLayout.Setr(0);
|
|
215 |
iTextLayout.Setl(0);
|
|
216 |
iTextLayout.Sett(0);
|
|
217 |
iParentRect = aParentRect;
|
|
218 |
}
|
|
219 |
|
|
220 |
void CHgVgPopup::EnableLandscapeRendering(TBool enabled)
|
|
221 |
{
|
|
222 |
iLandscape = enabled;
|
|
223 |
}
|
|
224 |
|
|
225 |
|
|
226 |
// End of File
|