ManaPlus
keyboardconfig.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2007 Joshua Langley <[email protected]>
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef INPUT_KEYBOARDCONFIG_H
25 #define INPUT_KEYBOARDCONFIG_H
26 
27 #include "localconsts.h"
28 
29 #ifndef USE_SDL2
30 #include "utils/cast.h"
31 #endif // USE_SDL2
32 
33 PRAGMA48(GCC diagnostic push)
34 PRAGMA48(GCC diagnostic ignored "-Wshadow")
35 #include <SDL_events.h>
36 PRAGMA48(GCC diagnostic pop)
37 
38 #include "sdlshared.h"
39 
40 #include "events/inputevent.h"
41 
43 {
44  public:
46 
48 
49 
52  void init();
53 
54  void deinit();
55 
60  { return mEnabled; }
61 
65  static InputActionT getKeyIndex(const SDL_Event &event,
66  const int grp) A_WARN_UNUSED;
67 
71  void setEnabled(const bool flag)
72  { mEnabled = flag; }
73 
77  void refreshActiveKeys();
78 
79  static std::string getKeyShortString(const std::string &key)
81 
82  constexpr static SDLKey getKeyFromEvent(const SDL_Event &event)
84  {
85 #ifdef USE_SDL2
86  return event.key.keysym.scancode;
87 #else // USE_SDL2
88 
89  return event.key.keysym.sym;
90 #endif // USE_SDL2
91  }
92 
93  constexpr2 static int getKeyValueFromEvent(const SDL_Event &event)
95  {
96 #ifdef USE_SDL2
97  return event.key.keysym.scancode;
98 #else // USE_SDL2
99 
100  if (event.key.keysym.sym != 0U)
101  return CAST_S32(event.key.keysym.sym);
102  else if (event.key.keysym.scancode > 1)
103  return -event.key.keysym.scancode;
104  return 0;
105 #endif // USE_SDL2
106  }
107 
108 
109  KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
110 
112 
113  static std::string getKeyName(const int key) A_WARN_UNUSED;
114 
115  bool isActionActive(const InputActionT index) const A_WARN_UNUSED;
116 
117  void update();
118 
119  void handleActivateKey(const SDL_Event &event);
120 
121  void handleActivateKey(const int key);
122 
123  void handleDeActicateKey(const SDL_Event &event);
124 
125  void handleDeActicateKey(const int key);
126 
127  InputActionT getActionId(const SDL_Event &event) A_WARN_UNUSED;
128 
129  void handleRepeat(const int time);
130 
131  void resetRepeat(const int key);
132 
133 #ifdef USE_SDL2
134  bool ignoreKey(const SDL_Event &restrict event) A_WARN_UNUSED;
135 #endif // USE_SDL2
136 
137  private:
138  bool mEnabled;
140  const uint8_t *mActiveKeys;
142  uint8_t *mActiveKeys2;
144  unsigned int mRepeatTime;
145 
147 
149 
151 
153 };
154 
155 extern KeyboardConfig keyboard;
156 
157 #endif // INPUT_KEYBOARDCONFIG_H
#define CAST_S32
Definition: cast.h:30
InputActionT getActionId(const SDL_Event &event)
void refreshActiveKeys()
static std::string getKeyShortString(const std::string &key)
KeyToActionMap mKeyToAction
KeyToIdMap mKeyToId
KeyTimeMap mKeyTimeMap
void resetRepeat(const int key)
static InputActionT getKeyIndex(const SDL_Event &event, const int grp)
static SDLKey getKeyFromEvent(const SDL_Event &event)
void setEnabled(const bool flag)
void handleActivateKey(const SDL_Event &event)
bool isEnabled() const
void handleRepeat(const int time)
KeysVector * getActionVector(const SDL_Event &event)
const uint8_t * mActiveKeys
bool isActionActive(const InputActionT index) const
KeysVector * getActionVectorByKey(const int i)
static std::string getKeyName(const int key)
static int getKeyValueFromEvent(const SDL_Event &event)
uint8_t * mActiveKeys2
void handleDeActicateKey(const SDL_Event &event)
unsigned int mRepeatTime
InputAction ::T InputActionT
Definition: inputaction.h:717
std::map< int, KeysVector > KeyToActionMap
Definition: inputevent.h:40
std::map< int, InputActionT > KeyToIdMap
Definition: inputevent.h:43
std::vector< InputActionT > KeysVector
Definition: inputevent.h:34
std::map< int, int > KeyTimeMap
Definition: inputevent.h:46
KeyboardConfig keyboard
#define restrict
Definition: localconsts.h:165
#define constexpr2
Definition: localconsts.h:49
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define constexpr
Definition: localconsts.h:48
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define PRAGMA48(str)
Definition: localconsts.h:199
#define A_DELETE_COPY(func)
Definition: localconsts.h:53