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

Author Topic: Why is RenderWindow::GetDefaultView () const in SFML2?  (Read 3445 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Why is RenderWindow::GetDefaultView () const in SFML2?
« on: June 11, 2011, 03:40:35 pm »
I have the following Code snippet:
Code: [Select]
       case sf::Event::Resized:
            {
                window->GetDefaultView ().SetSize (event.Size.Width, event.Size.Height);
                break;
            }
        case sf::Event::MouseWheelMoved:
            {
                // When zooming in, center view on Mouse Cursor Position
                if (event.MouseWheel.Delta > 0)
                {
                    window->GetDefaultView ().SetCenter (window->ConvertCoords (window->GetInput ().GetMouseX (), window->GetInput ().GetMouseY ()));
                    window->SetCursorPosition (window->GetWidth () / 2, window->GetHeight () / 2);
                }
                window->GetDefaultView ().Zoom (event.MouseWheel.Delta < 0 ? 0.5f : 2.f);
                break;
            }

And get the following errors for it:
Code: [Select]
GUI.cc:79:87: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::SetSize(float, float)’ discards qualifiers [-fpermissive]
GUI.cc:88:148: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::SetCenter(const Vector2f&)’ discards qualifiers [-fpermissive]
GUI.cc:91:88: error: passing ‘const sf::View’ as ‘this’ argument of ‘void sf::View::Zoom(float)’ discards qualifiers [-fpermissive]

That did work in SFML1.6. I think the problem is, that RenderWindow::GetDefaultView () became const in SFML2.
Now i would like to know why and maybe a suggestion, how to archieve what i want.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #1 on: June 11, 2011, 06:54:35 pm »
The change is more important than just adding const: views are now handled by copy rather than by reference. And you can't change the default view anymore.
Laurent Gomila - SFML developer

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #2 on: June 12, 2011, 01:45:41 am »
But how do i react on ResizeEvents, or do a zoom then?
Do i have to create a new view everytime?

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #3 on: June 12, 2011, 08:59:00 am »
Quote from: "MickeyKnox"
But how do i react on ResizeEvents, or do a zoom then?
Do i have to create a new view everytime?
Unfortunately, yes.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #4 on: June 12, 2011, 09:47:03 am »
It just requires two more lines of code, it's not a big deal really.
Code: [Select]
case sf::Event::MouseWheelMoved:
{
    sf::View view = window->GetView();
    view.Zoom(...);
    window.SetView(view);
}
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #5 on: June 12, 2011, 12:08:55 pm »
An alternative is to keep the view stored and call sf::RenderWindow::SetView() before drawing. This is useful when you have multiple views, e.g. for different background/foreground layers. Then you can still change the view directly.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MickeyKnox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Why is RenderWindow::GetDefaultView () const in SFML2?
« Reply #6 on: June 12, 2011, 07:04:36 pm »
thanks, i stick with nexus' suggestion.