From 023890fd052cd92ea05e6f4d5b9bc7e0cc5d2ca5 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Sat, 22 May 2021 00:59:54 +0200 Subject: [PATCH] more conversion operator to avoid extracting data methods --- lib/Ray/sources/Color.cpp | 2 +- lib/Ray/sources/Color.hpp | 2 +- lib/Ray/sources/Drawables/2D/Circle.cpp | 4 ++-- lib/Ray/sources/Drawables/2D/Line.cpp | 4 ++-- lib/Ray/sources/Drawables/2D/Point.cpp | 4 ++-- lib/Ray/sources/Drawables/2D/Rectangle.cpp | 4 ++-- lib/Ray/sources/Drawables/2D/Text.cpp | 12 ++++++------ lib/Ray/sources/Drawables/2D/Triangle.cpp | 2 +- lib/Ray/sources/Drawables/3D/Circle.cpp | 2 +- lib/Ray/sources/Drawables/3D/Cube.cpp | 2 +- lib/Ray/sources/Drawables/3D/Cylinder.cpp | 2 +- lib/Ray/sources/Drawables/3D/Line.cpp | 2 +- lib/Ray/sources/Drawables/3D/Plane.cpp | 2 +- lib/Ray/sources/Drawables/3D/Point.cpp | 2 +- lib/Ray/sources/Drawables/3D/Ray.cpp | 2 +- lib/Ray/sources/Drawables/3D/Sphere.cpp | 2 +- lib/Ray/sources/Drawables/3D/Triangle.cpp | 2 +- lib/Ray/sources/Drawables/Image.cpp | 13 ++++++++++++- lib/Ray/sources/Drawables/Image.hpp | 8 +++++++- lib/Ray/sources/Drawables/Texture.cpp | 7 +------ lib/Ray/sources/Drawables/Texture.hpp | 5 +---- lib/Ray/sources/Window.cpp | 6 +++--- lib/wal/sources/Scene/SceneManager.hpp | 2 +- sources/Util/vector.cpp | 6 +++--- 24 files changed, 54 insertions(+), 45 deletions(-) diff --git a/lib/Ray/sources/Color.cpp b/lib/Ray/sources/Color.cpp index b4e8a92a..945a8353 100644 --- a/lib/Ray/sources/Color.cpp +++ b/lib/Ray/sources/Color.cpp @@ -77,7 +77,7 @@ namespace RAY return this->_color.a; } - const ::Color &Color::getColor(void) const + RAY::Color::operator ::Color() const { return this->_color; } diff --git a/lib/Ray/sources/Color.hpp b/lib/Ray/sources/Color.hpp index a246e8d9..7c29cf19 100644 --- a/lib/Ray/sources/Color.hpp +++ b/lib/Ray/sources/Color.hpp @@ -68,7 +68,7 @@ namespace RAY { unsigned char getA(void) const; //! @return color struct - const ::Color &getColor(void) const; + operator ::Color() const; //! @return hexadecimal value of color int toHex(void) const; diff --git a/lib/Ray/sources/Drawables/2D/Circle.cpp b/lib/Ray/sources/Drawables/2D/Circle.cpp index 1360ea78..9ce10ad1 100644 --- a/lib/Ray/sources/Drawables/2D/Circle.cpp +++ b/lib/Ray/sources/Drawables/2D/Circle.cpp @@ -32,10 +32,10 @@ RAY::Drawables::Drawables2D::Circle &RAY::Drawables::Drawables2D::Circle::setRad void RAY::Drawables::Drawables2D::Circle::drawOn(RAY::Window &) { - DrawCircleV(this->_position, this->_radius, this->_color.getColor()); + DrawCircleV(this->_position, this->_radius, this->_color); } void RAY::Drawables::Drawables2D::Circle::drawOn(RAY::Image &image) { - ImageDrawCircleV(&(image.getImage()), this->_position, this->_radius, this->_color.getColor()); + ImageDrawCircleV(image, this->_position, this->_radius, this->_color); } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/2D/Line.cpp b/lib/Ray/sources/Drawables/2D/Line.cpp index 77496d93..3580aba0 100644 --- a/lib/Ray/sources/Drawables/2D/Line.cpp +++ b/lib/Ray/sources/Drawables/2D/Line.cpp @@ -34,10 +34,10 @@ RAY::Drawables::Drawables2D::Line &RAY::Drawables::Drawables2D::Line::setEndPosi void RAY::Drawables::Drawables2D::Line::drawOn(RAY::Window &) { - DrawLineV(this->_position, this->_end, this->_color.getColor()); + DrawLineV(this->_position, this->_end, this->_color); } void RAY::Drawables::Drawables2D::Line::drawOn(RAY::Image &image) { - ImageDrawLineV(&(image.getImage()), this->_position, this->_end, this->_color.getColor()); + ImageDrawLineV(image, this->_position, this->_end, this->_color); } diff --git a/lib/Ray/sources/Drawables/2D/Point.cpp b/lib/Ray/sources/Drawables/2D/Point.cpp index ced578b3..be937c78 100644 --- a/lib/Ray/sources/Drawables/2D/Point.cpp +++ b/lib/Ray/sources/Drawables/2D/Point.cpp @@ -21,11 +21,11 @@ RAY::Drawables::Drawables2D::Point::Point(int x, int y, const Color &color): void RAY::Drawables::Drawables2D::Point::drawOn(RAY::Window &) { - DrawPixel(this->_position.x, this->_position.y, this->_color.getColor()); + DrawPixel(this->_position.x, this->_position.y, this->_color); } void RAY::Drawables::Drawables2D::Point::drawOn(RAY::Image &image) { - ImageDrawPixel(&(image.getImage()), this->_position.x, this->_position.y, this->_color.getColor()); + ImageDrawPixel(image, this->_position.x, this->_position.y, this->_color); } diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.cpp b/lib/Ray/sources/Drawables/2D/Rectangle.cpp index f90fa6cb..4a5bd23e 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.cpp @@ -40,10 +40,10 @@ RAY::Drawables::Drawables2D::Rectangle &RAY::Drawables::Drawables2D::Rectangle:: void RAY::Drawables::Drawables2D::Rectangle::drawOn(RAY::Window &) { - DrawRectangleV(this->_position, this->_dimensions, this->_color.getColor()); + DrawRectangleV(this->_position, this->_dimensions, this->_color); } void RAY::Drawables::Drawables2D::Rectangle::drawOn(RAY::Image &image) { - ImageDrawRectangleV(&(image.getImage()), this->_position, this->_dimensions, this->_color.getColor()); + ImageDrawRectangleV(image, this->_position, this->_dimensions, this->_color); } diff --git a/lib/Ray/sources/Drawables/2D/Text.cpp b/lib/Ray/sources/Drawables/2D/Text.cpp index f89af51d..72a5086f 100644 --- a/lib/Ray/sources/Drawables/2D/Text.cpp +++ b/lib/Ray/sources/Drawables/2D/Text.cpp @@ -62,18 +62,18 @@ void RAY::Drawables::Drawables2D::Text::drawOn(RAY::Window &) { if (!this->_font.recs) DrawText(this->_text.c_str(), this->_position.x, this->_position.y, - this->_size, this->_color.getColor()); + this->_size, this->_color); else DrawTextEx(this->_font, this->_text.c_str(), this->_position, - this->_size, this->_spacing, this->_color.getColor()); + this->_size, this->_spacing, this->_color); } void RAY::Drawables::Drawables2D::Text::drawOn(RAY::Image &image) { if (!this->_font.recs) - ImageDrawText(&(image.getImage()), this->_text.c_str(), this->_position.x, this->_position.y, - this->_size, this->_color.getColor()); + ImageDrawText(image, this->_text.c_str(), this->_position.x, this->_position.y, + this->_size, this->_color); else - ImageDrawTextEx(&(image.getImage()), this->_font, this->_text.c_str(), this->_position, - this->_size, this->_spacing, this->_color.getColor()); + ImageDrawTextEx(image, this->_font, this->_text.c_str(), this->_position, + this->_size, this->_spacing, this->_color); } diff --git a/lib/Ray/sources/Drawables/2D/Triangle.cpp b/lib/Ray/sources/Drawables/2D/Triangle.cpp index d74ff230..3baae3ec 100644 --- a/lib/Ray/sources/Drawables/2D/Triangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Triangle.cpp @@ -49,7 +49,7 @@ RAY::Drawables::Drawables2D::Triangle &RAY::Drawables::Drawables2D::Triangle::se void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Window &) { - DrawTriangle(this->_position, this->_posB, this->_posC, this->_color.getColor()); + DrawTriangle(this->_position, this->_posB, this->_posC, this->_color); } void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Image &image) diff --git a/lib/Ray/sources/Drawables/3D/Circle.cpp b/lib/Ray/sources/Drawables/3D/Circle.cpp index 62bad1c2..c174a30e 100644 --- a/lib/Ray/sources/Drawables/3D/Circle.cpp +++ b/lib/Ray/sources/Drawables/3D/Circle.cpp @@ -33,5 +33,5 @@ const RAY::Vector3 &RAY::Drawables::Drawables3D::Circle::getCenterPos(void) cons void RAY::Drawables::Drawables3D::Circle::drawOn(RAY::Window &) { DrawCircle3D(this->_centerPos, this->_radius,this->_rotationAxis, - this->_rotationAngle, this->_color.getColor()); + this->_rotationAngle, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index c5c68a74..edbd9474 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -38,5 +38,5 @@ RAY::Drawables::Drawables3D::Cube &RAY::Drawables::Drawables3D::Cube::setPositio void RAY::Drawables::Drawables3D::Cube::drawOn(RAY::Window &) { - DrawCubeV(this->_position, this->_dimenstions, this->_color.getColor()); + DrawCubeV(this->_position, this->_dimenstions, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index 6117c552..eab4e1da 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -62,5 +62,5 @@ RAY::Drawables::Drawables3D::Cylinder &RAY::Drawables::Drawables3D::Cylinder::se void RAY::Drawables::Drawables3D::Cylinder::drawOn(RAY::Window &) { - DrawCylinder(this->_centerPos, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color.getColor()); + DrawCylinder(this->_centerPos, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Line.cpp b/lib/Ray/sources/Drawables/3D/Line.cpp index 627cd6f2..76022af1 100644 --- a/lib/Ray/sources/Drawables/3D/Line.cpp +++ b/lib/Ray/sources/Drawables/3D/Line.cpp @@ -37,5 +37,5 @@ RAY::Drawables::Drawables3D::Line &RAY::Drawables::Drawables3D::Line::setEndPosi void RAY::Drawables::Drawables3D::Line::drawOn(RAY::Window &) { - DrawLine3D(this->_startPosition, this->_endPosition, this->_color.getColor()); + DrawLine3D(this->_startPosition, this->_endPosition, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Plane.cpp b/lib/Ray/sources/Drawables/3D/Plane.cpp index 10673eb9..1a874ba2 100644 --- a/lib/Ray/sources/Drawables/3D/Plane.cpp +++ b/lib/Ray/sources/Drawables/3D/Plane.cpp @@ -37,5 +37,5 @@ RAY::Drawables::Drawables3D::Plane &RAY::Drawables::Drawables3D::Plane::setDimen void RAY::Drawables::Drawables3D::Plane::drawOn(RAY::Window &) { - DrawPlane(this->_position, this->_dimensions, this->_color.getColor()); + DrawPlane(this->_position, this->_dimensions, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Point.cpp b/lib/Ray/sources/Drawables/3D/Point.cpp index 3f8bf73a..21a9f933 100644 --- a/lib/Ray/sources/Drawables/3D/Point.cpp +++ b/lib/Ray/sources/Drawables/3D/Point.cpp @@ -27,5 +27,5 @@ RAY::Drawables::Drawables3D::Point &RAY::Drawables::Drawables3D::Point::setPosit void RAY::Drawables::Drawables3D::Point::drawOn(RAY::Window &) { - DrawPoint3D(this->_position, this->_color.getColor()); + DrawPoint3D(this->_position, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Ray.cpp b/lib/Ray/sources/Drawables/3D/Ray.cpp index eb096e25..b6d5bfa2 100644 --- a/lib/Ray/sources/Drawables/3D/Ray.cpp +++ b/lib/Ray/sources/Drawables/3D/Ray.cpp @@ -37,5 +37,5 @@ RAY::Drawables::Drawables3D::Ray &RAY::Drawables::Drawables3D::Ray::setDirection void RAY::Drawables::Drawables3D::Ray::drawOn(RAY::Window &) { - DrawRay(this->_ray, this->_color.getColor()); + DrawRay(this->_ray, this->_color); } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 31c24d4c..10c9a576 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -37,5 +37,5 @@ RAY::Drawables::Drawables3D::Sphere &RAY::Drawables::Drawables3D::Sphere::setRad void RAY::Drawables::Drawables3D::Sphere::drawOn(RAY::Window &) { - DrawSphere(this->_centerPos, this->_radius, this->_color.getColor()); + DrawSphere(this->_centerPos, this->_radius, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Triangle.cpp b/lib/Ray/sources/Drawables/3D/Triangle.cpp index 652a2474..d3b4ea8b 100644 --- a/lib/Ray/sources/Drawables/3D/Triangle.cpp +++ b/lib/Ray/sources/Drawables/3D/Triangle.cpp @@ -49,7 +49,7 @@ RAY::Drawables::Drawables3D::Triangle &RAY::Drawables::Drawables3D::Triangle::se void RAY::Drawables::Drawables3D::Triangle::drawOn(RAY::Window &) { - DrawTriangle3D(this->_posA, this->_posB, this->_posC, this->_color.getColor()); + DrawTriangle3D(this->_posA, this->_posB, this->_posC, this->_color); } diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index 83ec1c81..ee28e3e0 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -17,6 +17,12 @@ RAY::Image::Image() } +RAY::Image::Image(RAY::Texture &texture): + _image(GetTextureData(texture)) +{ + +} + RAY::Image::~Image() { UnloadImage(_image); @@ -40,7 +46,12 @@ bool RAY::Image::unload() return true; } -::Image &RAY::Image::getImage(void) +RAY::Image::operator ::Image() const { return _image; +} + +RAY::Image::operator ::Image *() +{ + return &this->_image; } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index adc988d1..4472106f 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -11,6 +11,7 @@ #include #include #include "Canvas.hpp" +#include "Texture.hpp" #include "IRessource.hpp" namespace RAY @@ -25,6 +26,10 @@ namespace RAY //! @param filename: path to file to load Image(const std::string &filename); + //! @brief Create an image, using data from a texure + //! @param texture: texture to extract data from + Image(Texture &texture); + //! @brief A default copy constructor Image(const Image &image) = default; @@ -49,7 +54,8 @@ namespace RAY bool unload() override; //! @brief get image - ::Image &getImage(void); + operator ::Image() const; + operator ::Image *(); //! @brief draw drawable void draw(Drawables::ADrawable2D &); diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index 0c889f79..6255002e 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -40,12 +40,7 @@ bool RAY::Texture::unload() return true; } -Image RAY::Texture::toImage(void) const -{ - return GetTextureData(_texture); -} - -const ::Texture &RAY::Texture::getTexture(void) const +RAY::Texture::operator ::Texture() const { return this->_texture; } diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 9e4bb87d..8a782c90 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -44,11 +44,8 @@ namespace RAY //! @brief unload ressources bool unload() override; - //! @brief get image - ::Image toImage(void) const; - //! @return libray Texture struct - const ::Texture &getTexture(void) const; + operator ::Texture() const; protected: private: diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index ed6578da..6040f87d 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -90,7 +90,7 @@ void RAY::Window::setFPS(unsigned int fps) void RAY::Window::clear(const RAY::Color &color) { - ClearBackground(color.getColor()); + ClearBackground(color); } void RAY::Window::beginDrawing(void) @@ -135,7 +135,7 @@ void RAY::Window::draw(RAY::Drawables::IDrawable &drawable) void RAY::Window::draw(const RAY::Texture &texture, const Vector2 &position, const Color &tint) { - DrawTexture(texture.getTexture(), position.x, position.y, tint.getColor()); + DrawTexture(texture, position.x, position.y, tint); } void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix &transform) @@ -145,5 +145,5 @@ void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix void RAY::Window::setIcon(RAY::Image &img) { - SetWindowIcon(img.getImage()); + SetWindowIcon(img); } \ No newline at end of file diff --git a/lib/wal/sources/Scene/SceneManager.hpp b/lib/wal/sources/Scene/SceneManager.hpp index 16268e75..a0f017db 100644 --- a/lib/wal/sources/Scene/SceneManager.hpp +++ b/lib/wal/sources/Scene/SceneManager.hpp @@ -24,7 +24,7 @@ namespace WAL //! @return The manager instance used to call this function is returned. This allow method chaining. SceneManager &addBackScene(Scene &&scene); - //! @breif Get the current scene + //! @brief Get the current scene Scene &getCurrent(); //! @brief Remove the current scene and switch to the previous scene on the stack. diff --git a/sources/Util/vector.cpp b/sources/Util/vector.cpp index 8ae2669a..294f9d55 100644 --- a/sources/Util/vector.cpp +++ b/sources/Util/vector.cpp @@ -5,10 +5,10 @@ ** Vector */ -#include "Vector.hpp" +#include "Vector/Vector3.hpp" #include "Models/Vector3.hpp" -RAY::Vector3 toRAY(const WAL::Vector3 &wal) +RAY::Vector3 toRAY(const WAL::Vector3f &wal) { - return (RAY::Vector3){wal.x, wal.y, wal.y}; + return RAY::Vector3(wal.x, wal.y, wal.y); } \ No newline at end of file