|
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: Alf mapping functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef M_ALFMAPPINGFUNCTIONS_H |
|
21 #define M_ALFMAPPINGFUNCTIONS_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <alf/alftimedvalue.h> |
|
25 |
|
26 class CAlfEnv; |
|
27 |
|
28 /** |
|
29 * Mapping function interface. |
|
30 * Timed values use this interface for mapping |
|
31 * the return value of a timed value evaluation. Can be used to define |
|
32 * custom interpolation functions for example timed values. |
|
33 * |
|
34 * @lib alfclient.lib |
|
35 * @since S60 v3.2 |
|
36 */ |
|
37 class MAlfMappingFunction |
|
38 { |
|
39 |
|
40 public: |
|
41 |
|
42 /** |
|
43 * Perform the mapping. Defines a function y = f(x, mode). |
|
44 * |
|
45 * Implement this method that calculates a output value for |
|
46 * a timed value based on the input value and a component/mode |
|
47 * parameter. |
|
48 * |
|
49 * For example the aValue input could be an angle, and the aMode |
|
50 * could be a X or Y component enumeration, then the MapValue could |
|
51 * calculate return a x or y position on a curve path. |
|
52 * |
|
53 * @param aValue Unmapped value. |
|
54 * @param aMode Mapping mode used for mapping this value. |
|
55 * |
|
56 * @return Mapped value. |
|
57 */ |
|
58 virtual TReal32 MapValue(TReal32 aValue, TInt aMode) const __SOFTFP = 0; |
|
59 |
|
60 /** |
|
61 * Returns the mapping function identifier on the server side. |
|
62 */ |
|
63 virtual TInt MappingFunctionIdentifier() const = 0; |
|
64 |
|
65 }; |
|
66 |
|
67 |
|
68 /** |
|
69 * Constant value mapping function. |
|
70 * |
|
71 * Does not implement change flags, which means that if iValue is changed |
|
72 * while the mapping function is in use, timed values will not notify the |
|
73 * change. |
|
74 * Usage: |
|
75 * @code |
|
76 * //Create constant mapping function instant |
|
77 * CAlfConstantMappingFunction* imageXposMappingFun = CAlfConstantMappingFunction::NewL(*iEnv); |
|
78 * |
|
79 * TAlfTimedPoint timedPoint; |
|
80 * //Set mapping function on x timed value |
|
81 * timedPoint.iX.SetValueNow(0); |
|
82 * timedPoint.iX.SetTarget( 2000 ); |
|
83 * timedPoint.iX.SetMappingFunctionIdentifier( imageXposMappingFun->MappingFunctionIdentifier() ); |
|
84 * |
|
85 * //Set mapping function on Y timed value |
|
86 * timedPoint.iY.SetValueNow(0); |
|
87 * timedPoint.iY.SetTarget(2000); |
|
88 * timedPoint.iY.SetMappingFunctionIdentifier( imageYposMappingFunction->MappingFunctionIdentifier() ); |
|
89 * //Set position of image visual |
|
90 * iImageVisual->SetPos( timedPoint ); |
|
91 * @endcode |
|
92 */ |
|
93 class CAlfConstantMappingFunction : public CBase, public MAlfMappingFunction |
|
94 { |
|
95 public: |
|
96 |
|
97 /** |
|
98 * Constructor. |
|
99 */ |
|
100 IMPORT_C static CAlfConstantMappingFunction* NewL( |
|
101 CAlfEnv& aEnv, |
|
102 TReal32 aValue = 0.0 ) __SOFTFP; |
|
103 IMPORT_C ~CAlfConstantMappingFunction(); |
|
104 |
|
105 /* implements MAlfMappingFunction */ |
|
106 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
107 |
|
108 /* implements MAlfMappingFunction */ |
|
109 TInt MappingFunctionIdentifier() const; |
|
110 |
|
111 IMPORT_C void SetValue( TReal32 aValue ) __SOFTFP; |
|
112 IMPORT_C TReal32 Value() const __SOFTFP; |
|
113 |
|
114 private: |
|
115 |
|
116 CAlfConstantMappingFunction(); |
|
117 void ConstructL( CAlfEnv& aEnv, TReal32 aValue ); |
|
118 |
|
119 private: |
|
120 |
|
121 struct TPrivateData; |
|
122 TPrivateData* iData; |
|
123 |
|
124 }; |
|
125 |
|
126 /** |
|
127 * Linear mapping function. |
|
128 * |
|
129 * Does not implement change flags, which means that if iFactor or iOffset |
|
130 * is changed while the mapping function is in use, timed values will |
|
131 * not notify the change. |
|
132 */ |
|
133 class CAlfLinearMappingFunction : public CBase, public MAlfMappingFunction |
|
134 { |
|
135 public: |
|
136 |
|
137 /** |
|
138 * Constructor. |
|
139 */ |
|
140 IMPORT_C static CAlfLinearMappingFunction* NewL( |
|
141 CAlfEnv& aEnv, |
|
142 TReal32 aFactor = 1.0, |
|
143 TReal32 aOffset = 0.0 ) __SOFTFP; |
|
144 IMPORT_C ~CAlfLinearMappingFunction(); |
|
145 |
|
146 /* implements MAlfMappingFunction */ |
|
147 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
148 |
|
149 /* implements MAlfMappingFunction */ |
|
150 TInt MappingFunctionIdentifier() const; |
|
151 |
|
152 IMPORT_C void SetFactor( TReal32 aFactor ) __SOFTFP; |
|
153 IMPORT_C TReal32 Factor() const __SOFTFP; |
|
154 |
|
155 IMPORT_C void SetOffset( TReal32 aOffset ) __SOFTFP; |
|
156 IMPORT_C TReal32 Offset() const __SOFTFP; |
|
157 |
|
158 private: |
|
159 |
|
160 CAlfLinearMappingFunction(); |
|
161 void ConstructL( CAlfEnv& aEnv,TReal32 aFactor, TReal32 aOffset ); |
|
162 |
|
163 private: |
|
164 |
|
165 struct TPrivateData; |
|
166 TPrivateData* iData; |
|
167 |
|
168 }; |
|
169 |
|
170 /** |
|
171 * Sine mapping function. |
|
172 * |
|
173 * Does not implement change flags, which means that if iFactor or iOffset |
|
174 * is changed while the mapping function is in use, timed values will |
|
175 * not notify the change. |
|
176 */ |
|
177 class CAlfSineMappingFunction : public CBase, public MAlfMappingFunction |
|
178 { |
|
179 public: |
|
180 |
|
181 /** |
|
182 * Constructor. |
|
183 */ |
|
184 IMPORT_C static CAlfSineMappingFunction* NewL( |
|
185 CAlfEnv& aEnv, |
|
186 TReal32 aFactor = 1.0, |
|
187 TReal32 aOffset = 0.0 ) __SOFTFP; |
|
188 IMPORT_C ~CAlfSineMappingFunction(); |
|
189 |
|
190 /* implements MAlfMappingFunction */ |
|
191 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
192 |
|
193 /* implements MAlfMappingFunction */ |
|
194 TInt MappingFunctionIdentifier() const; |
|
195 |
|
196 IMPORT_C void SetFactor( TReal32 aFactor ) __SOFTFP; |
|
197 IMPORT_C TReal32 Factor() const __SOFTFP; |
|
198 |
|
199 IMPORT_C void SetOffset( TReal32 aOffset ) __SOFTFP; |
|
200 IMPORT_C TReal32 Offset() const __SOFTFP; |
|
201 |
|
202 private: |
|
203 CAlfSineMappingFunction(); |
|
204 void ConstructL( CAlfEnv& aEnv, TReal32 aFactor, TReal32 aOffset ); |
|
205 |
|
206 private: |
|
207 |
|
208 struct TPrivateData; |
|
209 TPrivateData* iData; |
|
210 |
|
211 }; |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 /** |
|
217 * Cosine mapping function. |
|
218 * |
|
219 * Does not implement change flags, which means that if iFactor or iOffset |
|
220 * is changed while the mapping function is in use, timed values will |
|
221 * not notify the change. |
|
222 */ |
|
223 class CAlfCosineMappingFunction : public CBase, public MAlfMappingFunction |
|
224 { |
|
225 public: |
|
226 |
|
227 /** |
|
228 * Constructor. |
|
229 */ |
|
230 IMPORT_C static CAlfCosineMappingFunction* NewL( |
|
231 CAlfEnv& aEnv, |
|
232 TReal32 aFactor = 1.0, |
|
233 TReal32 aOffset = 0.0 ) __SOFTFP; |
|
234 IMPORT_C ~CAlfCosineMappingFunction(); |
|
235 |
|
236 /* implements MAlfMappingFunction */ |
|
237 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
238 |
|
239 /* implements MAlfMappingFunction */ |
|
240 TInt MappingFunctionIdentifier() const; |
|
241 |
|
242 IMPORT_C void SetFactor( TReal32 aFactor ) __SOFTFP; |
|
243 IMPORT_C TReal32 Factor() const __SOFTFP; |
|
244 |
|
245 IMPORT_C void SetOffset( TReal32 aOffset ) __SOFTFP; |
|
246 IMPORT_C TReal32 Offset() const __SOFTFP; |
|
247 |
|
248 private: |
|
249 CAlfCosineMappingFunction(); |
|
250 void ConstructL( CAlfEnv& aEnv, TReal32 aFactor, TReal32 aOffset ); |
|
251 |
|
252 private: |
|
253 |
|
254 struct TPrivateData; |
|
255 TPrivateData* iData; |
|
256 |
|
257 }; |
|
258 |
|
259 |
|
260 /** |
|
261 * Weighted average function between two other mapping functions. |
|
262 * By default calculates the average of the two functions. |
|
263 */ |
|
264 class CAlfAverageMappingFunction : public CBase, public MAlfMappingFunction |
|
265 { |
|
266 public: |
|
267 |
|
268 /** |
|
269 * Constructor. |
|
270 * |
|
271 * @param aFunc1 Function 1. |
|
272 * @param aFunc2 Function 2. |
|
273 */ |
|
274 IMPORT_C static CAlfAverageMappingFunction* NewL( |
|
275 CAlfEnv& aEnv, |
|
276 MAlfMappingFunction* aFunc1 = 0, |
|
277 MAlfMappingFunction* aFunc2 = 0 ); |
|
278 |
|
279 IMPORT_C ~CAlfAverageMappingFunction(); |
|
280 |
|
281 /* Implements MAlfMappingFunction. */ |
|
282 |
|
283 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
284 |
|
285 TInt MappingFunctionIdentifier() const; |
|
286 |
|
287 IMPORT_C void SetMappingFunction1( MAlfMappingFunction* aFunction1 ); |
|
288 IMPORT_C void SetMappingFunction2( MAlfMappingFunction* aFunction2 ); |
|
289 IMPORT_C void SetMappingFunctions( |
|
290 MAlfMappingFunction* aFunction1, |
|
291 MAlfMappingFunction* aFunction2 ); |
|
292 |
|
293 IMPORT_C void SetWeight( const TAlfTimedValue& aWeight ); |
|
294 |
|
295 private: |
|
296 |
|
297 CAlfAverageMappingFunction(); |
|
298 |
|
299 void ConstructL( |
|
300 CAlfEnv& aEnv, |
|
301 MAlfMappingFunction* aFunc1, |
|
302 MAlfMappingFunction* aFunc2 |
|
303 ); |
|
304 |
|
305 private: |
|
306 |
|
307 struct TPrivateData; |
|
308 TPrivateData* iData; |
|
309 }; |
|
310 |
|
311 |
|
312 /** |
|
313 * Mapping table function data provider, to be used with CAlfTableMappingFunction. |
|
314 * |
|
315 */ |
|
316 class MAlfTableMappingFunctionDataProvider |
|
317 { |
|
318 |
|
319 public: |
|
320 |
|
321 /** |
|
322 * Perform the mapping. Defines a function y = f(x, mode). |
|
323 * |
|
324 * Implement this method that calculates a output value for |
|
325 * a timed value based on the input value and a component/mode |
|
326 * parameter. |
|
327 * |
|
328 * For example the aValue input could be an angle, and the aMode |
|
329 * could be a X or Y component enumeration, then the MapValue could |
|
330 * calculate return a x or y position on a curve path. |
|
331 * |
|
332 * @param aValue Unmapped value. |
|
333 * @param aMode Mapping mode used for mapping this value. |
|
334 * |
|
335 * @return Mapped value. |
|
336 */ |
|
337 virtual TReal32 MapValue(TReal32 aValue, TInt aMode) const __SOFTFP = 0; |
|
338 }; |
|
339 |
|
340 /** |
|
341 * |
|
342 * Mapping table based mapping function. This can be used in some situations |
|
343 * to implement new mapping function functionality, without writing a whole new |
|
344 * mapping function (as a server extension). |
|
345 * |
|
346 */ |
|
347 class CAlfTableMappingFunction : public CBase, public MAlfMappingFunction |
|
348 { |
|
349 public: |
|
350 |
|
351 /** |
|
352 * Constructor. |
|
353 */ |
|
354 IMPORT_C static CAlfTableMappingFunction* NewL(CAlfEnv& aEnv); |
|
355 |
|
356 /** |
|
357 * Destructor. |
|
358 */ |
|
359 IMPORT_C ~CAlfTableMappingFunction(); |
|
360 |
|
361 /** |
|
362 * Calculates mapping table for given range using given mapping data provider function. This fucntion |
|
363 * should be called at least once to initialize the mapping table values. |
|
364 * |
|
365 * @param aStart Start value for the mapping table |
|
366 * @param aEnd End value for the mapping table |
|
367 * @param aFunction Function that is used to calculate mapping table values. |
|
368 * |
|
369 */ |
|
370 IMPORT_C void SetMappingTableValues(TReal32 aStart, TReal32 aEnd, MAlfTableMappingFunctionDataProvider* aFunction) __SOFTFP; |
|
371 |
|
372 /* Implements MAlfMappingFunction. */ |
|
373 |
|
374 TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
375 |
|
376 TInt MappingFunctionIdentifier() const; |
|
377 |
|
378 private: |
|
379 |
|
380 CAlfTableMappingFunction(); |
|
381 |
|
382 void ConstructL(CAlfEnv& aEnv); |
|
383 |
|
384 private: |
|
385 |
|
386 struct TPrivateData; |
|
387 TPrivateData* iData; |
|
388 }; |
|
389 |
|
390 |
|
391 #endif // M_ALFMAPPINGFUNCTIONS_H |