Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Sprite.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_SPRITE_HPP
8 #define NAZARA_SPRITE_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Graphics/InstancedRenderable.hpp>
12 #include <Nazara/Graphics/Material.hpp>
13 #include <array>
14 
15 namespace Nz
16 {
17  class Sprite;
18 
19  using SpriteConstRef = ObjectRef<const Sprite>;
20  using SpriteLibrary = ObjectLibrary<Sprite>;
21  using SpriteRef = ObjectRef<Sprite>;
22 
23  class NAZARA_GRAPHICS_API Sprite : public InstancedRenderable
24  {
25  friend SpriteLibrary;
26  friend class Graphics;
27 
28  public:
29  inline Sprite();
30  inline Sprite(MaterialRef material);
31  inline Sprite(Texture* texture);
32  inline Sprite(const Sprite& sprite);
33  Sprite(Sprite&&) = delete;
34  ~Sprite() = default;
35 
36  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
37 
38  inline const Color& GetColor() const;
39  inline const Color& GetCornerColor(RectCorner corner) const;
40  inline const Vector3f& GetOrigin() const;
41  inline const Vector2f& GetSize() const;
42  inline const Rectf& GetTextureCoords() const;
43 
44  inline void SetColor(const Color& color);
45  inline void SetCornerColor(RectCorner corner, const Color& color);
46  inline void SetDefaultMaterial();
47  inline void SetMaterial(MaterialRef material, bool resizeSprite = true);
48  bool SetMaterial(String materialName, bool resizeSprite = true);
49  inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite = true);
50  bool SetMaterial(std::size_t skinIndex, String materialName, bool resizeSprite = true);
51  inline void SetOrigin(const Vector3f& origin);
52  inline void SetSize(const Vector2f& size);
53  inline void SetSize(float sizeX, float sizeY);
54  bool SetTexture(String textureName, bool resizeSprite = true);
55  inline void SetTexture(TextureRef texture, bool resizeSprite = true);
56  bool SetTexture(std::size_t skinIndex, String textureName, bool resizeSprite = true);
57  inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite = true);
58  inline void SetTextureCoords(const Rectf& coords);
59  inline void SetTextureRect(const Rectui& rect);
60 
61  inline Sprite& operator=(const Sprite& sprite);
62  Sprite& operator=(Sprite&& sprite) = delete;
63 
64  template<typename... Args> static SpriteRef New(Args&&... args);
65 
66  private:
67  inline void InvalidateVertices();
68  void MakeBoundingVolume() const override;
69  void UpdateData(InstanceData* instanceData) const override;
70 
71  static bool Initialize();
72  static void Uninitialize();
73 
74  std::array<Color, 4> m_cornerColor;
75  Color m_color;
76  Rectf m_textureCoords;
77  Vector2f m_size;
78  Vector3f m_origin;
79 
80  static SpriteLibrary::LibraryMap s_library;
81  };
82 }
83 
84 #include <Nazara/Graphics/Sprite.inl>
85 
86 #endif // NAZARA_SPRITE_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 module initializer of Graphics.
Definition: Graphics.hpp:15
Core class that represents a string.
Definition: String.hpp:22
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.
Definition: Sprite.hpp:23