Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputManager.h @ 1208

Last change on this file since 1208 was 1204, checked in by rgrieder, 17 years ago
  • added some const qualifiers
  • renamed a few very ugly variables for the 7th time
  • added new functions (isHandlerActive, isDeviceInitialised)
File size: 6.6 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
[1182]40#include <map>
41#include <list>
[973]42
[1195]43#include "ois/OIS.h"
[1062]44#include "Tickable.h"
[973]45
46namespace orxonox
47{
[1203]48  class Mouse : public OIS::Mouse
49  {
50  };
51
[973]52  /**
53    @brief Captures and distributes mouse and keyboard input.
54  */
55  class _CoreExport InputManager
[1182]56        : public Tickable,
[1204]57          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
[973]58  {
[1193]59  public: // enumerations
[1182]60    /**
[1193]61      @brief Designates the way input is handled and redirected.
[1182]62    */
63    enum InputState
64    {
[1193]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.
[1182]71    };
72
[1203]73  public: // static functions
[1204]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);
[1203]76    static bool initialiseKeyboard();
77    static bool initialiseMouse();
78    static bool initialiseJoySticks();
[1204]79    static bool isKeyboardInitialised();
80    static bool isMouseInitialised();
81    static bool areJoySticksInitialised();
[1203]82
[1182]83    static void destroy();
[1203]84    static void destroyKeyboard();
85    static void destroyMouse();
86    static void destroyJoySticks();
[1066]87
[1204]88    static void setWindowExtents(const int width, const int height);
[1193]89
[1182]90    static void setInputState(const InputState state);
91    static InputState getInputState();
92
[1204]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);
[1182]99
[1204]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);
[1182]106
[1204]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);
[1182]113
[973]114    // Temporary solutions. Will be removed soon!
[1182]115    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
116    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
[973]117
[1193]118  private: // functions
[973]119    // don't mess with a Singleton
120    InputManager ();
121    InputManager (const InputManager&);
122    ~InputManager();
123
[1193]124    // Intenal methods
[1204]125    bool _initialise(const size_t, const int, const int, const bool, const bool, const bool);
[1203]126    bool _initialiseKeyboard();
127    bool _initialiseMouse();
128    bool _initialiseJoySticks();
129
[1182]130    void _destroy();
[1203]131    void _destroyKeyboard();
132    void _destroyMouse();
133    void _destroyJoySticks();
[973]134
[1203]135    //void _setNumberOfJoysticks(int size);
136
[1193]137    void tick(float dt);
138
[1182]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);
[973]150
[1182]151    static InputManager& _getSingleton();
152    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
153
[1193]154  private: // variables
[1204]155    OIS::InputManager*                          inputSystem_; //!< OIS input manager
156    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
157    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
158    std::map<int, OIS::JoyStick*>               joySticks_;   //!< OIS joy sticks
[1182]159
160    InputState state_;
161    InputState stateRequest_;
162
[1204]163    std::map<std::string, KeyHandler*>          keyHandlers_;
164    std::map<std::string, MouseHandler*>        mouseHandlers_;
165    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
[1182]166
[1204]167    std::list<KeyHandler*>                      activeKeyHandlers_;
168    std::list<MouseHandler*>                    activeMouseHandlers_;
169    std::map<int, std::list<JoyStickHandler*> > activeJoyStickHandlers_;
[1182]170
[1204]171    std::list<OIS::KeyCode>                     keysDown_;
172    std::list<OIS::MouseButtonID>               mouseButtonsDown_;
173    std::map< int, std::list<int> >             joyStickButtonsDown_;
[1182]174
[973]175  };
176}
177
178#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.