61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include <SDL.h>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
enum CBUTTONS
|
|
{
|
|
DPAD_UP = SDL_CONTROLLER_BUTTON_DPAD_UP,
|
|
DPAD_DOWN = SDL_CONTROLLER_BUTTON_DPAD_DOWN,
|
|
DPAD_LEFT = SDL_CONTROLLER_BUTTON_DPAD_LEFT,
|
|
DPAD_RIGHT = SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
|
|
A = SDL_CONTROLLER_BUTTON_A,
|
|
B = SDL_CONTROLLER_BUTTON_B,
|
|
X = SDL_CONTROLLER_BUTTON_X,
|
|
Y = SDL_CONTROLLER_BUTTON_Y,
|
|
BACK = SDL_CONTROLLER_BUTTON_BACK,
|
|
GUIDE = SDL_CONTROLLER_BUTTON_GUIDE,
|
|
START = SDL_CONTROLLER_BUTTON_START,
|
|
LEFTSTICK = SDL_CONTROLLER_BUTTON_LEFTSTICK,
|
|
RIGHTSTICK = SDL_CONTROLLER_BUTTON_RIGHTSTICK,
|
|
LEFTSHOULDER = SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
|
|
RIGHTSHOULDER = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
|
|
};
|
|
|
|
struct Controller
|
|
{
|
|
SDL_GameController* controller;
|
|
std::string name;
|
|
std::map<Uint8, bool> buttons;
|
|
Sint16 leftStickX = 0;
|
|
Sint16 leftStickY = 0;
|
|
Sint16 rightStickX = 0;
|
|
Sint16 rightStickY = 0;
|
|
Sint16 leftTrigger = 0;
|
|
Sint16 rightTrigger = 0;
|
|
};
|
|
|
|
struct Mouse
|
|
{
|
|
int x;
|
|
int y;
|
|
int wheel;
|
|
std::map<int, bool> buttons;
|
|
};
|
|
|
|
class Input
|
|
{
|
|
private:
|
|
SDL_Event event;
|
|
|
|
public:
|
|
bool exit;
|
|
std::map<int, Controller> controllers;
|
|
std::map<SDL_Keycode, bool> activeKeys;
|
|
Mouse mouse;
|
|
|
|
Input();
|
|
void update();
|
|
bool keysPressed(std::vector<SDL_Keycode> keys);
|
|
bool controllerPressed(std::vector<Uint8> buttons, int controller = 0);
|
|
}; |