raylib-cpp
C++ object-oriented wrapper library for raylib.
Text.hpp
1#ifndef RAYLIB_CPP_INCLUDE_TEXT_HPP_
2#define RAYLIB_CPP_INCLUDE_TEXT_HPP_
3
4#include <string>
5
6#include "./raylib.hpp"
7#include "./RaylibException.hpp"
8#include "./raylib-cpp-utils.hpp"
9
10namespace raylib {
14class Text {
15 public:
19 std::string text;
20
24 float fontSize;
25
29 ::Color color;
30
34 ::Font font;
35
39 float spacing;
40
51 const std::string& text = "",
52 float fontSize = 10,
53 const ::Color& color = WHITE,
54 const ::Font& font = ::GetFontDefault(),
55 float spacing = 0) :
56 text(text),
58 color(color),
59 font(font),
61 // Nothing.
62 }
63
74 const ::Font& font,
75 const std::string& text = "",
76 float fontSize = 10,
77 float spacing = 0,
78 const ::Color& color = WHITE) :
79 text(text),
81 color(color),
82 font(font),
84 // Nothing.
85 }
86
87 GETTERSETTER(std::string, Text, text)
88 GETTERSETTER(float, FontSize, fontSize)
89 GETTERSETTER(::Font, Font, font)
90 GETTERSETTER(::Color, Color, color)
91 GETTERSETTER(float, Spacing, spacing)
92
96 inline void Draw(const ::Vector2& position) {
97 ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
98 }
99
103 inline void Draw(int posX, int posY) {
105 text.c_str(),
106 { static_cast<float>(posX), static_cast<float>(posY) },
107 fontSize,
108 spacing,
109 color);
110 }
111
117 inline void Draw(const ::Vector2& position, float rotation, const Vector2& origin = {0, 0}) {
118 ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
119 }
120
124 inline int Measure() {
125 return ::MeasureText(text.c_str(), static_cast<int>(fontSize));
126 }
127
132 return ::MeasureTextEx(font, text.c_str(), fontSize, spacing);
133 }
134
135 Text& operator=(const Text& other) {
136 if (this == &other) {
137 return *this;
138 }
139
140 text = other.text;
141 fontSize = other.fontSize;
142 color = other.color;
143 font = other.font;
144 spacing = other.spacing;
145
146 return *this;
147 }
148
154 static inline void Draw(
155 const std::string& text,
156 const int posX,
157 const int posY,
158 const int fontSize,
159 const ::Color& color) {
160 ::DrawText(text.c_str(), posX, posY, fontSize, color);
161 }
162
168 static inline void Draw(
169 const std::string& text,
170 const ::Vector2& pos,
171 const int fontSize,
172 const ::Color& color) {
173 ::DrawText(text.c_str(), static_cast<int>(pos.x), static_cast<int>(pos.y), fontSize, color);
174 }
175
181 static inline void Draw(
182 const ::Font& font,
183 const std::string& text,
184 const ::Vector2& position,
185 const float fontSize,
186 const float spacing,
187 const ::Color& color) {
188 ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
189 }
190
196 static inline void Draw(
197 const ::Font& font,
198 const std::string& text,
199 const ::Vector2& position,
200 const ::Vector2& origin,
201 const float rotation,
202 const float fontSize,
203 const float spacing,
204 const ::Color& color) {
205 ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
206 }
207};
208} // namespace raylib
209
210#endif // RAYLIB_CPP_INCLUDE_TEXT_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:14
Font type, includes texture and charSet array data.
Definition: Font.hpp:14
Text Functions.
Definition: Text.hpp:14
void Draw(const ::Vector2 &position)
Draw text with values in class.
Definition: Text.hpp:96
float fontSize
The size of the text.
Definition: Text.hpp:24
void Draw(int posX, int posY)
Draw text with values in class.
Definition: Text.hpp:103
Text(const ::Font &font, const std::string &text="", float fontSize=10, float spacing=0, const ::Color &color=WHITE)
Initializes a new Text object with a custom font.
Definition: Text.hpp:73
static void Draw(const std::string &text, const ::Vector2 &pos, const int fontSize, const ::Color &color)
Draw text using font and color, with position defined as Vector2.
Definition: Text.hpp:168
static void Draw(const ::Font &font, const std::string &text, const ::Vector2 &position, const float fontSize, const float spacing, const ::Color &color)
Draw text using font, color, position, font size and spacing.
Definition: Text.hpp:181
float spacing
The character spacing for the text.
Definition: Text.hpp:39
int Measure()
Measure string width for default font.
Definition: Text.hpp:124
void Draw(const ::Vector2 &position, float rotation, const Vector2 &origin={0, 0})
Draw text using Font and pro parameters (rotation).
Definition: Text.hpp:117
::Font font
The internal raylib font to use for the text.
Definition: Text.hpp:34
Text(const std::string &text="", float fontSize=10, const ::Color &color=WHITE, const ::Font &font=::GetFontDefault(), float spacing=0)
Initializes a new Text object.
Definition: Text.hpp:50
static void Draw(const std::string &text, const int posX, const int posY, const int fontSize, const ::Color &color)
Draw text using font and color.
Definition: Text.hpp:154
Text & operator=(const Text &other)
Definition: Text.hpp:135
Vector2 MeasureEx()
Measure string size for Font.
Definition: Text.hpp:131
::Color color
The color of the text.
Definition: Text.hpp:29
std::string text
The internal text.
Definition: Text.hpp:19
static void Draw(const ::Font &font, const std::string &text, const ::Vector2 &position, const ::Vector2 &origin, const float rotation, const float fontSize, const float spacing, const ::Color &color)
Draw text using font, color, position, origin, font size and spacing.
Definition: Text.hpp:196
Vector2 type.
Definition: Vector2.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
static void DrawText(const std::string &text, int posX, int posY, int fontSize, ::Color color)
Draw text (using default font)
Definition: Functions.hpp:256
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)
Definition: Functions.hpp:271
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.
Definition: Functions.hpp:263