Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputHandler.cc @ 1205

Last change on this file since 1205 was 1205, checked in by rgrieder, 16 years ago
  • removed obsolete files
File size: 8.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30 @file
31 @brief Implementation of the different input handlers.
32 */
33
34#include "InputHandler.h"
35#include "Debug.h"
36#include "util/Convert.h"
37#include "core/CommandExecutor.h"
38
39namespace orxonox
40{
41  // ###############################
42  // ######     KeyBinder     ######
43  // ###############################
44
45  /**
46    @brief Constructor that does as little as necessary.
47  */
48  KeyBinder::KeyBinder()
49  {
50    clearBindings();
51  }
52
53  /**
54    @brief Destructor
55  */
56  KeyBinder::~KeyBinder()
57  {
58  }
59
60  /**
61    @brief Overwrites all bindings with ""
62  */
63  void KeyBinder::clearBindings()
64  {
65    for (int i = 0; i < numberOfKeys_s; i++)
66    {
67      bindingsKeyPress_  [i] = "";
68      bindingsKeyRelease_[i] = "";
69      bindingsKeyHold_   [i] = "";
70    }
71    for (int i = 0; i < numberOfMouseButtons_s; i++)
72    {
73      bindingsMouseButtonPress_  [i] = "";
74      bindingsMouseButtonRelease_[i] = "";
75      bindingsMouseButtonHold_   [i] = "";
76    }
77    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
78    {
79      bindingsJoyStickButtonPress_  [i] = "";
80      bindingsJoyStickButtonRelease_[i] = "";
81      bindingsJoyStickButtonHold_   [i] = "";
82    }
83  }
84
85  /**
86    @brief Loads the key and button bindings.
87    @return True if loading succeeded.
88  */
89  bool KeyBinder::loadBindings()
90  {
91    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl;
92
93    // clear all the bindings at first.
94    clearBindings();
95
96    // TODO: Insert the code to load the bindings from file.
97    bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole";
98    bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
99    bindingsKeyHold_ [OIS::KC_U] = "exec disco.txt";
100
101    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
102    return true;
103  }
104
105
106  /**
107    @brief Event handler for the keyPressed Event.
108    @param e Event information
109  */
110  bool KeyBinder::keyPressed(const OIS::KeyEvent &e)
111  {
112    // find the appropriate key binding
113    std::string cmdStr = bindingsKeyPress_[int(e.key)];
114    if (cmdStr != "")
115    {
116      CommandExecutor::execute(cmdStr);
117      COUT(3) << "Executing command: " << cmdStr << std::endl;
118    }
119   
120    return true;
121  }
122
123  /**
124    @brief Event handler for the keyReleased Event.
125    @param e Event information
126  */
127  bool KeyBinder::keyReleased(const OIS::KeyEvent &e)
128  {
129    // find the appropriate key binding
130    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
131    if (cmdStr != "")
132    {
133      CommandExecutor::execute(cmdStr);
134      COUT(3) << "Executing command: " << cmdStr << std::endl;
135    }
136
137    return true;
138  }
139
140  /**
141    @brief Event handler for the keyHeld Event.
142    @param e Event information
143  */
144  bool KeyBinder::keyHeld(const OIS::KeyEvent &e)
145  {
146    // find the appropriate key binding
147    std::string cmdStr = bindingsKeyHold_[int(e.key)];
148    if (cmdStr != "")
149    {
150      CommandExecutor::execute(cmdStr);
151      COUT(3) << "Executing command: " << cmdStr << std::endl;
152    }
153
154    return true;
155  }
156
157  /**
158    @brief Event handler for the mouseMoved Event.
159    @param e Event information
160  */
161  bool KeyBinder::mouseMoved(const OIS::MouseEvent &e)
162  {
163    return true;
164  }
165
166  /**
167    @brief Event handler for the mousePressed Event.
168    @param e Event information
169    @param id The ID of the mouse button
170  */
171  bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
172  {
173    // find the appropriate key binding
174    std::string cmdStr = bindingsMouseButtonPress_[int(id)];
175    if (cmdStr != "")
176    {
177      CommandExecutor::execute(cmdStr);
178      COUT(3) << "Executing command: " << cmdStr << std::endl;
179    }
180
181    return true;
182  }
183
184  /**
185    @brief Event handler for the mouseReleased Event.
186    @param e Event information
187    @param id The ID of the mouse button
188  */
189  bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
190  {
191    // find the appropriate key binding
192    std::string cmdStr = bindingsMouseButtonRelease_[int(id)];
193    if (cmdStr != "")
194    {
195      CommandExecutor::execute(cmdStr);
196      COUT(3) << "Executing command: " << cmdStr << std::endl;
197    }
198
199    return true;
200  }
201
202  /**
203    @brief Event handler for the mouseHeld Event.
204    @param e Event information
205    @param id The ID of the mouse button
206  */
207  bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id)
208  {
209    // find the appropriate key binding
210    std::string cmdStr = bindingsMouseButtonHold_[int(id)];
211    if (cmdStr != "")
212    {
213      CommandExecutor::execute(cmdStr);
214      COUT(3) << "Executing command: " << cmdStr << std::endl;
215    }
216
217    return true;
218  }
219
220  bool KeyBinder::buttonPressed(const OIS::JoyStickEvent &arg, int button)
221  {
222    // find the appropriate key binding
223    std::string cmdStr = bindingsJoyStickButtonPress_[button];
224    if (cmdStr != "")
225    {
226      CommandExecutor::execute(cmdStr);
227      COUT(3) << "Executing command: " << cmdStr << std::endl;
228    }
229
230    return true;
231  }
232
233  bool KeyBinder::buttonReleased(const OIS::JoyStickEvent &arg, int button)
234  {
235    // find the appropriate key binding
236    std::string cmdStr = bindingsJoyStickButtonRelease_[button];
237    if (cmdStr != "")
238    {
239      CommandExecutor::execute(cmdStr);
240      COUT(3) << "Executing command: " << cmdStr << std::endl;
241    }
242
243    return true;
244  }
245
246  bool KeyBinder::buttonHeld(const OIS::JoyStickEvent &arg, int button)
247  {
248    // find the appropriate key binding
249    std::string cmdStr = bindingsJoyStickButtonHold_[button];
250    if (cmdStr != "")
251    {
252      CommandExecutor::execute(cmdStr);
253      COUT(3) << "Executing command: " << cmdStr << std::endl;
254    }
255
256    return true;
257  }
258
259  bool KeyBinder::axisMoved(const OIS::JoyStickEvent &arg, int axis)
260  {
261    return true;
262  }
263
264  bool KeyBinder::sliderMoved(const OIS::JoyStickEvent &arg, int id)
265  {
266    return true;
267  }
268
269  bool KeyBinder::povMoved(const OIS::JoyStickEvent &arg, int id)
270  {
271    return true;
272  }
273
274
275
276  // ###############################
277  // ###     GUIInputHandler     ###
278  // ###############################
279
280  ///**
281  //  @brief standard constructor
282  //*/
283  //GUIInputHandler::GUIInputHandler()
284  //{
285  //}
286
287  ///**
288  //  @brief Destructor
289  //*/
290  //GUIInputHandler::~GUIInputHandler()
291  //{
292  //}
293
294  ///**
295  //  @brief Event handler for the keyPressed Event.
296  //  @param e Event information
297  //*/
298  //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e)
299  //{
300                ////CEGUI::System::getSingleton().injectKeyDown( arg.key );
301                ////CEGUI::System::getSingleton().injectChar( arg.text );
302  //  return true;
303  //}
304
305  ///**
306  //  @brief Event handler for the keyReleased Event.
307  //  @param e Event information
308  //*/
309  //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e)
310  //{
311                ////CEGUI::System::getSingleton().injectKeyUp( arg.key );
312  //  return true;
313  //}
314
315  ///**
316  //  @brief Event handler for the mouseMoved Event.
317  //  @param e Event information
318  //*/
319  //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e)
320  //{
321                ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
322  //  return true;
323  //}
324
325  ///**
326  //  @brief Event handler for the mousePressed Event.
327  //  @param e Event information
328  //  @param id The ID of the mouse button
329  //*/
330  //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
331  //{
332                ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
333  //  return true;
334  //}
335
336  ///**
337  //  @brief Event handler for the mouseReleased Event.
338  //  @param e Event information
339  //  @param id The ID of the mouse button
340  //*/
341  //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
342  //{
343                ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
344  //  return true;
345  //}
346
347}
Note: See TracBrowser for help on using the repository browser.