135 lines
3.3 KiB
C++
135 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifndef INPUT_H
|
|
#define INPUT_H
|
|
|
|
using namespace std;
|
|
|
|
// Tipos diferentes de eventos de entrada
|
|
#define INPUT_NULL 0
|
|
#define INPUT_UP 1
|
|
#define INPUT_DOWN 2
|
|
#define INPUT_LEFT 3
|
|
#define INPUT_RIGHT 4
|
|
#define INPUT_BUTTON_1 5
|
|
#define INPUT_BUTTON_2 6
|
|
#define INPUT_BUTTON_3 7
|
|
#define INPUT_BUTTON_4 8
|
|
#define INPUT_BUTTON_5 9
|
|
#define INPUT_BUTTON_6 10
|
|
#define INPUT_BUTTON_7 11
|
|
#define INPUT_BUTTON_8 12
|
|
#define INPUT_BUTTON_9 13
|
|
#define INPUT_BUTTON_10 14
|
|
#define INPUT_BUTTON_11 15
|
|
#define INPUT_BUTTON_12 16
|
|
#define INPUT_BUTTON_13 17
|
|
#define INPUT_BUTTON_14 18
|
|
#define INPUT_BUTTON_15 19
|
|
#define INPUT_BUTTON_16 20
|
|
#define INPUT_BUTTON_17 21
|
|
#define INPUT_BUTTON_18 22
|
|
#define INPUT_BUTTON_19 23
|
|
#define INPUT_BUTTON_20 24
|
|
|
|
#define INPUT_PAUSE 25
|
|
#define INPUT_EXIT 26
|
|
#define INPUT_ACCEPT 27
|
|
#define INPUT_CANCEL 28
|
|
|
|
#define INPUT_TOTAL 29
|
|
|
|
// Para saber si el input se puede repetir sin soltarlo
|
|
#define REPEAT_TRUE true
|
|
#define REPEAT_FALSE false
|
|
|
|
// Tipo de control asociado
|
|
#define INPUT_USE_KEYBOARD 0
|
|
#define INPUT_USE_GAMECONTROLLER 1
|
|
#define INPUT_USE_ANY 2
|
|
|
|
enum i_disable_e
|
|
{
|
|
d_notDisabled,
|
|
d_forever,
|
|
d_keyPressed
|
|
};
|
|
|
|
class Input
|
|
{
|
|
private:
|
|
struct keyBindings_t
|
|
{
|
|
Uint8 scancode; // Scancode asociado
|
|
bool active; // Indica si está activo
|
|
};
|
|
|
|
struct GameControllerBindings_t
|
|
{
|
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
|
bool active; // Indica si está activo
|
|
};
|
|
|
|
// Objetos y punteros
|
|
vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
|
|
|
// Variables
|
|
vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
|
vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
|
vector<string> controllerNames; // Vector con los nombres de los mandos
|
|
int numGamepads; // Numero de mandos conectados
|
|
string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
|
bool verbose; // Indica si ha de mostrar mensajes
|
|
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
|
bool enabled; // Indica si está habilitado
|
|
|
|
public:
|
|
// Constructor
|
|
Input(string file, bool verbose=true);
|
|
|
|
// Actualiza el estado del objeto
|
|
void update();
|
|
|
|
// Asigna inputs a teclas
|
|
void bindKey(Uint8 input, SDL_Scancode code);
|
|
|
|
// Asigna inputs a botones del mando
|
|
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
|
|
|
// Comprueba si un input esta activo
|
|
bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
|
|
|
// Comprueba si hay almenos un input activo
|
|
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
|
|
|
// Busca si hay un mando conectado
|
|
bool discoverGameController();
|
|
|
|
// Comprueba si hay algun mando conectado
|
|
bool gameControllerFound();
|
|
|
|
// Obten el numero de mandos conectados
|
|
int getNumControllers();
|
|
|
|
// Obten el nombre de un mando de juego
|
|
string getControllerName(int index);
|
|
|
|
// Establece si ha de mostrar mensajes
|
|
void setVerbose(bool value);
|
|
|
|
// Deshabilita las entradas durante un periodo de tiempo
|
|
void disableUntil(i_disable_e value);
|
|
|
|
// Hablita las entradas
|
|
void enable();
|
|
|
|
// Establece unas teclas y botones del mando por defectp
|
|
void setDefaultBindings();
|
|
};
|
|
|
|
#endif
|