Mountain  1.0.0
Simple C++ 2D Game Framework
font.hpp
1 #pragma once
2 
3 #include <array>
4 #include <map>
5 
6 #include <Maths/vector2i.hpp>
7 
8 #include "Mountain/core.hpp"
9 #include "Mountain/rendering/gpu_texture.hpp"
11 
12 namespace Mountain
13 {
15  class Font : public Resource
16  {
17  public:
19  MOUNTAIN_API static constexpr std::array<const char_t*, 1> FileExtensions
20  {
21  ".ttf"
22  };
23 
24  DEFAULT_COPY_MOVE_OPERATIONS(Font)
25 
26  // Same constructor from base class
27  using Resource::Resource;
28 
29  MOUNTAIN_API ~Font() override;
30 
32  MOUNTAIN_API bool_t SetSourceData(const Pointer<File>& file, uint32_t size); // NOLINT(clang-diagnostic-overloaded-virtual)
33 
35  MOUNTAIN_API void ResetSourceData() override;
36 
37  MOUNTAIN_API Vector2 CalcTextSize(std::string_view text) const;
38 
39  private:
40  struct Character
41  {
42  Graphics::GpuTexture texture{};
43  Vector2i size; // Size of glyph
44  Vector2i bearing; // Offset from baseline to left/top of glyph
45  uint32_t advance;
46  };
47 
48  std::map<char_t, Character> m_Characters;
49 
50  uint32_t m_Size = 0;
51 
52  void Load() override;
53 
54  void Unload() override;
55 
56  friend class Draw;
57  };
58 }
59 
static MOUNTAIN_API constexpr std::array< const char_t *, 1 > FileExtensions
Allowed extensions for font files.
Definition: font.hpp:20
Defines the Mountain::Resource class.
Low-level interface for OpenGL textures.
Definition: gpu_texture.hpp:12
MOUNTAIN_API bool_t SetSourceData(const Pointer< File > &file, uint32_t size)
This also loads the font.
Custom Mountain smart pointer. Represents both a std::shared_ptr and a std::weak_ptr.
MOUNTAIN_API void ResetSourceData() override
This also unloads the font.
Holds the necessary information to draw text using a Font.
Definition: font.hpp:15
The Draw class contains static functions to draw various things on screen.
Definition: draw.hpp:32
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22