|
1 /* |
|
2 * Copyright (c) 2007 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: Gradient brush |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alf/alfgradientbrush.h" |
|
21 #include "alf/alfconstants.h" |
|
22 #include "alf/alfgencomponent.h" |
|
23 #include "alf/alfimage.h" |
|
24 #include "alf/alftexture.h" |
|
25 #include "alflogger.h" |
|
26 #include "alf/alfenv.h" |
|
27 #include "alfskinnableimage.h" |
|
28 |
|
29 #include <uiacceltk/HuiUtil.h> |
|
30 |
|
31 struct CAlfGradientBrush::TGradientBrushPrivateData |
|
32 { |
|
33 CAlfSkinnableImage* iImage; |
|
34 }; |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CAlfGradientBrush* CAlfGradientBrush::NewL( CAlfEnv& aEnv ) |
|
43 { |
|
44 CAlfGradientBrush* self = CAlfGradientBrush::NewLC( aEnv ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // Constructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CAlfGradientBrush* CAlfGradientBrush::NewLC( CAlfEnv& aEnv ) |
|
54 { |
|
55 CAlfGradientBrush* self = new( ELeave ) CAlfGradientBrush; |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aEnv ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Constructor |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CAlfGradientBrush::CAlfGradientBrush() |
|
66 { |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Second phase constructor |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CAlfGradientBrush::ConstructL( CAlfEnv& aEnv ) |
|
74 { |
|
75 CAlfBrush::ConstructL( |
|
76 aEnv, |
|
77 EAlfGradientBrushCreate, |
|
78 0, |
|
79 KNullDesC8() |
|
80 ); |
|
81 |
|
82 iGradientBrushData = new (ELeave) TGradientBrushPrivateData; |
|
83 iGradientBrushData->iImage = NULL; |
|
84 iGradientBrushData->iImage = new (ELeave) CAlfSkinnableImage(&aEnv); |
|
85 |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Destructor |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CAlfGradientBrush::~CAlfGradientBrush() |
|
93 { |
|
94 if ( iGradientBrushData ) |
|
95 { |
|
96 delete iGradientBrushData->iImage; |
|
97 iGradientBrushData->iImage = NULL; |
|
98 } |
|
99 delete iGradientBrushData; |
|
100 iGradientBrushData = NULL; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Set gradient direction |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C void CAlfGradientBrush::SetDirection(TDirection aDirection) |
|
108 { |
|
109 TPckgC<TDirection> buf(aDirection); |
|
110 |
|
111 TInt err = Comms()->DoCmdNoReply( EAlfGradientBrushSetDirection, buf ); |
|
112 |
|
113 if ( err != KErrNone ) |
|
114 { |
|
115 __ALFLOGSTRING1( "CAlfGradientBrush::SetDirection panic error %d", err ) |
|
116 USER_INVARIANT(); |
|
117 } |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // Set gradient base color |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C void CAlfGradientBrush::SetColor(const TRgb& aColor, TReal32 aOpacity ) __SOFTFP |
|
125 { |
|
126 TAlfGradientBrushSetColorParams params; |
|
127 params.iColor = aColor; |
|
128 params.iOpacity = aOpacity; |
|
129 |
|
130 TPckgC<TAlfGradientBrushSetColorParams> buf(params); |
|
131 |
|
132 TInt err = Comms()->DoCmdNoReply( EAlfGradientBrushSetColor, buf ); |
|
133 |
|
134 if ( err != KErrNone ) |
|
135 { |
|
136 __ALFLOGSTRING1( "CAlfGradientBrush::SetColor panic error %d", err ) |
|
137 USER_INVARIANT(); |
|
138 } |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // Set gradient image |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CAlfGradientBrush::SetImage(const TAlfImage& aImage) |
|
146 { |
|
147 iGradientBrushData->iImage->SetImage(aImage); // This texturizes skin graphics if needed |
|
148 |
|
149 TAlfImageParams params(iGradientBrushData->iImage->Image()); |
|
150 |
|
151 TPckgC<TAlfImageParams> buf(params); |
|
152 |
|
153 TInt err = Comms()->DoCmdNoReply(EAlfGradientBrushSetImage, buf ); |
|
154 |
|
155 if ( err ) |
|
156 { |
|
157 __ALFLOGSTRING1( "CAlfGradientBrush::SetImage ignore error %d", err ) |
|
158 } |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Return color at index |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C TRgb CAlfGradientBrush::Color(TInt aIndex) const |
|
166 { |
|
167 TPckgC<TInt> inBuf(aIndex); |
|
168 TRgb result; |
|
169 TPckg<TRgb> outBuf(result); |
|
170 TInt err = Comms()->DoSynchronousCmd( EAlfGradientBrushColor, inBuf, outBuf); |
|
171 |
|
172 if ( err != KErrNone ) |
|
173 { |
|
174 __ALFLOGSTRING1( "CAlfGradientBrush::Color panic error %d", err ) |
|
175 USER_INVARIANT(); |
|
176 } |
|
177 |
|
178 return result; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // Return opacity at index |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C TReal32 CAlfGradientBrush::Opacity(TInt aIndex) const |
|
186 { |
|
187 TPckgC<TInt> inBuf(aIndex); |
|
188 TReal32 result = 1.f; |
|
189 TPckg<TReal32> outBuf(result); |
|
190 TInt err = Comms()->DoSynchronousCmd( EAlfGradientBrushOpacity, inBuf, outBuf); |
|
191 |
|
192 if ( err != KErrNone ) |
|
193 { |
|
194 __ALFLOGSTRING1( "CAlfGradientBrush::Opacity panic error %d", err ) |
|
195 USER_INVARIANT(); |
|
196 } |
|
197 |
|
198 return result; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // Return image |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C const TAlfImage& CAlfGradientBrush::Image() const |
|
206 { |
|
207 return iGradientBrushData->iImage->Image(); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Add color bar to gradient |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C void CAlfGradientBrush::AppendColorL( |
|
215 TReal32 aPosition, |
|
216 const TRgb& aColor, |
|
217 TReal32 aOpacity ) __SOFTFP |
|
218 { |
|
219 TAlfGradientBrushAppendColorParams params; |
|
220 params.iPosition = aPosition; |
|
221 params.iColor = aColor; |
|
222 params.iOpacity = aOpacity; |
|
223 |
|
224 TPckgC<TAlfGradientBrushAppendColorParams> buf(params); |
|
225 TBuf8<1> dum; |
|
226 TInt err = Comms()->DoSynchronousCmd( EAlfGradientBrushAppendColor, buf, dum); |
|
227 |
|
228 if ( err ) |
|
229 { |
|
230 __ALFLOGSTRING1( "CAlfGradientBrush::AppendColorL leave error %d", err ) |
|
231 User::Leave( err ); |
|
232 } |
|
233 } |
|
234 |