diff --git a/lib/Ray/.gitignore b/lib/Ray/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/lib/Ray/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/lib/Ray/CMakeLists.txt b/lib/Ray/CMakeLists.txt index 701ce3f5..f76b8ab0 100644 --- a/lib/Ray/CMakeLists.txt +++ b/lib/Ray/CMakeLists.txt @@ -68,6 +68,8 @@ set(SRC src/Controllers/Mouse.cpp src/Drawables/ADrawable2D.cpp src/Drawables/ADrawable3D.cpp + src/Drawables/Image.cpp + src/Drawables/Texture.cpp ) add_library(${LIB_NAME} STATIC ${SRC} ${HEADERS}) diff --git a/lib/Ray/include/Drawables/2D/Circle.hpp b/lib/Ray/include/Drawables/2D/Circle.hpp index 56aaad6b..02b0dbdf 100644 --- a/lib/Ray/include/Drawables/2D/Circle.hpp +++ b/lib/Ray/include/Drawables/2D/Circle.hpp @@ -44,7 +44,7 @@ namespace RAY::Drawables::Drawables2D { Circle &setRadius(int radius) const; //! @brief Draw Circle on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Radius of the circle diff --git a/lib/Ray/include/Drawables/2D/Line.hpp b/lib/Ray/include/Drawables/2D/Line.hpp index 759a7f64..3ec73bb0 100644 --- a/lib/Ray/include/Drawables/2D/Line.hpp +++ b/lib/Ray/include/Drawables/2D/Line.hpp @@ -51,7 +51,7 @@ namespace RAY::Drawables::Drawables2D { Line &setRotation(int); //! @brief Draw line on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Length of the line int _length; diff --git a/lib/Ray/include/Drawables/2D/Point.hpp b/lib/Ray/include/Drawables/2D/Point.hpp index cfd36aa6..e8f09e68 100644 --- a/lib/Ray/include/Drawables/2D/Point.hpp +++ b/lib/Ray/include/Drawables/2D/Point.hpp @@ -36,7 +36,7 @@ namespace RAY::Drawables::Drawables2D { ~Point() = default; //! @brief Draw point on window - void drawOn(Window &); + void drawOn(Canvas &); }; }; diff --git a/lib/Ray/include/Drawables/2D/Rectangle.hpp b/lib/Ray/include/Drawables/2D/Rectangle.hpp index 11fae3fe..ac5864a3 100644 --- a/lib/Ray/include/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/include/Drawables/2D/Rectangle.hpp @@ -48,7 +48,7 @@ namespace RAY::Drawables::Drawables2D { Rectangle &setDimensions(int x, int y); //! @brief Draw rectangle on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Diemnsions of the rectangle diff --git a/lib/Ray/include/Drawables/2D/Text.hpp b/lib/Ray/include/Drawables/2D/Text.hpp index 99e81bf5..4435063b 100644 --- a/lib/Ray/include/Drawables/2D/Text.hpp +++ b/lib/Ray/include/Drawables/2D/Text.hpp @@ -55,7 +55,7 @@ namespace RAY::Drawables::Drawables2D { Text &setFontSize(int size); //! @brief Draw text on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Text, just text diff --git a/lib/Ray/include/Drawables/2D/Triangle.hpp b/lib/Ray/include/Drawables/2D/Triangle.hpp index 912685ac..fb7a6deb 100644 --- a/lib/Ray/include/Drawables/2D/Triangle.hpp +++ b/lib/Ray/include/Drawables/2D/Triangle.hpp @@ -52,7 +52,7 @@ namespace RAY::Drawables::Drawables2D { Triangle &setPositionC(Vector2); //! @brief Draw triangle on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Position of A diff --git a/lib/Ray/include/Drawables/3D/Circle.hpp b/lib/Ray/include/Drawables/3D/Circle.hpp index 1fc37b13..ef2ecf95 100644 --- a/lib/Ray/include/Drawables/3D/Circle.hpp +++ b/lib/Ray/include/Drawables/3D/Circle.hpp @@ -44,7 +44,7 @@ namespace RAY::Drawables::Drawables3D { Circle &setRadius(const Vector3 &pos) const; //! @brief Draw circle on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Radius of the circle diff --git a/lib/Ray/include/Drawables/3D/Cylinder.hpp b/lib/Ray/include/Drawables/3D/Cylinder.hpp index 54e29cc5..997c466c 100644 --- a/lib/Ray/include/Drawables/3D/Cylinder.hpp +++ b/lib/Ray/include/Drawables/3D/Cylinder.hpp @@ -58,7 +58,7 @@ namespace RAY::Drawables::Drawables3D { Cylinder &setHeigth(float heigth) const; //! @brief Draw cylinder on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Radius of the cylinder diff --git a/lib/Ray/include/Drawables/3D/Grid.hpp b/lib/Ray/include/Drawables/3D/Grid.hpp index ea682a05..b758cd6f 100644 --- a/lib/Ray/include/Drawables/3D/Grid.hpp +++ b/lib/Ray/include/Drawables/3D/Grid.hpp @@ -42,7 +42,7 @@ namespace RAY::Drawables::Drawables3D { Grid &setSpacing(float spacing); //! @brief Draw grid on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Grid slices diff --git a/lib/Ray/include/Drawables/3D/Line.hpp b/lib/Ray/include/Drawables/3D/Line.hpp index 1144d549..182f3a86 100644 --- a/lib/Ray/include/Drawables/3D/Line.hpp +++ b/lib/Ray/include/Drawables/3D/Line.hpp @@ -46,7 +46,7 @@ namespace RAY::Drawables::Drawables3D { Line &setEndPosition(const Vector3 &endPosition); //! @brief Draw line on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief start position diff --git a/lib/Ray/include/Drawables/3D/Plane.hpp b/lib/Ray/include/Drawables/3D/Plane.hpp index 98a405b2..b8254885 100644 --- a/lib/Ray/include/Drawables/3D/Plane.hpp +++ b/lib/Ray/include/Drawables/3D/Plane.hpp @@ -43,7 +43,7 @@ namespace RAY::Drawables::Drawables3D { Plane &setDimensions(const Vector3 &dimensions); //! @brief Draw plane on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief plane position Vector3 _position; diff --git a/lib/Ray/include/Drawables/3D/Point.hpp b/lib/Ray/include/Drawables/3D/Point.hpp index 0d5b60d4..7e9993c1 100644 --- a/lib/Ray/include/Drawables/3D/Point.hpp +++ b/lib/Ray/include/Drawables/3D/Point.hpp @@ -36,7 +36,7 @@ namespace RAY::Drawables::Drawables3D { Point &setPosition(const Vector3 &Position); //! @brief Draw point on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief point position diff --git a/lib/Ray/include/Drawables/3D/Ray.hpp b/lib/Ray/include/Drawables/3D/Ray.hpp index 50767b79..323dafdf 100644 --- a/lib/Ray/include/Drawables/3D/Ray.hpp +++ b/lib/Ray/include/Drawables/3D/Ray.hpp @@ -46,7 +46,7 @@ namespace RAY::Drawables::Drawables3D { Ray &setDirection(const Vector3 &dimensions); //! @brief Draw ray on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief start position diff --git a/lib/Ray/include/Drawables/3D/Sphere.hpp b/lib/Ray/include/Drawables/3D/Sphere.hpp index 32c8656a..0e814d40 100644 --- a/lib/Ray/include/Drawables/3D/Sphere.hpp +++ b/lib/Ray/include/Drawables/3D/Sphere.hpp @@ -44,7 +44,7 @@ namespace RAY::Drawables::Drawables3D { Sphere &setRadius(const Vector3 &pos) const; //! @brief Draw sphere on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Radius of the sphere diff --git a/lib/Ray/include/Drawables/3D/Triangle.hpp b/lib/Ray/include/Drawables/3D/Triangle.hpp index 11836f0b..b2bed7a5 100644 --- a/lib/Ray/include/Drawables/3D/Triangle.hpp +++ b/lib/Ray/include/Drawables/3D/Triangle.hpp @@ -52,7 +52,7 @@ namespace RAY::Drawables::Drawables3D { Triangle &setPositionC(Vector3); //! @brief Draw triangle on window - void drawOn(Window &); + void drawOn(Canvas &); private: //! @brief Position of A diff --git a/lib/Ray/include/Drawables/ADrawable2D.hpp b/lib/Ray/include/Drawables/ADrawable2D.hpp index 3e6715e6..7bf2f2e7 100644 --- a/lib/Ray/include/Drawables/ADrawable2D.hpp +++ b/lib/Ray/include/Drawables/ADrawable2D.hpp @@ -12,6 +12,7 @@ #include #include "Drawables/IDrawable.hpp" #include "Color.hpp" +#include "Canvas.hpp" namespace RAY::Drawables::Drawables2D { class ADrawable2D: public IDrawable @@ -49,7 +50,7 @@ namespace RAY::Drawables::Drawables2D { ADrawable2D &setColor(const Color &color); //! @brief Draw drawble on window - virtual void drawOn(Window &) = 0; + virtual void drawOn(RAY::Canvas &) = 0; private: //! @brief Top-left position diff --git a/lib/Ray/include/Drawables/ADrawable3D.hpp b/lib/Ray/include/Drawables/ADrawable3D.hpp index 2251fc8c..aa88d896 100644 --- a/lib/Ray/include/Drawables/ADrawable3D.hpp +++ b/lib/Ray/include/Drawables/ADrawable3D.hpp @@ -27,7 +27,7 @@ namespace RAY::Drawables::Drawables3D { virtual ~ADrawable3D() = default; //! @brief Draw drawble on window - virtual void drawOn(Window &) = 0; + virtual void drawOn(Canvas &) = 0; //! @return the color of the ADrawable diff --git a/lib/Ray/include/Drawables/IDrawable.hpp b/lib/Ray/include/Drawables/IDrawable.hpp index 1fe63119..cd255b06 100644 --- a/lib/Ray/include/Drawables/IDrawable.hpp +++ b/lib/Ray/include/Drawables/IDrawable.hpp @@ -10,13 +10,13 @@ namespace RAY { - class Window; + class Canvas; namespace Drawables { class IDrawable { public: virtual ~IDrawable() = 0; - virtual void drawOn(RAY::Window &) = 0; + virtual void drawOn(RAY::Canvas &) = 0; protected: private: diff --git a/lib/Ray/include/Drawables/Image.hpp b/lib/Ray/include/Drawables/Image.hpp index c5320b11..16cc7c24 100644 --- a/lib/Ray/include/Drawables/Image.hpp +++ b/lib/Ray/include/Drawables/Image.hpp @@ -12,6 +12,7 @@ #include #include "Canvas.hpp" #include "IRessource.hpp" +#include "Drawables/IDrawable.hpp" namespace RAY { @@ -22,7 +23,7 @@ namespace RAY Image(const std::string &filename); //! @brief A default copy constructor - Image(const Image &); + Image(const Image &) = default; //! @brief A default constructor, no ressources loaded Image(); @@ -48,7 +49,7 @@ namespace RAY const ::Image &getImage(void) const; //! @brief draw drawable - void draw(const Drawables::IDrawable &); + void draw(Drawables::IDrawable &); protected: private: diff --git a/lib/Ray/include/Drawables/Texture.hpp b/lib/Ray/include/Drawables/Texture.hpp index ca89093e..1f667767 100644 --- a/lib/Ray/include/Drawables/Texture.hpp +++ b/lib/Ray/include/Drawables/Texture.hpp @@ -26,7 +26,7 @@ namespace RAY Texture(const Image &image); //! @brief A default copy constructor - Texture(const Texture &); + Texture(const Texture &) = default; //! @brief A default constructor, no ressources loaded Texture(); @@ -53,7 +53,7 @@ namespace RAY protected: private: //! @brief Texture, really, that's just it... - ::Texture _image; + ::Texture _texture; }; } diff --git a/lib/Ray/src/Drawables/ADrawable2D.cpp b/lib/Ray/src/Drawables/ADrawable2D.cpp index 435de498..58531bf5 100644 --- a/lib/Ray/src/Drawables/ADrawable2D.cpp +++ b/lib/Ray/src/Drawables/ADrawable2D.cpp @@ -8,14 +8,14 @@ #include "Drawables/ADrawable2D.hpp" RAY::Drawables::Drawables2D::ADrawable2D::ADrawable2D(const Vector2 &position, const RAY::Color &color): - _color(color), _position(position) + _position(position), _color(color) { } RAY::Drawables::Drawables2D::ADrawable2D::ADrawable2D(int x, int y, const RAY::Color &color): - _color(color), _position({(float)x, (float)y}) + _position({(float)x, (float)y}), _color(color) { } diff --git a/lib/Ray/src/Drawables/Image.cpp b/lib/Ray/src/Drawables/Image.cpp new file mode 100644 index 00000000..9ec97c40 --- /dev/null +++ b/lib/Ray/src/Drawables/Image.cpp @@ -0,0 +1,51 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** Image +*/ + +#include "Drawables/Image.hpp" + +RAY::Image::Image(const std::string &filename): + _image(LoadImage(filename.c_str())) +{ +} + +RAY::Image::Image() +{ + +} + +RAY::Image::~Image() +{ + UnloadImage(_image); +} + +bool RAY::Image::load(const std::string &filename) +{ + this->_image = LoadImage(filename.c_str()); + return true; +} + +bool RAY::Image::exportTo(const std::string &outputPath) +{ + ExportImage(_image, outputPath.c_str()); + return true; +} + +bool RAY::Image::unload() +{ + UnloadImage(_image); + return true; +} + +const ::Image &RAY::Image::getImage(void) const +{ + return _image; +} + +void RAY::Image::draw(Drawables::IDrawable & drawable) +{ + drawable.drawOn(*this); +} diff --git a/lib/Ray/src/Drawables/Texture.cpp b/lib/Ray/src/Drawables/Texture.cpp new file mode 100644 index 00000000..c108f51c --- /dev/null +++ b/lib/Ray/src/Drawables/Texture.cpp @@ -0,0 +1,45 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** Texture +*/ + +#include "Drawables/Texture.hpp" + +RAY::Texture::Texture(const std::string &filename): + _texture(LoadTexture(filename.c_str())) +{ +} + +RAY::Texture::Texture(const Image &image): + _texture(LoadTextureFromImage(image)) +{ + +} + +RAY::Texture::Texture() +{ + +} + +RAY::Texture::~Texture() +{ + UnloadTexture(this->_texture); +} + +bool RAY::Texture::load(const std::string &filename) +{ + this->_texture = LoadTexture(filename.c_str()); + return true; +} + +Image RAY::Texture::toImage(void) const +{ + return GetTextureData(_texture); +} + +const ::Texture &RAY::Texture::getTexture(void) const +{ + return this->_texture; +} \ No newline at end of file