64
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 <alf/alfenv.h>
|
|
19 |
#include <alf/alftexture.h>
|
|
20 |
#include <StringLoader.h>
|
|
21 |
#include <alf/alfroster.h>
|
|
22 |
#include <alf/alftransformation.h>
|
|
23 |
|
|
24 |
|
|
25 |
//Events
|
|
26 |
#include <alf/alfevent.h>
|
|
27 |
|
|
28 |
//Layouts
|
|
29 |
#include <alf/alfdecklayout.h>
|
|
30 |
|
|
31 |
//Visuals
|
|
32 |
#include <alf/alftextvisual.h>
|
|
33 |
|
|
34 |
//Brushes
|
|
35 |
#include <alf/alfborderbrush.h>
|
|
36 |
#include <alf/alfimagebrush.h>
|
|
37 |
#include <alf/alfdropshadowbrush.h>
|
|
38 |
#include <alf/alfbrush.h>
|
|
39 |
#include <alf/alfbrusharray.h>
|
|
40 |
|
|
41 |
//Own
|
|
42 |
#include "alfexstickerlayout.h"
|
|
43 |
#include "alfexstickerscontrol.h"
|
|
44 |
#include <alfexstickers.rsg>
|
|
45 |
|
|
46 |
//TEMP
|
|
47 |
#include <alf/alfcontrol.h>
|
|
48 |
|
|
49 |
//Literals
|
|
50 |
|
|
51 |
|
|
52 |
//Constants
|
|
53 |
const TInt KXCoordinate = 30;
|
|
54 |
const TInt KYCoordinate = 30;
|
|
55 |
|
|
56 |
|
|
57 |
//Factory functions are not currently used
|
|
58 |
CAlfExStickerLayout* CAlfExStickerLayout::NewL(CAlfExStickersControl& aControl, CAlfEnv& aEnv)
|
|
59 |
{
|
|
60 |
CAlfExStickerLayout* self = new (ELeave) CAlfExStickerLayout;
|
|
61 |
CleanupStack::PushL(self);
|
|
62 |
self->ConstructL(aControl, aEnv);
|
|
63 |
CleanupStack::Pop();
|
|
64 |
return self;
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
CAlfExStickerLayout::CAlfExStickerLayout()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
void CAlfExStickerLayout::ConstructL(CAlfExStickersControl& aControl, CAlfEnv& aEnv)
|
|
74 |
{
|
|
75 |
iControl = &aControl;
|
|
76 |
iEnv = &aEnv;
|
|
77 |
}
|
|
78 |
|
|
79 |
|
|
80 |
CAlfExStickerLayout::~CAlfExStickerLayout()
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
void CAlfExStickerLayout::SetStickerPlaceL(CAlfExStickersControl* aControl)
|
|
86 |
{
|
|
87 |
// Create TAlfRealRect which contains TextVisual placement (KXCoordinate, KYCoordinate)
|
|
88 |
// and TextVisual size (KStickerWidth, KStickerHeight).
|
|
89 |
TAlfRealRect rect(TRect(TPoint(KXCoordinate, KYCoordinate), TSize(KStickerWidth, KStickerHeight)));
|
|
90 |
|
|
91 |
//Use SetRect function to set the afore mentioned placement and size
|
|
92 |
SetRect(rect);
|
|
93 |
|
|
94 |
//Get parent control
|
|
95 |
CAlfControl* control = aControl->GetControl();
|
|
96 |
|
|
97 |
//Add new text visual into the deck layout
|
|
98 |
iTextVisual = CAlfTextVisual::AddNewL(*control, this);
|
|
99 |
|
|
100 |
//Set the text visual to fill the same space as the deck layout
|
|
101 |
iTextVisual->SetRect(TAlfRealRect(TRect(TPoint(0, 0), TSize(KStickerWidth, KStickerHeight))));
|
|
102 |
|
|
103 |
//Set sticker size to small
|
|
104 |
iStickerIsLarge = ETrue;
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
void CAlfExStickerLayout::SetStickerTextContentL()
|
|
109 |
{
|
|
110 |
//Function is used to set text inside the text visual and to format it
|
|
111 |
//Set example text to sticker
|
|
112 |
iTextVisual->SetTextL(*StringLoader::LoadLC(R_ALFEXSTICKERS_DEFAULT_TEXT));
|
|
113 |
CleanupStack::PopAndDestroy(1);
|
|
114 |
|
|
115 |
//Set text to wrap so that the lines are broken to the visual's content area.
|
|
116 |
iTextVisual->SetWrapping(CAlfTextVisual::ELineWrapBreak);
|
|
117 |
|
|
118 |
//Set text color to black
|
|
119 |
iTextVisual->SetColor(KRgbBlack);
|
|
120 |
|
|
121 |
//Set line spacing
|
|
122 |
iTextVisual->EnableShadow(EFalse);
|
|
123 |
|
|
124 |
//Set predefined style for the text
|
|
125 |
iTextVisual->SetTextStyle( EAlfTextStyleSmall );
|
|
126 |
|
|
127 |
//Align the text content to visuals center, in both axis
|
|
128 |
iTextVisual->SetAlign(EAlfAlignHCenter, EAlfAlignVCenter);
|
|
129 |
|
|
130 |
//Add padding between text and visual border, 10 pixels to every side
|
|
131 |
iTextVisual->SetPadding(TAlfBoxMetric(10, 10, 10, 10));
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
void CAlfExStickerLayout::SetStickerDropShadowBrushL()
|
|
136 |
{
|
|
137 |
//First we must enable brushes
|
|
138 |
//NOTE: Before adding brushes to visual, EnableBrushesL() needs to be invoked or the application crashes
|
|
139 |
EnableBrushesL();
|
|
140 |
|
|
141 |
//Create Drop Shadow Brush, second parameter is the shadow size in pixels
|
|
142 |
CAlfDropShadowBrush* dropBrush = CAlfDropShadowBrush::NewLC(Env(), 5);
|
|
143 |
|
|
144 |
//Append the brush to the visual
|
|
145 |
Brushes()->AppendL(dropBrush, EAlfHasOwnership);
|
|
146 |
|
|
147 |
CleanupStack::Pop(1, dropBrush);
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
void CAlfExStickerLayout::SetStickerImageBrushL(CAlfTexture& aTexture)
|
|
152 |
{
|
|
153 |
//NOTE: Before adding brushes to visual, EnableBrushesL() needs to be invoked or the application crashes
|
|
154 |
|
|
155 |
//Create image brush using the texture from loaded above
|
|
156 |
CAlfImageBrush* imageBrush = CAlfImageBrush::NewLC(Env(), TAlfImage(aTexture));
|
|
157 |
|
|
158 |
//Set the image brush to background layer
|
|
159 |
imageBrush->SetLayer(EAlfBrushLayerBackground);
|
|
160 |
|
|
161 |
//Append the brush to the visual
|
|
162 |
Brushes()->AppendL(imageBrush, EAlfHasOwnership);
|
|
163 |
|
|
164 |
CleanupStack::Pop(1, imageBrush);
|
|
165 |
}
|
|
166 |
|
|
167 |
|
|
168 |
CAlfVisual* CAlfExStickerLayout::GetVisual() {
|
|
169 |
{
|
|
170 |
//Function return the text visual for the control, needed in event handling
|
|
171 |
return iTextVisual;
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
|
|
176 |
void CAlfExStickerLayout::ChangeStickerSizeL()
|
|
177 |
{
|
|
178 |
//Transformations need to be enabled or else the application crashes on scaling
|
|
179 |
iTextVisual->EnableTransformationL();
|
|
180 |
|
|
181 |
if (iStickerIsLarge)
|
|
182 |
{
|
|
183 |
//Timed values for scaling
|
|
184 |
TAlfTimedValue x;
|
|
185 |
TAlfTimedValue y;
|
|
186 |
|
|
187 |
//Set starting state scale
|
|
188 |
x.SetValueNow(1.0);
|
|
189 |
y.SetValueNow(1.0);
|
|
190 |
|
|
191 |
//Set scale target, halve the size and do it in 1000ms
|
|
192 |
x.SetTarget(0.5, 1000);
|
|
193 |
y.SetTarget(0.5, 1000);
|
|
194 |
|
|
195 |
//Resize the deck
|
|
196 |
SetSize(TAlfRealSize(150, 150), 1000);
|
|
197 |
|
|
198 |
//Scale the text visual
|
|
199 |
iTextVisual->Transformation().Scale(x, y);
|
|
200 |
|
|
201 |
iStickerIsLarge = EFalse;
|
|
202 |
}
|
|
203 |
else if (!iStickerIsLarge)
|
|
204 |
{
|
|
205 |
//Timed values for scaling
|
|
206 |
TAlfTimedValue x;
|
|
207 |
TAlfTimedValue y;
|
|
208 |
|
|
209 |
//Set starting state scale
|
|
210 |
x.SetValueNow(1.0);
|
|
211 |
y.SetValueNow(1.0);
|
|
212 |
|
|
213 |
//Set scale target, double the size and do it in 1000ms
|
|
214 |
x.SetTarget(2.0, 1000);
|
|
215 |
y.SetTarget(2.0, 1000);
|
|
216 |
|
|
217 |
//Scale the text visual
|
|
218 |
iTextVisual->Transformation().Scale(x, y);
|
|
219 |
|
|
220 |
//Resize the deck
|
|
221 |
SetSize(TAlfRealSize(300, 300), 1000);
|
|
222 |
|
|
223 |
iStickerIsLarge = ETrue;
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|