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
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <SDL_joystick.h>
|
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
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
//you should only ever instantiate one of these, by the way
|
|
|
|
class InputManager
|
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
private:
|
2014-04-18 18:07:32 +00:00
|
|
|
InputManager();
|
|
|
|
|
|
|
|
static InputManager* mInstance;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2014-04-18 18:07:32 +00:00
|
|
|
static const int DEADZONE = 23000;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
void loadDefaultKBConfig();
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks;
|
2013-08-19 14:05:30 +00:00
|
|
|
std::map<SDL_JoystickID, InputConfig*> mInputConfigs;
|
|
|
|
InputConfig* mKeyboardInputConfig;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2013-08-19 14:05:30 +00:00
|
|
|
std::map<SDL_JoystickID, int*> mPrevAxisValues;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2013-08-19 14:05:30 +00:00
|
|
|
bool initialized() const;
|
2013-05-24 11:44:40 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
void addJoystickByDeviceIndex(int id);
|
|
|
|
void removeJoystickByJoystickID(SDL_JoystickID id);
|
|
|
|
bool loadInputConfig(InputConfig* config); // returns true if successfully loaded, false if not (or didn't exist)
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
public:
|
2014-04-18 18:07:32 +00:00
|
|
|
virtual ~InputManager();
|
|
|
|
|
|
|
|
static InputManager* getInstance();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
void writeDeviceConfig(InputConfig* config);
|
2015-04-19 09:57:10 +00:00
|
|
|
void doOnFinish();
|
2013-04-08 16:52:40 +00:00
|
|
|
static std::string getConfigPath();
|
2015-04-19 09:57:10 +00:00
|
|
|
static std::string getTemporaryConfigPath();
|
2013-04-08 16:52:40 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
int getNumJoysticks();
|
2014-03-22 01:12:57 +00:00
|
|
|
int getButtonCountByDevice(int deviceId);
|
|
|
|
int getNumConfiguredDevices();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
std::string getDeviceGUIDString(int deviceId);
|
|
|
|
|
|
|
|
InputConfig* getInputConfigByDevice(int deviceId);
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2014-04-18 18:07:32 +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
|