Defining GUI events
Providing fluid interactivity with the interface and a painless way of associating changes with actions inside your application may be the most important criterion to separate good GUI systems from bad ones. As we are already learning SFML, we can use the SFML method and omit events.
Firstly, we have to define all the possible events that could take place in an interface. Create a GUI_Event.h
file and construct an enumeration, as shown here:
enum class GUI_EventType{ None, Click, Release, Hover, Leave };
We must also define a custom structure in the same file that is used to hold event information:
struct ClickCoordinates{ float x, y; }; struct GUI_Event{ GUI_EventType m_type; const char* m_element; const char* m_interface; union{ ClickCoordinates m_clickCoords; }; };
The first thing to talk about here is the structure. It should be possible to merely use sf::Vector2f
here. That would work fine under most circumstances but, a few lines below...