Planeshift
econtrolmanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
3  *
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation (version 2 of the License)
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  */
17 
18 #ifndef ECONTROLMANAGER_H
19 #define ECONTROLMANAGER_H
20 
21 #include <csutil/csstring.h>
22 #include <iutil/event.h>
23 #include <csutil/array.h>
24 
29 #define CMD_DECLARATION(func) static void func(eControlManager *obj, bool down)
30 
31 struct iObjectRegistry;
32 
34 {
35 public:
41  eControlManager(iObjectRegistry* object_reg);
43 
50  bool HandleEvent(iEvent &event);
51 
59  bool LoadKeyMap(const char* filename);
60 
63  void ClearKeyMap();
64 
65  // Actions
66  CMD_DECLARATION( HandleForward );
67  CMD_DECLARATION( HandleBackward );
68  CMD_DECLARATION( HandleRotateLeft );
69  CMD_DECLARATION( HandleRotateRight );
70  CMD_DECLARATION( HandleLookUp );
71  CMD_DECLARATION( HandleLookDown );
72 
73 private:
79  void ExecuteKeyCommand(csKeyEventData &key);
80 
87  void Map(const char *action, csKeyEventData &data);
88 
95  size_t StringToAction(const char *name);
96 
100  struct ActionKeyMap
101  {
102  csString action;
103  csKeyEventData csKey;
104  };
105 
106  csArray<ActionKeyMap*> keyMap;
107 
108 
109  iObjectRegistry* object_reg;
110 };
111 
114 #endif
bool HandleEvent(iEvent &event)
Handles the given even if it is a key even.
void ClearKeyMap()
Removes all current key mappings.
bool LoadKeyMap(const char *filename)
Imports key mappings from the given files.
eControlManager(iObjectRegistry *object_reg)
Initialise the eControlManager with an object registry.
CMD_DECLARATION(HandleForward)