blob: 764ca966a2afa3c54c62ebab8e12a2e3d144896b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#pragma once
#include <SDL3/SDL.h>
#include <glm/glm.hpp>
// Simple polling-based input state. Call begin_frame() once per frame,
// then query state during update.
class Input {
public:
// Call once per frame BEFORE reading any input state.
// Processes the SDL event queue and updates internal state.
void begin_frame();
// Keyboard
bool key_down(SDL_Keycode key) const;
bool key_pressed(SDL_Keycode key) const; // true only on the frame it went down
bool key_released(SDL_Keycode key) const; // true only on the frame it went up
// Mouse
glm::vec2 mouse_pos() const; // in window coordinates
glm::vec2 mouse_delta() const; // movement since last frame
float scroll_delta() const; // vertical scroll (positive = scroll up)
bool mouse_down(int button) const; // SDL_BUTTON_LEFT, MIDDLE, RIGHT
bool mouse_pressed(int button) const;
bool mouse_released(int button) const;
// Window
bool quit_requested() const { return quit_; }
private:
// Keyboard
bool key_state_[SDL_SCANCODE_COUNT] = {};
bool key_prev_[SDL_SCANCODE_COUNT] = {};
bool key_just_pressed_[SDL_SCANCODE_COUNT] = {};
bool key_just_released_[SDL_SCANCODE_COUNT] = {};
// Mouse
glm::vec2 mouse_pos_ = {0.0f, 0.0f};
glm::vec2 mouse_prev_ = {0.0f, 0.0f};
glm::vec2 mouse_delta_ = {0.0f, 0.0f};
float scroll_ = 0.0f;
bool mouse_state_[8] = {};
bool mouse_prev_state_[8] = {};
bool mouse_pressed_[8] = {};
bool mouse_released_[8] = {};
bool quit_ = false;
};
|