[Orxonox-commit 1143] r5864 - code/branches/core5/src/libraries/core/input

rgrieder at orxonox.net rgrieder at orxonox.net
Sat Oct 3 17:36:10 CEST 2009


Author: rgrieder
Date: 2009-10-03 17:36:10 +0200 (Sat, 03 Oct 2009)
New Revision: 5864

Modified:
   code/branches/core5/src/libraries/core/input/KeyDetector.cc
   code/branches/core5/src/libraries/core/input/KeyDetector.h
Log:
Missing changes for previous commit (whatever happened...)

Modified: code/branches/core5/src/libraries/core/input/KeyDetector.cc
===================================================================
--- code/branches/core5/src/libraries/core/input/KeyDetector.cc	2009-10-03 15:33:31 UTC (rev 5863)
+++ code/branches/core5/src/libraries/core/input/KeyDetector.cc	2009-10-03 15:36:10 UTC (rev 5864)
@@ -28,48 +28,45 @@
 
 #include "KeyDetector.h"
 
-#include "util/Debug.h"
+#include "core/ConsoleCommand.h"
 #include "core/CoreIncludes.h"
 #include "Button.h"
 
 namespace orxonox
 {
-    /**
-    @brief
-        Constructor
-    */
+    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
+    KeyDetector* KeyDetector::singletonPtr_s = 0;
+
     KeyDetector::KeyDetector()
+        : KeyBinder("")
     {
         RegisterObject(KeyDetector);
-    }
 
-    /**
-    @brief
-        Destructor
-    */
-    KeyDetector::~KeyDetector()
-    {
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
+        this->assignCommands();
     }
 
-    /**
-    @brief
-        Assigns all the buttons 'command' plus the button's name.
-    */
-    void KeyDetector::setCallbackCommand(const std::string& command)
+    void KeyDetector::assignCommands()
     {
-        callbackCommand_ = command;
+        // Assign every button/axis the same command, but with its name as argument
         clearBindings();
         for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
         {
-            it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
+            it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
             it->second->parse();
         }
     }
 
+    void KeyDetector::callback(const std::string& name)
+    {
+        // Call the registered function
+        if (this->callbackFunction_)
+            (*this->callbackFunction_)(name);
+    }
+
     void KeyDetector::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
     {
         KeyBinder::JoyStickQuantityChanged(joyStickList);
-        if (!callbackCommand_.empty())
-            setCallbackCommand(callbackCommand_);
+        this->assignCommands();
     }
 }

Modified: code/branches/core5/src/libraries/core/input/KeyDetector.h
===================================================================
--- code/branches/core5/src/libraries/core/input/KeyDetector.h	2009-10-03 15:33:31 UTC (rev 5863)
+++ code/branches/core5/src/libraries/core/input/KeyDetector.h	2009-10-03 15:36:10 UTC (rev 5864)
@@ -31,21 +31,31 @@
 
 #include "InputPrereqs.h"
 
-#include <string>
+#include "util/Singleton.h"
 #include "KeyBinder.h"
 
 namespace orxonox
 {
-    class _CoreExport KeyDetector : public KeyBinder
+    class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector>
     {
+        friend class Singleton<KeyDetector>;
+
     public:
         KeyDetector();
-        ~KeyDetector();
-        void setCallbackCommand(const std::string& command);
+        ~KeyDetector() { }
+
+        void setCallback(Functor* function) { this->callbackFunction_ = function; }
+
+    private:
+        KeyDetector(const KeyDetector&);
+
+        void callback(const std::string& name);
         void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
+        void assignCommands();
 
-    private:
-        std::string callbackCommand_;
+        Functor* callbackFunction_;
+        static std::string callbackCommand_s;
+        static KeyDetector* singletonPtr_s;
     };
 }
 




More information about the Orxonox-commit mailing list