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 COMMON_ACTION_H
24 #define COMMON_ACTION_H
25 
26 #include "common/scummsys.h"
27 
28 #ifdef ENABLE_KEYMAPPER
29 
30 #include "common/events.h"
31 #include "common/func.h"
32 #include "common/list.h"
33 #include "common/str.h"
34 
35 namespace Common {
36 
37 struct HardwareInput;
38 class Keymap;
39 
40 #define ACTION_ID_SIZE (5)
41 
42 struct KeyActionEntry {
43 	const KeyState ks;
44 	const char *id;
45 	const char *description;
46 };
47 
48 struct Action {
49 	/** unique id used for saving/loading to config */
50 	char id[ACTION_ID_SIZE];
51 	/** Human readable description */
52 	String description;
53 
54 	/** Events to be sent when mapped key is pressed */
55 	List<Event> events;
56 
57 private:
58 	/** Hardware input that is mapped to this Action */
59 	const HardwareInput *_hwInput;
60 	Keymap *_boss;
61 
62 public:
63 	Action(Keymap *boss, const char *id, String des = "");
64 
addEventAction65 	void addEvent(const Event &evt) {
66 		events.push_back(evt);
67 	}
68 
addEventAction69 	void addEvent(const EventType evtType) {
70 		Event evt;
71 
72 		evt.type = evtType;
73 		events.push_back(evt);
74 	}
75 
addKeyEventAction76 	void addKeyEvent(const KeyState &ks) {
77 		Event evt;
78 
79 		evt.type = EVENT_KEYDOWN;
80 		evt.kbd = ks;
81 		addEvent(evt);
82 	}
83 
addLeftClickEventAction84 	void addLeftClickEvent() {
85 		addEvent(EVENT_LBUTTONDOWN);
86 	}
87 
addMiddleClickEventAction88 	void addMiddleClickEvent() {
89 		addEvent(EVENT_MBUTTONDOWN);
90 	}
91 
addRightClickEventAction92 	void addRightClickEvent() {
93 		addEvent(EVENT_RBUTTONDOWN);
94 	}
95 
getParentAction96 	Keymap *getParent() {
97 		return _boss;
98 	}
99 
100 	void mapInput(const HardwareInput *input);
101 	const HardwareInput *getMappedInput() const;
102 
103 };
104 
105 } // End of namespace Common
106 
107 #endif // #ifdef ENABLE_KEYMAPPER
108 
109 #endif // #ifndef COMMON_ACTION_H
110