Polling the window events
Call fplPollEvent() in a while-loop inside your actual main-loop with a pointer to a fplEvent argument to poll the next event from the OS event queue.
Each event is translated into the fplEvent argument which you can handle or not. If there are no events left, the function returns false.
}
fpl_platform_api bool fplPollEvent(fplEvent *ev)
Polls the next event from the internal event queue or from the OS, handles them, and removes it from ...
A structure containing event data for all event types (Window, Keyboard, Mouse, etc....
Handling the Events
Each event has a fplEvent::type field which you can check to read the actual data (Keyboard, Mouse, Window, etc.).
switch (currentEvent.
type) {
{
}
} break;
{
}
} break;
{
}
} break;
{
}
} break;
}
}
@ fplEventType_Keyboard
Keyboard event.
@ fplEventType_Window
Window event.
@ fplEventType_Mouse
Mouse event.
@ fplEventType_Gamepad
Gamepad event.
fplMouseEvent mouse
Mouse event data.
fplKeyboardEvent keyboard
Keyboard event data.
fplWindowEvent window
Window event data.
fplGamepadEvent gamepad
Gamepad event data.
fplEventType type
Event type.
fplGamepadEventType type
Gamepad event type.
fplKeyboardEventType type
Keyboard event type.
fplMouseEventType type
Mouse event type.
fplWindowEventType type
Window event type.
All available event types are stored in the fplEventType enumeration.
Handle the event data
All relevant event data are stored in fields that match the lowercase fplEventType name.
Each event structure has another type field to check for the actual type (Key-Down, Mouse-Move, Window-Resize, etc.).
Button states
All mouse/keyboard or gamepad button states are described as a fplButtonState.
To detect a non-repeatable button press, you simply compare against fplButtonState_Press.
To detect a repeatable button press, you simply compare against fplButtonState_Repeat.
To detect a button release, you simply compare against fplButtonState_Release.
If you just want to know if a key is pressed or held down, just do a greater-or-equal comparison against fplButtonState_Press and you are golden.
Mouse events
Mouse event data are stored in the fplMouseEvent structure.
A mouse event contains either a single button click/release or a mouse wheel change or a position change.
{
switch (button) {
{
} break;
{
} break;
{
} break;
}
} break;
{
if (wheelDelta < 0.0f) {
} else if (wheelDelta > 0.0f) {
}
} break;
{
} break;
}
@ fplMouseEventType_Move
Mouse position has been changed.
@ fplMouseEventType_Button
Mouse button event.
@ fplMouseEventType_Wheel
Mouse wheel event.
int32_t mouseX
Mouse X-Position.
fplButtonState buttonState
Button state.
int32_t mouseY
Mouse Y-Position.
float wheelDelta
Mouse wheel delta.
- Note
- Any mouse button event contains the position of the click as well.
Keyboard events
Keyboard event data are stored in the fplKeyboardEvent structure.
You can either check for the original fplKeyboardEvent::keyCode or use the fplKeyboardEvent.mappedKey field - which is much easier and less error-prone.
case fplKeyboardEventType_KeyButton:
{
if (state >= fplButtonState_Pressed) {
if (keyCode == 65 || keyCode == 97) {
}
}
if (state == fplButtonState_Released) {
}
}
} break;
case fplKeyboardEventType_CharInput:
{
if(currentEvent.
keyboard.
keyCode > 0 && event.keyboard.keyCode < 0x10000) {
}
} break;
}
uint64_t keyCode
Raw ASCII key code or 32-bit Unicode for text input.
fplKey mappedKey
Mapped key.
fplButtonState buttonState
Button state.
Gamepad events
Gamepad event data are stored in the fplGamepadEvent structure.
{
} break;
{
} break;
{
if (absf(currentEvent.
gamepad.leftStickX) > 0) {
}
if (currentEvent.
gamepad.actionX.isDown) {
}
} break;
}
Window events
Window event data are stored in the fplWindowEvent structure.
{
uint32_t newWidth = currentEvent.
window.width;
uint32_t newHeight = currentEvent.
window.height;
} break;
case fplWindowEventType_GetFocus:
{
} break;
{
} break;
case fplWindowEventType_DropSingleFile:
{
const char *filePath = ev.window.dropFiles.single.filePath;
} break;
{
} break;
}
@ fplWindowEventType_Minimized
Window has been minimized.
@ fplWindowEventType_LostFocus
Window lost focus.
@ fplWindowEventType_Exposed
Window was exposed.
@ fplWindowEventType_Restored
Window has been restored.
@ fplWindowEventType_Resized
Window has been resized.
@ fplWindowEventType_Maximized
Window has been maximized.
Ignoring the events
When you don't care about any events you can simply call fplPollEvents() to process the events and be done with them.
}
fpl_platform_api bool fplWindowUpdate(void)
Clears the internal event queue and updates input devices if needed.
fpl_platform_api void fplPollEvents(void)
Polls all the events from the OS and clears the internal event queue.
Important Notes
- Note
- FPL does not cache the events from the previous update. If you don't handle or cache the event - the data is lost!