I came up with a simple solution to keep the aspect ratio of my window correct, even if the user choses to manually resize the window. This I am doing by resizing the window to the proper aspect ratio once the resize event fires (user has released the mouse button). This has worked well under OS X and Windows for SFML 2.0.
Sadly with SFML 2.1 it stopped working under OS X ( 10.6 - 10.
, it still works under Windows as intended. (Tested Versions 7, 8 and XP x64 & x86)
Under Windows it works. The user resizes the window. It resizes itself again to the nearest matching aspect correct size and then then stops. This all happens within a couple of milliseconds, barely noticeable.
Under OS X It resizes several times a second, very quickly the window jittering between various sizes. After some time it settles on a (correct aspect) size. I have noticed that it seems to fire the window::Resized event during OS X resizing animation. Could this be the culprit?
Under Linux (Ubuntu x64), the event seems to fire properly but it does not resize the window. i.e. the size remains unchanged from after the user input. (e.g. squashed)
The main part of the code is basically this:
//Window Resized?
if ( event.type == sf::Event::Resized )
{
//The Window was Resized - Maintain Aspect Ratio
float AspectX = (float)window.getSize().x / 800.0f;
float AspectY = (float)window.getSize().y / 600.0f;
//Find Which Is the smaller aspect
if ( AspectX < AspectY )
{
//Resize Y To Fit
sf::Vector2u tempSize = sf::Vector2u( window.getSize().x, (int)(AspectX * 600.0f) );
window.setSize( tempSize );
}
else if ( AspectX > AspectY )
{
//Resize X To Fit
sf::Vector2u tempSize = sf::Vector2u( (int)(AspectY * 800.0f), window.getSize().y );
window.setSize( tempSize );
}
}
Is this a bad idea?
Are there more elegant ways to do this? A work around to the issue?
I have also attached a minimum example based on my application that reproduces the problem.
Do you think it is possible to devise a work around until the issue is fixed?
Edit: Tried the latest nightly SFML build, still the issue persists.