cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Event Union Reference

Object that represent an event captured by SDL. More...

#include <event.hpp>

Classes

struct  EventFilter
 Event filter object. More...
 

Public Types

enum  State : int { State::Query = SDL_QUERY, State::Ignore = SDL_IGNORE, State::Enable = SDL_ENABLE }
 For type safety, we will use these scoped enum values instead of raw numbers like the C api. More...
 

Public Member Functions

 Event ()
 Default ctor an event. More...
 
 Event (SDL_Event const &e)
 converting ctor to create an sdl::Event from an SDL_Event struct More...
 
 operator SDL_Event () const
 Implicit convertion to SDL_Event() More...
 
SDL_Event const * ptr () const
 Get a pointer to an SDL_Event. More...
 
SDL_Event * ptr ()
 Get a pointer to an SDL_Event. More...
 
bool poll ()
 Pool for events, return false when there are no more events to poll. More...
 
void wait ()
 Wait until next event occur. This will stop the execution of your code until something happens. More...
 
void wait (int timeout)
 Wait until next event occur, or until the given duration expired. More...
 
void push () const
 Push the current event to the list of event to process. More...
 
void peek ()
 Peek the next event in the list. More...
 
bool has_events ()
 Return true if there are events in the queue. More...
 
bool has_events (Uint32 type)
 Return true if there are events of a specific type in the queue. More...
 
bool has_events (Uint32 minType, Uint32 maxType)
 Return true if there are events of a specific range of types in the queue. More...
 
void pump_events ()
 Pump the event loop from the OS event system. More...
 
void flush_events (Uint32 minType, Uint32 maxType)
 Clear events of a range of types from the event queue. More...
 
void flush_events ()
 Clear all events from the event queue. More...
 
void flush_events (Uint32 type)
 Clear events from a specific type from the event queue. More...
 
void add_events (std::vector< Event > const &events, Uint32 minType, Uint32 maxType)
 Add events of a specific range of types to the event queue. More...
 
void add_events (std::vector< Event > const &events)
 Add events to the queue. More...
 
void add_events (std::vector< Event > const &events, Uint32 type)
 Add events of a specific type to the queue. More...
 
std::vector< Eventpeek_events (size_t maxEvents, Uint32 minType, Uint32 maxType)
 Peek at multiple future events. More...
 
std::vector< Eventpeek_events (size_t maxEvents)
 Peek at future events. More...
 
std::vector< Eventpeek_events (size_t maxEvents, Uint32 type)
 Peek events from a specific type. More...
 
std::vector< Eventget_events (size_t maxEvents, Uint32 minType, Uint32 maxType)
 Get events from the queue maxEvents max number of events to get. More...
 
std::vector< Eventget_events (size_t maxEvents)
 Get events from the queue. More...
 
std::vector< Eventget_events (size_t maxEvents, Uint32 type)
 Get events from a specific type. More...
 
Event::State event_state (Uint32 type)
 
void set_event_state (Uint32 type, Event::State state)
 

Static Public Member Functions

static Event const & ref_from (SDL_Event const &e)
 Get a const reference to an sdl::Event from an SDL_Event. More...
 
static Eventref_from (SDL_Event &e)
 Get a non-const reference to an sdl::Event from an SDL_Event. More...
 
static Event const & ref_from (SDL_Event const *e)
 & ref_from(SDL_Event const* e) More...
 
static Eventref_from (SDL_Event *e)
 ref_from(SDL_Event& e) More...
 

Public Attributes

Uint32 type
 Event type, shared with all events. More...
 
SDL_CommonEvent common
 Common event data. More...
 
SDL_WindowEvent window
 Window event data. More...
 
SDL_KeyboardEvent key
 Keyboard event data. More...
 
SDL_TextEditingEvent edit
 Text editing event data. More...
 
SDL_TextInputEvent text
 Text input event data. More...
 
SDL_MouseMotionEvent motion
 Mouse motion event data. More...
 
SDL_MouseButtonEvent button
 Mouse button event data. More...
 
SDL_MouseWheelEvent wheel
 Mouse wheel event data. More...
 
SDL_JoyAxisEvent jaxis
 Joystick axis event data. More...
 
SDL_JoyBallEvent jball
 Joystick ball event data. More...
 
SDL_JoyHatEvent jhat
 Joystick hat event data. More...
 
