TGUI  0.8.1
Texture.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 <TGUI/Vector2f.hpp>
33 #include <SFML/System/String.hpp>
34 #include <functional>
35 
37 
38 namespace tgui
39 {
40  class TGUI_API Texture
41  {
42  public:
43 
44  using CallbackFunc = std::function<void(std::shared_ptr<TextureData>)>;
45  using ImageLoaderFunc = std::function<std::unique_ptr<sf::Image>(const sf::String&)>;
46  using TextureLoaderFunc = std::function<std::shared_ptr<TextureData>(Texture&, const sf::String&, const sf::IntRect&)>;
47 
48 
53  Texture() {}
54 
55 
65  Texture(const char* id,
66  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
67  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
68  bool smooth = false)
69  : Texture(sf::String{id}, partRect, middlePart, smooth)
70  {
71  }
72 
73 
85  Texture(const std::string& id,
86  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
87  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
88  bool smooth = false)
89  : Texture(sf::String{id}, partRect, middlePart, smooth)
90  {
91  }
92 
93 
105  Texture(const sf::String& id,
106  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
107  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0),
108  bool smooth = false);
109 
110 
123  Texture(const sf::Texture& texture,
124  const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
125  const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
126 
127 
131  Texture(const Texture&);
132 
136  Texture(Texture&&);
137 
141  ~Texture();
142 
146  Texture& operator=(const Texture&);
147 
151  Texture& operator=(Texture&&);
152 
153 
163  void load(const sf::String& id,
164  const sf::IntRect& partRect = {},
165  const sf::IntRect& middleRect = {},
166  bool smooth = false);
167 
168 
179  void load(const sf::Texture& texture,
180  const sf::IntRect& partRect = {},
181  const sf::IntRect& middleRect = {});
182 
183 
190  const sf::String& getId() const;
191 
192 
199  std::shared_ptr<TextureData> getData() const;
200 
201 
208  Vector2f getImageSize() const;
209 
210 
223  void setSmooth(bool smooth);
224 
225 
234  bool isSmooth() const;
235 
236 
241  void setShader(sf::Shader* shader);
242 
243 
248  sf::Shader* getShader() const;
249 
250 
257  sf::IntRect getMiddleRect() const;
258 
259 
268  bool isTransparentPixel(sf::Vector2u pos) const;
269 
270 
279  void setCopyCallback(const CallbackFunc& func);
280 
281 
290  void setDestructCallback(const CallbackFunc& func);
291 
292 
296  bool operator==(const Texture& right) const;
297 
298 
302  bool operator!=(const Texture& right) const;
303 
304 
315  static void setImageLoader(const ImageLoaderFunc& func);
316 
317 
326  static const ImageLoaderFunc& getImageLoader();
327 
328 
339  static void setTextureLoader(const TextureLoaderFunc& func);
340 
341 
350  static const TextureLoaderFunc& getTextureLoader();
351 
352 
354  private:
355 
363  void setTextureData(std::shared_ptr<TextureData> data, const sf::IntRect& middleRect = {});
364 
365 
367  private:
368 
369  std::shared_ptr<TextureData> m_data = nullptr;
370 
371  sf::IntRect m_middleRect;
372  sf::String m_id;
373 
374  CallbackFunc m_copyCallback;
375  CallbackFunc m_destructCallback;
376 
377  static TextureLoaderFunc m_textureLoader;
378  static ImageLoaderFunc m_imageLoader;
379  };
380 
382 }
383 
385 
386 #endif // TGUI_TEXTURE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Texture()
Default constructor.
Definition: Texture.hpp:53
TGUI_CONSTEXPR bool operator!=(const Vector2f &left, const Vector2f &right)
Overload of binary operator ==.
Definition: Vector2f.hpp:224
TGUI_CONSTEXPR bool operator==(const Vector2f &left, const Vector2f &right)
Overload of binary operator ==.
Definition: Vector2f.hpp:216
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:65
Definition: Texture.hpp:40
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:85