Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: iOS incorrect window size on reorientation  (Read 5763 times)

0 Members and 1 Guest are viewing this topic.

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
iOS incorrect window size on reorientation
« 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:


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;
    shape.setFillColor(sf::Color::Red);
   
    while(window.isOpen())
    {
        sf::Event ev;
        while(window.pollEvent(ev))
        {
            if (ev.type == sf::Event::Resized)
            {
                std::cout << std::to_string(ev.size.width) + "," + std::to_string(ev.size.height) << std::endl;
                shape.setSize(sf::Vector2f(ev.size.width,ev.size.height));
            }
        }
        window.clear();
        window.draw(shape);
        window.display();
    }

 
« Last Edit: January 25, 2018, 06:43:24 am by Jonny »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11046
    • View Profile
    • development blog
    • Email
Re: iOS incorrect window size on reorientation
« Reply #1 on: January 25, 2018, 08:14:34 am »
I remember we had similar reports in the best and even some fixes for iOS.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
Re: iOS incorrect window size on reorientation
« Reply #2 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!
« Last Edit: April 12, 2018, 05:06:55 am by Jonny »

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: iOS incorrect window size on reorientation
« Reply #3 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.
Want to play movies in your SFML application? Check out sfeMovie!