Cogs.Core
EventBasedInput.h
1#pragma once
2#include "Input/InputManager.h"
3#include "Input/KeyboardMapping.h"
4
5namespace Cogs::Core
6{
9 {
10 None = 0,
11 Control = 1 << 0,
12 Shift = 1 << 1,
13 Alt = 1 << 2
14 };
15
16 ENABLE_ENUM_FLAGS(KeyboardModifiers);
17
19 enum class InputEventType {
23 Mouse,
25 Reset
26 };
27
30 Key key = Key::None;
31 };
32
39 struct InputEvent {
42
44 KeyboardModifiers modifiers = KeyboardModifiers::None;
45
47 double timestamp_ms = 0.0;
48
51
54 };
55
65 public:
66 // Should check Modifier state here? TBD
67 EventBasedInput() = default;
68
71 void updateState(const Cogs::Keyboard& keyboard, const Cogs::Mouse& mouse);
72
74 std::span<const InputEvent> events() const { return newEvents; }
75
76 private:
77 void handleMouseEvent(const Cogs::Mouse::Event& mouseEvent);
78 void handleKeyboardEvent(const Cogs::Keyboard::Event& keyboardEvent);
79
80 private:
82 KeyboardModifiers modifiers = KeyboardModifiers::None;
83
85 std::vector<InputEvent> newEvents;
86 };
87}
Event based input handler.
void updateState(const Cogs::Keyboard &keyboard, const Cogs::Mouse &mouse)
void handleKeyboardEvent(const Cogs::Keyboard::Event &keyboardEvent)
std::vector< InputEvent > newEvents
New list of input events.
KeyboardModifiers modifiers
Current modifiers state.
std::span< const InputEvent > events() const
Return new input events from last frame.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
KeyboardModifiers
Current keyboard modifiers.
InputEventType
Type of data in input event queue.
@ Reset
Input Focus lost event. Typically reset any cached mouse/keyboard state.
Event input queue event. Contains either a keyboard or mouse event. Keyboard event:
InputEventType inputEventType
Marks if this entry if a Keyboard event.
KeyboardModifiers modifiers
Current keyboard modifiers.
double timestamp_ms
Event time stamp. Unique and increasing.
Cogs::Mouse::Event mouseEvent
Mouse event data if mouse event.
InputKeyEvent keyEvent
Keyboard event data if keyboard event.
Event based input data for Keyboard events.