|
1 /* |
|
2 * Copyright (c) 2005-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: General functions |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef M2GUTILS_H |
|
19 #define M2GUTILS_H |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <gdi.h> // DisplayMode, Draw, BitBlt |
|
23 #include <fbs.h> // CFbsBitmap |
|
24 #include <mswtclient.h> |
|
25 #include "M2GGeneral.h" |
|
26 |
|
27 M2G_NS_START |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CFbsBitmapDevice; |
|
37 class CFbsBitGc; |
|
38 |
|
39 // FUNCTION PROTOTYPES |
|
40 |
|
41 // CLASS DECLARATION |
|
42 |
|
43 |
|
44 /** |
|
45 * @class M2GBitmapUtils |
|
46 * @brief Static methods for alpha blending and bitmaps |
|
47 */ |
|
48 class M2GBitmapUtils |
|
49 { |
|
50 public: // STATIC METHODS |
|
51 /** |
|
52 * Blits two bitmap |
|
53 * @since Series S60 3.0 |
|
54 * @param aTarget Target bitmap. |
|
55 * @param aSource Source bitmap. |
|
56 * @param aPoint Position for the top left corner of the bitmap. |
|
57 * @param aRect Rectangle defining the piece of the bitmap to be drawn. |
|
58 * @param aSourceMask Mask. |
|
59 * @return M2G_OK if ok |
|
60 */ |
|
61 static TInt BitBlt(CFbsBitmap& aTarget, |
|
62 const CFbsBitmap& aSource, |
|
63 const TPoint& aPoint, |
|
64 const TRect* aRect = NULL, |
|
65 const CFbsBitmap* aSourceMask = NULL); |
|
66 |
|
67 static TInt BitBlt(CBitmapContext& aTargetContext, |
|
68 const CFbsBitmap& aSource, |
|
69 const TPoint& aPoint, |
|
70 const TRect* aRect, |
|
71 const CFbsBitmap* aSourceMask, |
|
72 MSwtClient* aClientHandle, |
|
73 TBool aUseNativeClear = EFalse); |
|
74 /** |
|
75 * Checks if two bitmap are equal. |
|
76 * @since Series S60 3.0 |
|
77 * @param aLhs Left side bitmap |
|
78 * @param aRhs Right side bitmap |
|
79 * @return ETrue if bitmaps are equal. |
|
80 */ |
|
81 inline static TBool Equals(const CFbsBitmap& aLhs, const CFbsBitmap& aRhs) |
|
82 { |
|
83 return (aLhs.SizeInPixels() == aRhs.SizeInPixels()); |
|
84 } |
|
85 |
|
86 /** |
|
87 * Checks if a bitmap has same values as given values. |
|
88 * @since Series S60 3.0 |
|
89 * @param aBitmap Bitmap |
|
90 * @param aSz Size in pixels. |
|
91 * @param aMode Display mode. |
|
92 * @return ETrue if bitmaps are equal. |
|
93 */ |
|
94 inline static TBool Equals( |
|
95 const CFbsBitmap& aBitmap, |
|
96 const TSize& aSz, |
|
97 const TDisplayMode* aMode) |
|
98 { |
|
99 return (((aBitmap.SizeInPixels() == aSz) && |
|
100 ((aMode == NULL) || (aBitmap.DisplayMode() == *aMode)) |
|
101 ) ? ETrue : EFalse); |
|
102 } |
|
103 |
|
104 /** |
|
105 * Return byte per pixel |
|
106 * @since Series S60 3.1 |
|
107 * @param aBitmap |
|
108 * @param aRhs Right side bitmap |
|
109 * @return ETrue if bitmaps are equal. |
|
110 */ |
|
111 inline static TInt BytesPerPixel(const CFbsBitmap& aBitmap) |
|
112 { |
|
113 switch (aBitmap.DisplayMode()) |
|
114 { |
|
115 case EGray256 : |
|
116 case EColor256 : |
|
117 return 1; |
|
118 case EColor64K : |
|
119 return 2; |
|
120 case EColor16M : |
|
121 case EColor16MU : |
|
122 case EColor16MA : |
|
123 return 4; |
|
124 default : |
|
125 return 0; |
|
126 } |
|
127 } |
|
128 |
|
129 }; |
|
130 |
|
131 /** |
|
132 * @class TM2GRenderRect |
|
133 * @brief Class for handling rendering rectangle |
|
134 */ |
|
135 class TM2GRenderRect : public TRect |
|
136 { |
|
137 private: |
|
138 // NOTE ELength should be always the last one and indexing |
|
139 // should start from 0 |
|
140 enum TArrayIndexes |
|
141 { |
|
142 EAnchorX = 0, |
|
143 EAnchorY = 1, |
|
144 EClipX = 2, |
|
145 EClipY = 3, |
|
146 EClipW = 4, |
|
147 EClipH = 5, |
|
148 ELength |
|
149 }; |
|
150 |
|
151 public: // METHODS |
|
152 /** |
|
153 * Ctor |
|
154 * @since Series S60 3.0 |
|
155 * @param aAnchorX X anchor |
|
156 * @param aAnchorY Y anchor |
|
157 * @param aClipX Clip x |
|
158 * @param aClipY Clip y |
|
159 * @param aClipWidth Clip width |
|
160 * @param aClipHeight Clip height |
|
161 */ |
|
162 TM2GRenderRect( |
|
163 TInt aAnchorX, TInt aAnchorY, |
|
164 TInt aClipX, TInt aClipY, |
|
165 TInt aClipW, TInt aClipH); |
|
166 |
|
167 /** |
|
168 * Ctor |
|
169 * @since Series S60 3.0 |
|
170 * @param aDimensions Dimensions. @see TArrayIndexes. |
|
171 * @param aLength Array length |
|
172 */ |
|
173 TM2GRenderRect(TInt* aDimensions, TInt aLength); |
|
174 |
|
175 /** |
|
176 * Copy ctor |
|
177 * @since Series S60 3.0 |
|
178 * @param aRd |
|
179 */ |
|
180 TM2GRenderRect(const TM2GRenderRect& aRd); |
|
181 |
|
182 /** |
|
183 * Assignment operator |
|
184 * @since Series S60 3.0 |
|
185 * @param aRd |
|
186 * @return TM2GRenderRect |
|
187 */ |
|
188 TM2GRenderRect& operator=(const TM2GRenderRect& aRd); |
|
189 |
|
190 /** |
|
191 * Dtor |
|
192 * @since Series S60 3.0 |
|
193 */ |
|
194 virtual ~TM2GRenderRect(); |
|
195 |
|
196 /** |
|
197 * Returns x anchor |
|
198 * @since Series S60 3.0 |
|
199 * @return X anchor |
|
200 */ |
|
201 inline TInt GetAnchorX() |
|
202 { |
|
203 return iAnchorX; |
|
204 } |
|
205 |
|
206 /** |
|
207 * Returns y anchor |
|
208 * @since Series S60 3.0 |
|
209 * @return Y anchor |
|
210 */ |
|
211 inline TInt GetAnchorY() |
|
212 { |
|
213 return iAnchorY; |
|
214 } |
|
215 |
|
216 /** |
|
217 * Returns clip height |
|
218 * @since Series S60 3.0 |
|
219 * @return Clip height |
|
220 */ |
|
221 inline TInt GetClipH() |
|
222 { |
|
223 return Height(); |
|
224 } |
|
225 |
|
226 /** |
|
227 * Returns x clip |
|
228 * @since Series S60 3.0 |
|
229 * @return X clip |
|
230 */ |
|
231 inline TInt GetClipX() |
|
232 { |
|
233 return iTl.iX; |
|
234 } |
|
235 |
|
236 /** |
|
237 * Returns y clip |
|
238 * @since Series S60 3.0 |
|
239 * @return Y clip |
|
240 */ |
|
241 inline TInt GetClipY() |
|
242 { |
|
243 return iTl.iY; |
|
244 } |
|
245 |
|
246 /** |
|
247 * Returns clip width |
|
248 * @since Series S60 3.0 |
|
249 * @return Clip width |
|
250 */ |
|
251 inline TInt GetClipW() |
|
252 { |
|
253 return Width(); |
|
254 } |
|
255 |
|
256 /** |
|
257 * Sets x anchor |
|
258 * @since Series S60 3.0 |
|
259 * @param aX X anchor |
|
260 */ |
|
261 inline void SetAnchorX(TInt aX) |
|
262 { |
|
263 iAnchorX = aX; |
|
264 } |
|
265 |
|
266 /** |
|
267 * Sets y anchor |
|
268 * @since Series S60 3.0 |
|
269 * @param aY Y anchor |
|
270 */ |
|
271 inline void SetAnchorY(TInt aY) |
|
272 { |
|
273 iAnchorY = aY; |
|
274 } |
|
275 |
|
276 /** |
|
277 * Sets clip height |
|
278 * @since Series S60 3.0 |
|
279 * @param aH Clip height |
|
280 */ |
|
281 inline void SetClipH(TInt aH) |
|
282 { |
|
283 SetHeight(aH); |
|
284 } |
|
285 |
|
286 /** |
|
287 * Sets x clip |
|
288 * @since Series S60 3.0 |
|
289 * @param aX X clip |
|
290 */ |
|
291 inline void SetClipX(TInt aX) |
|
292 { |
|
293 iTl.iX = aX; |
|
294 } |
|
295 |
|
296 /** |
|
297 * Sets y clip |
|
298 * @since Series S60 3.0 |
|
299 * @param aY Y clip |
|
300 */ |
|
301 inline void SetClipY(TInt aY) |
|
302 { |
|
303 iTl.iY = aY; |
|
304 } |
|
305 |
|
306 /** |
|
307 * Sets clip width |
|
308 * @since Series S60 3.0 |
|
309 * @param aW Clip width |
|
310 */ |
|
311 inline void SetClipW(TInt aW) |
|
312 { |
|
313 SetWidth(aW); |
|
314 } |
|
315 |
|
316 public: // STATIC METHODS |
|
317 /** |
|
318 * Gets region size |
|
319 * @since Series S60 3.0 |
|
320 * @param aRect Render dimensions |
|
321 * @param aSz Source surface size |
|
322 * @return Region size to be paint |
|
323 */ |
|
324 static TSize GetRegionSizeInPixels( |
|
325 TM2GRenderRect& aRect, |
|
326 const TSize& aSz); |
|
327 |
|
328 public: // VARIABLES |
|
329 TInt iAnchorX; |
|
330 TInt iAnchorY; |
|
331 }; |
|
332 |
|
333 |
|
334 /** |
|
335 * @class TM2GBitmapLock |
|
336 * @brief Bitmap autolocker |
|
337 */ |
|
338 class TM2GBitmapLock |
|
339 { |
|
340 public: // METHODS |
|
341 /** |
|
342 * Ctor |
|
343 * @param aBitmap Bitmap |
|
344 * @param aLock If ETrue then bitmap is locked by ctor. |
|
345 */ |
|
346 TM2GBitmapLock(const CFbsBitmap* aBitmap, TBool aLock = ETrue); |
|
347 |
|
348 /** |
|
349 * Dtor |
|
350 * @since Series S60 3.0 |
|
351 */ |
|
352 virtual ~TM2GBitmapLock(); |
|
353 |
|
354 /** |
|
355 * Locks bitmap heap |
|
356 * @since Series S60 3.0 |
|
357 */ |
|
358 void Lock(); |
|
359 |
|
360 /** |
|
361 * Unlocks bitmap heap |
|
362 * @since Series S60 3.0 |
|
363 */ |
|
364 void Unlock(); |
|
365 |
|
366 protected: // METHODS |
|
367 /** |
|
368 * Copy ctor |
|
369 * @since Series S60 3.0 |
|
370 * @param aRd |
|
371 */ |
|
372 TM2GBitmapLock(const TM2GBitmapLock& aRd); |
|
373 |
|
374 /** |
|
375 * Assignment operator |
|
376 * @since Series S60 3.0 |
|
377 * @param aRd |
|
378 * @return TM2GBitmapLock |
|
379 */ |
|
380 TM2GBitmapLock& operator=(const TM2GBitmapLock& aRd); |
|
381 |
|
382 public: // VARIABLES |
|
383 const CFbsBitmap* iBitmap; |
|
384 TBool iIsLocked; |
|
385 }; |
|
386 class TSWTBitBlt: public MSwtFunctor |
|
387 { |
|
388 public: |
|
389 TSWTBitBlt(CBitmapContext& aTargetContext, |
|
390 const TPoint& aPoint, |
|
391 const CFbsBitmap* aBitmap, |
|
392 const TRect* aSourceRect, |
|
393 const CFbsBitmap* aMaskBitmap, |
|
394 TBool aUseNativeClear); |
|
395 |
|
396 void operator()() const; |
|
397 CBitmapContext& iTargetContext; |
|
398 const TPoint iPoint; |
|
399 const CFbsBitmap* iBitmap; |
|
400 const TRect* iRect; |
|
401 const CFbsBitmap* iMaskBitmap; |
|
402 TBool iUseNativeClear; |
|
403 }; |
|
404 M2G_NS_END |
|
405 |
|
406 |
|
407 #endif // M2GUTILS_H |