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

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

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6275
  • Thor Developer
    • View Profile
    • Bromeon
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #255 on: October 30, 2012, 05:48:46 am »
For Function and Bind, you don't need Boost. They are part of the TR1.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #256 on: October 30, 2012, 10:15:24 am »
Well I don't really know enough about these things and I don't have the time to find out and test how to use it on different compilers.

It will be a temporary solution anyway. I will try to make v0.6 support older compilers, but from v0.7 on I will probably drop this support and start using c++11.
So whether I decide to use boost or tr1, it will only be for the next release.
TGUI: C++ SFML GUI

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #257 on: November 12, 2012, 05:03:52 pm »
Mouse wheel support was added. You can now scroll through the list boxes, text boxes, ... without having to drag the thumb around.


I think I have also found a nice solution for the new callback system.
There is no need for boost, tr1 or c++11 in the user code and the function name can stay the same.
void function1();
void function2(const tgui::Callback& callback);

class myClass
{
    void function3();
    void function4(const tgui::Callback& callback);
}

// Bind free functions (either with or without the callback parameter)
button->bindCallback(function1, tgui::Button::LeftMouseClick);
button->bindCallback(function2, tgui::Button::LeftMouseClick);

// Bind member functions (either with or without the callback parameter)
myClass app;
button->bindCallback(&app, &myClass::function3, tgui::Button::LeftMouseClick);
button->bindCallback(&app, &myClass::function4, tgui::Button::LeftMouseClick);

// Make the button send the callback to its parent so that it can later be polled from the window
button->bindCallback(tgui::Button::LeftMouseClick);

The above code is just an example, it wouldn't work as you can only bind one function at a time (to a specific callback trigger). Also there probably won't be any definite decision in the next month, so the implementation can still be discussed and changed.
TGUI: C++ SFML GUI

Midleiro F

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #258 on: November 16, 2012, 10:51:32 am »
Nice! I believe this kind implementation would allow binding of lambdas as well.

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #259 on: November 16, 2012, 07:09:27 pm »
Lambdas should work. I just did some tests and you should be able to do the following:
auto function5 = [] () { /* ... */ };
auto function6 = [] (const tgui::Callback& callback) { /* ... */ };

button->bindCallback(function5, tgui::Button::LeftMouseClick);
button->bindCallback(function6, tgui::Button::LeftMouseClick);
TGUI: C++ SFML GUI

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #260 on: November 22, 2012, 08:01:54 pm »
The post is a bit long, if you don't want to read it all, voting on the polls at the bottom of my home page will already help me a lot. But I hope that some people will take the time to read it and give me their opinion about how the new callback system should be implemented.

First a small explanation on how the new callback system will work.
The current implementation is just polling the callbacks from the window, which is only a small part of the new system.


When a callback is triggered (e.g. the button has been clicked) then the following process will happen:
A: If bindCallback was used to bind a function to the callback trigger (mouse click), then the function will be called.
When a callback was requested for the trigger which isn't bound to a function (a bindCallback call were only the trigger was passed) then the callback will be passed to the parent object.

B: If a global callback function was set then this function will be called. Otherwise the callback will again be passed to the parent until it reaches the window.

C: If a global callback function was set then this function will be called. Otherwise the callback will be added to the callback queue and you will later be able to poll it from the window with getCallback.

When starting implementing it, I found out that it's not a big problem to bind multiple functions to one trigger so forget what I said before about binding only one function. You will be able to bind as many functions as you want to.


There are still a few things that could be changed.
First of all, I am not sure if bindCallback is a good name. Functions aren't really bound as you can connect multiple functions and calling the function with only the trigger parameter won't bind anything, it just tells the object to warn its parent on a callback.
Secondly, wouldn't the name pollCallback be better than getCallback (looks more like pollEvent)?
I have added polls for this on my site, so you can tell what you think is best there.

