Skip to content

Engine → Platform

event.h

The event stream a window produces once per frame. Every alternative is a trivially copyable struct; the one payload with external data (drop_files_event) points into a window-owned buffer that stays valid until the next pump_events(). input_event lists the alternatives input::apply consumes; event adds the window-level ones. Both list the input alternatives first and in the same order, so the conversions below are index remaps.

Structs

File Description
close_event
content_scale_changed_event
cursor_enter_event
drop_files_event
focus_event
framebuffer_resized_event
gamepad_axis_event
gamepad_button_event
gamepad_connection_event
key_event
minimise_event
mouse_button_event
mouse_move_event
mouse_scroll_event
text_event

Type Aliases

event

using event = std::variant< key_event, text_event, mouse_move_event, mouse_button_event, mouse_scroll_event, cursor_enter_event, gamepad_connection_event, gamepad_button_event, gamepad_axis_event, framebuffer_resized_event, content_scale_changed_event, focus_event, minimise_event, close_event, drop_files_event>;

input_event

using input_event = std::variant< key_event, text_event, mouse_move_event, mouse_button_event, mouse_scroll_event, cursor_enter_event, gamepad_connection_event, gamepad_button_event, gamepad_axis_event>;

Constants

Name Type Value Description
EVENT_COUNT inline constexpr usize std::variant_size_v<event> Number of alternatives of event.
INPUT_EVENT_COUNT inline constexpr usize std::variant_size_v<input_event> Number of input alternatives; they occupy the first INPUT_EVENT_COUNT indices of event.

Functions

Public

event_as

template <typename EventType> [[nodiscard]] const EventType *event_as(
    const event &value) noexcept;

The payload when the event holds EventType, otherwise nullptr (std::get_if).

event_name

[[nodiscard]] CONJURE_API std::string_view event_name(
    const event &value) noexcept;

The alternative name of an event ("key_event", "close_event", ...).

is_input_event

[[nodiscard]] CONJURE_API bool is_input_event(
    const event &value) noexcept;

True when the event is one of the input alternatives (what input::apply consumes).

to_event

[[nodiscard]] CONJURE_API event to_event(
    const input_event &value) noexcept;

Widens an input_event to an event (never fails).

to_input_event

[[nodiscard]] CONJURE_API std::optional<input_event> to_input_event(
    const event &value) noexcept;

The event as an input_event, or nullopt for a window event.

to_string

[[nodiscard]] CONJURE_API std::string to_string(
    const event &value);

The alternative name and payload, e.g. "key_event{key=SPACE, scancode=57, action=PRESS, modifiers=SHIFT}", for the editor console and window diagnostics.