ScummVM API documentation
keys.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_KEYBINDING_KEYS_H
23 #define NUVIE_KEYBINDING_KEYS_H
24 
25 #include "ultima/nuvie/keybinding/keys_enum.h"
26 #include "ultima/nuvie/core/nuvie_defs.h"
27 #include "ultima/shared/std/containers.h"
28 #include "ultima/shared/std/string.h"
29 #include "common/events.h"
30 #include "common/hash-str.h"
31 
32 namespace Ultima {
33 namespace Nuvie {
34 
35 enum joy_axes_pairs {
36  AXES_PAIR1, AXES_PAIR2, AXES_PAIR3, AXES_PAIR4, UNHANDLED_AXES_PAIR
37 };
38 
39 enum altCodeMode {
40  kAltCodeModeBegin = 0,
41  kAltCodeModeEnd = 1
42 };
43 
44 struct Action;
45 struct ActionType {
46  const Action *action;
47  int param;
48 };
49 
51 
55 
56 class Configuration;
57 
58 char get_ascii_char_from_keysym(Common::KeyState keysym);
59 
60 class KeyBinder {
61 private:
62  KeyMap _bindings;
63 
64  ParseKeyMap _keys;
65  ParseActionMap _actions;
66  ParseHashedActionMap _actionsHashed;
67  int16 _joyAxisPositions[8];
68 
69  bool repeat_hat, joy_repeat_enabled; // repeat hat instead of axis when hat is found
70  uint32 next_axes_pair_update, next_axes_pair2_update, next_axes_pair3_update,
71  next_axes_pair4_update, next_joy_repeat_time;
72  uint16 pair1_delay, pair2_delay, pair3_delay, pair4_delay, joy_repeat_delay;
73  uint8 x_axis, y_axis, x_axis2, y_axis2, x_axis3, y_axis3, x_axis4, y_axis4;
74  sint8 enable_joystick;
75 
76  void LoadFromFileInternal(const char *filename);
77 public:
78  KeyBinder(const Configuration *config);
79  ~KeyBinder();
80  /* Add keybinding */
81  void AddKeyBinding(Common::KeyCode sym, byte mod, const Action *action,
82  int nparams, int param);
83 
84  /* Delete keybinding */
85 // void DelKeyBinding(Common::KeyCode sym, int mod); // unused
86 
87  /* Other methods */
88  void Flush() {
89  _bindings.clear();
90  }
91  ActionType get_ActionType(const Common::KeyState &key);
92  ActionKeyType GetActionKeyType(ActionType a);
93  bool DoAction(ActionType const &a) const;
94  KeyMap::iterator get_sdlkey_index(const Common::KeyState &key);
95  bool HandleEvent(const Common::Event *event);
96  bool handleScummVMBoundEvent(const Common::Event *event);
97 
98  void LoadFromFile(const char *filename);
99  void LoadGameSpecificKeys();
100  void LoadFromPatch();
101  void handle_wrong_key_pressed();
102  bool handle_always_available_keys(ActionType a);
103 
104  void ShowKeys() const;
105  void AddIosBindings();
106 
107  uint8 get_axis(uint8 index) const;
108  void set_axis(uint8 index, uint8 value);
109  Common::KeyCode get_key_from_joy_walk_axes() {
110  return get_key_from_joy_axis_motion(x_axis, true);
111  }
112  Common::KeyCode get_key_from_joy_axis_motion(int axis, bool repeating);
113  Common::KeyCode get_key_from_joy_hat_button(uint8 hat_button) const;
114  Common::KeyCode get_key_from_joy_events(Common::Event *event);
115  void init_joystick(sint8 joy_num);
116 // SDL_Joystick *get_joystick() { return joystick; }
117  uint32 get_next_joy_repeat_time() const {
118  return next_joy_repeat_time;
119  }
120  void set_enable_joy_repeat(bool val) {
121  if (joy_repeat_delay == 10000) return;
122  joy_repeat_enabled = val;
123  }
124  bool is_joy_repeat_enabled() const {
125  return joy_repeat_enabled;
126  }
127  bool is_hat_repeating() const {
128  return repeat_hat;
129  }
130  void set_hat_repeating(bool val) {
131  repeat_hat = val;
132  }
133  sint8 get_enable_joystick() const {
134  return enable_joystick;
135  }
136  void set_enable_joystick(bool val) {
137  enable_joystick = val;
138  }
139 
140 private:
141  void ParseText(char *text, int len);
142  void ParseLine(const char *line);
143  void FillParseMaps();
144 
145  joy_axes_pairs get_axes_pair(int axis) const;
146  Common::KeyCode get_key_from_joy_button(uint8 button);
147  Common::Array<Common::U32String> buildKeyHelp() const;
148 };
149 
150 } // End of namespace Nuvie
151 } // End of namespace Ultima
152 
153 #endif
void clear(bool shrinkArray=0)
Definition: hashmap.h:427
Definition: configuration.h:61
Definition: keys.h:60
Definition: keys.h:45
Definition: detection.h:27
Definition: events.h:199
Definition: keyboard.h:294