Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core4/src/core/input/InputState.cc @ 3276

Last change on this file since 3276 was 3274, checked in by rgrieder, 15 years ago

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

  • Property svn:eol-style set to native
File size: 3.4 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#include "InputState.h"
30#include "core/Functor.h"
31
32namespace orxonox
33{
34    InputState::InputState()
35        : priority_(0)
36        , bAlwaysGetsInput_(false)
37        , bTransparent_(false)
38        , bExpired_(true)
39        , handlers_(2)
40        , joyStickHandlerAll_(0)
41        , enterFunctor_(0)
42        , leaveFunctor_(0)
43    {
44    }
45
46    bool InputState::isInputDeviceEnabled(unsigned int device)
47    {
48        if (device < handlers_.size())
49            return handlers_[device] != NULL;
50        else
51            return false;
52    }
53
54    void InputState::JoyStickQuantityChanged(unsigned int n)
55    {
56        unsigned int oldSize = handlers_.size();
57        handlers_.resize(InputDeviceEnumerator::FirstJoyStick + n, NULL);
58
59        for (unsigned int i = oldSize; i < handlers_.size(); ++i)
60            handlers_[i] = joyStickHandlerAll_;
61
62        bExpired_ = true;
63    }
64
65    /**
66    @brief
67        Adds a joy stick handler.
68    @param handler
69        Pointer to the handler object.
70    @param joyStickID
71        ID of the joy stick
72    @return
73        True if added, false otherwise.
74    */
75    bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick)
76    {
77        unsigned device = joyStick + firstJoyStickIndex_s;
78        if (joyStick >= handlers_.size() - device)
79            return false;
80
81        handlers_[device] = handler;
82        bExpired_ = true;
83        return true;
84    }
85
86    /**
87    @brief
88        Adds a joy stick handler.
89    @param handler
90        Pointer to the handler object.
91    @return
92        True if added, false if handler already existed.
93    */
94    bool InputState::setJoyStickHandler(InputHandler* handler)
95    {
96        joyStickHandlerAll_ = handler;
97        for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i)
98            handlers_[i] = handler;
99        bExpired_ = true;
100        return true;
101    }
102
103    /**
104    @brief
105        Adds a handler of any kind. dynamic_cast determines to which list it is added.
106    @param handler
107        Pointer to the handler object.
108    @return
109        True if added, false if handler already existed.
110    */
111    bool InputState::setHandler(InputHandler* handler)
112    {
113        setKeyHandler(handler);
114        setMouseHandler(handler);
115        return setJoyStickHandler(handler);
116    }
117
118    void InputState::entered()
119    {
120        if (enterFunctor_)
121            (*enterFunctor_)();
122           
123    }
124
125    void InputState::left()
126    {
127        if (leaveFunctor_)
128            (*leaveFunctor_)();
129    }
130}
Note: See TracBrowser for help on using the repository browser.