Bromeon
Resources/GraphicsKeys.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 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/SmartPtr/MovedPtr.hpp>
00034 #include <Thor/Detail/Swap.hpp>
00035 #include <Thor/Config.hpp>
00036 
00037 #include <SFML/Graphics/Color.hpp>
00038 #include <SFML/Graphics/Rect.hpp>
00039 #include <SFML/Config.hpp>
00040 
00041 #include THOR_TR1_HEADER(functional)
00042 #include <string>
00043 
00044 
00045 namespace thor
00046 {
00047 
00050 
00053 namespace Resources
00054 {
00055 
00058     class THOR_API ImageKey
00059     {
00060         // ---------------------------------------------------------------------------------------------------------------------------
00061         // Public member functions
00062         public:
00068             static ImageKey             FromSize(unsigned int width, unsigned int height, const sf::Color& fillColor = sf::Color(0, 0, 0),
00069                                             const std::string& tag = "");
00070 
00075             static ImageKey             FromFile(const std::string& fileName, const std::string& tag = "");
00076 
00082             static ImageKey             FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00083 
00089             static ImageKey             FromPixels(unsigned int width, unsigned int height, const sf::Uint8* pixels,
00090                                             const std::string& tag = "");
00091 
00096             static ImageKey             FromStream(sf::InputStream& stream, const std::string& tag = "");
00097 
00100             MovedPtr<sf::Image, NoCopy> Load() const;
00101 
00104             void                        Swap(ImageKey& other);
00105 
00106 
00107         // ---------------------------------------------------------------------------------------------------------------------------
00108         // Private member functions
00109         private:
00110             // Make default constructor private
00111                                         ImageKey();
00112 
00113         
00114         // ---------------------------------------------------------------------------------------------------------------------------
00115         // Private variables
00116         private:
00117             std::tr1::function<bool(sf::Image&)>    mLoader;
00118             std::string                             mKey;
00119 
00120     
00121         // ---------------------------------------------------------------------------------------------------------------------------
00122         // Friends
00123         friend struct detail::KeyInfoAccessor;
00124     };
00125 
00126 
00129     class THOR_API TextureKey
00130     {
00131         // ---------------------------------------------------------------------------------------------------------------------------
00132         // Public member functions
00133         public:
00138             static TextureKey           FromSize(unsigned int width, unsigned int height, const std::string& tag = "");
00139 
00145             static TextureKey           FromFile(const std::string& fileName, const sf::IntRect& area = sf::IntRect(),
00146                                             const std::string& tag = "");
00147 
00154             static TextureKey           FromMemory(const void* data, std::size_t size, const sf::IntRect& area = sf::IntRect(),
00155                                             const std::string& tag = "");
00156 
00162             static TextureKey           FromImage(const sf::Image& image, const sf::IntRect& area = sf::IntRect(),
00163                                             const std::string& tag = "");
00164 
00170             static TextureKey           FromStream(sf::InputStream& stream, const sf::IntRect& area = sf::IntRect(), 
00171                                             const std::string& tag = "");
00172 
00175             MovedPtr<sf::Texture, NoCopy>   Load() const;
00176 
00179             void                        Swap(TextureKey& other);
00180 
00181 
00182         // ---------------------------------------------------------------------------------------------------------------------------
00183         // Private member functions
00184         private:
00185             // Make default constructor private
00186                                         TextureKey();
00187 
00188         
00189         // ---------------------------------------------------------------------------------------------------------------------------
00190         // Private variables
00191         private:
00192             std::tr1::function<bool(sf::Texture&)>  mLoader;
00193             std::string                             mKey;
00194 
00195     
00196         // ---------------------------------------------------------------------------------------------------------------------------
00197         // Friends
00198         friend struct detail::KeyInfoAccessor;
00199     };
00200 
00201 
00204     class THOR_API FontKey
00205     {
00206         // ---------------------------------------------------------------------------------------------------------------------------
00207         // Public member functions
00208         public:
00213             static FontKey              FromFile(const std::string& fileName, const std::string& tag = "");
00214 
00220             static FontKey              FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00221 
00226             static FontKey              FromStream(sf::InputStream& stream, const std::string& tag = "");
00227 
00231             MovedPtr<sf::Font, NoCopy>  Load() const;
00232 
00235             void                        Swap(FontKey& other);
00236 
00237 
00238         // ---------------------------------------------------------------------------------------------------------------------------
00239         // Private member functions
00240         private:
00241             // Make default constructor private
00242                                         FontKey();
00243 
00244         
00245         // ---------------------------------------------------------------------------------------------------------------------------
00246         // Private variables
00247         private:
00248             std::tr1::function<bool(sf::Font&)>     mLoader;
00249             std::string                             mKey;
00250 
00251     
00252         // ---------------------------------------------------------------------------------------------------------------------------
00253         // Friends
00254         friend struct detail::KeyInfoAccessor;
00255     };
00256 
00257 
00260     class THOR_API ShaderKey
00261     {
00262         // ---------------------------------------------------------------------------------------------------------------------------
00263         // Public member functions
00264         public:
00270             static ShaderKey            FromFile(const std::string& fileName, THOR_FAKE_DOC(unsigned int, sf::Shader::Type) shaderType, const std::string& tag = "");
00271 
00277             static ShaderKey            FromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename, const std::string& tag = "");
00278 
00284             static ShaderKey            FromMemory(const std::string& shaderCode, THOR_FAKE_DOC(unsigned int, sf::Shader::Type) shaderType, const std::string& tag = "");
00285 
00291             static ShaderKey            FromMemory(const std::string& vertexShaderCode, const std::string& fragmentShaderCode, const std::string& tag = "");
00292             
00298             static ShaderKey            FromStream(sf::InputStream& stream, THOR_FAKE_DOC(unsigned int, sf::Shader::Type) shaderType, const std::string& tag = "");
00299 
00305             static ShaderKey            FromStream(sf::InputStream& vertexShaderStream, sf::InputStream& fragmentShaderStream, const std::string& tag = "");
00306 
00309             MovedPtr<sf::Shader, NoCopy> Load() const;
00310 
00313             void                        Swap(ShaderKey& other);
00314 
00315 
00316         // ---------------------------------------------------------------------------------------------------------------------------
00317         // Private member functions
00318         private:
00319             // Make default constructor private
00320                                         ShaderKey();
00321 
00322         
00323         // ---------------------------------------------------------------------------------------------------------------------------
00324         // Private variables
00325         private:
00326             std::tr1::function<bool(sf::Shader&)>   mLoader;
00327             std::string                             mKey;
00328 
00329     
00330         // ---------------------------------------------------------------------------------------------------------------------------
00331         // Friends
00332         friend struct detail::KeyInfoAccessor;
00333     };
00334 
00335 
00338     bool THOR_API               operator< (const ImageKey& lhs, const ImageKey& rhs);
00339 
00342     bool THOR_API               operator< (const TextureKey& lhs, const TextureKey& rhs);
00343 
00346     bool THOR_API               operator< (const FontKey& lhs, const FontKey& rhs);
00347 
00350     bool THOR_API               operator< (const ShaderKey& lhs, const ShaderKey& rhs);
00351 
00352 
00355     THOR_GLOBAL_SWAP(ImageKey)
00356 
00357     
00358 
00359     THOR_GLOBAL_SWAP(TextureKey)
00360 
00363     THOR_GLOBAL_SWAP(FontKey)
00364 
00367     THOR_GLOBAL_SWAP(ShaderKey)
00368 
00369 } // namespace Resources
00370 
00372 
00373 } // namespace thor
00374 
00375 #endif // THOR_GRAPHICSKEYS_HPP