GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
EventPump.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_EVENTS_EVENT_PUMP_HPP
5#define GREM_EVENTS_EVENT_PUMP_HPP
6
8
16
17namespace grem::events {
18
19struct Event; // Forward declaration, to avoid including Event.hpp.
20
46
56
66 bool useRawMouseInput = true;
67};
68
78class EventPump {
79public:
89 GREM_API(events) EventPump(const EventPumpOptions& options = {});
90
92 GREM_API(events) ~EventPump();
93
95 EventPump(const EventPump&) = delete;
96
98 EventPump(EventPump&&) = delete;
99
101 EventPump& operator=(const EventPump&) = delete;
102
105
120 GREM_API(events) Span<const Event> pollEvents();
121
131 GREM_API(events) void showCursor();
132
141 GREM_API(events) void hideCursor();
142
155 GREM_API(events) void captureMouse();
156
165 GREM_API(events) void uncaptureMouse();
166
175 GREM_API(events) void enableScreenSaver();
176
185 GREM_API(events) void disableScreenSaver();
186
195 GREM_API(events) void setCursorStyle(CursorStyle newStyle);
196
205 GREM_API(events) void setClipboardText(CStringView newString);
206
214 GREM_API(events) void setRawMouseInputEnabled(bool useRawMouseInput);
215
227 [[nodiscard]] Span<const Event> getLatestPolledEvents() const noexcept {
228 return events;
229 }
230
240 [[nodiscard]] GREM_API(events) Optional<String> getClipboardText() const;
241
247 [[nodiscard]] GREM_API(events) bool isScreenSaverEnabled() const noexcept;
248
256 [[nodiscard]] Span<const uint32_t> getConnectedControllerIDs() const noexcept {
257 return controllerIDs;
258 }
259
270 [[nodiscard]] GREM_API(events) ControllerType getControllerType(uint32_t controllerID) const noexcept;
271
272private:
273 struct CursorDeleter {
274 GREM_API(events) void operator()(void* handle) const noexcept;
275 };
276
278
279 struct ControllerDeleter {
280 GREM_API(events) void operator()(void* handle) const noexcept;
281 };
282
284
285 bool controllerSupportEnabled;
287 ArrayList<Controller> controllers{};
288 ArrayList<uint32_t> controllerIDs{};
289 void* cursorRegular = nullptr;
290 Cursor cursorDefault{};
291 Cursor cursorText{};
292 Cursor cursorWait{};
293 Cursor cursorCrosshair{};
294 Cursor cursorProgress{};
295 Cursor cursorResizeDiagonalNwSe{};
296 Cursor cursorResizeDiagonalNeSw{};
297 Cursor cursorResizeHorizontal{};
298 Cursor cursorResizeVertical{};
299 Cursor cursorMove{};
300 Cursor cursorNotAllowed{};
301 Cursor cursorPointer{};
302 Cursor cursorResizeNw{};
303 Cursor cursorResizeN{};
304 Cursor cursorResizeNe{};
305 Cursor cursorResizeE{};
306 Cursor cursorResizeSw{};
307 Cursor cursorResizeS{};
308 Cursor cursorResizeSe{};
309 Cursor cursorResizeW{};
310};
311
312} // namespace grem::events
313
314#endif
Definition ArrayList.hpp:27
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition Span.hpp:146
Generic nullable RAII resource handle with exclusive ownership of a resource that is automatically de...
Definition UniqueHandle.hpp:26
Span< const uint32_t > getConnectedControllerIDs() const noexcept
Get the currently known connected controller IDs.
Definition EventPump.hpp:256
void setClipboardText(CStringView newString)
Set the current text contained in the clipboard.
EventPump(const EventPump &)=delete
Copying an event pump is not allowed, since it manages global state.
void setCursorStyle(CursorStyle newStyle)
Set the current style of the mouse cursor.
bool isScreenSaverEnabled() const noexcept
Check if the screen saver is currently enabled.
Span< const Event > pollEvents()
Poll events from the environment and update the internal event buffer.
void enableScreenSaver()
Allow the screen to be blanked by a screen saver.
void showCursor()
Show the mouse cursor.
Span< const Event > getLatestPolledEvents() const noexcept
Get the latest events in the internal event buffer that were polled using pollEvents().
Definition EventPump.hpp:227
void captureMouse()
Capture the mouse in order to track all mouse input even if the cursor is outside of the current wind...
void disableScreenSaver()
Prevent the screen to be blanked by a screen saver.
void uncaptureMouse()
Stop tracking mouse input outside the current window.
EventPump(EventPump &&)=delete
Moving an event pump is not allowed, since it manages global state.
Optional< String > getClipboardText() const
Get the current text contained in the clipboard.
EventPump & operator=(EventPump &&)=delete
Moving an event pump is not allowed, since it manages global state.
EventPump(const EventPumpOptions &options={})
Construct an event pump.
void hideCursor()
Hide the mouse cursor.
void setRawMouseInputEnabled(bool useRawMouseInput)
Set the current state of raw input for relative mouse motion.
ControllerType getControllerType(uint32_t controllerID) const noexcept
Get the controller type of a connected controller.
EventPump & operator=(const EventPump &)=delete
Copying an event pump is not allowed, since it manages global state.
Definition controller.hpp:11
CursorStyle
Visual mouse cursor style.
Definition EventPump.hpp:24
@ RESIZE_VERTICAL
Vertical double arrow cursor pointing north and south.
Definition EventPump.hpp:33
@ RESIZE_SE
Diagonal double arrow cursor pointing southeast. May be a single or double arrow.
Definition EventPump.hpp:43
@ RESIZE_NW
Diagonal double arrow cursor pointing northwest. May be a single or double arrow.
Definition EventPump.hpp:37
@ RESIZE_DIAGONAL_NW_SE
Diagonal double arrow cursor pointing northwest and southeast.
Definition EventPump.hpp:30
@ RESIZE_SW
Diagonal double arrow cursor pointing southwest. May be a single or double arrow.
Definition EventPump.hpp:41
@ NOT_ALLOWED
Not allowed cursor. Usually a slashed circle or crossbones.
Definition EventPump.hpp:35
@ RESIZE_NE
Diagonal double arrow cursor pointing northeast. May be a single or double arrow.
Definition EventPump.hpp:39
@ DEFAULT
Default cursor. Usually an arrow.
Definition EventPump.hpp:25
@ RESIZE_W
Diagonal double arrow cursor pointing west. May be a single or double arrow.
Definition EventPump.hpp:44
@ TEXT
Text selection cursor. Usually an I-beam.
Definition EventPump.hpp:26
@ CROSSHAIR
Crosshair cursor.
Definition EventPump.hpp:28
@ POINTER
Pointer cursor that indicates a link. Usually a pointing hand.
Definition EventPump.hpp:36
@ RESIZE_S
Diagonal double arrow cursor pointing south. May be a single or double arrow.
Definition EventPump.hpp:42
@ RESIZE_DIAGONAL_NE_SW
Diagonal double arrow cursor pointing northeast and southwest.
Definition EventPump.hpp:31
@ RESIZE_HORIZONTAL
Horizontal double arrow cursor pointing east and west.
Definition EventPump.hpp:32
@ WAIT
Waiting cursor. Usually an hourglass, watch or spinning ball.
Definition EventPump.hpp:27
@ RESIZE_N
Diagonal double arrow cursor pointing north. May be a single or double arrow.
Definition EventPump.hpp:38
@ PROGRESS
Waiting cursor indicating that the app is still interactive. Usually WAIT with an arrow.
Definition EventPump.hpp:29
@ MOVE
Four-pointed arrow cursor.
Definition EventPump.hpp:34
@ RESIZE_E
Diagonal double arrow cursor pointing east. May be a single or double arrow.
Definition EventPump.hpp:40
ControllerType
Common controller type categories.
Definition controller.hpp:19
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Configuration options for an EventPump.
Definition EventPump.hpp:50
bool enableControllerSupport
Enable the gamepad subsystem to allow for controller events to be produced.
Definition EventPump.hpp:55
bool useRawMouseInput
Use raw input for relative mouse motion.
Definition EventPump.hpp:66
Data structure containing information about an event.
Definition Event.hpp:370