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

Author Topic: Add flag to RenderWindow::setSize(), allowing automatic view resize?  (Read 2317 times)

0 Members and 1 Guest are viewing this topic.

Dar13

  • Newbie
  • *
  • Posts: 2
    • View Profile
Just dealt with an issue with my app/game where I didn't know that setSize didn't adjust the RenderWindow's view as well.

My proposed patch would have an optional(default value would be false) boolean flag appended to the sf::RenderWindow::setSize() method that controls whether setSize would also resize the application's view. It wouldn't break API compatibility since it's defaulted to false while allowing future users to automatically resize their view to match their window size.

Quick snippet of how I would go about it.
//Window.h
void setSize(const Vector2u size, bool autoResizeView = false);

//snip

//Window.cpp
void Window::setSize(const Vector2u size,bool autoResizeView)
{
    if (m_impl)
    {
        m_impl->setSize(size);

        if(autoResizeView)
            m_impl->setView(View(Vector2u(size.x / 2, size.y / 2), size));
    }
}

Or if you don't wish to go down that route, I suggest updating the documentation of setSize to explicitly state that it doesn't affect the render window's view.
« Last Edit: August 13, 2013, 05:34:19 am by Dar13 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add flag to RenderWindow::setSize(), allowing automatic view resize?
« Reply #1 on: August 13, 2013, 07:51:26 am »
setSize is inherited from sf::Window, which doesn't know sf::View at all (the former belongs to the window module, the latter to the graphics module). So it would be hard to talk about sf::View in the documentation of setSize, or to add such an argument to it.

However, everything is clearly explained in the tutorial about views. The code to resize the view when the window is resized is also given.

You want another argument against this feature? setSize is not the only way to resize a window, it can be resized manually too; so your proposal only covers half of the issue actually ;)
Laurent Gomila - SFML developer

Dar13

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Add flag to RenderWindow::setSize(), allowing automatic view resize?
« Reply #2 on: August 13, 2013, 08:09:34 am »
In light of that, why not overload the method in RenderWindow(where the class does know sf::View)?

//RenderWindow.cpp
void setSize(Vector2u size, bool autoResizeView)
{
    this->setSize(size);

    if(autoResizeView)
    {
         setView(sf::View(sfVector2u(size.x / 2,size.y / 2), size));
    }
}

And about only covering half the issue, I assume that if the developer is handling manual resizing they can also handle manually resizing the view. This is more of a convenience request, so if no is no then I'll drop it quick enough.  ::)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add flag to RenderWindow::setSize(), allowing automatic view resize?
« Reply #3 on: August 13, 2013, 08:37:45 am »
It wouldn't be overloading the function, but shadowing (hiding) it. Only the new definition would be available ; and when using a RenderWindow polymorphically as a Window*, this overload wouldn't be available.

Quote
And about only covering half the issue, I assume that if the developer is handling manual resizing they can also handle manually resizing the view.
It seems to be an argument against your proposal. If resizing is handled in code then it's easy to add that line of code that resizes the view too. But when the window is resized by user, there's nothing that already handles it in code, one must explicitly process the Resized event to handle this case.

Quote
This is more of a convenience request, so if no is no then I'll drop it quick enough.
It's no ;)
If I really wanted to implement automatic resize of the view, I'd do it with an extra function RenderTarget::setAutoResizeView(bool). But I won't ;)
Laurent Gomila - SFML developer

 

anything