| 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 _InputHandler_H__ |
|---|
| 35 | #define _InputHandler_H__ |
|---|
| 36 | |
|---|
| 37 | #include <OIS/OIS.h> |
|---|
| 38 | |
|---|
| 39 | #include "OrxonoxPrereqs.h" |
|---|
| 40 | #include "core/Tickable.h" |
|---|
| 41 | #include "InputEvent.h" |
|---|
| 42 | |
|---|
| 43 | namespace orxonox |
|---|
| 44 | { |
|---|
| 45 | /** |
|---|
| 46 | @brief Captures and distributes mouse and keyboard input. |
|---|
| 47 | It resolves the key bindings to InputEvents which can be heard by |
|---|
| 48 | implementing the InputEventListener interface. |
|---|
| 49 | */ |
|---|
| 50 | class _OrxonoxExport InputHandler |
|---|
| 51 | : public Tickable, public OIS::KeyListener, public OIS::MouseListener |
|---|
| 52 | { |
|---|
| 53 | //friend class ClassIdentifier<InputHandler>; |
|---|
| 54 | public: |
|---|
| 55 | bool initialise(size_t windowHnd, int windowWidth, int windowHeight); |
|---|
| 56 | void destroyDevices(); |
|---|
| 57 | void tick(float dt); |
|---|
| 58 | void setWindowExtents(int width, int height); |
|---|
| 59 | |
|---|
| 60 | // Temporary solutions. Will be removed soon! |
|---|
| 61 | OIS::Mouse *getMouse() { return this->mouse_ ; } |
|---|
| 62 | OIS::Keyboard *getKeyboard() { return this->keyboard_; } |
|---|
| 63 | |
|---|
| 64 | static InputHandler* getSingleton(); |
|---|
| 65 | static void destroy(); |
|---|
| 66 | |
|---|
| 67 | private: |
|---|
| 68 | // don't mess with a Singleton |
|---|
| 69 | InputHandler (); |
|---|
| 70 | InputHandler (const InputHandler&); |
|---|
| 71 | InputHandler& operator=(const InputHandler& instance); |
|---|
| 72 | ~InputHandler(); |
|---|
| 73 | |
|---|
| 74 | void callListeners(InputEvent &evt); |
|---|
| 75 | |
|---|
| 76 | // input events |
|---|
| 77 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
|---|
| 78 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
|---|
| 79 | bool mouseMoved (const OIS::MouseEvent &arg); |
|---|
| 80 | bool keyPressed (const OIS::KeyEvent &arg); |
|---|
| 81 | bool keyReleased (const OIS::KeyEvent &arg); |
|---|
| 82 | |
|---|
| 83 | OIS::InputManager *inputSystem_; //!< OIS input manager |
|---|
| 84 | OIS::Keyboard *keyboard_; //!< OIS mouse |
|---|
| 85 | OIS::Mouse *mouse_; //!< OIS keyboard |
|---|
| 86 | |
|---|
| 87 | /** denotes the maximum number of different keys there are in OIS. |
|---|
| 88 | 256 should be ok since the highest number in the enum is 237. */ |
|---|
| 89 | static const int numberOfKeys_ = 256; |
|---|
| 90 | //! Array of input events for every pressed key |
|---|
| 91 | InputEvent bindingsKeyPressed_[numberOfKeys_]; |
|---|
| 92 | //! Array of input events for every released key |
|---|
| 93 | InputEvent bindingsKeyReleased_[numberOfKeys_]; |
|---|
| 94 | |
|---|
| 95 | /** denotes the maximum number of different buttons there are in OIS. |
|---|
| 96 | 16 should be ok since the highest number in the enum is 7. */ |
|---|
| 97 | static const int numberOfButtons_ = 16; |
|---|
| 98 | //! Array of input events for every pressed key |
|---|
| 99 | InputEvent bindingsButtonPressed_[numberOfButtons_]; |
|---|
| 100 | //! Array of input events for every released key |
|---|
| 101 | InputEvent bindingsButtonReleased_[numberOfButtons_]; |
|---|
| 102 | |
|---|
| 103 | //! Pointer to the instance of the singleton |
|---|
| 104 | static InputHandler *singletonRef_s; |
|---|
| 105 | }; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | #endif /* _InputHandler_H__ */ |
|---|