Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
TextSprite.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_TEXTSPRITE_HPP
8 #define NAZARA_TEXTSPRITE_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Graphics/Material.hpp>
12 #include <Nazara/Graphics/InstancedRenderable.hpp>
13 #include <Nazara/Utility/AbstractAtlas.hpp>
14 #include <Nazara/Utility/VertexStruct.hpp>
15 
16 namespace Nz
17 {
18  class AbstractTextDrawer;
19  class TextSprite;
20 
21  using TextSpriteConstRef = ObjectRef<const TextSprite>;
22  using TextSpriteLibrary = ObjectLibrary<TextSprite>;
23  using TextSpriteRef = ObjectRef<TextSprite>;
24 
25  class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable
26  {
27  public:
28  inline TextSprite();
29  inline TextSprite(const AbstractTextDrawer& drawer);
30  inline TextSprite(const TextSprite& sprite);
31  ~TextSprite() = default;
32 
33  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
34 
35  inline void Clear();
36 
37  inline const Color& GetColor() const;
38  inline float GetScale() const;
39 
40  inline void SetColor(const Color& color);
41  inline void SetDefaultMaterial();
42  inline void SetMaterial(MaterialRef material);
43  inline void SetMaterial(std::size_t skinIndex, MaterialRef material);
44  inline void SetScale(float scale);
45 
46  void Update(const AbstractTextDrawer& drawer);
47 
48  inline TextSprite& operator=(const TextSprite& text);
49 
50  template<typename... Args> static TextSpriteRef New(Args&&... args);
51 
52  private:
53  inline void InvalidateVertices();
54  void MakeBoundingVolume() const override;
55  void OnAtlasInvalidated(const AbstractAtlas* atlas);
56  void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer);
57  void UpdateData(InstanceData* instanceData) const override;
58 
59  struct RenderIndices
60  {
61  unsigned int first;
62  unsigned int count;
63  };
64 
65  struct AtlasSlots
66  {
67  bool used;
68  NazaraSlot(AbstractAtlas, OnAtlasCleared, clearSlot);
69  NazaraSlot(AbstractAtlas, OnAtlasLayerChange, layerChangeSlot);
70  NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot);
71  };
72 
73  std::unordered_map<const AbstractAtlas*, AtlasSlots> m_atlases;
74  mutable std::unordered_map<Texture*, RenderIndices> m_renderInfos;
75  mutable std::vector<VertexStruct_XY_Color_UV> m_localVertices;
76  Color m_color;
77  Recti m_localBounds;
78  float m_scale;
79 
80  static TextSpriteLibrary::LibraryMap s_library;
81  };
82 }
83 
84 #include <Nazara/Graphics/TextSprite.inl>
85 
86 #endif // NAZARA_TEXTSPRITE_HPP
Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
Graphics class that represents an instancer renderable.
Definition: InstancedRenderable.hpp:30
Graphics class that represents the rendering of a sprite containing text.
Definition: TextSprite.hpp:25