Welcome to mirror list, hosted at ThFree Co, Russian Federation.

keyTranslator.h « UserInput « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ee0ee148ba48484db8a7ef8f4edadefe5ed156d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//-----------------------------------------------------------------------------
//           Name: keyTranslator.h
//      Developer: Wolfire Games LLC
//    Description:
//        License: Read below
//-----------------------------------------------------------------------------
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once

#include <SDL.h>

#include <string>

// Represents a combination of controller axes and buttons
namespace ControllerInput {
enum Input {
    A = 0,
    B,
    X,
    Y,
    D_UP,
    D_RIGHT,
    D_DOWN,
    D_LEFT,
    START,
    BACK,
    GUIDE,
    L_STICK_PRESSED,
    R_STICK_PRESSED,
    LB,
    RB,
    L_STICK_X,
    L_STICK_Y,
    R_STICK_X,
    R_STICK_Y,
    L_TRIGGER,
    R_TRIGGER,
    NUM_INPUTS,
    // There are constraints upon existing inputs, therefore they should not
    // count to the number of available inputs.
    L_STICK_XN,
    L_STICK_XP,
    L_STICK_YN,
    L_STICK_YP,
    R_STICK_XN,
    R_STICK_XP,
    R_STICK_YN,
    R_STICK_YP,
    NONE
};
}

void InitKeyTranslator();
// Translate to human readable strings
std::string SDLLocaleAdjustedStringFromScancode(SDL_Scancode scancode);
std::string StringFromMouseButton(int button);
std::string StringFromMouseString(const std::string& text);  // e.g. mouse0 -> Left Mouse Button
std::string StringFromControllerInput(ControllerInput::Input input);
std::string StringFromInput(const std::string& input);  // e.g. lshift -> Shift

SDL_Scancode StringToSDLScancode(const std::string& s);
/*#ifdef WIN32
    int XBoxToXInput(const std::string &s);
#endif*/
const char* SDLScancodeToString(SDL_Scancode key);
const char* SDLKeycodeToString(SDL_Keycode key);

// Convert between internal values
ControllerInput::Input SDLControllerButtonToController(SDL_GameControllerButton button);
ControllerInput::Input SDLControllerAxisToController(SDL_GameControllerAxis axis);

SDL_GameControllerButton ControllerToSDLControllerButton(ControllerInput::Input input);
SDL_GameControllerAxis ControllerToSDLControllerAxis(ControllerInput::Input input);

// SDL string, sort of. Converts leftx+, leftx-, etc. as well, even though these
// are not directory SDL strings.
ControllerInput::Input SDLStringToController(const char* string);