TGUI  0.8-dev
Texture.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_TEXTURE_HPP
27 #define TGUI_TEXTURE_HPP
28 
30 
31 #include <TGUI/TextureData.hpp>
32 #include <SFML/System/String.hpp>
33 #include <functional>
34 
36 
37 namespace tgui
38 {
39  class TGUI_API Texture
40  {
41  public:
42 
43  using ImageLoaderFunc = std::function<std::shared_ptr<sf::Image>(const sf::String&)>;
44  using TextureLoaderFunc = std::function<std::shared_ptr<TextureData>(Texture&, const sf::String&, const sf::IntRect&)>;
45 
46 
51  Texture() {}
52 
53 
62  Texture(const char* id,
63  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
64  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0))
65  : Texture(sf::String{id}, partRect, middlePart)
66  {
67  }
68 
69 
80  Texture(std::string id,
81  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
82  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0))
83  : Texture(sf::String{id}, partRect, middlePart)
84  {
85  }
86 
87 
98  Texture(const sf::String& id,
99  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
100  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
101 
102 
115  Texture(const sf::Texture& texture,
116  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
117  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
118 
119 
123  Texture(const Texture&);
124 
128  Texture(Texture&&);
129 
133  ~Texture();
134 
138  Texture& operator=(const Texture&);
139 
143  Texture& operator=(Texture&&);
144 
145 
154  void load(const sf::String& id,
155  const sf::IntRect& partRect = {},
156  const sf::IntRect& middleRect = {});
157 
158 
169  void load(const sf::Texture& texture,
170  const sf::IntRect& partRect = {},
171  const sf::IntRect& middleRect = {});
172 
173 
180  const sf::String& getId() const;
181 
182 
189  std::shared_ptr<TextureData> getData() const;
190 
191 
198  sf::Vector2f getImageSize() const;
199 
200 
213  void setSmooth(bool smooth);
214 
215 
224  bool isSmooth() const;
225 
226 
233  sf::IntRect getMiddleRect() const;
234 
235 
244  bool isTransparentPixel(sf::Vector2u pos) const;
245 
246 
255  void setCopyCallback(const std::function<void(std::shared_ptr<TextureData>)> func);
256 
257 
266  void setDestructCallback(const std::function<void(std::shared_ptr<TextureData>)> func);
267 
268 
279  static void setImageLoader(const ImageLoaderFunc& func);
280 
281 
290  static ImageLoaderFunc getImageLoader();
291 
292 
303  static void setTextureLoader(const TextureLoaderFunc& func);
304 
305 
314  static TextureLoaderFunc getTextureLoader();
315 
316 
318  private:
319 
327  void setTextureData(std::shared_ptr<TextureData> data, const sf::IntRect& middleRect = {});
328 
329 
331  private:
332 
333  std::shared_ptr<TextureData> m_data = nullptr;
334 
335  sf::IntRect m_middleRect;
336  sf::String m_id;
337 
338  std::function<void(std::shared_ptr<TextureData>)> m_copyCallback;
339  std::function<void(std::shared_ptr<TextureData>)> m_destructCallback;
340 
341  static TextureLoaderFunc m_textureLoader;
342  static ImageLoaderFunc m_imageLoader;
343  };
344 
346 }
347 
349 
350 #endif // TGUI_TEXTURE_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Texture()
Default constructor.
Definition: Texture.hpp:51
Texture(std::string id, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0))
Constructor that created the texture.
Definition: Texture.hpp:80
Definition: Texture.hpp:39
Texture(const char *id, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0))
Constructor that created the texture.
Definition: Texture.hpp:62