Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1213 was 1213, checked in by rgrieder, 16 years ago
  • Key bindings can now be stored in keybindings.ini
  • doesn't work for move movement yet, but for the buttons.
File size: 6.1 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 Different definitions of input processing.
32 */
33
34#ifndef _InputHandler_H__
35#define _InputHandler_H__
36
37#include "CorePrereqs.h"
38
39#include <string>
40#include "ois/OIS.h"
41#include "OrxonoxClass.h"
42
43namespace orxonox
44{
45  namespace KeybindSetting
46  {
47    enum KeybindSetting
48    {
49      None,
50      OnPress,
51      OnRelease,
52      Continuous,
53    };
54  }
55
56  /**
57    @brief Interface class used for key input listeners.
58  */
59  class _CoreExport KeyHandler : public OIS::KeyListener
60  {
61  public:
62    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
63  };
64
65  /**
66    @brief Interface class used for mouse input listeners.
67  */
68  class _CoreExport MouseHandler : public OIS::MouseListener
69  {
70  public:
71    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
72  };
73
74  /**
75    @brief Interface class used for joy stick input listeners.
76  */
77  class _CoreExport JoyStickHandler : public OIS::JoyStickListener
78  {
79  public:
80    virtual bool buttonHeld(const OIS::JoyStickEvent &arg, int button) = 0;
81  };
82 
83
84  /**
85    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
86           Manages the key bindings.
87  */
88  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
89  {
90  public:
91    KeyBinder ();
92    ~KeyBinder();
93
94    bool loadBindings();
95    void clearBindings();
96
97    void setConfigValues();
98
99    std::string testtest;
100
101  private: // functions
102                bool keyPressed   (const OIS::KeyEvent   &arg);
103                bool keyReleased  (const OIS::KeyEvent   &arg);
104                bool keyHeld      (const OIS::KeyEvent   &arg);
105
106    bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
107                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
108                bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
109    bool mouseMoved   (const OIS::MouseEvent &arg);
110
111                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
112                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
113                bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
114                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
115                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
116                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
117
118  private: // variables
119
120    //! denotes the number of different keys there are in OIS.
121    static const int numberOfKeys_s = 0xEE;
122    //! Array of input events for every pressed key
123    std::string bindingsKeyPress_  [numberOfKeys_s];
124    //! Array of input events for every released key
125    std::string bindingsKeyRelease_[numberOfKeys_s];
126    //! Array of input events for every held key
127    std::string bindingsKeyHold_   [numberOfKeys_s];
128    //! Names of the keys as strings
129    std::string keyNames_[numberOfKeys_s];
130
131    //! denotes the number of different mouse buttons there are in OIS.
132    static const int numberOfMouseButtons_s = 8;
133    //! Array of input events for every pressed mouse button
134    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
135    //! Array of input events for every released mouse button
136    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
137    //! Array of input events for every held mouse button
138    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
139    //! Names of the mouse buttons as strings
140    std::string mouseButtonNames_[numberOfMouseButtons_s];
141
142    //! denotes the number of different joy stick buttons there are in OIS.
143    static const int numberOfJoyStickButtons_s = 32;
144    //! Array of input events for every pressed joy stick button
145    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
146    //! Array of input events for every released joy stick button
147    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
148    //! Array of input events for every held joy stick button
149    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
150    //! Names of the joy stick buttons as strings
151    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
152
153  };
154
155
156  /**
157    @brief Captures mouse and keyboard input and distributes it to the
158    GUI.
159  */
160  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
161  //{
162  //public:
163  //  GUIInputHandler ();
164  //  ~GUIInputHandler();
165
166  //private:
167  //  // input events
168                //bool keyPressed   (const OIS::KeyEvent   &arg);
169                //bool keyReleased  (const OIS::KeyEvent   &arg);
170                //bool keyHeld      (const OIS::KeyEvent   &arg);
171
172  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
173                //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
174                //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
175  //  bool mouseMoved   (const OIS::MouseEvent &arg);
176
177                //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
178                //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
179                //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
180                //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
181                //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
182                //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
183  //};
184
185}
186
187#endif /* _InputHandler_H__ */
Note: See TracBrowser for help on using the repository browser.