openMSX
TTFFont.hh
Go to the documentation of this file.
1#ifndef TTFFONT_HH
2#define TTFFONT_HH
3
4#include "SDLSurfacePtr.hh"
5#include "openmsx.hh"
6#include "gl_vec.hh"
7#include "zstring_view.hh"
8#include <string>
9#include <utility>
10
11namespace openmsx {
12
14{
15public:
16 TTFFont(const TTFFont&) = delete;
17 TTFFont& operator=(const TTFFont&) = delete;
18
25 TTFFont() = default;
26
32 TTFFont(const std::string& filename, int ptSize);
33
35 TTFFont(TTFFont&& other) noexcept
36 : font(other.font)
37 {
38 other.font = nullptr;
39 }
40
42 TTFFont& operator=(TTFFont&& other) noexcept
43 {
44 std::swap(font, other.font);
45 return *this;
46 }
47
48 ~TTFFont();
49
51 [[nodiscard]] bool empty() const { return font == nullptr; }
52
57 [[nodiscard]] SDLSurfacePtr render(std::string text, byte r, byte g, byte b) const;
58
62 [[nodiscard]] unsigned getHeight() const;
63
65 [[nodiscard]] bool isFixedWidth() const;
66
71 [[nodiscard]] unsigned getWidth() const;
72
75 [[nodiscard]] gl::ivec2 getSize(zstring_view text) const;
76
77private:
78 void* font = nullptr; // TTF_Font*
79};
80
81} // namespace openmsx
82
83#endif
int g
Wrapper around a SDL_Surface.
bool empty() const
Is this an empty font? (a default constructed object).
Definition: TTFFont.hh:51
unsigned getWidth() const
Return the width of the font.
Definition: TTFFont.cc:243
TTFFont & operator=(const TTFFont &)=delete
TTFFont(TTFFont &&other) noexcept
Move construct.
Definition: TTFFont.hh:35
bool isFixedWidth() const
Returns true iff this is a fixed-with (=mono-spaced) font.
Definition: TTFFont.cc:238
SDLSurfacePtr render(std::string text, byte r, byte g, byte b) const
Render the given text to a new SDL_Surface.
Definition: TTFFont.cc:149
TTFFont & operator=(TTFFont &&other) noexcept
Move assignment.
Definition: TTFFont.hh:42
unsigned getHeight() const
Return the height of the font.
Definition: TTFFont.cc:233
gl::ivec2 getSize(zstring_view text) const
Return the size in pixels of the text if it would be rendered.
Definition: TTFFont.cc:256
TTFFont()=default
Construct an empty font.
TTFFont(const TTFFont &)=delete
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
void swap(openmsx::MemBuffer< T > &l, openmsx::MemBuffer< T > &r) noexcept
Definition: MemBuffer.hh:202