SDL_JoyButtonEvent jbutton
 Joystick button event data. More...
 
SDL_JoyDeviceEvent jdevice
 Joystick device change event data. More...
 
SDL_ControllerAxisEvent caxis
 Game Controller axis event data. More...
 
SDL_ControllerButtonEvent cbutton
 Game Controller button event data. More...
 
SDL_ControllerDeviceEvent cdevice
 Game Controller device event data. More...
 
SDL_AudioDeviceEvent adevice
 Audio device event data. More...
 
SDL_QuitEvent quit
 Quit request event data. More...
 
SDL_UserEvent user
 Custom event data. More...
 
SDL_SysWMEvent syswm
 System dependent window event data. More...
 
SDL_TouchFingerEvent tfinger
 Touch finger event data. More...
 
SDL_MultiGestureEvent mgesture
 Gesture event data. More...
 
SDL_DollarGestureEvent dgesture
 Gesture event data. More...
 
SDL_DropEvent drop
 Drag and drop event data. More...
 
SDL_SensorEvent sensor
 
SDL_DisplayEvent display
 Sensor event data. More...
 
Uint8 padding [56]
 Window event data. More...
 

Detailed Description

Object that represent an event captured by SDL.

This union has the exact same memory layout as the SDL_Event structure. An SDL_Event and an sdl::Event object are "the same bits" in memory if they hold infos about the same event. cpp-sdl2 convert the raw SDL_Event into an sdl::Event object to add an object-oriented API around them

Definition at line 32 of file event.hpp.

Member Enumeration Documentation

◆ State

enum sdl::Event::State : int
strong

For type safety, we will use these scoped enum values instead of raw numbers like the C api.

Enumerator
Query 
Ignore 
Enable 

Definition at line 119 of file event.hpp.

Constructor & Destructor Documentation

◆ Event() [1/2]

sdl::Event::Event ( )
inline

Default ctor an event.

Definition at line 78 of file event.hpp.

◆ Event() [2/2]

sdl::Event::Event ( SDL_Event const &  e)
inline

converting ctor to create an sdl::Event from an SDL_Event struct

Definition at line 95 of file event.hpp.

Member Function Documentation

◆ add_events() [1/3]

void sdl::Event::add_events ( std::vector< Event > const &  events,
Uint32  minType,
Uint32  maxType 
)
inline

Add events of a specific range of types to the event queue.

Parameters
eventsvector of events to be added
minTypelower type boundary of the range
maxTypeupper type boundary of the range

Definition at line 198 of file event.hpp.

Referenced by add_events().

◆ add_events() [2/3]

void sdl::Event::add_events ( std::vector< Event > const &  events)
inline

Add events to the queue.

Parameters
eventsvector of events to be added

Definition at line 210 of file event.hpp.

References add_events().

◆ add_events() [3/3]

void sdl::Event::add_events ( std::vector< Event > const &  events,
Uint32  type 
)
inline

Add events of a specific type to the queue.

Parameters
eventsvector of events to be added
typetype of events to be added

Definition at line 218 of file event.hpp.

References add_events().

◆ event_state()

Event::State sdl::Event::event_state ( Uint32  type)
inline

Definition at line 325 of file event.hpp.

◆ flush_events() [1/3]

void sdl::Event::flush_events ( Uint32  minType,
Uint32  maxType 
)
inline

Clear events of a range of types from the event queue.

Parameters
minTypelower type boundary of the range
maxTypeupper type boundary of the range

Definition at line 186 of file event.hpp.

◆ flush_events() [2/3]

void sdl::Event::flush_events ( )
inline

Clear all events from the event queue.

Definition at line 189 of file event.hpp.

References flush_events().

Referenced by flush_events().

◆ flush_events() [3/3]

void sdl::Event::flush_events ( Uint32  type)
inline

Clear events from a specific type from the event queue.

Definition at line 192 of file event.hpp.

References flush_events().

Referenced by flush_events().

◆ get_events() [1/3]

std::vector<Event> sdl::Event::get_events ( size_t  maxEvents,
Uint32  minType,
Uint32  maxType 
)
inline

Get events from the queue maxEvents max number of events to get.

Parameters
minTypelower bound of type range
maxTypeupper bound of type range

Definition at line 255 of file event.hpp.

Referenced by get_events().

◆ get_events() [2/3]

