Index: code/branches/input/src/core/InputManager.h
===================================================================
--- code/branches/input/src/core/InputManager.h	(revision 1158)
+++ code/branches/input/src/core/InputManager.h	(revision 1182)
@@ -38,4 +38,6 @@
 #include "CorePrereqs.h"
 
+#include <map>
+#include <list>
 #include <OIS/OIS.h>
 
@@ -46,18 +48,4 @@
 {
   /**
-    @brief Designates the way input is handled currently.
-    IM_GUI:      All the OIS input events are passed to CEGUI
-    IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer
-    IM_INGAME:   Normal game mode. Key bindings and mouse are active.
-  */
-  enum InputMode
-  {
-    IM_GUI      = 0,
-    IM_KEYBOARD = 1,
-    IM_INGAME   = 2,
-    IM_UNINIT   = 3,
-  };
-
-  /**
     @brief Captures and distributes mouse and keyboard input.
     It resolves the key bindings to InputEvents which can be heard by
@@ -65,23 +53,61 @@
   */
   class _CoreExport InputManager
-        : public Tickable
+        : public Tickable,
+          public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener
   {
   public:
-    bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
-    void destroy();
+    /**
+      @brief Designates the way input is handled currently.
+      IM_GUI:    All the OIS input events are passed to CEGUI
+      IM_BUFFER: Only keyboard input is captured and passed to the InputBuffer
+      IM_NORMAL: Normal game mode. Key bindings and mouse are active.
+    */
+    enum InputState
+    {
+      IS_UNINIT,
+      IS_NONE,
+      IS_NORMAL,
+      IS_GUI,
+      IS_CONSOLE,
+      IS_CUSTOM
+    };
+
+  public:
     void tick(float dt);
-    void setWindowExtents(int width, int height);
-    InputMode getInputMode();
 
-    // temporary hack
-    void feedInputBuffer(InputBuffer* buffer);
+    static bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
+    static void destroy();
+
+    static void setWindowExtents(int width, int height);
+    static void setInputState(const InputState state);
+    static InputState getInputState();
+
+    static bool addKeyListener(OIS::KeyListener* listener, const std::string& name);
+    //static bool removeKeyListener(OIS::KeyListener* listener);
+    static bool removeKeyListener(const std::string& name);
+    static bool enableKeyListener(const std::string& name);
+    static bool disableKeyListener(const std::string& name);
+    static OIS::KeyListener* getKeyListener(const std::string& name);
+    static bool isKeyListenerActive(const std::string& name);
+
+    static bool addMouseListener(OIS::MouseListener* listener, const std::string& name);
+    //static bool removeMouseListener(OIS::MouseListener* listener);
+    static bool removeMouseListener(const std::string& name);
+    static bool enableMouseListener(const std::string& name);
+    static bool disableMouseListener(const std::string& name);
+    static OIS::MouseListener* getMouseListener(const std::string& name);
+    static bool isMouseListenerActive(const std::string& name);
+
+    static bool addJoyStickListener(OIS::JoyStickListener* listener, const std::string& name);
+    //static bool removeJoyStickListener(OIS::JoyStickListener* listener);
+    static bool removeJoyStickListener(const std::string& name);
+    static bool enableJoyStickListener(const std::string& name);
+    static bool disableJoyStickListener(const std::string& name);
+    static OIS::JoyStickListener* getJoyStickListener(const std::string& name);
+    static bool isJoyStickListenerActive(const std::string& name);
 
     // Temporary solutions. Will be removed soon!
-    OIS::Mouse    *getMouse()    { return this->mouse_   ; }
-    OIS::Keyboard *getKeyboard() { return this->keyboard_; }
-
-    static InputManager& getSingleton();
-    static InputManager* getSingletonPtr() { return &getSingleton(); }
-    static void setInputMode(int mode);
+    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
+    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
 
   private:
@@ -91,17 +117,76 @@
     ~InputManager();
 
-    OIS::InputManager *inputSystem_;    //!< OIS input manager
-    OIS::Keyboard     *keyboard_;       //!< OIS mouse
-    OIS::Mouse        *mouse_;          //!< OIS keyboard
+    bool _initialise(size_t windowHnd, int windowWidth, int windowHeight);
+    void _destroy();
+    void _setDefaultState();
+    void _loadBindings();
 
-    InputMode          currentMode_;    //!< Input mode currently used
-    InputMode          setMode_;        //!< Input mode that has been set lately
-    InputHandlerGUI   *handlerGUI_;     //!< Handles the input if in GUI mode
-    // FIXME: insert the InputBuffer once merged with core2
-    InputBuffer       *handlerBuffer_;  //!< Handles the input if in Buffer mode
-    InputHandlerGame  *handlerGame_;    //!< Handles the input if in Game mode
+    // input events
+		bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
+		bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
+    bool mouseMoved    (const OIS::MouseEvent    &arg);
+		bool keyPressed    (const OIS::KeyEvent      &arg);
+		bool keyReleased   (const OIS::KeyEvent      &arg);
+		bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
+		bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
+		bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
+		bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
+		bool povMoved      (const OIS::JoyStickEvent &arg, int id);
 
-    //! Pointer to the instance of the singleton
-    //static InputManager *singletonRef_s;
+    static InputManager& _getSingleton();
+    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
+
+  private:
+    OIS::InputManager* inputSystem_;    //!< OIS input manager
+    OIS::Keyboard*     keyboard_;       //!< OIS mouse
+    OIS::Mouse*        mouse_;          //!< OIS keyboard
+
+    InputState state_;
+    InputState stateRequest_;
+
+    std::list<OIS::KeyCode> keysDown_;
+
+    bool bDefaultKeyInput;
+    bool bDefaultMouseInput;
+    bool bDefaultJoyStickInput;
+
+    std::map<std::string, OIS::KeyListener*>      keyListeners_;
+    std::list<OIS::KeyListener*>                  activeKeyListeners_;
+    std::map<std::string, OIS::MouseListener*>    mouseListeners_;
+    std::list<OIS::MouseListener*>                activeMouseListeners_;
+    std::map<std::string, OIS::JoyStickListener*> joystickListeners_;
+    std::list<OIS::JoyStickListener*>             activeJoyStickListeners_;
+
+
+    /** denotes the maximum number of different keys there are in OIS.
+        256 should be ok since the highest number in the enum is 237. */
+    static const int numberOfKeys_s = 256;
+    //! Array of input events for every pressed key
+    std::string bindingsKeyPress_  [numberOfKeys_s];
+    //! Array of input events for every released key
+    std::string bindingsKeyRelease_[numberOfKeys_s];
+    //! Array of input events for every held key
+    std::string bindingsKeyHold_   [numberOfKeys_s];
+
+    /** denotes the maximum number of different buttons there are in OIS.
+        16 should be ok since the highest number in the enum is 7. */
+    static const int numberOfMouseButtons_s = 16;
+    //! Array of input events for every pressed mouse button
+    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
+    //! Array of input events for every released mouse button
+    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
+    //! Array of input events for every held mouse button
+    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
+
+    /** denotes the maximum number of different buttons there are in OIS.
+        32 should be ok. */
+    static const int numberOfJoyStickButtons_s = 32;
+    //! Array of input events for every pressed joystick button
+    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
+    //! Array of input events for every released joystick button
+    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
+    //! Array of input events for every held joystick button
+    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
+
   };
 }
