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

Author Topic: TGUI: a c++ GUI for SFML (with Form Builder)  (Read 286737 times)

0 Members and 3 Guests are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #465 on: March 25, 2013, 11:48:54 am »
I think it is stable enough now.
There won't be many changes soon anyway because I don't have time for it.
There are still some serious changes that I have to make in v0.6, but these will come when I have more time (somewhere end June perhaps). But the most visible changes (callback and object creation) have already been finished.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #466 on: April 07, 2013, 09:52:39 pm »
Do you plan on writing some tutorial on the new callback system?

If not, could you write me very short guide of the new features?

The 0.6 tutorial only says about old callback id method and I'd like to bind functions, but I'm not quite sure how to do it as you once wrote many different ways of using it and it seemed quite complex.
« Last Edit: April 07, 2013, 10:05:56 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #467 on: April 07, 2013, 11:14:06 pm »
I'm going to write the tutorials when I have more time. Currently all tasks are postponed to July.

There are different bind functions because you should be able to bind any kind of function.

If you just want a function to be called when something happens then it isn't hard.
void function() {}
button->bindCallback(function, tgui::Button::LeftMouseClicked);  // Triggers can be combined with '|'

But if you want a function that is called for different objects (e.g. one callback function for every state in the game) then you'll need some information in the function to figure out who send the callback.
void function(const tgui::Callback& callback) { /* callback.callbackId == 3 */ }
button->setCallbackId(3);
button->bindCallbackEx(function, tgui::Button::LeftMousePressed);

But this only works for normal functions and not for member functions in classes.
I've already written in an older post how to bind these functions.

The bigger problem is to find the available triggers as they are not yet documented.
You'll have to go through the include files (can be found in the documentation).
But they are not listed in one place. For Button, look at ButtonCallbacks in Button.hpp, ClickableObjectCallbacks in ClickableObject.hpp and ObjectCallbacks in Object.hpp.
But don't despair, most objects follow the same inheritance and if you look at e.g. the ButtonCallbacks then you'll immediately see that it isn't hard to figure out where else to look.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #468 on: April 08, 2013, 04:06:22 pm »
Okay thanks. If in bindCallback I combine some triggers, it acts as AND (ie callback is send only if all triggers are true) or like OR (so only one of the triggers has to happen)?

Also:
void function(const tgui::Callback& callback) { /* callback.callbackId == 3 */ }
button->setCallbackId(3);
button->bindCallbackEx(function, tgui::Button::LeftMousePressed);
 

Really there is no way to bind class member function? That would match perfectly as handleEvents() function in my gui class... (I have a few game states and every state has its own gui object, which basically wraps tgui and I only call handleEvents() and draw() basically but right now callbacks are messed up so I need to fix it, ie use BindCallbackEx to class member function).

Thanks!
« Last Edit: April 08, 2013, 04:10:03 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #469 on: April 08, 2013, 04:20:54 pm »
Quote
Okay thanks. If in bindCallback I combine some triggers, it acts as AND (ie callback is send only if all triggers are true) or like OR (so only one of the triggers has to happen)?
It acts like an OR.

Quote
Really there is no way to bind class member function?
I meant that the above example didn't work for member functions, not that it wasn't possible at all.

In the post I linked to you can find how to bind to a member function.
struct myClass {
    void function3() {};
    void function4(const tgui::Callback& callback) {};
} myObj;

button->bindCallback(&myClass::function3, &myObj, trigger);
button->bindCallbackEx(&myClass::function4, &myObj, trigger);
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #470 on: April 08, 2013, 05:07:25 pm »
Thanks for quick reply, finally my gui class is very transparent and easy to develop :)

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #471 on: April 10, 2013, 08:52:53 pm »
1) I'm slowly switching to 0.6 and I'm not quite sure about ptr naming - once it is tgui::Button::Ptr and the other time it is SharedObjectPtr< Object > so I'm not sure what should I use... Why it's not tgui::Object::Ptr? It's very inconsistent and confusing. It should be consistent I think.

2) Also, as I don't know what should be proper names, how should I change this code to make it work with 0.6?

void correctChildWindow(tgui::SharedObjectPtr<ChildWindow> childWindow); //just a declaration

