|
1 /* |
|
2 * Copyright (c) 2006-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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "uiacceltk/HuiMappingFunctions.h" |
|
21 #include "uiacceltk/huifixmath.h" |
|
22 |
|
23 |
|
24 EXPORT_C |
|
25 THuiConstantMappingFunction::THuiConstantMappingFunction(TReal32 aValue) __SOFTFP |
|
26 : iValue(aValue) |
|
27 { |
|
28 } |
|
29 |
|
30 |
|
31 EXPORT_C TReal32 THuiConstantMappingFunction::MapValue(TReal32 /*aValue*/, |
|
32 TInt /*aComponent*/) const __SOFTFP |
|
33 { |
|
34 return iValue; |
|
35 } |
|
36 |
|
37 |
|
38 |
|
39 EXPORT_C THuiLinearMappingFunction::THuiLinearMappingFunction(TReal32 aFactor, TReal32 aOffset) __SOFTFP |
|
40 : iFactor(aFactor), iOffset(aOffset) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 EXPORT_C TReal32 THuiLinearMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
46 { |
|
47 return aValue * iFactor + iOffset; |
|
48 } |
|
49 |
|
50 |
|
51 EXPORT_C |
|
52 THuiSineMappingFunction::THuiSineMappingFunction(TReal32 aFactor, TReal32 aOffset) __SOFTFP |
|
53 : iFactor(aFactor), iOffset(aOffset) |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 EXPORT_C TReal32 THuiSineMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
59 { |
|
60 TReal32 mapped = HuiFixMath::FixToFloat(HuiFixMath::FixSin(HuiFixMath::FloatToFix(aValue))); |
|
61 return mapped * iFactor + iOffset; |
|
62 } |
|
63 |
|
64 |
|
65 EXPORT_C |
|
66 THuiCosineMappingFunction::THuiCosineMappingFunction(TReal32 aFactor, TReal32 aOffset) __SOFTFP |
|
67 : iFactor(aFactor), iOffset(aOffset) |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 EXPORT_C TReal32 THuiCosineMappingFunction::MapValue(TReal32 aValue, TInt /*aComponent*/) const __SOFTFP |
|
73 { |
|
74 TReal32 mapped = HuiFixMath::FixToFloat(HuiFixMath::FixCos(HuiFixMath::FloatToFix(aValue))); |
|
75 return mapped * iFactor + iOffset; |
|
76 } |
|
77 |
|
78 |
|
79 EXPORT_C |
|
80 THuiAverageMappingFunction::THuiAverageMappingFunction(MHuiMappingFunction* aFunc1, |
|
81 MHuiMappingFunction* aFunc2) |
|
82 : iFunc1(aFunc1), iFunc2(aFunc2), iFactor(0.5f), |
|
83 iWeight( 0.5f ) // Balance between the functions. |
|
84 { |
|
85 } |
|
86 |
|
87 |
|
88 EXPORT_C TReal32 THuiAverageMappingFunction::MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP |
|
89 { |
|
90 TReal32 value = 0; |
|
91 TReal32 weight = iWeight.Now(); |
|
92 |
|
93 if(iFunc1) |
|
94 { |
|
95 value += 2 * (1 - weight) * iFunc1->MapValue(aValue, aComponent); |
|
96 } |
|
97 if(iFunc2) |
|
98 { |
|
99 value += 2 * weight * iFunc2->MapValue(aValue, aComponent); |
|
100 } |
|
101 |
|
102 return value * iFactor.Now(); |
|
103 } |
|
104 |
|
105 |
|
106 EXPORT_C TBool THuiAverageMappingFunction::MappingFunctionChanged() const |
|
107 { |
|
108 return (iFunc1 && iFunc1->MappingFunctionChanged() || |
|
109 iFunc2 && iFunc2->MappingFunctionChanged() || |
|
110 iFactor.Changed() || iWeight.Changed()); |
|
111 } |
|
112 |
|
113 |
|
114 EXPORT_C void THuiAverageMappingFunction::MappingFunctionClearChanged() |
|
115 { |
|
116 if(iFunc1) |
|
117 { |
|
118 iFunc1->MappingFunctionClearChanged(); |
|
119 } |
|
120 if(iFunc2) |
|
121 { |
|
122 iFunc2->MappingFunctionClearChanged(); |
|
123 } |
|
124 iFactor.ClearChanged(); |
|
125 iWeight.ClearChanged(); |
|
126 } |