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