Adding ToString() func to Color, Vector2, Vector3, and Vector4 classes

This commit is contained in:
Daniel Bratsberg
2023-09-03 21:16:12 +02:00
parent 4fba82ccda
commit a68c3c96de
4 changed files with 35 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
#define RAYLIB_CPP_INCLUDE_COLOR_HPP_
#include <sstream>
#include <string>
#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; }

View File

@@ -5,6 +5,8 @@
#include <cmath>
#endif
#include <sstream>
#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;

View File

@@ -5,6 +5,8 @@
#include <cmath>
#endif
#include <sstream>
#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;

View File

@@ -6,6 +6,8 @@
#include <utility>
#endif
#include <sstream>
#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;