O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required