views in TGUI

Started by starkhorn, 17 January 2015, 07:36:48

starkhorn

Hey Folks,

I'm still new to programming in general and new to SFML. I've just installed TGUI and I'm trying to provide user input with a more professional feel than what I've been previous doing.

With SFML, I setup 3 views.
1 mainView where the game action happens.
1 lowerView which updates with stats info as the game progress
1 rightView which has some static data.

What I'd like to do with TGUI is to have 3 seperate views like above. I want to be able to display all of my game images in the mainView. however I want the option to have a menu bar within this mainview.

From what I see the tgui::Gui gui; doesn't have any views. So is there a way to create 3 seperate windows? With the main window I want to draw images that only appear within this window, i.e. if the image overlaps the mainview size, then it should not appear in right or lower views.

I see there is a child window but I don't want the user to be able to close any of those child windows - is there a way to remove close X button in a child window? Do child window's fufill the same function in tgui as view did in SFML? i.e. the ability to split up the window into multiple screens.

starkhorn

or better still. Is there a way for tgui widgets etc to be drawn in specific SFML views? i.e. if the widgets position is outside the view, then it doesn't appear on the screen or overlap onto other views?

I've tried something like the below where i set the window view, add some widgets and the call the gui->draw method. However the widgets don't seem to be drawn within the view. Instead they go onto the other views where i want them to actually go screen if they are not drawn within the view size.

Code (cpp) Select


     window.setView(mainView);

     tgui::RadioButton::Ptr radioButton1(gui);
     tgui::RadioButton::Ptr radioButton2(gui);
     tgui::RadioButton::Ptr radioButton3(gui);


    radioButton1->load(themeConfFile);
    radioButton1->setPosition(20, 20);
    radioButton1->setText("Quit Game");
    radioButton1->setSize(20, 20);
 

    radioButton2->load(themeConfFile);
    radioButton2->setPosition(20, 60);
    radioButton2->setText("Start New Game");
    radioButton2->setSize(20, 20);

    radioButton3->load(themeConfFile);
    radioButton3->setPosition(20, 100);
    radioButton3->setText("Load Old Game");
    radioButton3->setSize(20, 20);

     gui.draw();


texus

#2
TGUI was not intended to be used with multiple views. However that doesn't mean it won't work, it just hasn't been tested yet.

In v0.7-dev, the Gui object has its own setView which might makes things a little easier. In v0.6 the gui uses the view that is set at the moment you call the handleEvent and draw functions. But in order to use this view, you have to pass 'false' as an extra parameter to these two functions. Since you are working with different views, you will have to make sure that the same view is set at the time you call handleEvent as when you call draw.

Code would look like this. Using multiple Gui objects has not been tested, but as long as they don't contain the same widgets I don't immediately see any problems.
Code (cpp) Select
// ...
tgui::Gui gui1(window);
tgui::Gui gui2(window);
// ...
while (window.isOpen())
{
    // ...
    while (window.pollEvent(event))
    {
        // ...
        window.setView(wiew1);
        gui1.handleEvent(event, false);
        window.setView(wiew2);
        gui2.handleEvent(event, false);
    }

    // ...
    window.setView(wiew1);
    gui1.draw(false);
    window.setView(wiew2);
    gui2.draw(false);
    // ...
}


QuoteI see there is a child window but I don't want the user to be able to close any of those child windows - is there a way to remove close X button in a child window?
The close button cannot be removed. It can be blocked though (binding a callback when the window gets closed and not closing the window there). If you don't need a title bar either then you could use a Panel widget.

starkhorn

Thank you so much for the detailed and helpful reply Texus - much appreciated. Also this is a great set of libraries - I wish I had found this when I first started doing SFML.

I think panels might be the way forward, although I'll still retain one main View for actual game content that I've already written. I'll just have 2 panels that are currently doing the right and lower views currently. There sole purpose is to display game stats and get user input so that should actually work out ok.