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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ILLUSIONS_INPUT_H
24 #define ILLUSIONS_INPUT_H
25 
26 #include "common/array.h"
27 #include "common/events.h"
28 #include "common/keyboard.h"
29 #include "common/rect.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 {
52 	Common::KeyCode _key;
53 	int _mouseButton;
54 	bool _down;
55 };
56 
57 class KeyMap : public Common::Array<KeyMapping> {
58 public:
59 	void addKey(Common::KeyCode key);
60 	void addMouseButton(int mouseButton);
61 protected:
62 	void add(Common::KeyCode key, int mouseButton);
63 };
64 
65 class InputEvent {
66 public:
67 	InputEvent();
68 	InputEvent& setBitMask(uint bitMask);
69 	InputEvent& addKey(Common::KeyCode key);
70 	InputEvent& addMouseButton(int mouseButton);
71 	uint handle(Common::KeyCode key, int mouseButton, bool down);
getBitMask()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);
isCursorMovedByKeyboard()93 	bool isCursorMovedByKeyboard() const { return _cursorMovedByKeyboard; }
94 	bool isCheatModeActive();
95 protected:
96 	uint _cheatCodeIndex;
97 	uint _buttonStates, _newButtons, _buttonsDown;
98 	uint _enabledButtons;
99 	uint _newKeys;
100 	Common::Point _cursorPos, _prevCursorPos;
101 	InputEvent _inputEvents[kEventMax];
102 	bool _cursorMovedByKeyboard;
103 	void handleKey(Common::KeyCode key, int mouseButton, bool down);
104 	void handleMouseButton(int mouseButton, bool down);
105 	void discardButtons(uint bitMask);
106 	bool lookButtonStates(uint bitMask);
107 	bool lookNewButtons(uint bitMask);
108 	void setButtonState(uint bitMask);
109 	void moveCursorByKeyboard(int deltaX, int deltaY);
110 };
111 
112 } // End of namespace Illusions
113 
114 #endif // ILLUSIONS_INPUT_H
115