Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
TplInterpolators.h
1/***********************************************************************
2 created: 23/11/2010
3 author: Martin Preisler
4
5 purpose: Provides templated finger saving interpolators
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUITplInterpolators_h_
30#define _CEGUITplInterpolators_h_
31
32#include "CEGUI/Base.h"
33#include "CEGUI/Interpolator.h"
34#include "CEGUI/PropertyHelper.h"
35
36// Start of CEGUI namespace section
37namespace CEGUI
38{
39
40class CEGUIEXPORT TplInterpolatorBase : public Interpolator
41{
42public:
43 TplInterpolatorBase(const String& type):
44 d_type(type)
45 {}
46
49
51 virtual const String& getType() const
52 {
53 return d_type;
54 }
55
56private:
57 const String d_type;
58};
59
66template<typename T>
68{
69public:
71
72 TplLinearInterpolator(const String& type):
74 {}
75
78
81 const String& value2,
82 float position)
83 {
84 typename Helper::return_type val1 = Helper::fromString(value1);
85 typename Helper::return_type val2 = Helper::fromString(value2);
86
87 const T result = static_cast<const T>(val1 * (1.0f - position) + val2 * (position));
88
89 return Helper::toString(result);
90 }
91
94 const String& value1,
95 const String& value2,
96 float position)
97 {
98 typename Helper::return_type bas = Helper::fromString(base);
99 typename Helper::return_type val1 = Helper::fromString(value1);
100 typename Helper::return_type val2 = Helper::fromString(value2);
101
102 const T result = static_cast<const T>(bas + (val1 * (1.0f - position) + val2 * (position)));
103
104 return Helper::toString(result);
105 }
106
109 const String& value1,
110 const String& value2,
111 float position)
112 {
113 typename Helper::return_type bas = Helper::fromString(base);
116
117 const float mul = val1 * (1.0f - position) + val2 * (position);
118
119 const T result = static_cast<const T>(bas * mul);
120
121 return Helper::toString(result);
122 }
123};
124
132template<typename T>
134{
135public:
137
138 TplDiscreteInterpolator(const String& type):
140 {}
141
144
147 const String& value2,
148 float position)
149 {
150 typename Helper::return_type val1 = Helper::fromString(value1);
151 typename Helper::return_type val2 = Helper::fromString(value2);
152
153 typename Helper::return_type result = position < 0.5 ? val1 : val2;;
154
155 return Helper::toString(result);
156 }
157
159 virtual String interpolateRelative(const String& /*base*/,
160 const String& value1,
161 const String& value2,
162 float position)
163 {
164 //typename Helper::return_type bas = Helper::fromString(base);
165 typename Helper::return_type val1 = Helper::fromString(value1);
166 typename Helper::return_type val2 = Helper::fromString(value2);
167
168 typename Helper::return_type result = position < 0.5 ? val1 : val2;
169
170 return Helper::toString(result);
171 }
172
175 const String& /*value1*/,
176 const String& /*value2*/,
177 float /*position*/)
178 {
179 typename Helper::return_type bas = Helper::fromString(base);
180 /*const float val1 = PropertyHelper<float>::fromString(value1);
181 const float val2 = PropertyHelper<float>::fromString(value2);
182
183 const float mul = val1 * (1.0f - position) + val2 * (position);*/
184
185 // there is nothing we can do, we have no idea what operators T has overloaded
186 return Helper::toString(bas);
187 }
188};
189
198template<typename T>
200{
201public:
203
206 {}
207
210
213 const String& value1,
214 const String& value2,
215 float position)
216 {
217 typename Helper::return_type bas = Helper::fromString(base);
218 typename Helper::return_type val1 = Helper::fromString(value1);
219 typename Helper::return_type val2 = Helper::fromString(value2);
220
221 typename Helper::return_type result = bas + (position < 0.5 ? val1 : val2);
222
223 return Helper::toString(result);
224 }
225};
226
227} // End of CEGUI namespace section
228
229#endif // end of guard _CEGUITplInterpolators_h_
Defines a 'interpolator' class.
Definition Interpolator.h:55
Helper class used to convert various data types to and from the format expected in Property strings.
Definition ForwardRefs.h:84
String class used within the GUI system.
Definition String.h:64
Generic discrete interpolator class.
Definition TplInterpolators.h:134
virtual String interpolateAbsolute(const String &value1, const String &value2, float position)
Definition TplInterpolators.h:146
virtual ~TplDiscreteInterpolator()
destructor
Definition TplInterpolators.h:143
virtual String interpolateRelativeMultiply(const String &base, const String &, const String &, float)
Definition TplInterpolators.h:174
virtual String interpolateRelative(const String &, const String &value1, const String &value2, float position)
Definition TplInterpolators.h:159
Generic discrete relative interpolator class.
Definition TplInterpolators.h:200
virtual String interpolateRelative(const String &base, const String &value1, const String &value2, float position)
Definition TplInterpolators.h:212
virtual ~TplDiscreteRelativeInterpolator()
destructor
Definition TplInterpolators.h:209
Definition TplInterpolators.h:41
virtual const String & getType() const
returns type string of this interpolator
Definition TplInterpolators.h:51
virtual ~TplInterpolatorBase()
destructor
Definition TplInterpolators.h:48
Generic linear interpolator class.
Definition TplInterpolators.h:68
virtual String interpolateRelativeMultiply(const String &base, const String &value1, const String &value2, float position)
Definition TplInterpolators.h:108
virtual ~TplLinearInterpolator()
destructor
Definition TplInterpolators.h:77
virtual String interpolateRelative(const String &base, const String &value1, const String &value2, float position)
Definition TplInterpolators.h:93
virtual String interpolateAbsolute(const String &value1, const String &value2, float position)
Definition TplInterpolators.h:80
base class for properties able to do native set/get
Definition TypedProperty.h:50
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1