Bromeon
Resources/GraphicsKeys.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 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_GRAPHICSKEYS_HPP
00030 #define THOR_GRAPHICSKEYS_HPP
00031 
00032 #include <Thor/Resources/ResourceKeyTraits.hpp>
00033 #include <Thor/Detail/Swap.hpp>
00034 #include <Thor/Config.hpp>
00035 
00036 #include <SFML/Graphics/Color.hpp>
00037 #include <SFML/Config.hpp>
00038 
00039 #include THOR_TR1_HEADER(functional)
00040 #include <string>
00041 
00042 
00043 namespace thor
00044 {
00045 
00048 
00051 namespace Resources
00052 {
00053 
00056     class THOR_API ImageKey
00057     {
00058         // ---------------------------------------------------------------------------------------------------------------------------
00059         // Public member functions
00060         public:
00066             static ImageKey             FromSize(unsigned int width, unsigned int height, const sf::Color& fillColor = sf::Color(0, 0, 0),
00067                                             const std::string& tag = "");
00068 
00073             static ImageKey             FromFile(const std::string& fileName, const std::string& tag = "");
00074 
00080             static ImageKey             FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00081 
00087             static ImageKey             FromPixels(unsigned int width, unsigned int height, const sf::Uint8* pixels,
00088                                             const std::string& tag = "");
00089 
00092             MovedPtr<sf::Image>         Load() const;
00093 
00096             void                        Swap(ImageKey& other);
00097 
00098 
00099         // ---------------------------------------------------------------------------------------------------------------------------
00100         // Private member functions
00101         private:
00102             // Make default constructor private
00103                                         ImageKey();
00104 
00105         
00106         // ---------------------------------------------------------------------------------------------------------------------------
00107         // Private variables
00108         private:
00109             std::tr1::function<bool(sf::Image&)>    mLoader;
00110             std::string                             mKey;
00111 
00112     
00113         // ---------------------------------------------------------------------------------------------------------------------------
00114         // Friends
00115         friend struct detail::KeyInfoAccessor<true>;
00116     };
00117 
00118 
00121     class THOR_API FontKey
00122     {
00123         // ---------------------------------------------------------------------------------------------------------------------------
00124         // Public member functions
00125         public:
00130             static FontKey              FromFile(const std::string& fileName, const std::string& tag = "");
00131 
00137             static FontKey              FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00138 
00142             MovedPtr<sf::Font>          Load() const;
00143 
00146             void                        Swap(FontKey& other);
00147 
00148 
00149         // ---------------------------------------------------------------------------------------------------------------------------
00150         // Private member functions
00151         private:
00152             // Make default constructor private
00153                                         FontKey();
00154 
00155         
00156         // ---------------------------------------------------------------------------------------------------------------------------
00157         // Private variables
00158         private:
00159             std::tr1::function<bool(sf::Font&)>     mLoader;
00160             std::string                             mKey;
00161 
00162     
00163         // ---------------------------------------------------------------------------------------------------------------------------
00164         // Friends
00165         friend struct detail::KeyInfoAccessor<true>;
00166     };
00167 
00168 
00171     class THOR_API ShaderKey
00172     {
00173         // ---------------------------------------------------------------------------------------------------------------------------
00174         // Public member functions
00175         public:
00180             static ShaderKey            FromFile(const std::string& fileName, const std::string& tag = "");
00181 
00186             static ShaderKey            FromMemory(const std::string& shaderCode, const std::string& tag = "");
00187 
00190             MovedPtr<sf::Shader>        Load() const;
00191 
00194             void                        Swap(ShaderKey& other);
00195 
00196 
00197         // ---------------------------------------------------------------------------------------------------------------------------
00198         // Private member functions
00199         private:
00200             // Make default constructor private
00201                                         ShaderKey();
00202 
00203         
00204         // ---------------------------------------------------------------------------------------------------------------------------
00205         // Private variables
00206         private:
00207             std::tr1::function<bool(sf::Shader&)>   mLoader;
00208             std::string                             mKey;
00209 
00210     
00211         // ---------------------------------------------------------------------------------------------------------------------------
00212         // Friends
00213         friend struct detail::KeyInfoAccessor<true>;
00214     };
00215 
00216 
00219     bool THOR_API               operator< (const ImageKey& lhs, const ImageKey& rhs);
00220     
00223     bool THOR_API               operator< (const FontKey& lhs, const FontKey& rhs);
00224 
00227     bool THOR_API               operator< (const ShaderKey& lhs, const ShaderKey& rhs);
00228 
00229 
00232     THOR_GLOBAL_SWAP(ImageKey)
00233 
00234     
00235 
00236     THOR_GLOBAL_SWAP(FontKey)
00237 
00240     THOR_GLOBAL_SWAP(ShaderKey)
00241 
00242 } // namespace Resources
00243 
00245 
00246 } // namespace thor
00247 
00248 #endif // THOR_GRAPHICSKEYS_HPP