From 797589a8a0f86592c185c6a7ba286d773a149b6a Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Wed, 16 Jun 2021 12:27:40 +0200 Subject: [PATCH] fix posiion rescaling --- lib/Ray/sources/Window.hpp | 2 +- sources/Runner/Runner.cpp | 2 +- sources/System/Renderer/RenderSystem.cpp | 17 ++++++----------- sources/System/Renderer/RenderSystem.hpp | 6 +++--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index 1d346b5e..036e01ef 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -38,7 +38,7 @@ namespace RAY { static Window &getInstance(); //! @return A widow insta,ce. Only one window can be open at a time - static Window &getInstance(int width, int height, const std::string &title, unsigned flags = FLAG_WINDOW_RESIZABLE, bool openNow = true) noexcept; + static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true) noexcept; //! @brief A window is movable. Window(Window &&) = default; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 647ccfd6..021addbd 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -93,7 +93,7 @@ namespace BBM void Runner::enableRaylib(WAL::Wal &wal) { RAY::TraceLog::setLevel(LOG_WARNING); - RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman"); + RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman", FLAG_WINDOW_RESIZABLE); wal.addSystem() .addSystem() .addSystem(window); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index f5349209..946df471 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -45,20 +45,14 @@ namespace BBM drawable.drawable->drawWiresOn(this->_window); } - void RenderSystem::rescaleDrawablePosition(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims) + void RenderSystem::rescaleDrawablePosition(Vector3f &position, const Vector2f &newWinDims) { - RAY::Vector2 newPosition; - RAY::Vector2 oldPosition(drawable.getPosition()); - - newPosition.x = (oldPosition.x * newDims.x) / this->_previousDims.x; - newPosition.y = (oldPosition.y * newDims.y) / this->_previousDims.y; - - drawable.setPosition(newPosition); + position.x = (position.x * newWinDims.x) / this->_previousDims.x; + position.y = (position.y * newWinDims.y) / this->_previousDims.y; } void RenderSystem::rescaleDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims) { - this->rescaleDrawablePosition(drawable, newDims); RAY2D::Text *text = dynamic_cast(&drawable); if (text) { @@ -86,7 +80,6 @@ namespace BBM if (newDims == this->_previousDims) return; newDims.y = (newDims.x * 720) / 1280; - std::cout << newDims.x << " " << newDims.y << std::endl; this->_window.setDimensions(newDims); } @@ -122,8 +115,10 @@ namespace BBM if (shader) { RAY::Shader::BeginUsingCustomShader(shader->getShader()); } - if (windowDimensions != this->_previousDims) + if (windowDimensions != this->_previousDims) { + this->rescaleDrawablePosition(pos.position, windowDimensions); this->rescaleDrawable(*drawable.drawable, windowDimensions); + } drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y)); drawable.drawable->drawOn(this->_window); if (shader) { diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index c1e3705d..3eca69ce 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -37,10 +37,10 @@ namespace BBM //! @param newDims the new window's dimensions void rescaleDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims); - //! @brief rescale the drawables position according to new window dimensions - //! @param drawable the drawable to rescale position of + //! @brief rescale the drawables position according to new window dimensions + //! @param position a reference to position //! @param newDims the new window's dimensions - void rescaleDrawablePosition(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims); + void rescaleDrawablePosition(Vector3f &position, const Vector2f &newWinDims); void resizeWindow(Vector2f &newDims);