raylib-cpp
C++ object-oriented wrapper library for raylib.
Font.hpp
1 #ifndef RAYLIB_CPP_FONT_HPP_
2 #define RAYLIB_CPP_FONT_HPP_
3 
4 #include <string>
5 
6 #ifdef __cplusplus
7 extern "C"{
8 #endif
9 #include "raylib.h"
10 #ifdef __cplusplus
11 }
12 #endif
13 
14 #include "./raylib-cpp-utils.hpp"
15 
16 namespace raylib {
17  class Font : public ::Font {
18  public:
19  Font() {
20  set(::GetFontDefault());
21  }
22 
23  Font(const std::string& fileName) {
24  set(::LoadFont(fileName.c_str()));
25  }
26 
27  Font(const std::string& fileName, int fontSize, int* fontChars, int charCount) {
28  set(::LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount));
29  }
30 
31  Font(::Image& image, ::Color key, int firstChar) {
32  set(::LoadFontFromImage(image, key, firstChar));
33  }
34 
35  Font(const std::string& fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount) {
36  set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars, charsCount));
37  }
38 
39  ~Font() {
40  Unload();
41  }
42 
43  void Unload() {
44  UnloadFont(*this);
45  }
46 
47  void set(const ::Font font) {
48  baseSize = font.baseSize;
49  charsCount = font.charsCount;
50  texture = font.texture;
51  recs = font.recs;
52  chars = font.chars;
53  }
54 
55  void set(const Font& font) {
56  baseSize = font.baseSize;
57  charsCount = font.charsCount;
58  texture = font.texture;
59  recs = font.recs;
60  chars = font.chars;
61  }
62 
63  GETTERSETTER(int,BaseSize,baseSize)
64  GETTERSETTER(int,CharsCount,charsCount)
65  GETTERSETTER(Texture2D,Texture,texture)
66  GETTERSETTER(Rectangle*,Recs,recs)
67  GETTERSETTER(CharInfo*,Chars,chars)
68 
69  Font& operator=(const ::Font& font) {
70  set(font);
71  return *this;
72  }
73 
74  Font& operator=(const Font& font) {
75  set(font);
76  return *this;
77  }
78 
79  inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE) {
80  ::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
81  return *this;
82  }
83  inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint = WHITE) {
84  ::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
85  return *this;
86  }
87  inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText, Color selectBack) {
88  ::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint, selectStart, selectLength, selectText, selectBack);
89  return *this;
90  }
91 
92  inline Vector2 MeasureText(const std::string& text, float fontSize, float spacing) {
93  return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
94  }
95 
96  inline int GetGlyphIndex(int character) {
97  return ::GetGlyphIndex(*this, character);
98  }
99  };
100 }
101 
102 #endif
raylib::Font::Font
Font(const std::string &fileName)
Definition: Font.hpp:23
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
raylib::Image
Definition: Image.hpp:16
raylib::Font::DrawText
Font & DrawText(const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE)
Definition: Font.hpp:79
raylib::Font::Unload
void Unload()
Definition: Font.hpp:43
raylib::Font::operator=
Font & operator=(const Font &font)
Definition: Font.hpp:74
raylib::Font::DrawText
Font & DrawText(const std::string &text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText, Color selectBack)
Definition: Font.hpp:87
raylib::Font::Font
Font()
Definition: Font.hpp:19
raylib::Font::DrawText
Font & DrawText(const std::string &text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint=WHITE)
Definition: Font.hpp:83
raylib::Font::~Font
~Font()
Definition: Font.hpp:39
raylib::Font::set
void set(const ::Font font)
Definition: Font.hpp:47
raylib::Font::Font
Font(const std::string &fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
Definition: Font.hpp:35
raylib::Rectangle
Definition: Rectangle.hpp:16
raylib::Font::Font
Font(::Image &image, ::Color key, int firstChar)
Definition: Font.hpp:31
raylib::Font
Definition: Font.hpp:17
raylib::Vector2
Definition: Vector2.hpp:22
raylib::Font::Font
Font(const std::string &fileName, int fontSize, int *fontChars, int charCount)
Definition: Font.hpp:27
raylib::Font::set
void set(const Font &font)
Definition: Font.hpp:55
raylib::Font::MeasureText
Vector2 MeasureText(const std::string &text, float fontSize, float spacing)
Definition: Font.hpp:92
raylib::Color
Definition: Color.hpp:18
raylib::Texture2D
Definition: Texture2D.hpp:19
raylib::Font::GetGlyphIndex
int GetGlyphIndex(int character)
Definition: Font.hpp:96