|
1 /* |
|
2 * Copyright (c) 2006 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: Image brush |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alf/alfimagebrush.h" |
|
21 #include "alf/alfimage.h" |
|
22 #include "alf/alftexture.h" |
|
23 #include "alf/alfenv.h" |
|
24 #include "alf/alfgencomponent.h" |
|
25 #include "alflogger.h" |
|
26 #include "alfskinnableimage.h" |
|
27 #include "alf/alfconstants.h" |
|
28 |
|
29 #include <uiacceltk/HuiUtil.h> |
|
30 |
|
31 // Private data structure |
|
32 struct CAlfImageBrush::TImageBrushPrivateData |
|
33 { |
|
34 CAlfSkinnableImage* iImage; // owned |
|
35 TInt iLeftBorderWidth; |
|
36 TInt iRightBorderWidth; |
|
37 TInt iTopBorderWidth; |
|
38 TInt iBottomBorderWidth; |
|
39 TAlfTimedPoint iOffset; |
|
40 TAlfTimedValue iScale; |
|
41 }; |
|
42 |
|
43 |
|
44 // ======== MEMBER FUNCTIONS ======== |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Constructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CAlfImageBrush::CAlfImageBrush() |
|
51 : CAlfBrush() |
|
52 { |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // ConstructL |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void CAlfImageBrush::ConstructL(CAlfEnv& aEnv, const TAlfImage & aImage) |
|
61 { |
|
62 iImageBrushData = new (ELeave) TImageBrushPrivateData; |
|
63 iImageBrushData->iImage = NULL; |
|
64 iImageBrushData->iImage = new (ELeave) CAlfSkinnableImage(&aEnv); |
|
65 iImageBrushData->iImage->SetImage(aImage); // This texturizes skin graphics if needed |
|
66 iImageBrushData->iLeftBorderWidth = 0; |
|
67 iImageBrushData->iRightBorderWidth = 0; |
|
68 iImageBrushData->iTopBorderWidth = 0; |
|
69 iImageBrushData->iBottomBorderWidth = 0; |
|
70 |
|
71 TAlfImageBrushParams params; |
|
72 params.iTextureHandle = iImageBrushData->iImage->Image().Texture().ServerHandle(); |
|
73 params.iTl = aImage.TimedTopLeft(); |
|
74 params.iBr = aImage.TimedBottomRight(); |
|
75 params.iLeftBorderWidth = iImageBrushData->iLeftBorderWidth; |
|
76 params.iRightBorderWidth = iImageBrushData->iRightBorderWidth; |
|
77 params.iTopBorderWidth = iImageBrushData->iTopBorderWidth; |
|
78 params.iBottomBorderWidth = iImageBrushData->iBottomBorderWidth; |
|
79 |
|
80 TPckgC<TAlfImageBrushParams> paramsPckg(params); |
|
81 |
|
82 CAlfBrush::ConstructL( |
|
83 aEnv, |
|
84 EAlfImageBrushCreate, |
|
85 0, |
|
86 paramsPckg |
|
87 ); |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Constructor |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CAlfImageBrush* CAlfImageBrush::NewL(CAlfEnv& aEnv, |
|
96 const TAlfImage & aImage) |
|
97 { |
|
98 CAlfImageBrush* self = CAlfImageBrush::NewLC( aEnv, aImage ); |
|
99 CleanupStack::Pop( self ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // Constructor |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C CAlfImageBrush* CAlfImageBrush::NewLC(CAlfEnv& aEnv, |
|
109 const TAlfImage & aImage) |
|
110 { |
|
111 CAlfImageBrush* self = new( ELeave ) CAlfImageBrush; |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL(aEnv, aImage); |
|
114 return self; |
|
115 } |
|
116 |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Destructor. |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 CAlfImageBrush::~CAlfImageBrush() |
|
123 { |
|
124 if ( iImageBrushData ) |
|
125 { |
|
126 delete iImageBrushData->iImage; |
|
127 iImageBrushData->iImage = NULL; |
|
128 } |
|
129 delete iImageBrushData; |
|
130 iImageBrushData = NULL; |
|
131 } |
|
132 |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // Set image |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C void CAlfImageBrush::SetImage(const TAlfImage& aImage) |
|
139 { |
|
140 iImageBrushData->iImage->SetImage(aImage); // This texturizes skin graphics if needed |
|
141 |
|
142 TAlfImageBrushParams params; |
|
143 params.iTextureHandle = aImage.Texture().ServerHandle(); |
|
144 params.iTl = aImage.TimedTopLeft(); |
|
145 params.iBr = aImage.TimedBottomRight(); |
|
146 params.iLeftBorderWidth = iImageBrushData->iLeftBorderWidth; |
|
147 params.iRightBorderWidth = iImageBrushData->iRightBorderWidth; |
|
148 params.iTopBorderWidth = iImageBrushData->iTopBorderWidth; |
|
149 params.iBottomBorderWidth = iImageBrushData->iBottomBorderWidth; |
|
150 TPckgC<TAlfImageBrushParams> paramsPckg(params); |
|
151 |
|
152 TInt err = Comms()->DoCmdNoReply(EAlfImageBrushSetImage, paramsPckg); |
|
153 |
|
154 if ( err ) |
|
155 { |
|
156 __ALFLOGSTRING1( "CAlfImageBrush::SetImage ignore error %d", err ) |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // Get image |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C const TAlfImage& CAlfImageBrush::Image() const |
|
165 { |
|
166 return iImageBrushData->iImage->Image(); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CAlfImageBrush::SetBorders(TInt aLeftBorderWidth, |
|
174 TInt aRightBorderWidth, |
|
175 TInt aTopBorderHeight, |
|
176 TInt aBottomBorderHeight) |
|
177 { |
|
178 iImageBrushData->iLeftBorderWidth = aLeftBorderWidth; |
|
179 iImageBrushData->iRightBorderWidth = aRightBorderWidth; |
|
180 iImageBrushData->iTopBorderWidth = aTopBorderHeight; |
|
181 iImageBrushData->iBottomBorderWidth = aBottomBorderHeight; |
|
182 |
|
183 TAlfImageBrushParams params; |
|
184 params.iLeftBorderWidth = iImageBrushData->iLeftBorderWidth; |
|
185 params.iRightBorderWidth = iImageBrushData->iRightBorderWidth; |
|
186 params.iTopBorderWidth = iImageBrushData->iTopBorderWidth; |
|
187 params.iBottomBorderWidth = iImageBrushData->iBottomBorderWidth; |
|
188 TPckgC<TAlfImageBrushParams> paramsPckg(params); |
|
189 |
|
190 TInt err = Comms()->DoCmdNoReply(EAlfImageBrushSetBorders, paramsPckg); |
|
191 |
|
192 if ( err ) |
|
193 { |
|
194 __ALFLOGSTRING1( "CAlfImageBrush::SetBorders ignore error %d", err ) |
|
195 } |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C TBool CAlfImageBrush::BorderDrawingEnabled() const |
|
203 { |
|
204 return ((iImageBrushData->iLeftBorderWidth!=0) || (iImageBrushData->iRightBorderWidth!=0) |
|
205 || (iImageBrushData->iTopBorderWidth!=0) || (iImageBrushData->iBottomBorderWidth!=0)); |
|
206 |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C TBool CAlfImageBrush::CenterDrawingEnabled() const |
|
214 { |
|
215 if(!iImageBrushData->iImage->Image().HasTexture()) |
|
216 { |
|
217 return EFalse; |
|
218 } |
|
219 // determine if there are center pixels available inside borders |
|
220 // if not, we can't draw the center.. |
|
221 TSize imageSize = iImageBrushData->iImage->Image().Texture().Size(); |
|
222 if((imageSize.iWidth - iImageBrushData->iLeftBorderWidth - iImageBrushData->iRightBorderWidth <= 0) |
|
223 || (imageSize.iHeight - iImageBrushData->iTopBorderWidth - iImageBrushData->iBottomBorderWidth <= 0)) |
|
224 { |
|
225 return EFalse; |
|
226 } |
|
227 |
|
228 return ETrue; |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Set scale mode for the image brush |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C void CAlfImageBrush::SetScaleMode(CAlfImageVisual::TScaleMode aScaleMode) |
|
236 { |
|
237 TPckgC<TInt> paramsPckg(aScaleMode); |
|
238 |
|
239 TInt err = Comms()->DoCmdNoReply(EAlfImageBrushSetScaleMode, paramsPckg ); |
|
240 |
|
241 if ( err ) |
|
242 { |
|
243 __ALFLOGSTRING1( "CAlfImageBrush::SetScaleMode panic error %d", err ) |
|
244 USER_INVARIANT(); |
|
245 } |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Sets offfset for the image |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void CAlfImageBrush::SetOffset(const TAlfTimedPoint& aOffset) |
|
253 { |
|
254 iImageBrushData->iOffset.iX = aOffset.iX; |
|
255 iImageBrushData->iOffset.iY = aOffset.iY; |
|
256 |
|
257 |
|
258 TPckgC<TAlfTimedPoint> offsetPckg(iImageBrushData->iOffset); |
|
259 |
|
260 TInt err = Comms()->DoCmdNoReply(EAlfImageBrushSetOffset, offsetPckg); |
|
261 |
|
262 if ( err ) |
|
263 { |
|
264 __ALFLOGSTRING1( "CAlfImageBrush::SetOffset panic error %d", err ) |
|
265 USER_INVARIANT(); |
|
266 } |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // Returns the offset |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 EXPORT_C const TAlfTimedPoint& CAlfImageBrush::Offset() const |
|
274 { |
|
275 TPckg<TAlfTimedPoint> offsetPckg(iImageBrushData->iOffset); |
|
276 |
|
277 TInt err = Comms()->DoSynchronousCmd(EAlfImageBrushOffset, KNullDesC8, offsetPckg); |
|
278 |
|
279 if ( err ) |
|
280 { |
|
281 __ALFLOGSTRING1( "CAlfImageBrush::Offset ignore error %d", err ) |
|
282 } |
|
283 |
|
284 return iImageBrushData->iOffset; |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // Sets scale factor |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 EXPORT_C void CAlfImageBrush::SetScale(const TAlfTimedValue& aScale) |
|
292 { |
|
293 TPckgC<TAlfTimedValue> buf(aScale); |
|
294 |
|
295 TInt err = Comms()->DoCmdNoReply( EAlfImageBrushSetScale, buf ); |
|
296 |
|
297 if ( err == KErrNone ) |
|
298 { |
|
299 iImageBrushData->iScale = aScale; |
|
300 } |
|
301 else |
|
302 { |
|
303 __ALFLOGSTRING1( "CAlfImageBrush::SetScale panic error %d", err ) |
|
304 USER_INVARIANT(); |
|
305 } |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Returns scale factor |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C const TAlfTimedValue& CAlfImageBrush::Scale() const |
|
313 { |
|
314 TPckg<TAlfTimedValue> buf(iImageBrushData->iScale); |
|
315 TInt err = Comms()->DoSynchronousCmd( EAlfImageBrushScale, KNullDesC8, buf); |
|
316 |
|
317 if ( err != KErrNone ) |
|
318 { |
|
319 __ALFLOGSTRING1( "CAlfImageBrush::Scale panic error %d", err ) |
|
320 USER_INVARIANT(); |
|
321 } |
|
322 |
|
323 return iImageBrushData->iScale; |
|
324 } |