1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 /**
21  * \file common/key.h
22  * \brief Key-related macros and enums
23  */
24 
25 #pragma once
26 
27 
28 #include <SDL_keycode.h>
29 
30 // TODO: This is a bit ugly hack
31 #define SDLK_LAST (SDLK_SCANCODE_MASK << 1)
32 
33 /* Key definitions are specially defined here so that it is clear in other parts of the code
34   that these are used. It is to avoid having SDL-related enum values or #defines lying around
35   unchecked. With this approach it will be easier to maintain the code later on. */
36 
37 // Key symbol defined as concatenation to SDLK_...
38 // If need arises, it can be changed to custom function or anything else
39 #define KEY(x) SDLK_ ## x
40 
41 
42 // Key modifier defined as concatenation to KMOD_...
43 // If need arises, it can be changed to custom function or anything else
44 #define KEY_MOD(x) KMOD_ ## x
45 
46 /**
47  * \enum VirtualKmod
48  * \brief Virtual key codes generated on kmod presses
49  *
50  * These are provided here because left and right pair of keys generate different codes.
51  */
52 enum VirtualKmod
53 {
54     VIRTUAL_KMOD_CTRL  = SDLK_LAST + 100, //! < control (left or right)
55     VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right)
56     VIRTUAL_KMOD_ALT   = SDLK_LAST + 102, //! < alt (left or right)
57     VIRTUAL_KMOD_GUI   = SDLK_LAST + 103  //! < windows logo (on windows/linux) or command (on mac os) key (left or right)
58 };
59 
60 // Just syntax sugar
61 // So it is the same as other macros
62 #define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
63 
64 //! Converts individual codes to virtual keys if needed
65 unsigned int GetVirtualKey(unsigned int key);
66 
67 // Virtual key code generated on joystick button presses
68 // num is number of joystick button
69 #define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
70 
71 //! Special value for invalid key bindings
72 const unsigned int KEY_INVALID = SDLK_LAST + 1000;
73 
74 /**
75  * \enum InputSlot
76  * \brief Available slots for input bindings
77  * NOTE: When adding new values, remember to also update keyTable in input.cpp and their descriptions in restext.cpp
78  */
79 enum InputSlot
80 {
81     INPUT_SLOT_LEFT,
82     INPUT_SLOT_RIGHT,
83     INPUT_SLOT_UP,
84     INPUT_SLOT_DOWN,
85     INPUT_SLOT_GUP,
86     INPUT_SLOT_GDOWN,
87     INPUT_SLOT_CAMERA,
88     INPUT_SLOT_DESEL,
89     INPUT_SLOT_ACTION,
90     INPUT_SLOT_CAM_LEFT,
91     INPUT_SLOT_CAM_RIGHT,
92     INPUT_SLOT_CAM_UP,
93     INPUT_SLOT_CAM_DOWN,
94     INPUT_SLOT_CAM_NEAR,
95     INPUT_SLOT_CAM_AWAY,
96     INPUT_SLOT_CAM_ALT,
97     INPUT_SLOT_NEXT,
98     INPUT_SLOT_HUMAN,
99     INPUT_SLOT_QUIT,
100     INPUT_SLOT_HELP,
101     INPUT_SLOT_PROG,
102     INPUT_SLOT_VISIT,
103     INPUT_SLOT_SPEED_DEC,
104     INPUT_SLOT_SPEED_RESET,
105     INPUT_SLOT_SPEED_INC,
106     INPUT_SLOT_QUICKSAVE,
107     INPUT_SLOT_QUICKLOAD,
108     INPUT_SLOT_PAUSE,
109     INPUT_SLOT_CMDLINE,
110 
111     INPUT_SLOT_MAX
112 };
113 
114 /**
115  * \enum JoyAxisSlot
116  * \brief Slots for joystick axes inputs
117  */
118 enum JoyAxisSlot
119 {
120     JOY_AXIS_SLOT_X,
121     JOY_AXIS_SLOT_Y,
122     JOY_AXIS_SLOT_Z,
123     JOY_AXIS_SLOT_CAM_X,
124     JOY_AXIS_SLOT_CAM_Y,
125     JOY_AXIS_SLOT_CAM_Z,
126 
127     JOY_AXIS_SLOT_MAX
128 };
129