void checkChildWindows()
{
std::vector<tgui::SharedObjectPtr<Object>> &objects = tgui.getObjects();
        for (auto &i : objects)
        {
                if (tgui::SharedObjectPtr<ChildWindow> childWindow = dynamic_cast<tgui::SharedObjectPtr<ChildWindow>> (i))
        correctChildWindow(childWindow);
        }
}
 

3) Another question, is there some tgui built-in way of doing this planned for 0.6 or I still have to use that very slow performing dynamic cast method to make sure child windows are inside the window?

Thanks!
« Last Edit: April 10, 2013, 09:00:27 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #472 on: April 10, 2013, 09:19:43 pm »
I had some problems with objects required each other to be included already. By writing tgui::SharedObjectPtr<Object>, the Object class didn't already have to exist, while with tgui::Object::Ptr the Object class had to be defined already which wasn't possible.
Due to this the documentation might indeed by inconsistent at the moment, but both mean the exact same thing. I'll look at it again and see if I can fix this (when I wrote it I was too happy that it finally compiled, so I didn't bother much about this inconsistency).

Your code could be like this:
void correctChildWindow(tgui::ChildWindow::Ptr childWindow); //just a declaration

void checkChildWindows()
{
    std::vector<tgui::Object::Ptr> &objects = tgui.getObjects();
    for (auto &i : objects)
    {
        if (i->getObjectType() == tgui::Type_ChildWindow)
            correctChildWindow(childWindow);
    }
}
You'll see that tgui::Object::Ptr is converted automatically to tgui::ChildWindow::Ptr, however you'll still have to make sure that it is in fact a child window and there will still be a cast internally.

And I still don't know any way to make this easier.
« Last Edit: April 10, 2013, 09:21:28 pm by texus »
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #473 on: April 10, 2013, 09:24:59 pm »
Thank you, very quick response as always!

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #474 on: April 17, 2013, 06:20:22 pm »
How is global font handled in 0.6? Does it even exist?

If yes, what happens when I try to display some label without setting the font?

If no, what happens when I try to display some label without setting its font? Is it undefined behaviour or it is fail-safe and nothing gets displayed?
« Last Edit: April 17, 2013, 06:22:14 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #475 on: April 17, 2013, 06:25:21 pm »
Quote
How is global font handled in 0.6?
The only difference with v0.5 that I remember is that it is no longer accessible directly, you should use the setGlobalFont function (which takes either a font to copy or a filename to load the font).

Quote
what happens when I try to display some label without setting the font?
The same as what happens when drawing an sf::Text without setting a font. The text won't be drawn.
« Last Edit: April 17, 2013, 06:27:39 pm by texus »
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #476 on: April 22, 2013, 06:17:55 pm »
In 0.5 I could:
window.get<tgui::Panel>("leftPanel")->setSize();
 

However in 0.6 this obviously doesn't work:
window.get("leftPanel")->setSize();
//error: class tgui::Object has no member named setSize
 

What should be the preferred solution? Do I have to make tgui::DesiredObj::Ptr variable for such usage or there is some better solution? Coz I don't like unnecesary temporary variables.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #477 on: April 22, 2013, 07:01:16 pm »
This should do:
tgui::Panel::Ptr(window.get("leftPanel"))->setSize(...);
« Last Edit: April 22, 2013, 07:02:54 pm by texus »
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #478 on: April 22, 2013, 08:20:41 pm »
Thank you. I think I know what you could improve for easier usage.
tgui::Panel::Ptr leftPanel = window.get("leftPanel");

tgui::ClickableObject::Ptr tileButton(*leftPanel, "tileButton"); //it should accept pointer too
 

Object constructor accepts its parent by reference, which is good for window but with panel you rather work with pointers. It should be overloaded to accept pointers too.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #479 on: April 22, 2013, 08:59:25 pm »
The reason why it isn't possible is because it has a different meaning.
tgui::ClickableObject::Ptr object(panel);
already exists and just gives a downcast of a Panel::Ptr to a ClickableObject::Ptr.

It will work when I decide to force you to pass an object name, but I'm not going to make that decision right now.
TGUI: C++ SFML GUI