souleng
Game engine providing full Python scripting support
Loading...
Searching...
No Matches
Input.hpp
1#pragma once
2
3#include "util/Vector2.hpp"
4#include <map>
5#include <string>
6
8struct KeyState {
9 bool pressed;
10 bool held;
11 bool released;
12};
13
15struct MouseClick {
16 bool pressed;
17 bool held;
18 bool released;
19 int clicks;
20 Vector2 pos;
21 std::string mouseButton;
22};
23
26 Vector2 pos;
27 Vector2 motion;
28};
29
31struct Input {
32
34 static Input &instance();
35
37 void PollInputs();
38
41 KeyState GetKey(std::string key);
42
45
48
51
52private:
53 Input();
54
55 static Input *mInstance;
56
57 std::map<std::string, KeyState> keyStates;
58 std::map<std::string, KeyState> prevFrameKeyStates;
59 MouseClick clickState{};
60 MouseMotion motionState{};
61
62 bool programQuit{false};
63 bool userQuit{false};
64};
Singleton class for polling and retrieving input from the user.
Definition Input.hpp:31
KeyState GetKey(std::string key)
Definition Input.cpp:303
bool ReceivedProgramQuit()
Returns true if PollInputs receives an SDL_QuitEvent
Definition Input.cpp:309
static Input & instance()
Singleton accessor function for the Input class.
Definition Input.cpp:242
void PollInputs()
Updates all inputs by polling the SDL Event queue for any new events.
Definition Input.cpp:250
MouseMotion GetMouseMotion()
Retrieves the last mouse motion input by the user.
Definition Input.cpp:307
MouseClick GetMouseClick()
Retrieves the last known state of the mouse since being clicked.
Definition Input.cpp:305
Simple POD struct holding the state of a key press.
Definition Input.hpp:8
Simple POD struct holding the state of any mouse click.
Definition Input.hpp:15
Simple POD struct holding the state of any mouse motion.
Definition Input.hpp:25
Simple container for position data.
Definition Vector2.hpp:4