|
1 /* |
|
2 * Copyright (c) 2004, 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "bitmapmethods.h" |
|
22 |
|
23 #include <eikenv.h> |
|
24 #include <fbs.h> |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS ============================== |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // NBitmapMethods::CreateGraphicsContextLC() |
|
30 // Create a graphics context and leave it on the cleanup stack. |
|
31 // ---------------------------------------------------------------------------- |
|
32 // |
|
33 CFbsBitGc* NBitmapMethods |
|
34 ::CreateGraphicsContextLC( CFbsBitmapDevice& aBitmapDevice ) |
|
35 { |
|
36 CFbsBitGc* graphicsContext = NULL; |
|
37 User::LeaveIfError( aBitmapDevice.CreateContext( graphicsContext ) ); |
|
38 CleanupStack::PushL( graphicsContext ); |
|
39 return graphicsContext; |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // NBitmapMethods::CreateGraphicsContextL() |
|
44 // Create a graphics context. |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CFbsBitGc* NBitmapMethods |
|
48 ::CreateGraphicsContextL( CFbsBitmapDevice& aBitmapDevice ) |
|
49 { |
|
50 CFbsBitGc* gc = CreateGraphicsContextLC( aBitmapDevice ); |
|
51 CleanupStack::Pop( gc ); |
|
52 return gc; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // NBitmapMethods::CreateBitmapDeviceLC() |
|
57 // Create a bitmap device and leave it on the cleanup stack. |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CFbsBitmapDevice* NBitmapMethods::CreateBitmapDeviceLC( CFbsBitmap& aBitmap ) |
|
61 { |
|
62 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( &aBitmap ); |
|
63 CleanupStack::PushL( bitmapDevice ); |
|
64 return bitmapDevice; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // NBitmapMethods::CreateBitmapDeviceL() |
|
69 // Create a bitmap device. |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CFbsBitmapDevice* NBitmapMethods::CreateBitmapDeviceL( CFbsBitmap& aBitmap ) |
|
73 { |
|
74 CFbsBitmapDevice* device = CreateBitmapDeviceLC( aBitmap ); |
|
75 CleanupStack::Pop( device ); |
|
76 return device; |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // NBitmapMethods::CreateBitmapLC() |
|
81 // Create a bitmap and leave it on the cleanup stack. |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 CFbsBitmap* NBitmapMethods |
|
85 ::CreateBitmapLC( TSize aSizeInPixels, TDisplayMode aDispMode ) |
|
86 { |
|
87 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap(); |
|
88 CleanupStack::PushL( bitmap ); |
|
89 User::LeaveIfError( bitmap->Create( aSizeInPixels,aDispMode ) ); |
|
90 ASSERT( ( bitmap->DisplayMode() == KColourDepth ) |
|
91 || ( bitmap->DisplayMode() == EGray2 ) ); |
|
92 return bitmap; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // NBitmapMethods::CreateBitmapL() |
|
97 // Create a bitmap. |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 CFbsBitmap* NBitmapMethods |
|
101 ::CreateBitmapL( TSize aSizeInPixels, TDisplayMode aDispMode ) |
|
102 { |
|
103 CFbsBitmap* bitmap = CreateBitmapLC( aSizeInPixels, aDispMode ); |
|
104 CleanupStack::Pop( bitmap ); |
|
105 return bitmap; |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // NBitmapMethods::CreateBitmapLC() |
|
110 // Create a bitmap and leave it on the cleanup stack. |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 CFbsBitmap* NBitmapMethods::CreateBitmapLC( const TDesC& aFileName, TInt aId ) |
|
114 { |
|
115 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap(); |
|
116 |
|
117 CleanupStack::PushL( bitmap ); |
|
118 TInt loadException = bitmap->Load( aFileName, aId ); |
|
119 User::LeaveIfError( loadException ); |
|
120 |
|
121 if ( ( bitmap->DisplayMode() == KColourDepth ) |
|
122 || ( bitmap->DisplayMode() == EGray2 ) ) |
|
123 { |
|
124 return bitmap; |
|
125 } |
|
126 else |
|
127 { |
|
128 CFbsBitmap* newBitmap = CreateBitmapLC( bitmap->SizeInPixels(), |
|
129 KColourDepth ); |
|
130 |
|
131 CFbsBitmapDevice* bitmapDevice = CreateBitmapDeviceLC( *newBitmap ); |
|
132 CFbsBitGc* bitmapGc = CreateGraphicsContextLC( *bitmapDevice ); |
|
133 bitmapGc->BitBlt( TPoint( 0,0 ), |
|
134 bitmap, TRect( bitmap->SizeInPixels() ) ); |
|
135 CleanupStack::PopAndDestroy( 2 ); // gc and device |
|
136 // The next three lines are here to get rid |
|
137 // of the old bitmap but keep the new one |
|
138 CleanupStack::Pop( newBitmap ); |
|
139 CleanupStack::PopAndDestroy( bitmap ); |
|
140 CleanupStack::PushL( newBitmap ); |
|
141 |
|
142 return newBitmap; |
|
143 } |
|
144 } |
|
145 |
|
146 // ---------------------------------------------------------------------------- |
|
147 // NBitmapMethods::CreateBitmapL() |
|
148 // Create a bitmap. |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 CFbsBitmap* NBitmapMethods::CreateBitmapL( const TDesC& aFileName, TInt aId ) |
|
152 { |
|
153 CFbsBitmap* bitmap = CreateBitmapLC( aFileName, aId ); |
|
154 CleanupStack::Pop( bitmap ); |
|
155 return bitmap; |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // NBitmapMethods::BitBltMaskedEntireBitmap() |
|
160 // Blit the entire of a bitmap with a mask onto a gc. |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void NBitmapMethods::BitBltMaskedEntireBitmap( CFbsBitGc& aTargetGc, |
|
164 TPoint aTopLeft, |
|
165 const CFbsBitmap& aBitmap, |
|
166 const CFbsBitmap& aBitMask ) |
|
167 { |
|
168 PartialReset( aTargetGc ); |
|
169 aTargetGc.BitBltMasked( aTopLeft, |
|
170 &aBitmap, |
|
171 aBitmap.SizeInPixels(), |
|
172 &aBitMask, |
|
173 ETrue ); |
|
174 PartialReset( aTargetGc ); |
|
175 } |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // NBitmapMethods::PartialReset() |
|
179 // Reset a gc. |
|
180 // ---------------------------------------------------------------------------- |
|
181 // |
|
182 void NBitmapMethods::PartialReset( CFbsBitGc& aGc ) |
|
183 { |
|
184 aGc.SetPenSize( TSize( 1,1 ) ); |
|
185 aGc.SetPenColor( KRgbBlack ); |
|
186 aGc.SetPenStyle( CFbsBitGc::ESolidPen ); |
|
187 aGc.SetDrawMode( CFbsBitGc::EDrawModePEN ); |
|
188 aGc.DiscardFont(); |
|
189 aGc.DiscardBrushPattern(); |
|
190 aGc.SetBrushColor( KRgbWhite ); |
|
191 aGc.SetBrushStyle( CFbsBitGc::ENullBrush ); |
|
192 aGc.SetCharJustification( 0,0 ); |
|
193 aGc.SetWordJustification( 0,0 ); |
|
194 aGc.SetDitherOrigin( TPoint( 0,0 ) ); |
|
195 aGc.SetPenStyle( CFbsBitGc::ENullPen ); |
|
196 aGc.SetShadowMode( EFalse ); |
|
197 aGc.SetStrikethroughStyle( EStrikethroughOff ); |
|
198 aGc.SetUnderlineStyle( EUnderlineOff ); |
|
199 aGc.SetUserDisplayMode( ENone ); |
|
200 } |
|
201 |
|
202 // End of File |