diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.hpp b/lib/Ray/sources/Drawables/2D/Rectangle.hpp index 67e69ad4..fc1e08ff 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.hpp @@ -49,11 +49,11 @@ namespace RAY::Drawables::Drawables2D { Rectangle &setDimensions(int x, int y); //! @brief Draw point on window - void drawOn(RAY::Window &) override; + virtual void drawOn(RAY::Window &) override; //! @brief Draw point on image - void drawOn(RAY::Image &image) override; + virtual void drawOn(RAY::Image &image) override; - private: + protected: //! @brief Diemnsions of the rectangle Vector2 _dimensions; diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index 5796e954..33108364 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -13,9 +13,10 @@ namespace RAY { std::unordered_map> Image::_modelsCache; Image::Image(const std::string &filename): - ADrawable2D(Vector2(0, 0), WHITE), + Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), _image(fetchImageInCache(filename)) { + this->_dimensions = Vector2(this->_image->width, this->_image->height); } bool Image::exportTo(const std::string &outputPath) @@ -33,16 +34,7 @@ namespace RAY { { return this->_image.get(); } - Image &Image::resize(const Vector2 &dimensions) - { - ImageResize(this->_image.get(), dimensions.x, dimensions.y); - return *this; - } - - Vector2 Image::getDimensions() const - { - return Vector2(this->_image->width, this->_image->height); - } + std::shared_ptr<::Image> Image::fetchImageInCache(const std::string &path) { if (Image::_modelsCache.find(path) == Image::_modelsCache.end()) @@ -61,9 +53,14 @@ namespace RAY { void Image::drawOn(RAY::Window &) { + //Since the image is a shared object, when it is resized, it mush be resized after to its previous dimensions + Vector2 oldDims = Vector2(this->_image->width, this->_image->height); + + ImageResize(*this, this->_dimensions.x, this->_dimensions.y); Texture texture(*this); DrawTexture(texture, this->_position.x, this->_position.y, this->_color); + ImageResize(*this, oldDims.x, oldDims.y); } void Image::drawOn(RAY::Image &image) diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index a8a39b6b..b852c7eb 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -13,12 +13,12 @@ #include "Texture.hpp" #include #include -#include "Drawables/ADrawable2D.hpp" +#include "Drawables/2D/Rectangle.hpp" namespace RAY { //! @brief Object representation of a framebuffer - class Image: public Drawables::ADrawable2D { + class Image: public Drawables::Drawables2D::Rectangle { public: //! @brief Create an image, loading a file //! @param filename: path to file to load @@ -36,11 +36,6 @@ namespace RAY //! @brief export to file //! @param outputPath: path of output bool exportTo(const std::string &outputPath); - //! @brief Resize picture - Image &resize(const Vector2 &dimensions); - //! @return current sprite dimensions - Vector2 getDimensions() const; - //! @brief draw drawable on image void draw(Drawables::ADrawable2D &);