dimanche 13 mai 2018

Multiple independent if statements with same else

I'm currently working in SFML for c++ and trying to resize a window however the solution I found to my problem doesn't quite feel right and I'm looking if there is a better way.

I have an object that gets resized multiple times so it may fit inside the window or not, I have to expand the window if its bigger and shrink it if its smaller. However I have a minimum size for the window, if the object fits inside that I want to reset the window to that size.

This is the pseudo-code I'm using right now:

if (Object.getSize().x > window.getSize().x || Object.getSize().y > window.getSize.y){
    if(Object.getSize().x > windowMinSize.x){
        window.resize(Object.getSize().x, window.getSize().y)
    }
    if(Object.getSize().y > windowMinSize.y){
        window.resize(window.getSize().x, Object.getSize().y)
    }
}
else{
    window.resize(windowMinSize);
}

I've looked into switch and other options but I haven't found what I'm looking for.

Aucun commentaire:

Enregistrer un commentaire