2013-04-20 04:52:54 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2013-07-06 18:44:34 +00:00
|
|
|
#include <vector>
|
2013-06-25 04:34:14 +00:00
|
|
|
#include "input/keycodes.h" // keyboard keys
|
2013-07-03 18:37:31 +00:00
|
|
|
#include "../Core/HLE/sceCtrl.h" // psp keys
|
2013-04-20 04:52:54 +00:00
|
|
|
|
|
|
|
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
|
|
|
|
#define KEYMAP_ERROR_UNKNOWN_KEY 0
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
enum {
|
|
|
|
VIRTKEY_FIRST = 0x10000,
|
|
|
|
VIRTKEY_AXIS_X_MIN = 0x10000,
|
|
|
|
VIRTKEY_AXIS_Y_MIN = 0x10001,
|
|
|
|
VIRTKEY_AXIS_X_MAX = 0x10002,
|
|
|
|
VIRTKEY_AXIS_Y_MAX = 0x10003,
|
2013-07-07 02:41:28 +00:00
|
|
|
VIRTKEY_RAPID_FIRE = 0x10004,
|
2013-07-07 08:42:39 +00:00
|
|
|
VIRTKEY_UNTHROTTLE = 0x10005,
|
2013-07-07 12:08:08 +00:00
|
|
|
VIRTKEY_PAUSE = 0x10006,
|
|
|
|
VIRTKEY_SPEED_TOGGLE = 0x10007,
|
2013-07-07 23:16:51 +00:00
|
|
|
VIRTKEY_AXIS_RIGHT_X_MIN = 0x10008,
|
|
|
|
VIRTKEY_AXIS_RIGHT_Y_MIN = 0x10009,
|
|
|
|
VIRTKEY_AXIS_RIGHT_X_MAX = 0x1000a,
|
|
|
|
VIRTKEY_AXIS_RIGHT_Y_MAX = 0x1000b,
|
2013-07-06 18:44:34 +00:00
|
|
|
VIRTKEY_LAST,
|
|
|
|
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
|
|
|
|
};
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
enum DefaultMaps {
|
|
|
|
DEFAULT_MAPPING_KEYBOARD,
|
|
|
|
DEFAULT_MAPPING_PAD,
|
|
|
|
DEFAULT_MAPPING_X360,
|
|
|
|
DEFAULT_MAPPING_SHIELD,
|
|
|
|
DEFAULT_MAPPING_OUYA,
|
|
|
|
};
|
|
|
|
|
2013-07-07 22:21:40 +00:00
|
|
|
const float AXIS_BIND_THRESHOLD = 0.75f;
|
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
class KeyDef {
|
|
|
|
public:
|
2013-08-16 17:34:44 +00:00
|
|
|
KeyDef() : deviceId(0), keyCode(0) {}
|
2013-07-06 17:08:59 +00:00
|
|
|
KeyDef(int devId, int k) : deviceId(devId), keyCode(k) {}
|
|
|
|
int deviceId;
|
|
|
|
int keyCode;
|
|
|
|
|
|
|
|
bool operator < (const KeyDef &other) const {
|
|
|
|
if (deviceId < other.deviceId) return true;
|
|
|
|
if (deviceId > other.deviceId) return false;
|
|
|
|
if (keyCode < other.keyCode) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-16 17:34:44 +00:00
|
|
|
bool operator == (const KeyDef &other) const {
|
|
|
|
if (deviceId != other.deviceId) return false;
|
|
|
|
if (keyCode != other.keyCode) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-06 17:08:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AxisPos {
|
|
|
|
int axis;
|
|
|
|
float position;
|
2013-08-16 17:34:44 +00:00
|
|
|
|
|
|
|
bool operator < (const AxisPos &other) const {
|
|
|
|
if (axis < other.axis) return true;
|
|
|
|
if (axis > other.axis) return false;
|
|
|
|
return position < other.position;
|
|
|
|
}
|
|
|
|
bool operator == (const AxisPos &other) const {
|
|
|
|
return axis == other.axis && position == other.position;
|
|
|
|
}
|
2013-07-06 17:08:59 +00:00
|
|
|
};
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
typedef std::map<int, std::vector<KeyDef>> KeyMapping;
|
2013-08-16 17:34:44 +00:00
|
|
|
|
2013-04-20 20:33:12 +00:00
|
|
|
// KeyMap
|
2013-07-06 17:08:59 +00:00
|
|
|
// A translation layer for key assignment. Provides
|
|
|
|
// integration with Core's config state.
|
2013-04-20 20:33:12 +00:00
|
|
|
//
|
2013-07-06 17:08:59 +00:00
|
|
|
// Does not handle input state managment.
|
2013-04-20 20:33:12 +00:00
|
|
|
//
|
2013-08-04 17:31:40 +00:00
|
|
|
// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).
|
2013-07-06 17:08:59 +00:00
|
|
|
//
|
|
|
|
// Then have KeyMap transform those into psp buttons.
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
class IniFile;
|
|
|
|
|
2013-04-20 04:52:54 +00:00
|
|
|
namespace KeyMap {
|
2013-08-17 08:34:38 +00:00
|
|
|
extern KeyMapping g_controllerMap;
|
|
|
|
|
|
|
|
// Key & Button names
|
|
|
|
struct KeyMap_IntStrPair {
|
|
|
|
int key;
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
// Use if you need to display the textual name
|
|
|
|
std::string GetKeyName(int keyCode);
|
2013-08-17 09:18:45 +00:00
|
|
|
std::string GetKeyOrAxisName(int keyCode);
|
|
|
|
std::string GetAxisName(int axisId);
|
2013-07-06 17:08:59 +00:00
|
|
|
std::string GetPspButtonName(int btn);
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
std::vector<KeyMap_IntStrPair> GetMappableKeys();
|
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
// Use if to translate KeyMap Keys to PSP
|
|
|
|
// buttons. You should have already translated
|
|
|
|
// your platform's keys to KeyMap keys.
|
|
|
|
//
|
|
|
|
// Returns KEYMAP_ERROR_UNKNOWN_KEY
|
|
|
|
// for any unmapped key
|
|
|
|
int KeyToPspButton(int deviceId, int key);
|
2013-08-17 09:18:45 +00:00
|
|
|
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-17 09:18:45 +00:00
|
|
|
int TranslateKeyCodeToAxis(int keyCode, int &direction);
|
2013-08-17 08:34:38 +00:00
|
|
|
int TranslateKeyCodeFromAxis(int axisId, int direction);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
|
|
|
// Configure the key mapping.
|
|
|
|
// Any configuration will be saved to the Core config.
|
2013-08-16 19:25:01 +00:00
|
|
|
void SetKeyMapping(int psp_key, KeyDef key, bool replace);
|
|
|
|
|
|
|
|
// Configure an axis mapping, saves the configuration.
|
|
|
|
// Direction is negative or positive.
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-07-07 22:21:40 +00:00
|
|
|
int AxisToPspButton(int deviceId, int axisId, int direction);
|
2013-08-16 17:34:44 +00:00
|
|
|
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
|
2013-07-07 22:21:40 +00:00
|
|
|
std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction);
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
void LoadFromIni(IniFile &iniFile);
|
|
|
|
void SaveToIni(IniFile &iniFile);
|
2013-08-16 17:34:44 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
|
|
|
|
|
2013-07-07 09:14:46 +00:00
|
|
|
void RestoreDefault();
|
2013-08-16 17:34:44 +00:00
|
|
|
void QuickMap(int device);
|
2013-04-20 04:52:54 +00:00
|
|
|
}
|
|
|
|
|