That leaves one last issue. When either in A, B or C, the callback is send to a function, it will never reach the callback queue. To illustrate it in the picture: if an arrow to the right is followed, then the process will stop and not continue going up.
This might be what you want, but in some situations you might want to silently bind a function, so that you are alerted about the callback but the process still continues.
I could make callback functions return a bool to signal if the callback has been handled or if it should continue to the other callback functions. An other option would be always go through all steps and don't stop when one callback function is called, but this means that all callback will reach the queue in the window and you must thus always poll the callbacks, even if you already handled them in different functions.
Any opinions on what the best option would be?
TGUI: C++ SFML GUI

trilavia

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #261 on: December 04, 2012, 07:29:25 pm »
Hey, I have a question. Your lib looks great and I want to use it for my project. However, as you posted here on new callback system (which I like a lot), I have a question if it's already implemented in 0.5? Because I need the api to be stable in terms of callbacks, so I don't want to change it in 2 months.

Thanks

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #262 on: December 04, 2012, 07:43:44 pm »
No, the new callback system won't make it in v0.5.
Actually v0.5 is ready, I am just waiting for sfml2 to be finished before I call v0.5 the stable release.

So v0.5 won't change anymore (except for perhaps bug fixes) and the first preview of v0.6 isn't coming before February, so you won't have to make any unexpected changes.
TGUI: C++ SFML GUI

trilavia

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #263 on: December 04, 2012, 07:55:39 pm »
Okay thanks mate.
But, you know, I wouldn't count for SFML 2.0 going stable before we retire :P So you may as well stable it now, as SFML 2.0 api won't change and it's now as close to stable as it can ever be.

Is 0.5 good enough for a hmm medium game (well, not tetris clone and not very big one too)? Or there are any design "bugs" that make some things hard to do and I should wait for 0.6?

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #264 on: December 04, 2012, 08:38:10 pm »
I was very close to decide to call v0.5 finished, but I am glad I didn't do it. The next day the convertCoords function got renamed to mapPixelsToCoords, so I had to change my code again. So although sfml2 is stable, I'd like to wait until I am 100% sure that no more changes will be made.

I think v0.5 will be good enough. There will always be some things to improve, but definitely don't wait for v0.6. Although I am planning to improve so many things, it won't be until August or so before all those changes are done. Even if I have enough time to launch an early prerelease in February, it won't contain much more than the new callback system.
TGUI: C++ SFML GUI

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #265 on: December 12, 2012, 02:42:24 am »
Hey,

I am trying out your lib for my current project. I think the design is great; very flexible and straightforward. It would be great to have some tutorials on your website about the way the different controls work with regards to the "load" function, that is, what my pngs should be named, what their functionality is, and what should go in the config text file. For example, I want to use a SpinButton, but you supply no example theme (that I could find) for that type of control, so I don't know how to create one.

Also instructions for writing forms would be helpful. The current FormBuilder does not support all the controls available, so I need to be able to hand-write forms.

Thanks!

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #266 on: December 12, 2012, 08:29:39 am »
There should be two example themes in the TGUI/objects/SpinButton folder.

An example code of a panel can be found in the tutorial section.

I admit that the loading isn't always the easiest thing. If I would know a better way then I would change it, but for now you will just have to experiment a little bit with those info.txt files. (There is some information here, but it is a bit outdated)
TGUI: C++ SFML GUI

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #267 on: December 17, 2012, 09:21:38 pm »
Ah, I only saw the "objects" in the "FormBuilder" folder, so that explains it.

The main issue for me now is that I don't know what parameters to put into my form.txt. If you could just put up a list of form parameters for each object, that would be great (because they don't all use the same parameters).

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #268 on: December 18, 2012, 09:31:17 am »
The parameters that you can use for all objects are size, width, height, scale, position, left, top and callbackid.

For now, for the parameters per object, you should take a look in Group.cpp in the loadObjectsFromFile function.
It checks for the object and looks at all possible parameters.

I will try to create a list tomorrow, I don't have time right now.

EDIT: I Created a tutorial about the Object Files which contains the list of all options.
« Last Edit: December 19, 2012, 09:41:38 pm by texus »
TGUI: C++ SFML GUI

trilavia

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #269 on: December 22, 2012, 11:54:02 am »
Btw, there is a little error on tgui's page. It should be "Texus' GUI" not "Texus's" ^^ (and it does not mean plural in this case)
« Last Edit: December 22, 2012, 11:55:53 am by trilavia »