Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 3, 2009, 5:36:10 PM (15 years ago)
Author:
rgrieder
Message:

Missing changes for previous commit (whatever happened…)

Location:
code/branches/core5/src/libraries/core/input
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/input/KeyDetector.cc

    r5738 r5864  
    2929#include "KeyDetector.h"
    3030
    31 #include "util/Debug.h"
     31#include "core/ConsoleCommand.h"
    3232#include "core/CoreIncludes.h"
    3333#include "Button.h"
     
    3535namespace orxonox
    3636{
    37     /**
    38     @brief
    39         Constructor
    40     */
     37    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
     38    KeyDetector* KeyDetector::singletonPtr_s = 0;
     39
    4140    KeyDetector::KeyDetector()
     41        : KeyBinder("")
    4242    {
    4343        RegisterObject(KeyDetector);
     44
     45        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
     46        this->assignCommands();
    4447    }
    4548
    46     /**
    47     @brief
    48         Destructor
    49     */
    50     KeyDetector::~KeyDetector()
     49    void KeyDetector::assignCommands()
    5150    {
    52     }
    53 
    54     /**
    55     @brief
    56         Assigns all the buttons 'command' plus the button's name.
    57     */
    58     void KeyDetector::setCallbackCommand(const std::string& command)
    59     {
    60         callbackCommand_ = command;
     51        // Assign every button/axis the same command, but with its name as argument
    6152        clearBindings();
    6253        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6354        {
    64             it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
     55            it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
    6556            it->second->parse();
    6657        }
     58    }
     59
     60    void KeyDetector::callback(const std::string& name)
     61    {
     62        // Call the registered function
     63        if (this->callbackFunction_)
     64            (*this->callbackFunction_)(name);
    6765    }
    6866
     
    7068    {
    7169        KeyBinder::JoyStickQuantityChanged(joyStickList);
    72         if (!callbackCommand_.empty())
    73             setCallbackCommand(callbackCommand_);
     70        this->assignCommands();
    7471    }
    7572}
  • code/branches/core5/src/libraries/core/input/KeyDetector.h

    r5738 r5864  
    3232#include "InputPrereqs.h"
    3333
    34 #include <string>
     34#include "util/Singleton.h"
    3535#include "KeyBinder.h"
    3636
    3737namespace orxonox
    3838{
    39     class _CoreExport KeyDetector : public KeyBinder
     39    class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector>
    4040    {
     41        friend class Singleton<KeyDetector>;
     42
    4143    public:
    4244        KeyDetector();
    43         ~KeyDetector();
    44         void setCallbackCommand(const std::string& command);
    45         void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     45        ~KeyDetector() { }
     46
     47        void setCallback(Functor* function) { this->callbackFunction_ = function; }
    4648
    4749    private:
    48         std::string callbackCommand_;
     50        KeyDetector(const KeyDetector&);
     51
     52        void callback(const std::string& name);
     53        void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     54        void assignCommands();
     55
     56        Functor* callbackFunction_;
     57        static std::string callbackCommand_s;
     58        static KeyDetector* singletonPtr_s;
    4959    };
    5060}
Note: See TracChangeset for help on using the changeset viewer.