SFML community forums

Help => Window => Topic started by: Jonny on January 25, 2018, 06:40:49 am

Title: iOS incorrect window size on reorientation
Post by: Jonny on January 25, 2018, 06:40:49 am
It looks like the Resized event is reporting the previous window size when the screen orientation is changed.

Debug output here shows the value from the Resized event, graphic is just a 320x200 sprite, and I'm not transforming either the sprite or the view at any point: https://www.youtube.com/watch?v=cJ2af72hiDo

I've tested this on iOS 11 and 9, and I'm using Xcode 9 on macOS 10.13. Has anybody else got this working successfully?

Example code (Not the one used in above video, but has same outcome for me)
 sf::RenderWindow window(sf::VideoMode(),"SFML Doesn't work :(");
    sf::RectangleShape shape;
        sf::Event ev;
            if (ev.type == sf::Event::Resized)
                std::cout << std::to_string(ev.size.width) + "," + std::to_string(ev.size.height) << std::endl;

Title: Re: iOS incorrect window size on reorientation
Post by: eXpl0it3r on January 25, 2018, 08:14:34 am
I remember we had similar reports in the best and even some fixes for iOS.
Title: Re: iOS incorrect window size on reorientation
Post by: Jonny on April 12, 2018, 03:23:15 am
I've finally got round to debugging this a bit more, and have found there's a couple of things which came together to cause this:

For the first point, I can kind of see the connection now between autorotation and sf::Style::Resize, however I don't find it terribly intuitive. I'd prefer a more explicit way of specifying whether to autorotate or not, does anybody have an opinion on how this could fit into the API?

For the second point, I'd say we should assume the same as the OS, which simply means changing it to return false on the line I linked above. This means the event contains the correct window sizes, however upside-down orientation doesn't look completely correct...

I think for the second point it actually needs to return
(1 << orientation) & [rootViewController supportedInterfaceOrientations]
but have SFML's override of supportedInterfaceOrientations removed, because the override just returns that all orientations are supported, whereas the default returns different values for iPhone/iPad, and matches what I'd expect (and fixes the issue) based on documentation here: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations

I'm still kind of learning this as I go along, so anybody with more experienced input please speak up!
Title: Re: iOS incorrect window size on reorientation
Post by: Ceylo on April 12, 2018, 08:16:57 pm
Really nice that you've found the culprit!

For 1) in terms on API I don't see any reasonable solution apart from replacing the Style::Resize enum value with Style::Rotate or similar when compiling for mobile. By the way Style::Close also looks to make no sense on mobile.

For 2), I'd also go for keeping the same behavior as the OS. It doesn't make sense to have no orientation supported.