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