Skip to content

Commit d536215

Browse files
authored
Merge pull request #249 from dbrats/toString
Adding ToString() and std::string cast to Color and Vector classes
2 parents 1e8b821 + bb5ae78 commit d536215

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

include/Color.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class Color : public ::Color {
6565
return ::ColorToInt(*this);
6666
}
6767

68+
inline std::string ToString() const {
69+
return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a);
70+
}
71+
72+
inline operator std::string() const {
73+
return ToString();
74+
}
75+
6876
/**
6977
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
7078
*/

include/Vector2.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class Vector2 : public ::Vector2 {
4747
return !(*this == other);
4848
}
4949

50+
inline std::string ToString() const {
51+
return TextFormat("Vector2(%f, %f)", x, y);
52+
}
53+
54+
inline operator std::string() const {
55+
return ToString();
56+
}
57+
5058
#ifndef RAYLIB_CPP_NO_MATH
5159
/**
5260
* Add two vectors (v1 + v2)

include/Vector3.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class Vector3 : public ::Vector3 {
4545
return !(*this == other);
4646
}
4747

48+
inline std::string ToString() const {
49+
return TextFormat("Vector3(%f, %f, %f)", x, y, z);
50+
}
51+
52+
inline operator std::string() const {
53+
return ToString();
54+
}
55+
4856
#ifndef RAYLIB_CPP_NO_MATH
4957
/**
5058
* Add two vectors

include/Vector4.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class Vector4 : public ::Vector4 {
5858
return {x, y, z, w};
5959
}
6060

61+
inline std::string ToString() const {
62+
return TextFormat("Vector4(%f, %f, %f, %f)", x, y, z, w);
63+
}
64+
65+
inline operator std::string() const {
66+
return ToString();
67+
}
68+
6169
#ifndef RAYLIB_CPP_NO_MATH
6270
inline Vector4 Multiply(const ::Vector4& vector4) const {
6371
return QuaternionMultiply(*this, vector4);

0 commit comments

Comments
 (0)