From a68c3c96de4d5ee4bb7273a1a9b2da8a10f7360f Mon Sep 17 00:00:00 2001 From: Daniel Bratsberg Date: Sun, 3 Sep 2023 21:16:12 +0200 Subject: [PATCH] Adding ToString() func to Color, Vector2, Vector3, and Vector4 classes --- include/Color.hpp | 8 ++++++++ include/Vector2.hpp | 9 +++++++++ include/Vector3.hpp | 9 +++++++++ include/Vector4.hpp | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/include/Color.hpp b/include/Color.hpp index 6b84b2f..0881c7f 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -1,6 +1,7 @@ #ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_ #define RAYLIB_CPP_INCLUDE_COLOR_HPP_ +#include #include #include "./raylib.hpp" @@ -209,6 +210,13 @@ 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; } diff --git a/include/Vector2.hpp b/include/Vector2.hpp index ca3d3fc..3404615 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -5,6 +5,8 @@ #include #endif +#include + #include "./raylib.hpp" #include "./raymath.hpp" #include "./raylib-cpp-utils.hpp" @@ -422,6 +424,13 @@ 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; diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 04e9fdb..c28f681 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -5,6 +5,8 @@ #include #endif +#include + #include "./raylib.hpp" #include "./raymath.hpp" #include "./raylib-cpp-utils.hpp" @@ -329,6 +331,13 @@ 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; diff --git a/include/Vector4.hpp b/include/Vector4.hpp index 6901393..556c80c 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -6,6 +6,8 @@ #include #endif +#include + #include "./raylib.hpp" #include "./raymath.hpp" #include "./raylib-cpp-utils.hpp" @@ -151,6 +153,13 @@ 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;