In part 2 of this tutorial, you have seen how to create a login screen. It all looks fine but there is one important thing missing: the callbacks.
You will need to find out when the user clicked on the login button. This is what you will learn in this part of the tutorial. Note that this page only gives a short intro on how to handle callbacks, polling is not the only way.
At the bottom of the page you will find the full code for the working login screen.
The easiest way to handle callback is to poll them from the window. This is very similar to the pollEvent function from sfml.
The other ways to handle callbacks are discussed in the callback tutorial.
By default, widgets will not send any callback. You will have to explicitly ask the widget to send you callback. You do this with the bindCallback function. Because we get all callback in one place when polling it from the window, you will also have to set an id. This id is part of the callback so that you can distinguish the widgets from each other when receiving callbacks.
Now that the button is sending callbacks, it is time to receive them.
First we will check if the id is 1 to make sure that the event comes from the button.
Then we get the username and password that were filled in inside the edit boxes. As the pointers are not accessible in this scope, we will use the get function to get the pointers back.
Here is the full code of the introduction tutorial.
There is still one very important thing that you should take into account: errors.
In the above code, there is no error checking. If you write a program then you will probably want to add error checking to the following places:
gui.setGlobalFont will return false when the font couldn’t be loaded.
All load functions return false on failure. (you could also use the isLoaded function later).
The get function will return NULL when the widget name was wrong.