Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/InputManager.h @ 1239

Last change on this file since 1239 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
RevLine 
[918]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[918]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
[918]29/**
30 @file
31 @brief Implementation of a little Input handler that distributes everything
32        coming from OIS.
33 */
[973]34
35#ifndef _InputManager_H__
36#define _InputManager_H__
37
[1062]38#include "CorePrereqs.h"
39
[1219]40#include <map>
41#include <list>
[973]42
[1219]43#include "ois/OIS.h"
[1062]44#include "Tickable.h"
[973]45
46namespace orxonox
47{
[1219]48  class Mouse : public OIS::Mouse
[973]49  {
50  };
51
52  /**
53    @brief Captures and distributes mouse and keyboard input.
54  */
55  class _CoreExport InputManager
[1219]56        : public Tickable,
57          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
[973]58  {
[1219]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    };
[973]72
[1219]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();
[1066]82
[1219]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
[973]114    // Temporary solutions. Will be removed soon!
[1219]115    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
116    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
[973]117
[1219]118  private: // functions
[973]119    // don't mess with a Singleton
120    InputManager ();
121    InputManager (const InputManager&);
122    ~InputManager();
123
[1219]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();
[973]129
[1219]130    void _destroy();
131    void _destroyKeyboard();
132    void _destroyMouse();
133    void _destroyJoySticks();
[973]134
[1219]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
[973]176  };
177}
178
179#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.