Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputHandler.h @ 1215

Last change on this file since 1215 was 1215, checked in by rgrieder, 16 years ago
  • SpaceShip is now a default listener for mouse input. still a hack..
  • several changes in InputManager.cc regarding joy sticks
  • Key bindings work, but not very advanced
File size: 7.1 KB
RevLine 
[971]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[971]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 */
[973]28
[971]29/**
30 @file
[1022]31 @brief Different definitions of input processing.
[971]32 */
[973]33
34#ifndef _InputHandler_H__
35#define _InputHandler_H__
36
[1062]37#include "CorePrereqs.h"
38
[1022]39#include <string>
[1203]40#include "ois/OIS.h"
[1213]41#include "OrxonoxClass.h"
[1215]42#include "CommandExecutor.h"
[973]43
44namespace orxonox
45{
[1182]46  namespace KeybindSetting
47  {
48    enum KeybindSetting
49    {
50      None,
51      OnPress,
52      OnRelease,
53      Continuous,
54    };
55  }
56
[1203]57  /**
58    @brief Interface class used for key input listeners.
59  */
60  class _CoreExport KeyHandler : public OIS::KeyListener
[1182]61  {
[1203]62  public:
[1215]63    virtual ~KeyHandler() { }
[1203]64    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
[1182]65  };
[1203]66
[973]67  /**
[1203]68    @brief Interface class used for mouse input listeners.
[973]69  */
[1203]70  class _CoreExport MouseHandler : public OIS::MouseListener
[973]71  {
72  public:
[1215]73    virtual ~MouseHandler() { }
[1203]74    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
75  };
[973]76
[1203]77  /**
78    @brief Interface class used for joy stick input listeners.
79  */
[1215]80  class _CoreExport JoyStickHandler
[1203]81  {
82  public:
[1215]83    virtual ~JoyStickHandler() { }
84                virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
85                virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
86    virtual bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
87                virtual bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis)   = 0;
88                virtual bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
89                virtual bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
90                virtual bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
[1203]91  };
[1215]92
93  struct _CoreExport KeyBinding
94  {
95    std::string commandStr;
96    CommandEvaluation evaluation;
97  };
[1203]98 
99
100  /**
101    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
102           Manages the key bindings.
103  */
[1213]104  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
[1203]105  {
106  public:
107    KeyBinder ();
108    ~KeyBinder();
109
[1022]110    bool loadBindings();
[1203]111    void clearBindings();
[1213]112
113    void setConfigValues();
114
115    std::string testtest;
[1022]116
[1203]117  private: // functions
[1215]118
119    bool executeBinding(KeyBinding &binding);
120
[973]121                bool keyPressed   (const OIS::KeyEvent   &arg);
122                bool keyReleased  (const OIS::KeyEvent   &arg);
[1203]123                bool keyHeld      (const OIS::KeyEvent   &arg);
[1022]124
[1203]125    bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
126                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
127                bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
128    bool mouseMoved   (const OIS::MouseEvent &arg);
[1182]129
[1215]130                bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);
131                bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);
132                bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button);
133                bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis);
134                bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int id);
135                bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int id);
136                bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int id);
[1022]137
[1203]138  private: // variables
[1213]139
140    //! denotes the number of different keys there are in OIS.
141    static const int numberOfKeys_s = 0xEE;
[1022]142    //! Array of input events for every pressed key
[1215]143    KeyBinding bindingsKeyPress_  [numberOfKeys_s];
[1022]144    //! Array of input events for every released key
[1215]145    KeyBinding bindingsKeyRelease_[numberOfKeys_s];
[1213]146    //! Array of input events for every held key
[1215]147    KeyBinding bindingsKeyHold_   [numberOfKeys_s];
[1213]148    //! Names of the keys as strings
149    std::string keyNames_[numberOfKeys_s];
[1022]150
[1213]151    //! denotes the number of different mouse buttons there are in OIS.
152    static const int numberOfMouseButtons_s = 8;
[1203]153    //! Array of input events for every pressed mouse button
154    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
155    //! Array of input events for every released mouse button
156    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
157    //! Array of input events for every held mouse button
158    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
[1213]159    //! Names of the mouse buttons as strings
160    std::string mouseButtonNames_[numberOfMouseButtons_s];
[1022]161
[1213]162    //! denotes the number of different joy stick buttons there are in OIS.
[1203]163    static const int numberOfJoyStickButtons_s = 32;
164    //! Array of input events for every pressed joy stick button
165    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
166    //! Array of input events for every released joy stick button
167    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
168    //! Array of input events for every held joy stick button
169    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
[1213]170    //! Names of the joy stick buttons as strings
171    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
[1203]172
[973]173  };
174
175
176  /**
[1022]177    @brief Captures mouse and keyboard input and distributes it to the
178    GUI.
[973]179  */
[1203]180  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
181  //{
182  //public:
183  //  GUIInputHandler ();
184  //  ~GUIInputHandler();
[973]185
[1203]186  //private:
187  //  // input events
188                //bool keyPressed   (const OIS::KeyEvent   &arg);
189                //bool keyReleased  (const OIS::KeyEvent   &arg);
190                //bool keyHeld      (const OIS::KeyEvent   &arg);
[1182]191
[1203]192  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
193                //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
194                //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
195  //  bool mouseMoved   (const OIS::MouseEvent &arg);
[973]196
[1203]197                //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
198                //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
199                //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
200                //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
201                //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
202                //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
203  //};
204
[973]205}
206
207#endif /* _InputHandler_H__ */
Note: See TracBrowser for help on using the repository browser.