ScummVM API documentation
input.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 NANCY_INPUT_H
23 #define NANCY_INPUT_H
24 
25 #include "engines/nancy/commontypes.h"
26 
27 #include "common/rect.h"
28 #include "common/keyboard.h"
29 
30 namespace Common {
31 class Keymap;
32 typedef class Array<Keymap *> KeymapArray;
33 }
34 
35 namespace Nancy {
36 
37 namespace State {
38 class State;
39 }
40 
41 struct NancyInput {
42  enum InputType : uint16 {
43  kLeftMouseButtonDown = 1 << 0,
44  kLeftMouseButtonHeld = 1 << 1,
45  kLeftMouseButtonUp = 1 << 2,
46  kRightMouseButtonDown = 1 << 3,
47  kRightMouseButtonHeld = 1 << 4,
48  kRightMouseButtonUp = 1 << 5,
49  kMoveUp = 1 << 6,
50  kMoveDown = 1 << 7,
51  kMoveLeft = 1 << 8,
52  kMoveRight = 1 << 9,
53  kMoveFastModifier = 1 << 10,
54  kOpenMainMenu = 1 << 11,
55  kRaycastMap = 1 << 12,
56  kMouseWheelUp = 1 << 13,
57  kMouseWheelDown = 1 << 14,
58 
59  kLeftMouseButton = kLeftMouseButtonDown | kLeftMouseButtonHeld | kLeftMouseButtonUp,
60  kRightMouseButton = kRightMouseButtonDown | kRightMouseButtonHeld | kRightMouseButtonUp,
61  kMouseWheel = kMouseWheelUp | kMouseWheelDown
62  };
63 
64  Common::Point mousePos;
65  uint16 input;
66  Common::Array<Common::KeyState> otherKbdInput;
67 
68  void eatMouseInput() { mousePos.x = -1; input &= ~(kLeftMouseButton | kRightMouseButton | kMouseWheel); }
69 
70  // Consumes just the wheel input, leaving the mouse position and buttons alone,
71  // so a widget that scrolls can still keep updating its hover state
72  void eatMouseWheelInput() { input &= ~kMouseWheel; }
73 };
74 
75 // This class handles collecting events and translating them to a NancyInput object,
76 // which can then be pulled by interested classes through getInput()
77 class InputManager {
78 
79 public:
80  enum NancyAction {
81  kNancyActionMoveUp,
82  kNancyActionMoveDown,
83  kNancyActionMoveLeft,
84  kNancyActionMoveRight,
85  kNancyActionMoveFast,
86  kNancyActionLeftClick,
87  kNancyActionRightClick,
88  kNancyActionOpenMainMenu,
89  kNancyActionShowRaycastMap
90  };
91 
92  InputManager() :
93  _inputs(0),
94  _mouseEnabled(true),
95  _inputBeginState(NancyState::kNone) {}
96 
97  void processEvents();
98 
99  NancyInput getInput() const;
100  void forceCleanInput();
101  void setMouseInputEnabled(bool enabled) { _mouseEnabled = enabled; }
102  void setKeymapEnabled(Common::String keymapName, bool enabled);
103  void setVKEnabled(bool enabled);
104 
105  static void initKeymaps(Common::KeymapArray &keymaps, const char *target);
106 
107  static const char *_mazeKeymapID;
108 
109 private:
110  uint16 _inputs;
111  Common::Array<Common::KeyState> _otherKbdInput;
112  bool _mouseEnabled;
113  NancyState::NancyState _inputBeginState;
114 };
115 
116 } // End of namespace Nancy
117 
118 #endif // NANCY_INPUT_H
Definition: str.h:59
Definition: input.h:41
Definition: input.h:77
Definition: algorithm.h:29
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: actionmanager.h:32