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.
At the bottom of the page you will find the full code for the working login screen.
First of all, you will need to get the callbacks from the window.
This procedure is very similar to polling events from sfml.
By default, objects will not send any callback. You will have to explicitly ask the object to send you callback. You do this by changing the callback id of the object. When receiving the callbacks, you will also use this id to find out where the callback came from.
So you will need to add the following line to the button creation:
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 check if the button was clicked (it also sends mouseDown events).
Finally 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:
window.globalFont.loadFromFile will return false when the font couldn’t be loaded.
All load functions return false on failure. (you could also use isLoaded later).
The get function will return NULL when the object name was wrong.