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 "common/str.h"
28 #include "common/events.h"
29 #include "common/hash-str.h"
30 
31 namespace Ultima {
32 namespace Nuvie {
33 
34 enum joy_axes_pairs {
35  AXES_PAIR1, AXES_PAIR2, AXES_PAIR3, AXES_PAIR4, UNHANDLED_AXES_PAIR
36 };
37 
38 enum altCodeMode {
39  kAltCodeModeBegin = 0,
40  kAltCodeModeEnd = 1
41 };
42 
43 struct Action;
44 struct ActionType {
45  const Action *action;
46  int param;
47 };
48 
50 
54 
55 class Configuration;
56 
57 char get_ascii_char_from_keysym(Common::KeyState keysym);
58 
59 class KeyBinder {
60 private:
61  KeyMap _bindings;
62 
63  ParseKeyMap _keys;
64  ParseActionMap _actions;
65  ParseHashedActionMap _actionsHashed;
66  int16 _joyAxisPositions[8];
67 
68  bool repeat_hat, joy_repeat_enabled; // repeat hat instead of axis when hat is found
69  uint32 next_axes_pair_update, next_axes_pair2_update, next_axes_pair3_update,
70  next_axes_pair4_update, next_joy_repeat_time;
71  uint16 pair1_delay, pair2_delay, pair3_delay, pair4_delay, joy_repeat_delay;
72  uint8 x_axis, y_axis, x_axis2, y_axis2, x_axis3, y_axis3, x_axis4, y_axis4;
73  sint8 enable_joystick;
74 
75  void LoadFromFileInternal(const char *filename);
76 public:
77  KeyBinder(const Configuration *config);
78  ~KeyBinder();
79  /* Add keybinding */
80  void AddKeyBinding(Common::KeyCode sym, byte mod, const Action *action,
81  int nparams, int param);
82 
83  /* Delete keybinding */
84 // void DelKeyBinding(Common::KeyCode sym, int mod); // unused
85 
86  /* Other methods */
87  void Flush() {
88  _bindings.clear();
89  }
90  ActionType get_ActionType(const Common::KeyState &key);
91  ActionKeyType GetActionKeyType(ActionType a);
92  bool DoAction(ActionType const &a) const;
93  KeyMap::iterator get_sdlkey_index(const Common::KeyState &key);
94  bool HandleEvent(const Common::Event *event);
95  bool handleScummVMBoundEvent(const Common::Event *event);
96 
97  void LoadFromFile(const char *filename);
98  void LoadGameSpecificKeys();
99  void LoadFromPatch();
100  void handle_wrong_key_pressed();
101  bool handle_always_available_keys(ActionType a);
102 
103  void ShowKeys() const;
104  void AddIosBindings();
105 
106  uint8 get_axis(uint8 index) const;
107  void set_axis(uint8 index, uint8 value);
108  Common::KeyCode get_key_from_joy_walk_axes() {
109  return get_key_from_joy_axis_motion(x_axis, true);
110  }
111  Common::KeyCode get_key_from_joy_axis_motion(int axis, bool repeating);
112  Common::KeyCode get_key_from_joy_hat_button(uint8 hat_button) const;
113  Common::KeyCode get_key_from_joy_events(Common::Event *event);
114  void init_joystick(sint8 joy_num);
115 // SDL_Joystick *get_joystick() { return joystick; }
116  uint32 get_next_joy_repeat_time() const {
117  return next_joy_repeat_time;
118  }
119  void set_enable_joy_repeat(bool val) {
120  if (joy_repeat_delay == 10000) return;
121  joy_repeat_enabled = val;
122  }
123  bool is_joy_repeat_enabled() const {
124  return joy_repeat_enabled;
125  }
126  bool is_hat_repeating() const {
127  return repeat_hat;
128  }
129  void set_hat_repeating(bool val) {
130  repeat_hat = val;
131  }
132  sint8 get_enable_joystick() const {
133  return enable_joystick;
134  }
135  void set_enable_joystick(bool val) {
136  enable_joystick = val;
137  }
138 
139 private:
140  void ParseText(char *text, int len);
141  void ParseLine(const char *line);
142  void FillParseMaps();
143 
144  joy_axes_pairs get_axes_pair(int axis) const;
145  Common::KeyCode get_key_from_joy_button(uint8 button);
146  Common::Array<Common::U32String> buildKeyHelp() const;
147 };
148 
149 } // End of namespace Nuvie
150 } // End of namespace Ultima
151 
152 #endif
void clear(bool shrinkArray=0)
Definition: hashmap.h:431
Definition: configuration.h:60
Definition: keys.h:59
Definition: keys.h:44
Definition: detection.h:27
Definition: events.h:218
Definition: keyboard.h:294