[SOLVED] sf::View and TGUI

Started by Hronom, 04 September 2013, 15:24:08

Hronom

Than sf::View in my game follow the object gui is steel remain on its world position. So then i move sf:View i need to move all gui elements manualy? Or its bug?

texus

If you want to change the view in your game then you will need to work with two views, one for the gui and one for the game.

So you do something like this:
reset the view
draw gui
set view like you want it
draw other stuff

Hronom

Thanks for reply.
So i need this do this steps:
m_window->setView(m_window->getDefaultView());
m_gui->draw();

m_window->setView(my_view);
// render some other stuff
m_window->display();


But i think i didn't understand, maybe some code example helps me.

texus

That's exactly what I meant.
So if that isn't what you were looking for then you will have to describe what you want a little bit better.

Hronom

#4
In the end of my frame update logic i make this and looks like it work:
if(m_window->isOpen())
    {
    sf::View currentView;
    currentView = m_window->getView();

    m_window->setView(m_window->getDefaultView());
    m_gui->draw();

    m_window->setView(currentView);

    // end the current frame
    m_window->display();
}


But i didn't understand what is happens...

And for me it will be good if, then i make gui->draw its draw elements in sf::View rectangle.

texus

QuoteBut i didn't understand what is happens...
And for me it will be good if, then i make gui->draw its draw elements in sf::View rectangle.
I'm having problems understanding your english.
I know that it can be hard, but if you are asking something, could you try to explain it in more words? I really can't make anything from what you said, especially not from the second line.

Hronom

#6
Sorry for bad english its not my native language.
I mean it would be good if method tgui::Gui::draw make draw widgets with offset of current sf::View.

So if i do this steps:
sf::View currentView;
currentView.setCenter(100, 100);
m_window->setView(currentView);

// Draw my SFML objects
m_gui->draw(); // Draw GUI

m_window->display();

GUI elements must recalculates them positions with current sf::View.

But now i need to do magic like this:
sf::View currentView;
currentView.setCenter(100, 100);
m_window->setView(currentView);

// Draw my SFML objects
m_window->setView(m_window->getDefaultView());
m_gui->draw(); // Draw GUI

m_window->display();

To display widgets in my view.

And thanks for fast replies it's awesome!

texus

I don't think it is a good idea to make the gui handle the view itself. It would be easier in your situation (which is I guess the most common situation of changing the view), but it will limit other possibilities.

By making you set the view yourself, I don't limit your possibilities. You can scale the gui, you can even move the widgets throught the screen without even accessing the widgets. All that by just setting a different view (the view also has to be set while handling events, otherwise it won't work).

If I would automatically make the widgets draw inside your screen, even when the view is changed, then these advanced things with views will no longer be possible. That is why you will always have to set the view yourself, to keep full control on how the gui is drawn.

texus

I decided to make it a bit easier.

gui.draw now has a parameter to reset the view. By default false will be passed and the current view will be used. But you can pass true to render the widgets with the default view. After the gui has been drawn, your old view will be restored.

So you no longer have to set a separate view for sfml and tgui every frame, just set your view once for sfml and pass true to gui.draw.

Hronom

Big thanks, now my code looks like:
    if(m_window->isOpen())
    {
        m_gui->draw(true);
        // end the current frame
        m_window->display();
    }