sftools  2.0 dev
Bunch of tools for SFML application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Frame.hpp
Go to the documentation of this file.
1 /*
2 
3  sftools - Copyright (c) 2012-2013 Marco Antognini <antognini.marco@gmail.com>
4 
5  This software is provided 'as-is', without any express or implied warranty. In
6  no event will the authors be held liable for any damages arising from the use
7  of this software.
8 
9  Permission is granted to anyone to use this software for any purpose, including
10  commercial applications, and to alter it and redistribute it freely, subject to
11  the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim
14  that you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 
23  */
24 
30 #ifndef __SFTOOLS_FRAME_HPP__
31 #define __SFTOOLS_FRAME_HPP__
32 
33 #include <SFML/Graphics/Texture.hpp>
34 #include <SFML/Graphics/Rect.hpp>
35 #include <SFML/Graphics/Color.hpp>
36 
37 #include <sftools/Singleton.hpp>
38 
43 namespace sftools
44 {
45 
57  struct Frame
58  {
68  Frame(sf::Vector2i size = sf::Vector2i(0, 0), sf::Color color = sf::Color::White)
69  : texture(&getDummyTexture())
70  , area(sf::Vector2i(0, 0), size)
71  , color(color)
72  {
73  // That's it
74  }
75 
85  Frame(sf::Texture const& texture, sf::IntRect area, sf::Color color = sf::Color::White)
86  : texture(&texture)
87  , area(area)
88  , color(color)
89  {
90  // That's it
91  }
92 
93  sf::Texture const* texture;
94  sf::IntRect area;
95  sf::Color color;
96 
97  private:
98  /*
99  In order to create uniformly colored frames we need a dummy texture.
100  But we don't want a texture to be created before the main() function
101  so we use our Singleton utility and create the dummy texture at the
102  last moment.
103 
104  Hopefully the user won't use any global Frame object!
105  */
106  struct DummyTexture { sf::Texture texture; };
107  static sf::Texture& getDummyTexture()
108  {
109  return Singleton<DummyTexture>::getInstance().texture;
110  }
111  };
112 
113 }
114 
115 #endif // __SFTOOLS_FRAME_HPP__