ColorAnimation.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_COLORANIMATION_HPP
30 #define THOR_COLORANIMATION_HPP
31 
32 #include <Thor/Config.hpp>
35 
36 
37 namespace thor
38 {
39 
42 
45 class THOR_API ColorAnimation
46 {
47  // ---------------------------------------------------------------------------------------------------------------------------
48  // Public member functions
49  public:
52  explicit ColorAnimation(const ColorGradient& gradient);
53 
58  template <class Animated>
59  void operator() (Animated& animated, float progress) const;
60 
61 
62  // ---------------------------------------------------------------------------------------------------------------------------
63  // Private variables
64  private:
65  ColorGradient mGradient;
66 };
67 
69 
70 // ---------------------------------------------------------------------------------------------------------------------------
71 
72 
73 template <class Animated>
74 void ColorAnimation::operator() (Animated& target, float progress) const
75 {
76  setColor(target, mGradient.sampleColor(progress));
77 }
78 
79 } // namespace thor
80 
81 #endif // THOR_COLORANIMATION_HPP
Class thor::ColorGradient.
void setColor(T &object, const sf::Color &color)
Sets the color of a graphical object.
Global functions to access SFML and Thor objects uniformly.
Definition: AnimationMap.hpp:42
Configuration header of the library.
Changes an object's color smoothly over time.
Definition: ColorAnimation.hpp:45
sf::Color sampleColor(float position) const
Interpolates a color in the gradient.
void operator()(Animated &animated, float progress) const
Animates the object.
Definition: ColorAnimation.hpp:74
Class to implement color gradients.
Definition: ColorGradient.hpp:49