libdonut  2.3.2
Application framework for cross-platform game development in C++20
Public Member Functions | List of all members
donut::events::EventPump Class Reference

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

#include <donut/events/EventPump.hpp>

Public Member Functions

 EventPump ()
 Construct an event pump. More...
 
 ~EventPump ()
 Destructor. More...
 
 EventPump (const EventPump &)=delete
 Copying an event pump is not allowed, since it manages global state. More...
 
 EventPump (EventPump &&)=delete
 Moving an event pump is not allowed, since it manages global state. More...
 
EventPumpoperator= (const EventPump &)=delete
 Copying an event pump is not allowed, since it manages global state. More...
 
EventPumpoperator= (EventPump &&)=delete
 Moving an event pump is not allowed, since it manages global state. More...
 
std::span< const EventpollEvents ()
 Poll events from the environment and update the internal event buffer. More...
 
void setRelativeMouseMode (bool relativeMouseMode)
 Enable or disable relative mouse mode. More...
 
void setTextInputRectangle (ivec2 offset, ivec2 size)
 Set the input rectangle for text input. More...
 
void startTextInput ()
 Start accepting text input events in the current text input rectangle. More...
 
void stopTextInput ()
 Stop accepting text input events. More...
 
std::span< const EventgetLatestPolledEvents () const noexcept
 Get the latest events in the internal event buffer that were polled using pollEvents(). More...
 
std::string getClipboardText () const
 Get the current text contained in the clipboard. More...
 
bool hasScreenKeyboardSupport () const noexcept
 Check if the application supports a screen keyboard. More...
 

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.

Examples
example_game.cpp, and example_rectangle.cpp.

Constructor & Destructor Documentation

◆ EventPump() [1/3]

donut::events::EventPump::EventPump ( )

Construct an event pump.

Exceptions
events::Erroron failure to initialize the required global subsystems.

◆ ~EventPump()

donut::events::EventPump::~EventPump ( )

Destructor.

◆ EventPump() [2/3]

donut::events::EventPump::EventPump ( const EventPump )
delete

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

◆ EventPump() [3/3]

donut::events::EventPump::EventPump ( EventPump &&  )
delete

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

Member Function Documentation

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

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

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

◆ pollEvents()

std::span<const Event> donut::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::bad_allocon allocation failure.
See also
getLatestPolledEvents()

◆ setRelativeMouseMode()

void donut::events::EventPump::setRelativeMouseMode ( bool  relativeMouseMode)

Enable or disable relative mouse mode.

When relative mouse mode is enabled, it hides the mouse cursor, locks it to the window and causes all further mouse motion to be provided as relative motion events until it is disabled again.

Parameters
relativeMouseModetrue to enable relative mouse mode, false to disable.
Exceptions
events::Erroron failure to set the relative mouse mode.

◆ setTextInputRectangle()

void donut::events::EventPump::setTextInputRectangle ( ivec2  offset,
ivec2  size 
)

Set the input rectangle for text input.

Parameters
offsetoffset of the input rectangle, in screen coordinates.
sizesize of the input rectangle, in screen coordinates.
See also
startTextInput()
stopTextInput()

◆ startTextInput()

void donut::events::EventPump::startTextInput ( )

Start accepting text input events in the current text input rectangle.

See also
setTextInputRectangle()
stopTextInput()

◆ stopTextInput()

void donut::events::EventPump::stopTextInput ( )

Stop accepting text input events.

See also
setTextInputRectangle()
startTextInput()

◆ getLatestPolledEvents()

std::span<const Event> donut::events::EventPump::getLatestPolledEvents ( ) const
noexcept

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()

std::string donut::events::EventPump::getClipboardText ( ) const

Get the current text contained in the clipboard.

Returns
the text in the clipboard.
Exceptions
std::bad_allocon allocation failure.

◆ hasScreenKeyboardSupport()

bool donut::events::EventPump::hasScreenKeyboardSupport ( ) const
noexcept

Check if the application supports a screen keyboard.

Returns
true if a screen keyboard is supported, false otherwise.
See also
graphics::Window::isScreenKeyboardShown()

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