To use the events system, you simply need to inherit from the EventHandler class. From there, you can override any method you wish to receive input from. To actually begin receiving updates, you need to register your events handler to the window class using mainApp->getWindow().registerEvents();. Each event is described below:
Note - registerEvents() takes a raw pointer. If the class pointed to is destructed prior to being removed from events, it will cause a crash.
Note - All event handler callbacks are guaranteed to be called from the main thread. This is done every frame prior to any updates/pre updates.
- void onWindowResize(Vector2ui oldSize, Vector2ui newSize); - Called when the window is resized, includes both the new and old window sizes in terms of pixels. You should avoid using this since all rendering is done relative to 1080p.
- void onWindowLostFocus(); - Called right before the window is about to lose focus. Depending on OS, updates/rendering will stop.
- void onWindowGainedFocus(); - Called right before the window is about to regain focus. Depending on OS, updates/rendering will begin again.
- void onControllerConnect(unsigned int controller); - Called when a controller connects, also gives the id of the controller
- void onControllerDisconnect(unsigned int controller); - Called when a controller disconnects
- void onControllerButtonPress(unsigned int controller, ControllerButton button); - Called when a button is pressed on a controller.
- void onControllerButtonRelease(unsigned int controller, ControllerButton button); - Called when a button is released on a controller
- void onControllerHandle(unsigned int controller, ControllerAxis handle, float position); - Called when a controller handle is moved
- void onControllerJoystick(unsigned int controller, ControllerAxis joystick, Vector2f position); - Called when a controller joystick is moved
- void onKeyPress(Key key); - Called when the user presses a key
- void onKeyRelease(Key key); - Called when the user releases a key
- void onMouseMove(Vector2f pos); - Called when the mouse moves with focus on the window (this can be outside of the window depending on OS)
- void onMouseScroll(float scroll); - Called when the mosue is scrolled with focus on the window
- void onLeftClick(); - Called when the user left clicks on the window
- void onMiddleClick(); - Called when the user middle clicks on the window (try to avoid using this without an alternative/rebinds for trackpad users)
- void onRightClick(); - Called when the user right clicks on the window
- void onLeftClickRelease(); - Called when the user releases their left click
- void onMiddleClickRelease(); - Called when the user releases their middle click
- void onRightClickRelease(); - Called when the user releases their right click
- void onTouchBegin(unsigned int touch, Vector2f pos); - Called when touches begin (this doesn't necessarily apply only to mobile devices, also applies to window laptops with touch screens)
- void onTouchMove(unsigned int touch, Vector2f pos); - Called when touches change position
- void onTouchEnd(unsigned int touch); - Called when a touch is released
Note - Depending on your compile settings, these events are directly passed from GLFW or SDL2. GLFW is known to be more lightweight, but lacks some features such as controller databasing. This means that controller binds to enum values may be incorrect when using a GLFW build.