TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tbx_web_sprite.hpp
1 
9 #ifndef TurtleBrainsExpress_WebSprite_hpp
10 #define TurtleBrainsExpress_WebSprite_hpp
11 
12 #include <turtle_brains/graphics/tb_graphic.hpp>
13 #include <turtle_brains/graphics/tb_sprite.hpp>
14 #include <turtle_brains/graphics/tb_basic_shapes.hpp>
15 
16 #include <functional>
17 
18 namespace TurtleBrainsExpress
19 {
20  namespace Graphics
21  {
22 
28  {
29  public:
39  static void SetCacheDirectory(const tbCore::tbString& filepath);
40 
56  explicit WebSprite(const tbCore::tbString& spriteURL, const tbGraphics::PixelSpace width, const tbGraphics::PixelSpace height,
57  const tbCore::tbString& cacheID = "", const bool alwaysFetch = false);
58 
62  virtual ~WebSprite(void);
63 
71  void SetColorUntilLoaded(const tbGraphics::Color& color);
72 
79  void SetOnLoaded(std::function<void(void)> callback);
80 
84  virtual tbGraphics::PixelSpace GetPixelWidth(void) const override;
85 
89  virtual tbGraphics::PixelSpace GetPixelHeight(void) const override;
90 
91  protected:
92  virtual void OnRender(void) const override;
93 
94  private:
95  bool LoadFromCache(const tbCore::tbString& cacheID);
96 
97  tbGraphics::Sprite mSprite;
98  std::function<void(void)> mOnLoadedCallback;
99 
100  tbGraphics::PixelSpace mWidth;
101  tbGraphics::PixelSpace mHeight;
102  bool mResetColorOnLoad;
103  bool mLoadedFromCache;
104  };
105 
106  }; /* namespace Graphics */
107 }; /* namespace TurtleBrainsExpress */
108 
110 
111 #endif /* TurtleBrainsExpress_WebSprite_hpp */
Definition: tb_graphic.hpp:61
void SetColorUntilLoaded(const tbGraphics::Color &color)
void SetOnLoaded(std::function< void(void)> callback)
virtual tbGraphics::PixelSpace GetPixelHeight(void) const override
Definition: tbx_web_sprite.hpp:27
Definition: tbx_nine_slice.hpp:19
A collection of objects and functions to express games quickly.
WebSprite(const tbCore::tbString &spriteURL, const tbGraphics::PixelSpace width, const tbGraphics::PixelSpace height, const tbCore::tbString &cacheID="", const bool alwaysFetch=false)
Definition: tb_color.hpp:24
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
static void SetCacheDirectory(const tbCore::tbString &filepath)
virtual void OnRender(void) const override
virtual tbGraphics::PixelSpace GetPixelWidth(void) const override
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_sprite.hpp:136