Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource/src/core/input/InputState.cc @ 3363

Last change on this file since 3363 was 3327, checked in by rgrieder, 15 years ago

Merged all remaining revisions from core4 back to the trunk.

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