GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::events::EventPump Class Reference

Persistent system for polling Event data and other user input from the host environment on demand. More...

#include <GREM/events/EventPump.hpp>

Public Member Functions

 EventPump (const EventPumpOptions &options={})
 Construct an event pump.
 ~EventPump ()
 Destructor.
 EventPump (const EventPump &)=delete
 Copying an event pump is not allowed, since it manages global state.
 EventPump (EventPump &&)=delete
 Moving an event pump is not allowed, since it manages global state.
EventPump & operator= (const EventPump &)=delete
 Copying an event pump is not allowed, since it manages global state.
EventPump & operator= (EventPump &&)=delete
 Moving an event pump is not allowed, since it manages global state.
Span< const Event > pollEvents ()
 Poll events from the environment and update the internal event buffer.
void showCursor ()
 Show the mouse cursor.
void hideCursor ()
 Hide the mouse cursor.
void captureMouse ()
 Capture the mouse in order to track all mouse input even if the cursor is outside of the current window.
void uncaptureMouse ()
 Stop tracking mouse input outside the current window.
void enableScreenSaver ()
 Allow the screen to be blanked by a screen saver.
void disableScreenSaver ()
 Prevent the screen to be blanked by a screen saver.
void setCursorStyle (CursorStyle newStyle)
 Set the current style of the mouse cursor.
void setClipboardText (CStringView newString)
 Set the current text contained in the clipboard.
void setRawMouseInputEnabled (bool useRawMouseInput)
 Set the current state of raw input for relative mouse motion.
Span< const Event > getLatestPolledEvents () const noexcept
 Get the latest events in the internal event buffer that were polled using pollEvents().
Optional< String > getClipboardText () const
 Get the current text contained in the clipboard.
bool isScreenSaverEnabled () const noexcept
 Check if the screen saver is currently enabled.
Span< const uint32_t > getConnectedControllerIDs () const noexcept
 Get the currently known connected controller IDs.
ControllerType getControllerType (uint32_t controllerID) const noexcept
 Get the controller type of a connected controller.

Detailed Description

Persistent system for polling Event data and other user input from the host environment on demand.

The latest events are stored in a buffer that can be accessed until the next time events are polled. The main intended usage pattern for this is to call pollEvents() once at the start of each Application frame and then access the event buffer immediately or throughout the rest of the frame as necessary.

Constructor & Destructor Documentation

◆ EventPump() [1/3]

grem::events::EventPump::EventPump ( const EventPumpOptions & options = {})

Construct an event pump.

Parameters
optionsinitial configuration of the event pump, see EventPumpOptions.
Exceptions
events::Erroron failure to initialize the required global subsystems.

◆ ~EventPump()

grem::events::EventPump::~EventPump ( )

Destructor.

◆ EventPump() [2/3]

grem::events::EventPump::EventPump ( const EventPump & )
delete

Copying an event pump is not allowed, since it manages global state.

◆ EventPump() [3/3]

grem::events::EventPump::EventPump ( EventPump && )
delete

Moving an event pump is not allowed, since it manages global state.

Member Function Documentation

◆ operator=() [1/2]

EventPump & grem::events::EventPump::operator= ( const EventPump & )
delete

Copying an event pump is not allowed, since it manages global state.

◆ operator=() [2/2]

EventPump & grem::events::EventPump::operator= ( EventPump && )
delete

Moving an event pump is not allowed, since it manages global state.

◆ pollEvents()

Span< const Event > grem::events::EventPump::pollEvents ( )

Poll events from the environment and update the internal event buffer.

Returns
a non-owning read-only view over the polled events, stored in the internal event buffer, which is valid until the next call to pollEvents() or until the event pump is destroyed, whichever happens first.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
getLatestPolledEvents()

◆ showCursor()

void grem::events::EventPump::showCursor ( )

Show the mouse cursor.

Exceptions
events::Erroron failure to show the cursor.
std::bad_allocon allocation failure.
See also
hideCursor()
setCursorStyle()

