Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ogre/src/core/InputManager.h @ 1249

Last change on this file since 1249 was 1219, checked in by rgrieder, 17 years ago

merged input branch back to trunk. Not yet tested on tardis

File size: 6.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 a little Input handler that distributes everything
32        coming from OIS.
33 */
34
35#ifndef _InputManager_H__
36#define _InputManager_H__
37
38#include "CorePrereqs.h"
39
40#include <map>
41#include <list>
42
43#include "ois/OIS.h"
44#include "Tickable.h"
45
46namespace orxonox
47{
48  class Mouse : public OIS::Mouse
49  {
50  };
51
52  /**
53    @brief Captures and distributes mouse and keyboard input.
54  */
55  class _CoreExport InputManager
56        : public Tickable,
57          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
58  {
59  public: // enumerations
60    /**
61      @brief Designates the way input is handled and redirected.
62    */
63    enum InputState
64    {
65      IS_UNINIT,  //!< InputManager has not yet been initialised.
66      IS_NONE,    //!< Input is discarded.
67      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
68      IS_GUI,     //!< All OIS input events are passed to CEGUI.
69      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
70      IS_CUSTOM   //!< Any possible configuration.
71    };
72
73  public: // static functions
74    static bool initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
75          const bool createKeyboard = true, const bool createMouse = true, const bool createJoySticks = false);
76    static bool initialiseKeyboard();
77    static bool initialiseMouse();
78    static bool initialiseJoySticks();
79    static int  numberOfKeyboards();
80    static int  numberOfMice();
81    static int  numberOfJoySticks();
82
83    static void destroy();
84    static void destroyKeyboard();
85    static void destroyMouse();
86    static void destroyJoySticks();
87
88    static void setWindowExtents(const int width, const int height);
89
90    static void setInputState(const InputState state);
91    static InputState getInputState();
92
93    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
94    static bool removeKeyHandler              (const std::string& name);
95    static KeyHandler* getKeyHandler          (const std::string& name);
96    static bool enableKeyHandler              (const std::string& name);
97    static bool disableKeyHandler             (const std::string& name);
98    static bool isKeyHandlerActive            (const std::string& name);
99
100    static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
101    static bool removeMouseHandler            (const std::string& name);
102    static MouseHandler* getMouseHandler      (const std::string& name);
103    static bool enableMouseHandler            (const std::string& name);
104    static bool disableMouseHandler           (const std::string& name);
105    static bool isMouseHandlerActive          (const std::string& name);
106
107    static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
108    static bool removeJoyStickHandler         (const std::string& name);
109    static JoyStickHandler* getJoyStickHandler(const std::string& name);
110    static bool enableJoyStickHandler         (const std::string& name, const int id);
111    static bool disableJoyStickHandler        (const std::string& name, const int id);
112    static bool isJoyStickHandlerActive       (const std::string& name, const int id);
113
114    // Temporary solutions. Will be removed soon!
115    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
116    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
117
118  private: // functions
119    // don't mess with a Singleton
120    InputManager ();
121    InputManager (const InputManager&);
122    ~InputManager();
123
124    // Intenal methods
125    bool _initialise(const size_t, const int, const int, const bool, const bool, const bool);
126    bool _initialiseKeyboard();
127    bool _initialiseMouse();
128    bool _initialiseJoySticks();
129
130    void _destroy();
131    void _destroyKeyboard();
132    void _destroyMouse();
133    void _destroyJoySticks();
134
135    //void _setNumberOfJoysticks(int size);
136
137    void tick(float dt);
138
139    // input events
140                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
141                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
142    bool mouseMoved    (const OIS::MouseEvent    &arg);
143                bool keyPressed    (const OIS::KeyEvent      &arg);
144                bool keyReleased   (const OIS::KeyEvent      &arg);
145                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
146                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
147                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
148                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
149                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
150                bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
151
152    static InputManager& _getSingleton();
153    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
154
155  private: // variables
156    OIS::InputManager*                          inputSystem_; //!< OIS input manager
157    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
158    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
159    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
160
161    InputState state_;
162    InputState stateRequest_;
163
164    std::map<std::string, KeyHandler*>          keyHandlers_;
165    std::map<std::string, MouseHandler*>        mouseHandlers_;
166    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
167
168    std::vector<KeyHandler*>                    activeKeyHandlers_;
169    std::vector<MouseHandler*>                  activeMouseHandlers_;
170    std::map< OIS::JoyStick*, std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
171
172    std::list<OIS::KeyCode>                     keysDown_;
173    std::list<OIS::MouseButtonID>               mouseButtonsDown_;
174    std::map< OIS::JoyStick*, std::list<int> >  joyStickButtonsDown_;
175
176  };
177}
178
179#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.