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"
9 #include "./TextureUnmanaged.hpp"
22 ::GlyphInfo *glyphs =
nullptr) :
::Font{baseSize, glyphCount, glyphPadding, texture, recs, glyphs} {
30 set(::GetFontDefault());
33 Font(const ::Font& font) {
44 Font(
const std::string& fileName) {
57 Font(
const std::string& fileName,
int fontSize,
int* fontChars = 0,
int charCount = 0) {
58 Load(fileName, fontSize, fontChars, charCount);
70 Font(const ::Image& image, ::
Color key,
int firstChar) {
71 Load(image, key, firstChar);
81 Font(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
82 int *fontChars,
int charsCount) {
83 Load(fileType, fileData, dataSize, fontSize, fontChars, charsCount);
93 other.glyphPadding = 0;
96 other.glyphs =
nullptr;
107 GETTERSETTER(
int, BaseSize, baseSize)
108 GETTERSETTER(
int, GlyphCount, glyphCount)
109 GETTERSETTER(
int, GlyphPadding, glyphPadding)
111 GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)
124 texture = newTexture;
127 Font& operator=(const ::Font& font) {
133 Font& operator=(
const Font&) =
delete;
135 Font& operator=(
Font&& other) noexcept {
136 if (
this == &other) {
144 other.glyphCount = 0;
145 other.glyphPadding = 0;
147 other.recs =
nullptr;
148 other.glyphs =
nullptr;
162 void Load(
const std::string& fileName) {
165 throw new RaylibException(
"Failed to load Font with from file: " + fileName);
179 void Load(
const std::string& fileName,
int fontSize,
int* fontChars,
int charCount) {
180 set(::
LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount));
182 throw new RaylibException(
"Failed to load Font with from file with font size: " + fileName);
186 void Load(const ::Image& image, ::
Color key,
int firstChar) {
187 set(::LoadFontFromImage(image, key, firstChar));
193 void Load(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
194 int *fontChars,
int charsCount) {
195 set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars,
198 throw new RaylibException(
"Failed to load Font " + fileType +
" with from file data");
213 float spacing, ::
Color tint = WHITE)
const {
214 ::DrawTextEx(*
this, text.c_str(), position, fontSize, spacing, tint);
220 inline void DrawText(
const std::string& text,
int posX,
int posY,
float fontSize,
221 float spacing, ::
Color tint = WHITE)
const {
223 { static_cast<float>(posX), static_cast<float>(posY) },
224 fontSize, spacing, tint);
228 const std::string& text,
234 ::
Color tint = WHITE)
const {
247 ::
Color tint = { 255, 255, 255, 255 })
const {
248 ::DrawTextCodepoint(*
this, codepoint, position, fontSize, tint);
256 float fontSize,
float spacing,
257 ::
Color tint = { 255, 255, 255, 255 })
const {
258 ::DrawTextCodepoints(*
this,
268 return ::MeasureTextEx(*
this, text.c_str(), fontSize, spacing);
275 return ::GetGlyphIndex(*
this, character);
281 inline ::Image
ImageText(
const std::string& text,
float fontSize,
282 float spacing, ::
Color tint)
const {
283 return ::ImageTextEx(*
this, text.c_str(), fontSize, spacing, tint);
287 void set(const ::Font& font) {
288 baseSize = font.baseSize;
289 glyphCount = font.glyphCount;
290 glyphPadding = font.glyphPadding;
291 texture = font.texture;
293 glyphs = font.glyphs;
Font type, includes texture and charSet array data.
Font(const std::string &fileName, int fontSize, int *fontChars=0, int charCount=0)
Loads a Font from the given file, with generation parameters.
void DrawText(const int *codepoints, int count, ::Vector2 position, float fontSize, float spacing, ::Color tint={ 255, 255, 255, 255 }) const
Draw multiple character (codepoint)
void SetTexture(const ::Texture &newTexture)
Set the texture atlas containing the glyphs.
Vector2 MeasureText(const std::string &text, float fontSize, float spacing) const
Measure string size for Font.
void Load(const std::string &fileName, int fontSize, int *fontChars, int charCount)
Loads a font from a given file with generation parameters.
void Load(const std::string &fileName)
Loads a font from a given file.
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.
int GetGlyphIndex(int character) const
Get index position for a unicode character on font.
Font()
Retrieves the default Font.
void DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint={ 255, 255, 255, 255 }) const
Draw one character (codepoint)
Font(const std::string &fileName)
Loads a Font from the given file.
TextureUnmanaged GetTexture()
Get the texture atlas containing the glyphs.
Font(const ::Image &image, ::Color key, int firstChar)
Loads a Font from the given image with a color key.
void DrawText(const std::string &text, int posX, int posY, float fontSize, float spacing, ::Color tint=WHITE) const
Draw text using font and additional parameters.
bool IsReady()
Returns if the font is ready to be used.
void DrawText(const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE) const
Draw text using font and additional parameters.
inline ::Image ImageText(const std::string &text, float fontSize, float spacing, ::Color tint) const
Create an image from text (custom sprite font)
Exception used for most raylib-related exceptions.
A Texture that is not managed by the C++ garbage collector.
All raylib-cpp classes and functions appear in the raylib namespace.
static inline ::Font LoadFontEx(const std::string &fileName, int fontSize, int *fontChars, int charsCount)
Load font from file (filename must include file extension)
static inline ::Font LoadFont(const std::string &fileName)
Load font from file (filename must include file extension)
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)
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.