Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/core/input/KeyDetector.cc @ 10458

Last change on this file since 10458 was 10458, checked in by landauf, 9 years ago

renamed ScopedSingletonManager to ScopedSingletonWrapper. removed static maps.

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