Overload some of the std::string to const char* functions

This commit is contained in:
Rob Loach
2024-02-24 00:47:48 -05:00
parent 9d17610629
commit 61a3cee8b2
4 changed files with 134 additions and 3 deletions

View File

@@ -159,15 +159,35 @@ class Color : public ::Color {
::DrawLineStrip(points, numPoints, *this);
}
void DrawText(const char* text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
::DrawText(text, posX, posY, fontSize, *this);
}
void DrawText(const std::string& text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
::DrawText(text.c_str(), posX, posY, fontSize, *this);
}
void DrawText(const ::Font& font, const char* text, ::Vector2 position,
float fontSize, float spacing) const {
::DrawTextEx(font, text, position, fontSize, spacing, *this);
}
void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
float fontSize, float spacing) const {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
}
void DrawText(
const ::Font& font,
const char* text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing) const {
::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, *this);
}
void DrawText(
const ::Font& font,
const std::string& text,

View File

@@ -210,6 +210,14 @@ class Font : public ::Font {
return ::IsFontReady(*this);
}
/**
* Draw text using font and additional parameters.
*/
void DrawText(const char* text, ::Vector2 position, float fontSize,
float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text, position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
@@ -218,6 +226,16 @@ class Font : public ::Font {
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
void DrawText(const char* text, int posX, int posY, float fontSize,
float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text,
{ static_cast<float>(posX), static_cast<float>(posY) },
fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
@@ -228,6 +246,20 @@ class Font : public ::Font {
fontSize, spacing, tint);
}
void DrawText(
const char* text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextPro(*this, text,
position, origin,
rotation, fontSize,
spacing, tint);
}
void DrawText(
const std::string& text,
::Vector2 position,
@@ -265,6 +297,13 @@ class Font : public ::Font {
spacing, tint);
}
/**
* Measure string size for Font
*/
Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text, fontSize, spacing);
}
/**
* Measure string size for Font
*/
@@ -279,6 +318,14 @@ class Font : public ::Font {
return ::GetGlyphIndex(*this, character);
}
/**
* Create an image from text (custom sprite font)
*/
::Image ImageText(const char* text, float fontSize,
float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text, fontSize, spacing, tint);
}
/**
* Create an image from text (custom sprite font)
*/

View File

@@ -240,18 +240,41 @@ namespace raylib {
/**
* Draw text (using default font)
*/
[[maybe_unused]] RLCPPAPI inline void DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
[[maybe_unused]] RLCPPAPI inline void DrawText(const char* text, int posX, int posY, int fontSize, ::Color color) {
::DrawText(text, posX, posY, fontSize, color);
}
/**
* Draw text (using default font)
*/
[[maybe_unused]] RLCPPAPI inline void DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
::DrawText(text.c_str(), posX, posY, fontSize, color);
}
/**
* Draw text using font and additional parameters
*/
[[maybe_unused]] RLCPPAPI inline void DrawTextEx(const Font& font, const std::string& text, Vector2 position,
[[maybe_unused]] RLCPPAPI inline void DrawTextEx(const Font& font, char* text, Vector2 position,
float fontSize, float spacing, ::Color tint) {
::DrawTextEx(font, text, position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters
*/
[[maybe_unused]] RLCPPAPI inline void DrawTextEx(const Font& font, const std::string& text, Vector2 position,
float fontSize, float spacing, ::Color tint) {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using Font and pro parameters (rotation)
*/
[[maybe_unused]] RLCPPAPI inline void DrawTextPro(const Font& font, const char* text, Vector2 position,
Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint) {
::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, tint);
}
/**
* Draw text using Font and pro parameters (rotation)
*/
@@ -277,10 +300,24 @@ namespace raylib {
/**
* Measure string width for default font
*/
[[maybe_unused]] RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
[[maybe_unused]] RLCPPAPI inline int MeasureText(const char* text, int fontSize) {
return ::MeasureText(text, fontSize);
}
/**
* Measure string width for default font
*/
[[maybe_unused]] RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
return ::MeasureText(text.c_str(), fontSize);
}
/**
* Check if two text string are equal
*/
[[maybe_unused]] RLCPPAPI inline bool TextIsEqual(const char* text1, const char* text2) {
return ::TextIsEqual(text1, text2);
}
/**
* Check if two text string are equal
*/
@@ -288,6 +325,13 @@ namespace raylib {
return ::TextIsEqual(text1.c_str(), text2.c_str());
}
/**
* Check if two text string are equal
*/
[[maybe_unused]] RLCPPAPI inline unsigned int TextLength(const char* text) {
return ::TextLength(text);
}
/**
* Check if two text string are equal
*/

View File

@@ -645,6 +645,16 @@ class Image : public ::Image {
::ImageDraw(this, src, srcRec, dstRec, tint);
}
void DrawText(const char* text, ::Vector2 position, int fontSize,
::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this,
text,
static_cast<int>(position.x),
static_cast<int>(position.y),
fontSize,
color);
}
void DrawText(const std::string& text, ::Vector2 position, int fontSize,
::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this,
@@ -660,11 +670,21 @@ class Image : public ::Image {
::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
}
void DrawText(const char* text, int x, int y, int fontSize,
::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this, text, x, y, fontSize, color);
}
void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) {
::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
}
void DrawText(const ::Font& font, const char* text, ::Vector2 position,
float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) {
::ImageDrawTextEx(this, font, text, position, fontSize, spacing, tint);
}
/**
* Load color data from image as a Color array (RGBA - 32bit)
*/