2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// InputManager.h
|
|
|
|
//
|
|
|
|
// Low-level input handling.
|
|
|
|
// Initiates and maps the keyboard and controllers.
|
2021-06-16 17:20:53 +00:00
|
|
|
// Reads and writes the es_input.xml configuration file.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_INPUT_MANAGER_H
|
|
|
|
#define ES_CORE_INPUT_MANAGER_H
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
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>
|
2021-05-22 20:18:00 +00:00
|
|
|
#include <memory>
|
2020-11-28 21:27:00 +00:00
|
|
|
#include <string>
|
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
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputManager
|
|
|
|
{
|
|
|
|
public:
|
2021-05-22 20:18:00 +00:00
|
|
|
InputManager();
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual ~InputManager();
|
|
|
|
static InputManager* getInstance();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void writeDeviceConfig(InputConfig* config);
|
|
|
|
void doOnFinish();
|
2021-05-22 20:18:00 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::string getConfigPath();
|
|
|
|
static std::string getTemporaryConfigPath();
|
2013-04-08 16:52:40 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
int getNumJoysticks();
|
2021-05-22 20:18:00 +00:00
|
|
|
int getNumConfiguredDevices();
|
2020-06-21 12:25:28 +00:00
|
|
|
int getAxisCountByDevice(int deviceId);
|
|
|
|
int getButtonCountByDevice(int deviceId);
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string getDeviceGUIDString(int deviceId);
|
|
|
|
InputConfig* getInputConfigByDevice(int deviceId);
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
bool parseEvent(const SDL_Event& event, Window* window);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
|
|
|
private:
|
2021-05-22 20:18:00 +00:00
|
|
|
bool initialized() const;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
bool loadInputConfig(InputConfig* config);
|
|
|
|
void loadDefaultKBConfig();
|
|
|
|
void loadDefaultControllerConfig(SDL_JoystickID deviceIndex);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-06-26 20:54:00 +00:00
|
|
|
void addControllerByDeviceIndex(int deviceIndex);
|
|
|
|
void removeControllerByJoystickID(SDL_JoystickID joyID);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
static InputManager* sInstance;
|
|
|
|
static const int DEADZONE = 23000;
|
|
|
|
bool mConfigFileExists;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
|
|
|
std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks;
|
2021-05-22 20:18:00 +00:00
|
|
|
std::map<SDL_JoystickID, SDL_GameController*> mControllers;
|
|
|
|
std::map<SDL_JoystickID, std::unique_ptr<InputConfig>> mInputConfigs;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
std::unique_ptr<InputConfig> mKeyboardInputConfig;
|
|
|
|
std::unique_ptr<InputConfig> mCECInputConfig;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
std::map<std::pair<SDL_JoystickID, int>, int> mPrevAxisValues;
|
|
|
|
std::map<std::pair<SDL_JoystickID, int>, int> mPrevButtonValues;
|
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
|