Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud2/src/orxonox/core/InputManager.h @ 1207

Last change on this file since 1207 was 973, checked in by rgrieder, 17 years ago
  • not really done a lot, but svn create patch doesn't work with renamed files
File size: 3.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/**
29 @file
30 @brief Implementation of a little Input handler that distributes everything
31        coming from OIS.
32 */
33
34#ifndef _InputManager_H__
35#define _InputManager_H__
36
37#include <OIS/OIS.h>
38
39#include "CorePrereqs.h"
40#include "core/Tickable.h"
41#include "InputEvent.h"
42
43namespace orxonox
44{
45  /**
46    @brief Designates the way input is handled currently.
47    IM_GUI:      All the OIS input events are passed to CEGUI
48    IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer
49    IM_INGAME:   Normal game mode. Key bindings and mouse are active.
50  */
51  enum InputMode
52  {
53    IM_GUI      = 0,
54    IM_KEYBOARD = 1,
55    IM_INGAME   = 2,
56  };
57
58  /**
59    @brief Captures and distributes mouse and keyboard input.
60    It resolves the key bindings to InputEvents which can be heard by
61    implementing the InputEventListener interface.
62  */
63  class _CoreExport InputManager
64        : public Tickable, public OIS::KeyListener, public OIS::MouseListener
65  {
66  public:
67    bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
68    void destroyDevices();
69    void tick(float dt);
70    void setWindowExtents(int width, int height);
71
72    // Temporary solutions. Will be removed soon!
73    OIS::Mouse    *getMouse()    { return this->mouse_   ; }
74    OIS::Keyboard *getKeyboard() { return this->keyboard_; }
75
76    static InputManager* getSingleton();
77    static void destroySingleton();
78
79  private:
80    // don't mess with a Singleton
81    InputManager ();
82    InputManager (const InputManager&);
83    InputManager& operator=(const InputManager& instance);
84    ~InputManager();
85
86    void callListeners(InputEvent &evt);
87
88    // input events
89                bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
90                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
91    bool mouseMoved   (const OIS::MouseEvent &arg);
92                bool keyPressed   (const OIS::KeyEvent   &arg);
93                bool keyReleased  (const OIS::KeyEvent   &arg);
94
95    OIS::InputManager *inputSystem_;    //!< OIS input manager
96    OIS::Keyboard     *keyboard_;       //!< OIS mouse
97    OIS::Mouse        *mouse_;          //!< OIS keyboard
98
99    /** denotes the maximum number of different keys there are in OIS.
100        256 should be ok since the highest number in the enum is 237. */
101    static const int numberOfKeys_ = 256;
102    //! Array of input events for every pressed key
103    InputEvent bindingsKeyPressed_[numberOfKeys_];
104    //! Array of input events for every released key
105    InputEvent bindingsKeyReleased_[numberOfKeys_];
106
107    /** denotes the maximum number of different buttons there are in OIS.
108        16 should be ok since the highest number in the enum is 7. */
109    static const int numberOfButtons_ = 16;
110    //! Array of input events for every pressed key
111    InputEvent bindingsButtonPressed_[numberOfButtons_];
112    //! Array of input events for every released key
113    InputEvent bindingsButtonReleased_[numberOfButtons_];
114
115    //! Pointer to the instance of the singleton
116    static InputManager *singletonRef_s;
117  };
118}
119
120#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.