 |
raylib-cpp
C++ object-oriented wrapper library for raylib.
|
1 #ifndef RAYLIB_CPP_INCLUDE_FONT_HPP_
2 #define RAYLIB_CPP_INCLUDE_FONT_HPP_
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./RaylibException.hpp"
21 ::GlyphInfo *glyphs =
nullptr) :
::Font{baseSize, glyphCount, glyphPadding, texture, recs, glyphs} {
26 set(::GetFontDefault());
29 Font(const ::Font& font) {
40 Font(
const std::string& fileName) {
41 if (!
Load(fileName)) {
55 Font(
const std::string& fileName,
int fontSize,
int* fontChars = 0,
int charCount = 0) {
56 if (!
Load(fileName, fontSize, fontChars, charCount)) {
70 Font(const ::Image& image, ::
Color key,
int firstChar) {
71 if (!
Load(image, key, firstChar)) {
83 Font(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
84 int *fontChars,
int charsCount) {
85 if (!
Load(fileType, fileData, dataSize, fontSize, fontChars, charsCount)) {
97 other.glyphPadding = 0;
100 other.glyphs =
nullptr;
111 GETTERSETTER(
int, BaseSize, baseSize)
112 GETTERSETTER(
int, GlyphCount, glyphCount)
113 GETTERSETTER(
int, GlyphPadding, glyphPadding)
116 GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)
118 Font& operator=(const ::
Font& font) {
124 Font& operator=(
const Font&) =
delete;
126 Font& operator=(
Font&& other) noexcept {
127 if (
this == &other) {
135 other.glyphCount = 0;
136 other.glyphPadding = 0;
138 other.recs =
nullptr;
139 other.glyphs =
nullptr;
153 bool Load(
const std::string& fileName) {
168 bool Load(
const std::string& fileName,
int fontSize,
int* fontChars,
int charCount) {
169 set(::
LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount));
173 bool Load(const ::Image& image, ::
Color key,
int firstChar) {
174 set(::LoadFontFromImage(image, key, firstChar));
178 bool Load(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
179 int *fontChars,
int charsCount) {
180 set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars,
189 float spacing, ::
Color tint = WHITE) {
190 ::DrawTextEx(*
this, text.c_str(), position, fontSize, spacing, tint);
195 const std::string& text,
201 ::
Color tint = WHITE) {
202 ::DrawTextPro(*
this, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
212 ::
Color tint = { 255, 255, 255, 255 }) {
213 ::DrawTextCodepoint(*
this, codepoint, position, fontSize, tint);
221 return ::MeasureTextEx(*
this, text.c_str(), fontSize, spacing);
228 return ::GetGlyphIndex(*
this, character);
234 inline ::Image
ImageText(
const std::string& text,
float fontSize,
235 float spacing, ::
Color tint)
const {
236 return ::ImageTextEx(*
this, text.c_str(), fontSize, spacing, tint);
240 void set(const ::Font& font) {
241 baseSize = font.baseSize;
242 glyphCount = font.glyphCount;
243 glyphPadding = font.glyphPadding;
244 texture = font.texture;
246 glyphs = font.glyphs;
251 #endif // RAYLIB_CPP_INCLUDE_FONT_HPP_
Font(const std::string &fileName)
Loads a Font from the given file.
All raylib-cpp classes and functions appear in the raylib namespace.
Font & DrawText(const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE)
Draw text using font and additional parameters.
static inline ::Font LoadFont(const std::string &fileName)
Load font from file (filename must include file extension)
Font(const ::Image &image, ::Color key, int firstChar)
Loads a Font from the given image with a color key.
Font & DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint={ 255, 255, 255, 255 })
Draw one character (codepoint)
Font(const std::string &fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
Loads a font from memory, based on the given file type and file data.
Font(const std::string &fileName, int fontSize, int *fontChars=0, int charCount=0)
Loads a Font from the given file, with generation parameters.
static void DrawTextPro(const Font &font, const std::string &text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint)
Draw text using Font and pro parameters (rotation)
Font type, includes texture and charSet array data.
int GetGlyphIndex(int character) const
Get index position for a unicode character on font.
static inline ::Font LoadFontEx(const std::string &fileName, int fontSize, int *fontChars, int charsCount)
Load font from file (filename must include file extension)
inline ::Image ImageText(const std::string &text, float fontSize, float spacing, ::Color tint) const
Create an image from text (custom sprite font)
bool Load(const std::string &fileName, int fontSize, int *fontChars, int charCount)
Loads a font from a given file with generation parameters.
Vector2 MeasureText(const std::string &text, float fontSize, float spacing) const
Measure string size for Font.
bool Load(const std::string &fileName)
Loads a font from a given file.
Exception used for most raylib-related exceptions.
static void DrawTextEx(const Font &font, const std::string &text, Vector2 position, float fontSize, float spacing, ::Color tint)
Draw text using font and additional parameters.