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 #include <turtle_brains/core/tb_configuration.hpp>
12 #if defined(tb_with_networking)
13 
14 #include <turtle_brains/graphics/tb_graphic.hpp>
15 #include <turtle_brains/graphics/tb_sprite.hpp>
16 #include <turtle_brains/graphics/tb_basic_shapes.hpp>
17 
18 #include <functional>
19 
20 namespace TurtleBrains::Express::Graphics
21 {
22 
27  class WebSprite : public tbGraphics::Graphic
28  {
29  public:
39  static void SetCacheDirectory(const tbCore::String& filepath);
40 
56  explicit WebSprite(const tbCore::String& spriteURL, const tbGraphics::PixelSpace width, const tbGraphics::PixelSpace height,
57  const tbCore::String& 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::String& 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 TurtleBrains::Express::Graphics */
107 
108 namespace tbxGraphics = TurtleBrains::Express::Graphics;
109 
110 #endif /* tb_with_networking */
111 #endif /* TurtleBrainsExpress_WebSprite_hpp */
Definition: tb_color.hpp:24
Definition: tb_graphic.hpp:50
Definition: tb_sprite.hpp:135
std::string String
Definition: tb_string.hpp:302
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:34