From 3cc5c4192a4ffdbf7216214bfcb7f4d0128649be Mon Sep 17 00:00:00 2001 From: zvon Date: Mon, 24 Aug 2020 22:14:26 +0200 Subject: [PATCH] Add option to make window resizable, fix scaling --- sdlpp.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sdlpp.hpp b/sdlpp.hpp index 06b432f..320b378 100644 --- a/sdlpp.hpp +++ b/sdlpp.hpp @@ -49,6 +49,9 @@ public: throw "Couldn't create window"; } } + void setResizable(bool resizable) { + SDL_SetWindowResizable(window, resizable ? SDL_TRUE : SDL_FALSE); + } ~Window() { SDL_DestroyWindow( window ); } @@ -959,10 +962,10 @@ public: virtual void updateSizeAndPosition() override { updateXY(); auto dimension = renderer->getSmallerSide(); - rect.x = x_ * dimension; - rect.y = y_ * dimension; - rect.w = w_ * dimension; - rect.h = h_ * dimension; + rect.x = std::round(x_ * dimension); + rect.y = std::round(y_ * dimension); + rect.w = std::round((x_ + w_) * dimension) - rect.x; + rect.h = std::round((y_ + h_) * dimension) - rect.y; if ( polygon ) polygon->updateCollision( collisionPushX(), collisionPushY(), collisionWidth(), collisionHeight() );