~ppsspp/ppsspp/ppsspp-1.1.1

« back to all changes in this revision

Viewing changes to Common/KeyMap.h

  • Committer: Sérgio Benjamim
  • Date: 2015-10-17 01:37:55 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20151017013755-avrlz2pt37kwt43x
PPSSPP 1.1.1 source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2013- PPSSPP Project.
 
2
 
 
3
// This program is free software: you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation, version 2.0 or later versions.
 
6
 
 
7
// This program is distributed in the hope that it will be useful,
 
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
// GNU General Public License 2.0 for more details.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#pragma once
 
19
 
 
20
#include <string>
 
21
#include <map>
 
22
#include <vector>
 
23
#include <set>
 
24
#include "input/input_state.h" // KeyDef, AxisPos
 
25
#include "input/keycodes.h"     // keyboard keys
 
26
#include "../Core/HLE/sceCtrl.h"   // psp keys
 
27
 
 
28
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
 
29
#define KEYMAP_ERROR_UNKNOWN_KEY 0
 
30
 
 
31
enum {
 
32
        VIRTKEY_FIRST = 0x10000,
 
33
        VIRTKEY_AXIS_X_MIN = 0x10000,
 
34
        VIRTKEY_AXIS_Y_MIN = 0x10001,
 
35
        VIRTKEY_AXIS_X_MAX = 0x10002,
 
36
        VIRTKEY_AXIS_Y_MAX = 0x10003,
 
37
        VIRTKEY_RAPID_FIRE = 0x10004,
 
38
        VIRTKEY_UNTHROTTLE = 0x10005,
 
39
        VIRTKEY_PAUSE = 0x10006,
 
40
        VIRTKEY_SPEED_TOGGLE = 0x10007,
 
41
        VIRTKEY_AXIS_RIGHT_X_MIN = 0x10008,
 
42
        VIRTKEY_AXIS_RIGHT_Y_MIN = 0x10009,
 
43
        VIRTKEY_AXIS_RIGHT_X_MAX = 0x1000a,
 
44
        VIRTKEY_AXIS_RIGHT_Y_MAX = 0x1000b,
 
45
        VIRTKEY_REWIND = 0x1000c,
 
46
        VIRTKEY_SAVE_STATE = 0x1000d,
 
47
        VIRTKEY_LOAD_STATE = 0x1000e,
 
48
        VIRTKEY_NEXT_SLOT  = 0x1000f,
 
49
        VIRTKEY_TOGGLE_FULLSCREEN = 0x10010,
 
50
        VIRTKEY_ANALOG_LIGHTLY = 0x10011,
 
51
        VIRTKEY_AXIS_SWAP = 0x10012,
 
52
        VIRTKEY_DEVMENU = 0x10013,
 
53
        VIRTKEY_LAST,
 
54
        VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
 
55
};
 
56
 
 
57
enum DefaultMaps {
 
58
        DEFAULT_MAPPING_KEYBOARD,
 
59
        DEFAULT_MAPPING_PAD,
 
60
        DEFAULT_MAPPING_X360,
 
61
        DEFAULT_MAPPING_SHIELD,
 
62
        DEFAULT_MAPPING_BLACKBERRY_QWERTY,
 
63
        DEFAULT_MAPPING_OUYA,
 
64
        DEFAULT_MAPPING_XPERIA_PLAY,
 
65
};
 
66
 
 
67
const float AXIS_BIND_THRESHOLD = 0.75f;
 
68
 
 
69
typedef std::map<int, std::vector<KeyDef>> KeyMapping;
 
70
 
 
71
// KeyMap
 
72
// A translation layer for key assignment. Provides
 
73
// integration with Core's config state.
 
74
//
 
75
// Does not handle input state managment.
 
76
//
 
77
// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).
 
78
//
 
79
// Then have KeyMap transform those into psp buttons.
 
80
 
 
81
class IniFile;
 
82
 
 
83
namespace KeyMap {
 
84
        extern KeyMapping g_controllerMap;
 
85
 
 
86
        // Key & Button names
 
87
        struct KeyMap_IntStrPair {
 
88
                int key;
 
89
                std::string name;
 
90
        };
 
91
 
 
92
        // Use if you need to display the textual name
 
93
        std::string GetKeyName(int keyCode);
 
94
        std::string GetKeyOrAxisName(int keyCode);
 
95
        std::string GetAxisName(int axisId);
 
96
        std::string GetPspButtonName(int btn);
 
97
 
 
98
        std::vector<KeyMap_IntStrPair> GetMappableKeys();
 
99
 
 
100
        // Use to translate KeyMap Keys to PSP
 
101
        // buttons. You should have already translated
 
102
        // your platform's keys to KeyMap keys.
 
103
        bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
 
104
        bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys);
 
105
 
 
106
        int TranslateKeyCodeToAxis(int keyCode, int &direction);
 
107
        int TranslateKeyCodeFromAxis(int axisId, int direction);
 
108
 
 
109
        // Configure the key mapping.
 
110
        // Any configuration will be saved to the Core config.
 
111
        void SetKeyMapping(int psp_key, KeyDef key, bool replace);
 
112
 
 
113
        // Configure an axis mapping, saves the configuration.
 
114
        // Direction is negative or positive.
 
115
        void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
 
116
 
 
117
        bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys);
 
118
        bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
 
119
        std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction);
 
120
 
 
121
        void LoadFromIni(IniFile &iniFile);
 
122
        void SaveToIni(IniFile &iniFile);
 
123
 
 
124
        void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
 
125
 
 
126
        void RestoreDefault();
 
127
 
 
128
        void SwapAxis();
 
129
        void UpdateNativeMenuKeys();
 
130
 
 
131
        void NotifyPadConnected(const std::string &name);
 
132
        bool IsNvidiaShield(const std::string &name);
 
133
        bool IsNvidiaShieldTV(const std::string &name);
 
134
        bool IsBlackberryQWERTY(const std::string &name);
 
135
        bool IsXperiaPlay(const std::string &name);
 
136
        bool IsOuya(const std::string &name);
 
137
        bool HasBuiltinController(const std::string &name);
 
138
 
 
139
        const std::set<std::string> &GetSeenPads();
 
140
        void AutoConfForPad(const std::string &name);
 
141
}