Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
input_manager.h
Go to the documentation of this file.
1 #pragma once
2 #include "core/engine_structs.h"
3 
4 struct Joystick {
5  SDL_Joystick* joystick;
6  std::unordered_map<int, bool> buttonState;
7  std::vector<float> axisValues;
8 };
9 
10 struct TouchPoint {
11  bool active;
12  glm::vec2 position;
13 };
14 
16  std::string text = "";
17  bool bIsActive = false;
18 };
19 
20 class InputManager {
21 
22 public:
23  InputManager() = default;
24 
25  InputManager(SDL_Window* window) : _window(window) {}
26 
27  void ProcessEvents(const SDL_Event* pEvent);
28 
29  void Update();
30 
31  glm::vec2 GetMousePosition();
32 
33  bool IsMouseButtonPressed(Uint8 button);
34 
35  bool IsMouseButtonReleased(Uint8 button);
36 
37  bool IsKeyPressed(SDL_Scancode key);
38 
39  bool IsKeyHeld(SDL_Scancode key);
40 
41  bool IsKeyReleased(SDL_Scancode key);
42 
43  bool IsPositionInRect(glm::vec2 position, ember::Rectangle rect);
44 
45  std::string GetTypedText();
46 
47  void SetTextInputActive(bool status);
48 
49  bool IsTextInputActive();
50 
51 private:
52  SDL_Window* _window;
53 
54  std::queue<SDL_Event> events;
55 
56  std::unordered_map<SDL_Scancode, bool> keyState;
57 
58  std::unordered_map<SDL_Scancode, bool> prevKeyState;
59 
60  glm::vec2 mousePosition;
61 
62  Joystick joystickData;
63 
64  std::unordered_map<int, Joystick> joysticks;
65 
66  std::unordered_map<int, TouchPoint> touchPoints;
67 
68  TextInputEvent textInputEvt;
69 };
Definition: input_manager.h:20
bool IsKeyPressed(SDL_Scancode key)
Definition: input_manager.cpp:125
bool IsKeyHeld(SDL_Scancode key)
Definition: input_manager.cpp:133
std::string GetTypedText()
Definition: input_manager.cpp:102
bool IsMouseButtonPressed(Uint8 button)
Definition: input_manager.cpp:116
void ProcessEvents(const SDL_Event *pEvent)
Definition: input_manager.cpp:3
bool IsTextInputActive()
Definition: input_manager.cpp:98
void Update()
Definition: input_manager.cpp:60
void SetTextInputActive(bool status)
Definition: input_manager.cpp:88
bool IsMouseButtonReleased(Uint8 button)
Definition: input_manager.cpp:120
InputManager(SDL_Window *window)
Definition: input_manager.h:25
glm::vec2 GetMousePosition()
Definition: input_manager.cpp:111
bool IsPositionInRect(glm::vec2 position, ember::Rectangle rect)
Definition: input_manager.cpp:106
InputManager()=default
bool IsKeyReleased(SDL_Scancode key)
Definition: input_manager.cpp:129
Definition: input_manager.h:4
std::vector< float > axisValues
Definition: input_manager.h:7
SDL_Joystick * joystick
Definition: input_manager.h:5
std::unordered_map< int, bool > buttonState
Definition: input_manager.h:6
Definition: input_manager.h:15
std::string text
Definition: input_manager.h:16
bool bIsActive
Definition: input_manager.h:17
Definition: input_manager.h:10
glm::vec2 position
Definition: input_manager.h:12
bool active
Definition: input_manager.h:11
Definition: engine_structs.h:24