aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Font.h
blob: 012c2717a49d9ff5711cc03900f99519945d1c12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include <SDL2/SDL_ttf.h>
#include <functional>
#include <memory>

#include "Asset.h"

namespace crepe {

class SDLContext;

/**
 * \class Font
 * \brief Manages font loading and text rendering properties.
 *
 * The Font class is responsible for loading font resources and providing a way to render text
 * with different styles and sizes. It can be used for text rendering in the game engine.
 */
class Font {

public:
    /**
     * \brief Constructs a Font from an Asset resource.
     * \param src Asset with font data to load.
     * \param size The point size to render the font at.
     */
    Font(const Asset &src, int size);

    /**
     * \brief Destroys the Font instance, freeing associated resources.
     */
    ~Font();

    /**
     * \brief Gets the size of the font.
     * \return The point size of the font.
     */
    int get_size() const;

private:
    /**
     * \brief Loads the font from an Asset resource.
     * \param res The Asset resource containing the font data.
     * \param size The point size to render the font at.
     */
    void load(const Asset &res, int size);

private:
    //! The font resource from the SDL_ttf library.
    std::unique_ptr<TTF_Font, std::function<void(TTF_Font *)>> font;

    //! The size of the font in points.
    int font_size;

    //! Grants SDLContext access to private members.
    friend class SDLContext;
};

} // namespace crepe