Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/InputHandler.cc @ 1063

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