Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/input/ExtendedInputState.h @ 1637

Last change on this file since 1637 was 1637, checked in by rgrieder, 16 years ago

Finally! The InputManager is now working like I imagined it to. And it's even easier to use it as well.
A little explanation: Every time you change something about the input distribution, it is a change of 'state' represented by the class 'InputState'.
That can be for instance: "console", "game", "gui", etc. Every state has a name and a priority which describes who comes first. Now if one state doesn't handle mouse input or instance, then the one with the next lower priority gets it. To prevent that, you can add the 'EmptyHandler' to the state with setMouseHandler.
InputState is just an abstract base class. There are two classes implementing it: SimpleInputState and ExtendedInputState. The latter allows for multiple input handlers for one single device.

Basically, what you need to know is what you see in Orxonox.cc, InGameConsole.cc and Shell.cc.

  • Property svn:eol-style set to native
File size: 3.3 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
32*/
33
34#ifndef _ExtendedInputState_H__
35#define _ExtendedInputState_H__
36
37#include "core/CorePrereqs.h"
38
39#include <vector>
40
41#include "InputInterfaces.h"
42#include "InputState.h"
43
44namespace orxonox
45{
46
47    class _CoreExport ExtendedInputState : public InputState
48    {
49    public:
50        ExtendedInputState() { }
51        ~ExtendedInputState() { }
52
53        bool addKeyHandler        (KeyHandler* handler);
54        bool removeKeyHandler     (KeyHandler* handler);
55
56        bool addMouseHandler      (MouseHandler* handler);
57        bool removeMouseHandler   (MouseHandler* handler);
58
59        bool addJoyStickHandler   (JoyStickHandler* handler, unsigned int joyStickID);
60        bool removeJoyStickHandler(JoyStickHandler* handler, unsigned int joyStickID);
61        bool addJoyStickHandler   (JoyStickHandler* handler);
62        bool removeJoyStickHandler(JoyStickHandler* handler);
63
64        bool addHandler(InputTickable* handler);
65        bool removeHandler(InputTickable* handler);
66
67        void removeAndDestroyAllHandlers();
68
69    private:
70        void tickInput(float dt);
71        void tickInput(float dt, unsigned int device);
72
73        void keyPressed (const KeyEvent& evt);
74        void keyReleased(const KeyEvent& evt);
75        void keyHeld    (const KeyEvent& evt);
76
77        void mouseButtonPressed (MouseButton::Enum id);
78        void mouseButtonReleased(MouseButton::Enum id);
79        void mouseButtonHeld    (MouseButton::Enum id);
80        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
81        void mouseScrolled      (int abs, int rel);
82
83        void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
84        void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
85        void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
86        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);        void updateTickables();
87
88        void numberOfJoySticksChanged(unsigned int n);
89        void update();
90
91        std::vector<KeyHandler*>                    keyHandlers_;
92        std::vector<MouseHandler*>                  mouseHandlers_;
93        std::vector<std::vector<JoyStickHandler*> > joyStickHandlers_;
94        std::vector<JoyStickHandler*>               joyStickHandlersAll_;
95
96        std::vector<InputTickable*> allHandlers_;
97    };
98}
99
100#endif /* _ExtendedInputState_H__ */
Note: See TracBrowser for help on using the repository browser.