Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/InputHandler.cc @ 1313

Last change on this file since 1313 was 1313, checked in by landauf, 16 years ago
  • implemented Shell, but not yet linked with the graphical console
  • added new features (cursor, OIS::KeyCode listener) to InputBuffer
  • changed some includes to avoid circular header-dependencies in OrxonoxClass and Shell
File size: 5.7 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 "Iterator.h"
37#include "util/Convert.h"
38#include "InputEventListener.h"
39#include "InputEvent.h"
40#include "InputManager.h"
41
42namespace orxonox
43{
44  // ###############################
45  // ###    InputHandlerGame     ###
46  // ###############################
47
48  /**
49    @brief standard constructor
50  */
51  InputHandlerGame::InputHandlerGame()
52  {
53  }
54
55  /**
56    @brief Destructor
57  */
58  InputHandlerGame::~InputHandlerGame()
59  {
60  }
61
62  /**
63    @brief Loads the key bindings from the ini file.
64    Currently, this is just a simple test routine that fills the list with numbers.
65  */
66  bool InputHandlerGame::loadBindings()
67  {
68    for (int i = 0; i < numberOfKeys_s; i++)
69    {
70      // simply write the key number (i) in the string
71      this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i);
72      this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i);
73    }
74    return true;
75  }
76
77  /**
78    @brief Event handler for the keyPressed Event.
79    @param e Event information
80  */
81  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
82  {
83    if (e.key == OIS::KC_ESCAPE)
84    {
85      InputEvent e = {1, true, 0, 0, 0};
86      InputHandlerGame::callListeners(e);
87    }
88    else if (e.key == OIS::KC_UNASSIGNED || e.key == OIS::KC_NUMPADENTER)
89    {
90      InputManager::getSingleton().setInputMode(IM_KEYBOARD);
91    }
92    else
93    {
94      // find the appropriate key binding
95      std::string cmdStr = bindingsKeyPressed_[int(e.key)];
96      //COUT(3) << cmdStr << " pressed" << std::endl;
97    }
98    return true;
99  }
100
101  /**
102    @brief Event handler for the keyReleased Event.
103    @param e Event information
104  */
105  bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
106  {
107    // find the appropriate key binding
108    std::string cmdStr = bindingsKeyReleased_[int(e.key)];
109    //COUT(3) << cmdStr << " released" << std::endl;
110    return true;
111  }
112
113  /**
114    @brief Event handler for the mouseMoved Event.
115    @param e Event information
116  */
117  bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
118  {
119    return true;
120  }
121
122  /**
123    @brief Event handler for the mousePressed Event.
124    @param e Event information
125    @param id The ID of the mouse button
126  */
127  bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
128  {
129    return true;
130  }
131
132  /**
133    @brief Event handler for the mouseReleased Event.
134    @param e Event information
135    @param id The ID of the mouse button
136  */
137  bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
138  {
139    return true;
140  }
141
142  /**
143    @brief Calls all the objects from classes that derive from InputEventListener.
144    @param evt The input event that occured.
145  */
146  inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt)
147  {
148    for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; )
149    {
150      if (it->bActive_)
151        (it++)->eventOccured(evt);
152      else
153        it++;
154    }
155  }
156
157
158  // ###############################
159  // ###     InputHandlerGUI     ###
160  // ###############################
161
162  /**
163    @brief standard constructor
164  */
165  InputHandlerGUI::InputHandlerGUI()
166  {
167  }
168
169  /**
170    @brief Destructor
171  */
172  InputHandlerGUI::~InputHandlerGUI()
173  {
174  }
175
176  /**
177    @brief Event handler for the keyPressed Event.
178    @param e Event information
179  */
180  bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e)
181  {
182                //CEGUI::System::getSingleton().injectKeyDown( arg.key );
183                //CEGUI::System::getSingleton().injectChar( arg.text );
184    return true;
185  }
186
187  /**
188    @brief Event handler for the keyReleased Event.
189    @param e Event information
190  */
191  bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e)
192  {
193                //CEGUI::System::getSingleton().injectKeyUp( arg.key );
194    return true;
195  }
196
197  /**
198    @brief Event handler for the mouseMoved Event.
199    @param e Event information
200  */
201  bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e)
202  {
203                //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
204    return true;
205  }
206
207  /**
208    @brief Event handler for the mousePressed Event.
209    @param e Event information
210    @param id The ID of the mouse button
211  */
212  bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
213  {
214                //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
215    return true;
216  }
217
218  /**
219    @brief Event handler for the mouseReleased Event.
220    @param e Event information
221    @param id The ID of the mouse button
222  */
223  bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
224  {
225                //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
226    return true;
227  }
228
229}
Note: See TracBrowser for help on using the repository browser.