blob: 3eff3c6ff066b62522f62c0636be9df48cf7112e (
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
|
#pragma once
#include <SDL2/SDL_ttf.h>
#include <functional>
#include <memory>
#include <string>
#include "../Resource.h"
namespace crepe {
class Asset;
/**
* \brief Resource for managing font creation and destruction
*
* This class is a wrapper around an SDL_ttf font instance, encapsulating font loading and usage.
* It loads a font from an Asset and manages its lifecycle. The font is automatically unloaded
* when this object is destroyed.
*/
class Font : public Resource {
public:
/**
* \param src The Asset containing the font file path and metadata to load the font.
* \param mediator The Mediator object used for managing the SDL context or related systems.
*/
Font(const Asset & src, Mediator & mediator);
/**
* \brief Gets the underlying TTF_Font resource.
*
* This function returns the raw pointer to the SDL_ttf TTF_Font object that represents
* the loaded font. This can be used with SDL_ttf functions to render text.
*
* \return The raw TTF_Font object wrapped in a unique pointer.
*/
TTF_Font * get_font() const;
const std::string & get_path() const noexcept;
private:
//! The SDL_ttf font object with custom deleter.
std::unique_ptr<TTF_Font, std::function<void(TTF_Font *)>> font = nullptr;
};
} // namespace crepe
|