2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
// InputManager.h
|
|
|
|
//
|
|
|
|
// Low-level input handling.
|
|
|
|
// Initiates and maps the keyboard and controllers.
|
|
|
|
// Reads and writes the es_input.cfg configuration file.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_INPUT_MANAGER_H
|
|
|
|
#define ES_CORE_INPUT_MANAGER_H
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-07-03 18:23:51 +00:00
|
|
|
#if defined(__linux__) || defined(_WIN64)
|
2020-06-26 16:03:55 +00:00
|
|
|
#include <SDL2/SDL_joystick.h>
|
|
|
|
#else
|
|
|
|
#include "SDL_joystick.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-22 21:15:55 +00:00
|
|
|
#include <map>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputConfig;
|
|
|
|
class Window;
|
2017-11-01 22:21:10 +00:00
|
|
|
union SDL_Event;
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// You should only ever instantiate one of these, by the way.
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputManager
|
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
InputManager();
|
2014-04-18 18:07:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static InputManager* mInstance;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static const int DEADZONE = 23000;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void loadDefaultKBConfig();
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks;
|
|
|
|
std::map<SDL_JoystickID, InputConfig*> mInputConfigs;
|
|
|
|
InputConfig* mKeyboardInputConfig;
|
|
|
|
InputConfig* mCECInputConfig;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::map<SDL_JoystickID, int*> mPrevAxisValues;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool initialized() const;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void addJoystickByDeviceIndex(int id);
|
|
|
|
void removeJoystickByJoystickID(SDL_JoystickID id);
|
|
|
|
// Returns true if successfully loaded, false if not (or if it didn't exist).
|
|
|
|
bool loadInputConfig(InputConfig* config);
|
2014-03-22 01:12:57 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual ~InputManager();
|
2014-04-18 18:07:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static InputManager* getInstance();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void writeDeviceConfig(InputConfig* config);
|
|
|
|
void doOnFinish();
|
|
|
|
static std::string getConfigPath();
|
|
|
|
static std::string getTemporaryConfigPath();
|
2013-04-08 16:52:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
int getNumJoysticks();
|
|
|
|
int getAxisCountByDevice(int deviceId);
|
|
|
|
int getButtonCountByDevice(int deviceId);
|
|
|
|
int getNumConfiguredDevices();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string getDeviceGUIDString(int deviceId);
|
2014-03-22 01:12:57 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
InputConfig* getInputConfigByDevice(int deviceId);
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool parseEvent(const SDL_Event& ev, Window* window);
|
2013-04-08 14:41:25 +00:00
|
|
|
};
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_INPUT_MANAGER_H
|