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{ ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.