std::vector<Event> sdl::Event::get_events ( size_t  maxEvents)
inline

Get events from the queue.

Parameters
typeThe type of events to look for
maxEventsmax number of events to get

Definition at line 269 of file event.hpp.

References get_events().

◆ get_events() [3/3]

std::vector<Event> sdl::Event::get_events ( size_t  maxEvents,
Uint32  type 
)
inline

Get events from a specific type.

Parameters
typeThe type of events to look for
maxEventsmax number of events to get

Definition at line 277 of file event.hpp.

References get_events().

◆ has_events() [1/3]

bool sdl::Event::has_events ( )
inline

Return true if there are events in the queue.

Definition at line 165 of file event.hpp.

◆ has_events() [2/3]

bool sdl::Event::has_events ( Uint32  type)
inline

Return true if there are events of a specific type in the queue.

Parameters
typethe type of the events you want to check for

Definition at line 169 of file event.hpp.

◆ has_events() [3/3]

bool sdl::Event::has_events ( Uint32  minType,
Uint32  maxType 
)
inline

Return true if there are events of a specific range of types in the queue.

Parameters
minTypelower type boundary of the range
maxTypeupper type boundary of the range

Definition at line 174 of file event.hpp.

◆ operator SDL_Event()

sdl::Event::operator SDL_Event ( ) const
inline

Implicit convertion to SDL_Event()

Definition at line 110 of file event.hpp.

◆ peek()

void sdl::Event::peek ( )
inline

Peek the next event in the list.

Definition at line 156 of file event.hpp.

References ptr().

◆ peek_events() [1/3]

std::vector<Event> sdl::Event::peek_events ( size_t  maxEvents,
Uint32  minType,
Uint32  maxType 
)
inline

Peek at multiple future events.

Parameters
maxEventsmax number of events to get
minTypelower bound of event type range
maxTypeupper bound of event type range

Definition at line 227 of file event.hpp.

Referenced by peek_events().

◆ peek_events() [2/3]

std::vector<Event> sdl::Event::peek_events ( size_t  maxEvents)
inline

Peek at future events.

Definition at line 239 of file event.hpp.

References peek_events().

◆ peek_events() [3/3]

std::vector<Event> sdl::Event::peek_events ( size_t  maxEvents,
Uint32  type 
)
inline

Peek events from a specific type.

Parameters
typeThe type of events to look for

Definition at line 246 of file event.hpp.

References peek_events().

◆ poll()

bool sdl::Event::poll ( )
inline

Pool for events, return false when there are no more events to poll.

Definition at line 127 of file event.hpp.

References ptr().

◆ ptr() [1/2]

SDL_Event const* sdl::Event::ptr ( ) const
inline

Get a pointer to an SDL_Event.

Definition at line 113 of file event.hpp.

Referenced by peek(), poll(), push(), and wait().

◆ ptr() [2/2]

SDL_Event* sdl::Event::ptr ( )
inline

Get a pointer to an SDL_Event.

Definition at line 116 of file event.hpp.

◆ pump_events()

void sdl::Event::pump_events ( )
inline

Pump the event loop from the OS event system.

only call this from the main thread (or the thread that initialized the video/window systems) This is only usefull if you aren't polling or waiting for events

Definition at line 181 of file event.hpp.

◆ push()

void sdl::Event::push ( ) const
inline

Push the current event to the list of event to process.

Definition at line 146 of file event.hpp.

References ptr().

◆ ref_from() [1/4]

static Event const& sdl::Event::ref_from ( SDL_Event const &  e)
inlinestatic

Get a const reference to an sdl::Event from an SDL_Event.

Definition at line 98 of file event.hpp.

Referenced by sdl::Event::EventFilter::call_filter().

◆ ref_from() [2/4]

static Event& sdl::Event::ref_from ( SDL_Event &  e)
inlinestatic

Get a non-const reference to an sdl::Event from an SDL_Event.

Definition at line 101 of file event.hpp.

◆ ref_from() [3/4]

static Event const& sdl::Event::ref_from ( SDL_Event const *  e)
inlinestatic

◆ ref_from() [4/4]

static Event& sdl::Event::ref_from ( SDL_Event *  e)
inlinestatic

◆ set_event_state()

void sdl::Event::set_event_state ( Uint32  type,
Event::State  state 
)
inline

Definition at line 330 of file event.hpp.

