Add option to make window resizable, fix scaling

This commit is contained in:
zvon 2020-08-24 22:14:26 +02:00
parent f36890e124
commit 3cc5c4192a

View File

@ -49,6 +49,9 @@ public:
throw "Couldn't create window"; throw "Couldn't create window";
} }
} }
void setResizable(bool resizable) {
SDL_SetWindowResizable(window, resizable ? SDL_TRUE : SDL_FALSE);
}
~Window() { ~Window() {
SDL_DestroyWindow( window ); SDL_DestroyWindow( window );
} }
@ -959,10 +962,10 @@ public:
virtual void updateSizeAndPosition() override { virtual void updateSizeAndPosition() override {
updateXY(); updateXY();
auto dimension = renderer->getSmallerSide(); auto dimension = renderer->getSmallerSide();
rect.x = x_ * dimension; rect.x = std::round(x_ * dimension);
rect.y = y_ * dimension; rect.y = std::round(y_ * dimension);
rect.w = w_ * dimension; rect.w = std::round((x_ + w_) * dimension) - rect.x;
rect.h = h_ * dimension; rect.h = std::round((y_ + h_) * dimension) - rect.y;
if ( polygon ) if ( polygon )
polygon->updateCollision( collisionPushX(), collisionPushY(), polygon->updateCollision( collisionPushX(), collisionPushY(),
collisionWidth(), collisionHeight() ); collisionWidth(), collisionHeight() );