Animations/FadeAnimation.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2015 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_FADEANIMATION_HPP
00030 #define THOR_FADEANIMATION_HPP
00031 
00032 #include <Thor/Config.hpp>
00033 #include <Thor/Graphics/UniformAccess.hpp>
00034 
00035 
00036 namespace thor
00037 {
00038 
00041 
00044 class THOR_API FadeAnimation
00045 {
00046     // ---------------------------------------------------------------------------------------------------------------------------
00047     // Public member functions
00048     public:
00054                                     FadeAnimation(float inRatio, float outRatio);
00055 
00060         template <class Animated>
00061         void                        operator() (Animated& animated, float progress) const;
00062 
00063 
00064     // ---------------------------------------------------------------------------------------------------------------------------
00065     // Private variables
00066     private:
00067         float                       mInRatio;
00068         float                       mOutRatio;
00069 };
00070 
00072 
00073 // ---------------------------------------------------------------------------------------------------------------------------
00074 
00075 
00076 template <class Animated>
00077 void FadeAnimation::operator() (Animated& target, float progress) const
00078 {
00079     if (progress < mInRatio)
00080         setAlpha(target, static_cast<sf::Uint8>(256 * progress / mInRatio));
00081     else if (progress > 1.f - mOutRatio)
00082         setAlpha(target, static_cast<sf::Uint8>(256 * (1.f-progress) / mOutRatio));
00083 }
00084 
00085 } // namespace thor
00086 
00087 #endif // THOR_FADEANIMATION_HPP