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 CallbackFunc = std::function<void(std::shared_ptr<TextureData>)>;
44  using ImageLoaderFunc = std::function<std::unique_ptr<sf::Image>(const sf::String&)>;
45  using TextureLoaderFunc = std::function<std::shared_ptr<TextureData>(Texture&, const sf::String&, const sf::IntRect&)>;
46 
47 
52  Texture() {}
53 
54 
64  Texture(const char* id,
65  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
66  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
67  bool smooth = false)
68  : Texture(sf::String{id}, partRect, middlePart, smooth)
69  {
70  }
71 
72 
84  Texture(const std::string& id,
85  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
86  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
87  bool smooth = false)
88  : Texture(sf::String{id}, partRect, middlePart, smooth)
89  {
90  }
91 
92 
104  Texture(const sf::String& id,
105  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
106  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
107  bool smooth = false);
108 
109 
122  Texture(const sf::Texture& texture,
123  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
124  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
125 
126 
130  Texture(const Texture&);
131 
135  Texture(Texture&&);
136 
140  ~Texture();
141 
145  Texture& operator=(const Texture&);
146 
150  Texture& operator=(Texture&&);
151 
152 
162  void load(const sf::String& id,
163  const sf::IntRect& partRect = {},
164  const sf::IntRect& middleRect = {},
165  bool smooth = false);
166 
167 
178  void load(const sf::Texture& texture,
179  const sf::IntRect& partRect = {},
180  const sf::IntRect& middleRect = {});
181 
182 
189  const sf::String& getId() const;
190 
191 
198  std::shared_ptr<TextureData> getData() const;
199 
200 
207  sf::Vector2f getImageSize() const;
208 
209 
222  void setSmooth(bool smooth);
223 
224 
233  bool isSmooth() const;
234 
235 
242  sf::IntRect getMiddleRect() const;
243 
244 
253  bool isTransparentPixel(sf::Vector2u pos) const;
254 
255 
264  void setCopyCallback(const CallbackFunc& func);
265 
266 
275  void setDestructCallback(const CallbackFunc& func);
276 
277 
281  bool operator==(const Texture& right) const;
282 
283 
287  bool operator!=(const Texture& right) const;
288 
289 
300  static void setImageLoader(const ImageLoaderFunc& func);
301 
302 
311  static const ImageLoaderFunc& getImageLoader();
312 
313 
324  static void setTextureLoader(const TextureLoaderFunc& func);
325 
326 
335  static const TextureLoaderFunc& getTextureLoader();
336 
337 
339  private:
340 
348  void setTextureData(std::shared_ptr<TextureData> data, const sf::IntRect& middleRect = {});
349 
350 
352  private:
353 
354  std::shared_ptr<TextureData> m_data = nullptr;
355 
356  sf::IntRect m_middleRect;
357  sf::String m_id;
358 
359  CallbackFunc m_copyCallback;
360  CallbackFunc m_destructCallback;
361 
362  static TextureLoaderFunc m_textureLoader;
363  static ImageLoaderFunc m_imageLoader;
364  };
365 
367 }
368 
370 
371 #endif // TGUI_TEXTURE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Texture()
Default constructor.
Definition: Texture.hpp:52
Texture(const char *id, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0), bool smooth=false)
Constructor that created the texture.
Definition: Texture.hpp:64
Definition: Texture.hpp:39
Texture(const std::string &id, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0), bool smooth=false)
Constructor that created the texture.
Definition: Texture.hpp:84