Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1113 was 1112, checked in by rgrieder, 17 years ago

added calculate command ;)
In the console, you can now type something like "calculate sin(cos(3+4) - 8)*7" or even "calculate 7>8" and you'll get the result as a double.
The parser was something I've written 3 years ago when I first used C++ (the parser is mainly C).

File size: 5.6 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#include "InputManager.h"
40#include "core/CommandExecutor.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->bindingsKeyPress_[i] = "";
72      this->bindingsKeyRelease_[i] = "";
73    }
74    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
75    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
76    return true;
77  }
78
79  /**
80    @brief Event handler for the keyPressed Event.
81    @param e Event information
82  */
83  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
84  {
85    // find the appropriate key binding
86    std::string cmdStr = bindingsKeyPress_[int(e.key)];
87    if (cmdStr != "")
88    {
89      CommandExecutor::execute(cmdStr);
90      COUT(3) << "Executing command: " << cmdStr << 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 = bindingsKeyRelease_[int(e.key)];
103    if (cmdStr != "")
104    {
105      CommandExecutor::execute(cmdStr);
106      COUT(3) << "Executing command: " << cmdStr << std::endl;
107    }
108    return true;
109  }
110
111  /**
112    @brief Event handler for the mouseMoved Event.
113    @param e Event information
114  */
115  bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
116  {
117    return true;
118  }
119
120  /**
121    @brief Event handler for the mousePressed Event.
122    @param e Event information
123    @param id The ID of the mouse button
124  */
125  bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
126  {
127    return true;
128  }
129
130  /**
131    @brief Event handler for the mouseReleased Event.
132    @param e Event information
133    @param id The ID of the mouse button
134  */
135  bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
136  {
137    return true;
138  }
139
140  /**
141    @brief Calls all the objects from classes that derive from InputEventListener.
142    @param evt The input event that occured.
143  */
144  inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt)
145  {
146    for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; )
147    {
148      if (it->bActive_)
149        (it++)->eventOccured(evt);
150      else
151        it++;
152    }
153  }
154
155
156  // ###############################
157  // ###     InputHandlerGUI     ###
158  // ###############################
159
160  /**
161    @brief standard constructor
162  */
163  InputHandlerGUI::InputHandlerGUI()
164  {
165  }
166
167  /**
168    @brief Destructor
169  */
170  InputHandlerGUI::~InputHandlerGUI()
171  {
172  }
173
174  /**
175    @brief Event handler for the keyPressed Event.
176    @param e Event information
177  */
178  bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e)
179  {
180                //CEGUI::System::getSingleton().injectKeyDown( arg.key );
181                //CEGUI::System::getSingleton().injectChar( arg.text );
182    return true;
183  }
184
185  /**
186    @brief Event handler for the keyReleased Event.
187    @param e Event information
188  */
189  bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e)
190  {
191                //CEGUI::System::getSingleton().injectKeyUp( arg.key );
192    return true;
193  }
194
195  /**
196    @brief Event handler for the mouseMoved Event.
197    @param e Event information
198  */
199  bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e)
200  {
201                //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
202    return true;
203  }
204
205  /**
206    @brief Event handler for the mousePressed Event.
207    @param e Event information
208    @param id The ID of the mouse button
209  */
210  bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
211  {
212                //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
213    return true;
214  }
215
216  /**
217    @brief Event handler for the mouseReleased Event.
218    @param e Event information
219    @param id The ID of the mouse button
220  */
221  bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
222  {
223                //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
224    return true;
225  }
226
227}
Note: See TracBrowser for help on using the repository browser.