1 // Subsystem that manages interpolation of properties.
3 // Copyright (C) 2013 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef SG_PROPERTY_INTERPOLATION_MGR_HXX_
20 #define SG_PROPERTY_INTERPOLATION_MGR_HXX_
22 #include <simgear/structure/subsystem_mgr.hxx>
23 #include <simgear/props/PropertyInterpolator.hxx>
31 * Subsystem that manages interpolation of properties.
33 * By default the numeric values of the properties are interpolated. For
34 * example, for strings this is probably not the wanted behavior. For this
35 * adapter classes can be registered to allow providing specific
36 * interpolations for certain types of properties. Using the type "color",
37 * provided by ColorInterpolator, strings containing %CSS colors can also be
40 * Additionally different functions can be used for easing of the animation.
41 * By default "linear" (constant animation speed) and "swing" (smooth
42 * acceleration and deceleration) are available.
44 class PropertyInterpolationMgr:
48 typedef PropertyInterpolator*
49 (*InterpolatorFactory)(const SGPropertyNode* target);
51 PropertyInterpolationMgr();
54 * Update all active interpolators.
56 void update(double dt);
59 * Create a new property interpolator.
61 * @note To actually use it the interpolator needs to be attached to a
62 * property using PropertyInterpolationMgr::interpolate.
64 * @param type Type of animation ("numeric", "color", etc.)
65 * @param target Property containing target value
66 * @param duration Duration if the animation (in seconds)
67 * @param easing Type of easing ("linear", "swing", etc.)
69 PropertyInterpolatorRef
70 createInterpolator( const std::string& type,
71 const SGPropertyNode* target,
72 double duration = 1.0,
73 const std::string& easing = "swing" );
76 * Add animation of the given property from current its current value to
77 * the target value of the interpolator.
79 * @param prop Property to be interpolated
80 * @param interp Interpolator used for interpolation
82 void interpolate( SGPropertyNode* prop,
83 PropertyInterpolatorRef interp );
86 * Register factory for interpolation type.
88 void addInterpolatorFactory( const std::string& type,
89 InterpolatorFactory factory );
91 void addInterpolatorFactory(const std::string& type)
93 addInterpolatorFactory(type, &PropertyInterpolator::create<T>);
97 * Register easing function.
99 void addEasingFunction(const std::string& type, easing_func_t func);
103 typedef std::map<std::string, InterpolatorFactory> InterpolatorFactoryMap;
104 typedef std::map<std::string, easing_func_t> EasingFunctionMap;
105 typedef std::pair< SGPropertyNode*,
106 PropertyInterpolatorRef > PropertyInterpolatorPair;
107 typedef std::list<PropertyInterpolatorPair> InterpolatorList;
109 struct PredicateIsSameProp;
111 InterpolatorFactoryMap _interpolator_factories;
112 EasingFunctionMap _easing_functions;
113 InterpolatorList _interpolators;
116 } // namespace simgear
118 #endif /* SG_PROPERTY_INTERPOLATION_MGR_HXX_ */