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 ILLUSIONS_INPUT_H
23 #define ILLUSIONS_INPUT_H
24 
25 #include "common/array.h"
26 #include "common/events.h"
27 #include "common/keyboard.h"
28 #include "common/rect.h"
29 
30 namespace Illusions {
31 
32 enum {
33  MOUSE_NONE = 0,
34  MOUSE_LEFT_BUTTON = 1,
35  MOUSE_RIGHT_BUTTON = 2
36 };
37 
38 enum {
39  kEventLeftClick = 0,
40  kEventRightClick = 1,
41  kEventInventory = 2,
42  kEventAbort = 3,
43  kEventSkip = 4,
44  kEventF1 = 5,
45  kEventUp = 6,
46  kEventDown = 7,
47  kEventMax
48 };
49 
50 struct KeyMapping {
51  Common::KeyCode _key;
52  int _mouseButton;
53  bool _down;
54 };
55 
56 class KeyMap : public Common::Array<KeyMapping> {
57 public:
58  void addKey(Common::KeyCode key);
59  void addMouseButton(int mouseButton);
60 protected:
61  void add(Common::KeyCode key, int mouseButton);
62 };
63 
64 class InputEvent {
65 public:
66  InputEvent();
67  InputEvent& setBitMask(uint bitMask);
68  InputEvent& addKey(Common::KeyCode key);
69  InputEvent& addMouseButton(int mouseButton);
70  uint handle(Common::KeyCode key, int mouseButton, bool down);
71  uint getBitMask() const { return _bitMask; }
72 protected:
73  uint _bitMask;
74  KeyMap _keyMap;
75 };
76 
77 class Input {
78 public:
79  Input();
80  void processEvent(Common::Event event);
81  bool pollEvent(uint evt);
82  bool hasNewEvents();
83  void discardEvent(uint evt);
84  void discardAllEvents();
85  bool pollButton(uint bitMask);
86  void activateButton(uint bitMask);
87  void deactivateButton(uint bitMask);
88  Common::Point getCursorPosition();
89  void setCursorPosition(Common::Point mousePos);
90  Common::Point getCursorDelta();
91  InputEvent& setInputEvent(uint evt, uint bitMask);
92  bool isCursorMovedByKeyboard() const { return _cursorMovedByKeyboard; }
93  bool isCheatModeActive();
94 protected:
95  uint _cheatCodeIndex;
96  uint _buttonStates, _newButtons, _buttonsDown;
97  uint _enabledButtons;
98  uint _newKeys;
99  Common::Point _cursorPos, _prevCursorPos;
100  InputEvent _inputEvents[kEventMax];
101  bool _cursorMovedByKeyboard;
102  void handleKey(Common::KeyCode key, int mouseButton, bool down);
103  void handleMouseButton(int mouseButton, bool down);
104  void discardButtons(uint bitMask);
105  bool lookButtonStates(uint bitMask);
106  bool lookNewButtons(uint bitMask);
107  void setButtonState(uint bitMask);
108  void moveCursorByKeyboard(int deltaX, int deltaY);
109 };
110 
111 } // End of namespace Illusions
112 
113 #endif // ILLUSIONS_INPUT_H
Definition: input.h:77
Definition: input.h:50
Definition: array.h:52
Definition: actor.h:34
Definition: input.h:56
Definition: input.h:64
Definition: events.h:198
Definition: rect.h:45