◆ wait() [1/2]

void sdl::Event::wait ( )
inline

Wait until next event occur. This will stop the execution of your code until something happens.

Definition at line 130 of file event.hpp.

References ptr().

◆ wait() [2/2]

void sdl::Event::wait ( int  timeout)
inline

Wait until next event occur, or until the given duration expired.

Parameters
timeoutmax duration to wait for in milliseconds

Definition at line 137 of file event.hpp.

References ptr().

Member Data Documentation

◆ adevice

SDL_AudioDeviceEvent sdl::Event::adevice

Audio device event data.

Definition at line 54 of file event.hpp.

◆ button

SDL_MouseButtonEvent sdl::Event::button

Mouse button event data.

Definition at line 44 of file event.hpp.

◆ caxis

SDL_ControllerAxisEvent sdl::Event::caxis

Game Controller axis event data.

Definition at line 51 of file event.hpp.

◆ cbutton

SDL_ControllerButtonEvent sdl::Event::cbutton

Game Controller button event data.

Definition at line 52 of file event.hpp.

◆ cdevice

SDL_ControllerDeviceEvent sdl::Event::cdevice

Game Controller device event data.

Definition at line 53 of file event.hpp.

◆ common

SDL_CommonEvent sdl::Event::common

Common event data.

Definition at line 38 of file event.hpp.

◆ dgesture

SDL_DollarGestureEvent sdl::Event::dgesture

Gesture event data.

Definition at line 60 of file event.hpp.

◆ display

SDL_DisplayEvent sdl::Event::display

Sensor event data.

Definition at line 64 of file event.hpp.

◆ drop

SDL_DropEvent sdl::Event::drop

Drag and drop event data.

Definition at line 61 of file event.hpp.

◆ edit

SDL_TextEditingEvent sdl::Event::edit

Text editing event data.

Definition at line 41 of file event.hpp.

◆ jaxis

SDL_JoyAxisEvent sdl::Event::jaxis

Joystick axis event data.

Definition at line 46 of file event.hpp.

◆ jball

SDL_JoyBallEvent sdl::Event::jball

Joystick ball event data.

Definition at line 47 of file event.hpp.

◆ jbutton

SDL_JoyButtonEvent sdl::Event::jbutton

Joystick button event data.

Definition at line 49 of file event.hpp.

◆ jdevice

SDL_JoyDeviceEvent sdl::Event::jdevice

Joystick device change event data.

Definition at line 50 of file event.hpp.

◆ jhat

SDL_JoyHatEvent sdl::Event::jhat

Joystick hat event data.

Definition at line 48 of file event.hpp.

◆ key

SDL_KeyboardEvent sdl::Event::key

Keyboard event data.

Definition at line 40 of file event.hpp.

◆ mgesture

SDL_MultiGestureEvent sdl::Event::mgesture

Gesture event data.

Definition at line 59 of file event.hpp.

◆ motion

SDL_MouseMotionEvent sdl::Event::motion

Mouse motion event data.

Definition at line 43 of file event.hpp.

◆ padding

Uint8 sdl::Event::padding[56]

Window event data.

Definition at line 75 of file event.hpp.

◆ quit

SDL_QuitEvent sdl::Event::quit

Quit request event data.

Definition at line 55 of file event.hpp.

◆ sensor

SDL_SensorEvent sdl::Event::sensor

Definition at line 63 of file event.hpp.

◆ syswm

SDL_SysWMEvent sdl::Event::syswm

System dependent window event data.

Definition at line 57 of file event.hpp.

◆ text

SDL_TextInputEvent sdl::Event::text

Text input event data.

Definition at line 42 of file event.hpp.

◆ tfinger

SDL_TouchFingerEvent sdl::Event::tfinger

Touch finger event data.

Definition at line 58 of file event.hpp.

◆ type

Uint32 sdl::Event::type

Event type, shared with all events.

Definition at line 37 of file event.hpp.

◆ user

SDL_UserEvent sdl::Event::user

Custom event data.

Definition at line 56 of file event.hpp.

◆ wheel

SDL_MouseWheelEvent sdl::Event::wheel

Mouse wheel event data.

Definition at line 45 of file event.hpp.

◆ window

SDL_WindowEvent sdl::Event::window

Window event data.

Definition at line 39 of file event.hpp.


The documentation for this union was generated from the following file: