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

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

0 Members and 2 Guests are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #390 on: February 12, 2013, 03:58:38 pm »
I need an editbox which will only accept numbers. Is there any way for it? Ie it doesn't register other keys than numbers.

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #391 on: February 12, 2013, 05:47:54 pm »
I still have to write that feature.

You will have to do it manually for now:
- Catch the textChanged callback
- Check the callback.text for non-numeric symbols
- If a letter was found then erase it and use editBox->setText to set the new text
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #392 on: February 12, 2013, 06:55:55 pm »
Okay. I think I will make new class numEditBox and put that feature there, so it will be nicer to use. And I will just add the files to my project as I do with clickable object to keep tgui sources unmodified.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #393 on: February 12, 2013, 07:16:11 pm »
Did you decide something about storing widgets? I hope that tgui will still store them as it's very handful. I think all you need is just simply having containers for every type of widget and you can do that painlessy without wiriting manual containers using the code I showed you (that would also make possible storing user created widgets, as it would just create new function with static container for that type).

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #394 on: February 12, 2013, 07:32:28 pm »
I have ended up with using smart pointers. And the window will still store them.

Adding and retreiving items has been simplified without much loss of features.
The only broken thing that I found so far is that you won't be able to copy an object directly with it's name. You will first have to retreive the pointer that corresponds to that name and copy that pointer. I can live with that.

I am still testing everything though. This was a big change and at this point I can't guarantee that I didn't broke other features. So it might take a while before I put the changes online.
The big advantage of having this instable version is that I will have to write a lot of tests to make sure everything still works. This means that there will probably be more example codes available for v0.6.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #395 on: February 12, 2013, 07:39:10 pm »
No problem with no direct copying. You can always wrap it into one function. But, how smart pointers fixed the problem? Could you explain it and show me the code for adding and getting?

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #396 on: February 12, 2013, 08:00:56 pm »
It is implemented that the pointers are automatically up- and downcasted. So even though you would receive a pointer to the base class, you can just store it in a pointer to e.g. an editbox and start using the functions from editbox.

The code to add an object to the window will become:
tgui::Picture::Ptr picture(window, "myPic");

The code to get it back from the window:
tgui::Picture::Ptr pic = window.get("myPic");

You will still need explicit casting when not storing the object but try to call a function on it immediately.
But doing so could be considered bad practice in the first place because the get function can return a null pointer.
static_cast<tgui::EditBox::Ptr>(window.get("edit"))->getText();
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #397 on: February 14, 2013, 02:21:37 pm »
If I understand correctly, 0.6 will have something like signals and slots system? Something like qt.

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #398 on: February 14, 2013, 06:29:58 pm »
It doesn't work exactly like that, but it is a signal like system.

With the bindCallback function you can bind any function to any of the callback trigger of the object (e.g. LeftMouseClicked).

If no function is passed to bindCallback then the signal will be send to the parent object. If it reaches the window then it can be polled from it just like in v0.5.

To group objects (e.g. Panel, ChildWindow) you can also use bindGlobalCallback.
If the objects inside the panel send a callback to their parent, then instead of passing the callback to the window,
the panel will send it to this global callback function.

You can bind multiple functions to the same callback trigger, all of the functions will be called.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #399 on: February 14, 2013, 08:06:52 pm »
Okay. But you can't create a signal which contains some argument? Like you can for example in boost::signals2, where your signal may cointain data which are given as argument to the slot.
« Last Edit: February 14, 2013, 08:10:43 pm by netrick »

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #400 on: February 14, 2013, 08:25:36 pm »
There are two functions that can be bound by default.
The first one doesn't has a parameter and the other one has a "const tgui::Callback&" parameter.

But one of the bindCallback functions accepts a boost::function, which means you should be able to bind anything.

The following will give you a function that takes a pointer to an integer when the function is called.
You will have to use pointer because the variable itself cannot be changed after it is bound.
Note that you don't have to include boost. The function and bind parts are included with tgui. (std::bind also works)
void func(int *i)
{
    std::cout << *i << std::endl;  // Will print '3' when the picture is clicked
}

int *i = new int(5);
tgui::Picture::Ptr picture(window);
picture->load("Linux.jpg");
picture->bindCallback(boost::bind(func, i), tgui::Picture::LeftMouseClicked);
*i = 3;
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #401 on: February 14, 2013, 08:27:52 pm »
It's gonna be amazing, I can't wait for 0.6 stable. Great job.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #402 on: February 14, 2013, 08:36:02 pm »
Quote
You will have to use pointer because the variable itself cannot be changed after it is bound.
You should be able to avoid that with std/boost::ref (which wraps a reference to a variable -- so even if the std::ref instance itself is copied, it's still the original wrapped variable which is passed to the function).

void func(int i)
{
    std::cout << i << std::endl;  // Will print '3' when the picture is clicked
}

int i = 5;
tgui::Picture::Ptr picture(window);
picture->load("Linux.jpg");
picture->bindCallback(boost::bind(func, boost::ref(i)), tgui::Picture::LeftMouseClicked);
i = 3;

Just be careful about the scope of the referenced variable.
Laurent Gomila - SFML developer

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #403 on: February 14, 2013, 08:43:15 pm »
Thanks, thats nice to know.
TGUI: C++ SFML GUI

Sub

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #404 on: February 14, 2013, 09:46:11 pm »
I've been using this for the past few days, I rather like it.  Nicely done texus. 

Is there any possibility of adding an outline around text?