Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputHandler.h @ 1155

Last change on this file since 1155 was 1118, checked in by rgrieder, 17 years ago
  • classed FloatParser to ExprParser class
File size: 3.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 Different definitions of input processing.
32 */
33
34#ifndef _InputHandler_H__
35#define _InputHandler_H__
36
37#include "CorePrereqs.h"
38
39#include <string>
40#include <list>
41#include <OIS/OIS.h>
42
43#include "InputEvent.h"
44
45namespace orxonox
46{
47  namespace KeybindSetting
48  {
49    enum KeybindSetting
50    {
51      None,
52      OnPress,
53      OnRelease,
54      Continuous,
55    };
56  }
57
58  class _CoreExport BaseInputHandler
59      : public OIS::KeyListener, public OIS::MouseListener
60  {
61    virtual void tick(float dt) = 0;
62  };
63   
64  /**
65    @brief Captures mouse and keyboard input while in the actual game mode.
66    Manages the key bindings.
67  */
68  class _CoreExport InputHandlerGame : public BaseInputHandler
69  {
70  public:
71    InputHandlerGame ();
72    ~InputHandlerGame();
73
74    bool loadBindings();
75
76  private:
77    // input events
78                bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
79                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
80    bool mouseMoved   (const OIS::MouseEvent &arg);
81                bool keyPressed   (const OIS::KeyEvent   &arg);
82                bool keyReleased  (const OIS::KeyEvent   &arg);
83
84    void tick(float dt);
85
86    // temporary hack
87    void callListeners(InputEvent &evt);
88
89    //! Stores all the keys that are down
90    std::list<OIS::KeyCode> keysDown_;
91
92    /** denotes the maximum number of different keys there are in OIS.
93        256 should be ok since the highest number in the enum is 237. */
94    static const int numberOfKeys_s = 256;
95    //! Array of input events for every pressed key
96    std::string bindingsKeyPress_[numberOfKeys_s];
97    //! Array of input events for every released key
98    std::string bindingsKeyRelease_[numberOfKeys_s];
99    //! Array of input events for every holding key
100    std::string bindingsKeyHold_[numberOfKeys_s];
101
102    /** denotes the maximum number of different buttons there are in OIS.
103        16 should be ok since the highest number in the enum is 7. */
104    static const int numberOfButtons_s = 16;
105    //! Array of input events for every pressed key
106    std::string bindingsButtonPressed_[numberOfButtons_s];
107    //! Array of input events for every released key
108    std::string bindingsButtonReleased_[numberOfButtons_s];
109
110  };
111
112
113  /**
114    @brief Captures mouse and keyboard input and distributes it to the
115    GUI.
116  */
117  class _CoreExport InputHandlerGUI : public BaseInputHandler
118  {
119  public:
120    InputHandlerGUI ();
121    ~InputHandlerGUI();
122
123    void tick(float dt);
124
125  private:
126    // input events
127                bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
128                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
129    bool mouseMoved   (const OIS::MouseEvent &arg);
130                bool keyPressed   (const OIS::KeyEvent   &arg);
131                bool keyReleased  (const OIS::KeyEvent   &arg);
132  };
133
134}
135
136#endif /* _InputHandler_H__ */
Note: See TracBrowser for help on using the repository browser.