◆ hideCursor()

void grem::events::EventPump::hideCursor ( )

Hide the mouse cursor.

Exceptions
events::Erroron failure to hide the cursor.
std::bad_allocon allocation failure.
See also
showCursor()

◆ captureMouse()

void grem::events::EventPump::captureMouse ( )

Capture the mouse in order to track all mouse input even if the cursor is outside of the current window.

Exceptions
events::Erroron failure to set the mouse capture state.
std::bad_allocon allocation failure.
Note
Make sure to call uncaptureMouse() as soon as global mouse input is no longer needed.
See also
uncaptureMouse()

◆ uncaptureMouse()

void grem::events::EventPump::uncaptureMouse ( )

Stop tracking mouse input outside the current window.

Exceptions
events::Erroron failure to set the mouse capture state.
std::bad_allocon allocation failure.
See also
captureMouse()

◆ enableScreenSaver()

void grem::events::EventPump::enableScreenSaver ( )

Allow the screen to be blanked by a screen saver.

Exceptions
events::Erroron failure to set the screen saver allow state.
std::bad_allocon allocation failure.
See also
disableScreenSaver()

◆ disableScreenSaver()

void grem::events::EventPump::disableScreenSaver ( )

Prevent the screen to be blanked by a screen saver.

Exceptions
events::Erroron failure to set the screen saver allow state.
std::bad_allocon allocation failure.
See also
enableScreenSaver()

◆ setCursorStyle()

void grem::events::EventPump::setCursorStyle ( CursorStyle newStyle)

Set the current style of the mouse cursor.

Parameters
newStylenew cursor style to set.
Exceptions
events::Erroron failure to set the cursor style.
std::bad_allocon allocation failure.

◆ setClipboardText()

void grem::events::EventPump::setClipboardText ( CStringView newString)

Set the current text contained in the clipboard.

Parameters
newStringnew text string to set the clipboard to.
Exceptions
events::Erroron failure to set the clipboard text.
std::bad_allocon allocation failure.

◆ setRawMouseInputEnabled()

void grem::events::EventPump::setRawMouseInputEnabled ( bool useRawMouseInput)

Set the current state of raw input for relative mouse motion.

Parameters
useRawMouseInputwhether raw input should be enabled or not.
See also
EventPumpOptions::useRawMouseInput

◆ getLatestPolledEvents()

Span< const Event > grem::events::EventPump::getLatestPolledEvents ( ) const
inlinenodiscardnoexcept

Get the latest events in the internal event buffer that were polled using pollEvents().

Returns
a non-owning read-only view over the polled events, stored in the internal event buffer, which is valid until the next call to pollEvents() or until the event pump is destroyed, whichever happens first.
See also
pollEvents()

◆ getClipboardText()

Optional< String > grem::events::EventPump::getClipboardText ( ) const
nodiscard

Get the current text contained in the clipboard.

Returns
the text in the clipboard, or an empty optional if there is no text.
Exceptions
std::length_errorif the maximum clipboard size was exceeded.
std::bad_allocon allocation failure.

◆ isScreenSaverEnabled()

bool grem::events::EventPump::isScreenSaverEnabled ( ) const
nodiscardnoexcept

Check if the screen saver is currently enabled.

Returns
true if the screen saver state is allowed, false otherwise.

◆ getConnectedControllerIDs()

Span< const uint32_t > grem::events::EventPump::getConnectedControllerIDs ( ) const
inlinenodiscardnoexcept

Get the currently known connected controller IDs.

Returns
a non-owning read-only view over the controller IDs, which is valid until the next call to pollEvents() or until the event pump is destroyed, whichever happens first.

◆ getControllerType()

ControllerType grem::events::EventPump::getControllerType ( uint32_t controllerID) const
nodiscardnoexcept

Get the controller type of a connected controller.

Parameters
controllerIDID of the connected controller to get the type of.
Returns
the controller type, or ControllerType::UNKNOWN if it could not be determined.
See also
getConnectedControllerIDs()

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