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

Author Topic: Do I handle 'Resized' event correctly?  (Read 1667 times)

0 Members and 1 Guest are viewing this topic.

Baka

  • Guest
Do I handle 'Resized' event correctly?
« on: October 03, 2013, 08:55:40 pm »
I've never done any 2D programming, so I'm very paranoid just about everything.

while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Resized)
        {
            sf::View view = window.getDefaultView();
            view.setViewport(sf::FloatRect(0.f, 0.f, static_cast<float>(event.size.width),
                                          static_cast<float>(event.size.height));
            window.setView(view);
        }
    }
    window.clear();
    window.display();
}
 

Is this the correct way to handle this? Not just in SFML sense, but in general standpoint as well.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Do I handle 'Resized' event correctly?
« Reply #1 on: October 03, 2013, 09:14:29 pm »
If that has the effect you want then yes it looks fine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Do I handle 'Resized' event correctly?
« Reply #2 on: October 03, 2013, 10:12:32 pm »
Nop. Read the description of the viewport again.

And yes, as long as we don't know what you want to do, we can't tell you if this code does it well or not ;)
Laurent Gomila - SFML developer

Baka

  • Guest
Re: Do I handle 'Resized' event correctly?
« Reply #3 on: October 04, 2013, 01:33:32 pm »
Nop. Read the description of the viewport again.
Yep. sorry


And yes, as long as we don't know what you want to do, we can't tell you if this code does it well or not ;)

I'm basically interested in how other (most) games handle the change in resolution. Say, the native resolution of my application is 1024x768. The user then, during run-time, changes the resolution to, say, 1920x1080.

Would I just resize the view, and be done with it ?

sf::View view = window.getDefaultView();
view.setSize(event.size.width, event.size.height);
window.setView(view);

But then my 20x20 rectangle would get stretched, and it won't appear to be a square. That's what I'm confused about. Or is it perfectly okay, and that's just how things work?
« Last Edit: October 04, 2013, 01:43:44 pm by Baka »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Do I handle 'Resized' event correctly?
« Reply #4 on: October 04, 2013, 03:41:12 pm »
The default behaviour is to stretch things (the view doesn't change). What you show in your previous post (updating the size of the view) is exactly what you need if you don't want things to be stretched.
Laurent Gomila - SFML developer

Baka

  • Guest
Re: Do I handle 'Resized' event correctly?
« Reply #5 on: October 05, 2013, 11:16:31 am »
The default behaviour is to stretch things (the view doesn't change). What you show in your previous post (updating the size of the view) is exactly what you need if you don't want things to be stretched.

Okay! I've never done any graphical stuff, so I was very confused.
Thank you for clarifying this!

 

anything