Merge pull request #249 from dbrats/toString

Adding ToString() and std::string cast to Color and Vector classes
This commit is contained in:
Rob Loach
2023-09-03 15:54:18 -04:00
committed by GitHub
4 changed files with 32 additions and 0 deletions

View File

@@ -65,6 +65,14 @@ class Color : public ::Color {
return ::ColorToInt(*this);
}
inline std::string ToString() const {
return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a);
}
inline operator std::string() const {
return ToString();
}
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/

View File

@@ -47,6 +47,14 @@ class Vector2 : public ::Vector2 {
return !(*this == other);
}
inline std::string ToString() const {
return TextFormat("Vector2(%f, %f)", x, y);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors (v1 + v2)

View File

@@ -45,6 +45,14 @@ class Vector3 : public ::Vector3 {
return !(*this == other);
}
inline std::string ToString() const {
return TextFormat("Vector3(%f, %f, %f)", x, y, z);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors

View File

@@ -58,6 +58,14 @@ class Vector4 : public ::Vector4 {
return {x, y, z, w};
}
inline std::string ToString() const {
return TextFormat("Vector4(%f, %f, %f, %f)", x, y, z, w);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
inline Vector4 Multiply(const ::Vector4& vector4) const {
return QuaternionMultiply(*this, vector4);