Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/InputState.cc @ 7150

Last change on this file since 7150 was 6746, checked in by rgrieder, 15 years ago

Merged gamestates2 branch back to trunk.
This brings in some heavy changes in the GUI framework.
It should also fix problems with triggered asserts in the InputManager.

Note: PickupInventory does not seem to work —> Segfault when showing because before, the owner in GUIOverlay::setGUIName is already NULL.
I haven't tested it before, so I can't tell whether it's my changes.

  • 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#include "InputState.h"
30#include "core/Functor.h"
31
32namespace orxonox
33{
34    //! Sets priority of it's a high priority and resizes the handler list
35    InputState::InputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
36        : name_(name)
37        , bAlwaysGetsInput_(bAlwaysGetsInput)
38        , bTransparent_(bTransparent)
39        , exclusiveMouse_(TriBool::Dontcare)
40        , bExpired_(true)
41        , handlers_(2)
42        , joyStickHandlerAll_(0)
43        , enterFunctor_(0)
44        , leaveFunctor_(0)
45    {
46        if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
47            priority_ = priority;
48        else
49            priority_ = 0;
50
51        handlers_.resize(InputDeviceEnumerator::FirstJoyStick + this->getJoyStickList().size(), NULL);
52    }
53
54    bool InputState::isInputDeviceEnabled(unsigned int device)
55    {
56        if (device < handlers_.size())
57            return handlers_[device] != NULL;
58        else
59            return false;
60    }
61
62    //! Called by JoyStickQuantityListener upon joy stick adding/removal
63    void InputState::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
64    {
65        unsigned int oldSize = handlers_.size();
66        handlers_.resize(InputDeviceEnumerator::FirstJoyStick + joyStickList.size(), NULL);
67
68        for (unsigned int i = oldSize; i < handlers_.size(); ++i)
69            handlers_[i] = joyStickHandlerAll_;
70
71        bExpired_ = true;
72    }
73
74    bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick)
75    {
76        unsigned device = joyStick + firstJoyStickIndex_s;
77        if (joyStick >= handlers_.size() - device)
78            return false;
79
80        handlers_[device] = handler;
81        bExpired_ = true;
82        return true;
83    }
84
85    void InputState::setJoyStickHandler(InputHandler* handler)
86    {
87        joyStickHandlerAll_ = handler;
88        for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i)
89            handlers_[i] = handler;
90        bExpired_ = true;
91    }
92
93    void InputState::setHandler(InputHandler* handler)
94    {
95        setKeyHandler(handler);
96        setMouseHandler(handler);
97        setJoyStickHandler(handler);
98    }
99
100    void InputState::entered()
101    {
102        if (enterFunctor_)
103            (*enterFunctor_)();
104
105    }
106
107    void InputState::left()
108    {
109        if (leaveFunctor_)
110            (*leaveFunctor_)();
111    }
112}
Note: See TracBrowser for help on using the repository browser.