Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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