[SOLVED] sf::View and TGUI
« on: 04 September 2013, 15:24:08 »
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?
« Last Edit: 05 September 2013, 09:48:00 by Hronom »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: sf::View and TGUI
« Reply #1 on: 04 September 2013, 15:26:27 »
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

Re: sf::View and TGUI
« Reply #2 on: 04 September 2013, 15:41:02 »
Thanks for reply.
So i need this do this steps:
Code: [Select]
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: sf::View and TGUI
« Reply #3 on: 04 September 2013, 15:49:58 »
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.

Re: sf::View and TGUI
« Reply #4 on: 04 September 2013, 15:50:13 »
In the end of my frame update logic i make this and looks like it work:
Code: [Select]
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.
« Last Edit: 04 September 2013, 16:05:35 by Hronom »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: sf::View and TGUI
« Reply #5 on: 04 September 2013, 16:27:45 »
Quote
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.
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.

Re: sf::View and TGUI
« Reply #6 on: 04 September 2013, 16:45:34 »
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:
Code: [Select]
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:
Code: [Select]
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!
« Last Edit: 04 September 2013, 16:50:36 by Hronom »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: sf::View and TGUI
« Reply #7 on: 04 September 2013, 17:07:38 »
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: [SOLVED] sf::View and TGUI
« Reply #8 on: 18 September 2013, 18:25:17 »
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.

Re: [SOLVED] sf::View and TGUI
« Reply #9 on: 18 September 2013, 19:42:58 »
Big thanks, now my code looks like:
Code: [Select]
    if(m_window->isOpen())
    {
        m_gui->draw(true);
        // end the current frame
        m_window->display();
    }