sdl2_impl 0.1.0
Vendor SDL2 2.32 : IGraphic2Module / IAudioModule
Loading...
Searching...
No Matches
SdlFont.hpp
Go to the documentation of this file.
1
11#ifndef SDLFONT_HPP_
12#define SDLFONT_HPP_
13
14//Sdl
15#include <SDL.h>
16#include <SDL_ttf.h>
17
18//Interface
19#include "IFont.hpp"
20
21#include <iostream>
22#include <string>
23
32class SdlFont : public graphic::IFont {
33
34 public:
35 SdlFont(std::string path) : _path(path) {
36 _font = TTF_OpenFont(_path.c_str(), static_cast<int>(_size));
37 if (!_font)
38 std::cerr << "Failed to load font: " << TTF_GetError() << std::endl;
39 }
40
42 if (_font)
43 TTF_CloseFont(_font);
44 }
45
46 bool isReady() const override {
47 return _font != nullptr;
48 }
49
51 TTF_Font *handle(unsigned size) const {
52 if (_font && size != _size) {
53 TTF_SetFontSize(_font, static_cast<int>(size));
54 _size = size;
55 }
56 return _font;
57 }
58
59 private:
60 std::string _path;
61 TTF_Font *_font = nullptr;
62
64 mutable unsigned _size = 24;
65};
66
69#endif /* !SDLFONT_HPP_ */
Une police ouverte a une taille donnee.
Definition SdlFont.hpp:32
~SdlFont()
Definition SdlFont.hpp:41
bool isReady() const override
Definition SdlFont.hpp:46
TTF_Font * handle(unsigned size) const
La police, recalee sur size si besoin.
Definition SdlFont.hpp:51
SdlFont(std::string path)
Definition SdlFont.hpp:35