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  GETTERSETTER(int,BaseSize,baseSize)
48  GETTERSETTER(int,CharsCount,charsCount)
49  GETTERSETTER(Texture2D,Texture,texture)
50  GETTERSETTER(Rectangle*,Recs,recs)
51  GETTERSETTER(CharInfo*,Chars,chars)
52 
53  Font& operator=(const ::Font& font) {
54  set(font);
55  return *this;
56  }
57 
58  Font& operator=(const Font& font) {
59  set(font);
60  return *this;
61  }
62 
63  inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE) {
64  ::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
65  return *this;
66  }
67  inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint = WHITE) {
68  ::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
69  return *this;
70  }
71  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) {
72  ::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint, selectStart, selectLength, selectText, selectBack);
73  return *this;
74  }
75 
76  inline Vector2 MeasureText(const std::string& text, float fontSize, float spacing) {
77  return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
78  }
79 
80  inline int GetGlyphIndex(int character) const {
81  return ::GetGlyphIndex(*this, character);
82  }
83 
84  protected:
85  void set(const ::Font font) {
86  baseSize = font.baseSize;
87  charsCount = font.charsCount;
88  texture = font.texture;
89  recs = font.recs;
90  chars = font.chars;
91  }
92 
93  void set(const Font& font) {
94  baseSize = font.baseSize;
95  charsCount = font.charsCount;
96  texture = font.texture;
97  recs = font.recs;
98  chars = font.chars;
99  }
100  };
101 }
102 
103 #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:63
raylib::Font::Unload
void Unload()
Definition: Font.hpp:43
raylib::Font::operator=
Font & operator=(const Font &font)
Definition: Font.hpp:58
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:71
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:67
raylib::Font::~Font
~Font()
Definition: Font.hpp:39
raylib::Font::set
void set(const ::Font font)
Definition: Font.hpp:85
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::Font::GetGlyphIndex
int GetGlyphIndex(int character) const
Definition: Font.hpp:80
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:93
raylib::Font::MeasureText
Vector2 MeasureText(const std::string &text, float fontSize, float spacing)
Definition: Font.hpp:76
raylib::Color
Definition: Color.hpp:18
raylib::Texture
Definition: Texture.hpp:19