fix posiion rescaling

This commit is contained in:
arthur.jamet
2021-06-16 12:27:40 +02:00
parent 0d63fbab6c
commit 797589a8a0
4 changed files with 11 additions and 16 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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<AnimationsSystem>()
.addSystem<AnimatorSystem>()
.addSystem<RenderSystem>(window);
+6 -11
View File
@@ -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<RAY2D::Text *>(&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) {
+3 -3
View File
@@ -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);