Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/KeyDetector.cc @ 6896

Last change on this file since 6896 was 6428, checked in by rgrieder, 15 years ago

Changed config value handling in the KeyBinder. Doesn't change the interface though.

  • Property svn:eol-style set to native
File size: 2.8 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 "KeyDetector.h"
30
31#include "core/ConsoleCommand.h"
32#include "core/CoreIncludes.h"
33#include "core/ScopedSingletonManager.h"
34#include "Button.h"
35#include "InputManager.h"
36#include "InputState.h"
37
38namespace orxonox
39{
40    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
41    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
42
43    KeyDetector::KeyDetector()
44        : KeyBinder("")
45    {
46        RegisterObject(KeyDetector);
47
48        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
49        this->assignCommands();
50
51        inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector);
52        // Create a callback to avoid buttonHeld events after the key has been detected
53        inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance()));
54        inputState_->setHandler(this);
55    }
56
57    KeyDetector::~KeyDetector()
58    {
59        inputState_->setHandler(NULL);
60        InputManager::getInstance().destroyState("detector");
61    }
62
63    void KeyDetector::assignCommands()
64    {
65        // Assign every button/axis the same command, but with its name as argument
66        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
67            it->second->parse(callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_);
68    }
69
70    void KeyDetector::callback(const std::string& name)
71    {
72        // Call the registered function
73        if (this->callbackFunction_)
74            (*this->callbackFunction_)(name);
75    }
76
77    void KeyDetector::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
78    {
79        KeyBinder::JoyStickQuantityChanged(joyStickList);
80        this->assignCommands();
81    }
82}
Note: See TracBrowser for help on using the repository browser.