Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/libraries/core/input/KeyDetector.cc @ 5864

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

Missing changes for previous commit (whatever happened…)

  • Property svn:eol-style set to native
File size: 2.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 "KeyDetector.h"
30
31#include "core/ConsoleCommand.h"
32#include "core/CoreIncludes.h"
33#include "Button.h"
34
35namespace orxonox
36{
37    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
38    KeyDetector* KeyDetector::singletonPtr_s = 0;
39
40    KeyDetector::KeyDetector()
41        : KeyBinder("")
42    {
43        RegisterObject(KeyDetector);
44
45        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
46        this->assignCommands();
47    }
48
49    void KeyDetector::assignCommands()
50    {
51        // Assign every button/axis the same command, but with its name as argument
52        clearBindings();
53        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
54        {
55            it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
56            it->second->parse();
57        }
58    }
59
60    void KeyDetector::callback(const std::string& name)
61    {
62        // Call the registered function
63        if (this->callbackFunction_)
64            (*this->callbackFunction_)(name);
65    }
66
67    void KeyDetector::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
68    {
69        KeyBinder::JoyStickQuantityChanged(joyStickList);
70        this->assignCommands();
71    }
72}
Note: See TracBrowser for help on using the repository browser.