46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#ifndef INPUT_HPP
|
|
#define INPUT_HPP
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
// Structs
|
|
struct Vector2 {
|
|
int x;
|
|
int y;
|
|
Vector2(int x = 0, int y = 0) : x(x), y(y) {}
|
|
};
|
|
|
|
// Classes
|
|
class Input {
|
|
public:
|
|
Input();
|
|
~Input();
|
|
|
|
void handleEvents();
|
|
bool quitRequested() const;
|
|
bool isKeyPressed(SDL_Scancode key);
|
|
bool isKeyPressed(std::vector<SDL_Scancode> keys);
|
|
bool hasKeyBeenPressed(SDL_Scancode key);
|
|
bool hasKeyBeenPressed(std::vector<SDL_Scancode> keys);
|
|
bool isMouseButtonPressed(Uint8 button);
|
|
bool isMouseButtonPressed(std::vector<Uint8> buttons);
|
|
bool hasMouseButtonBeenPressed(Uint8 button);
|
|
bool hasMouseButtonBeenPressed(std::vector<Uint8> buttons);
|
|
Vector2 getMousePosition() const;
|
|
|
|
|
|
private:
|
|
SDL_Event event;
|
|
std::unordered_map<SDL_Scancode, bool> keyStates;
|
|
std::unordered_map<SDL_Scancode, bool> keyFallingEdgeStates;
|
|
std::unordered_map<Uint8, bool> mouseButtonStates;
|
|
std::unordered_map<Uint8, bool> mouseButtonFallingEdgeStates;
|
|
Vector2 mousePosition;
|
|
bool quitRequestedFlag = false;
|
|
};
|
|
|
|
#endif
|
|
|