Adding std::string casts to Color, Vector2, Vector3, and Vector4

This commit is contained in:
Daniel Bratsberg
2023-09-03 21:23:46 +02:00
parent a68c3c96de
commit f2a5238ed9
4 changed files with 40 additions and 28 deletions

View File

@@ -66,6 +66,16 @@ class Color : public ::Color {
return ::ColorToInt(*this);
}
inline std::string ToString() const {
std::ostringstream oss;
oss << "Color(" << r << ", " << g << ", " << b << ", " << a << ")";
return oss.str();
}
inline operator std::string() const {
return ToString();
}
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
@@ -210,13 +220,6 @@ class Color : public ::Color {
return ::ColorAlphaBlend(dst, *this, tint);
}
inline std::string ToString() const
{
std::ostringstream oss;
oss << "Color(" << r << ", " << g << ", " << b << ", " << a << ")";
return oss.str();
}
inline static Color LightGray() { return LIGHTGRAY; }
inline static Color Gray() { return GRAY; }
inline static Color DarkGray() { return DARKGRAY; }

View File

@@ -49,6 +49,16 @@ class Vector2 : public ::Vector2 {
return !(*this == other);
}
inline std::string ToString() const {
std::ostringstream oss;
oss << "Vector2(" << x << ", " << y << ")";
return oss.str();
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors (v1 + v2)
@@ -424,13 +434,6 @@ class Vector2 : public ::Vector2 {
return ::CheckCollisionPointLine(*this, p1, p2, threshold);
}
inline std::string ToString() const
{
std::ostringstream oss;
oss << "Vector2(" << x << ", " << y << ")";
return oss.str();
}
private:
void set(const ::Vector2& vec) {
x = vec.x;

View File

@@ -47,6 +47,16 @@ class Vector3 : public ::Vector3 {
return !(*this == other);
}
inline std::string ToString() const {
std::ostringstream oss;
oss << "Vector3(" << x << ", " << y << ", " << z << ")";
return oss.str();
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors
@@ -331,13 +341,6 @@ class Vector3 : public ::Vector3 {
return CheckCollisionSpheres(*this, radius1, center2, radius2);
}
inline std::string ToString() const
{
std::ostringstream oss;
oss << "Vector3(" << x << ", " << y << ", " << z << ")";
return oss.str();
}
private:
void set(const ::Vector3& vec) {
x = vec.x;

View File

@@ -60,6 +60,16 @@ class Vector4 : public ::Vector4 {
return {x, y, z, w};
}
inline std::string ToString() const {
std::ostringstream oss;
oss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ")";
return oss.str();
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
inline Vector4 Multiply(const ::Vector4& vector4) const {
return QuaternionMultiply(*this, vector4);
@@ -153,13 +163,6 @@ class Vector4 : public ::Vector4 {
return ColorFromNormalized();
}
inline std::string ToString() const
{
std::ostringstream oss;
oss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ")";
return oss.str();
}
private:
void set(const ::Vector4& vec4) {
x = vec4.x;