Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 2, 2008, 10:44:57 PM (17 years ago)
Author:
rgrieder
Message:

merged input branch back to trunk. Not yet tested on tardis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/InputHandler.h

    r1062 r1219  
    3838
    3939#include <string>
    40 #include <OIS/OIS.h>
    41 
    42 #include "InputEvent.h"
     40#include "ois/OIS.h"
     41#include "OrxonoxClass.h"
     42#include "CommandExecutor.h"
    4343
    4444namespace orxonox
    4545{
    46   /**
    47     @brief Captures mouse and keyboard input while in the actual game mode.
    48     Manages the key bindings.
    49   */
    50   class _CoreExport InputHandlerGame
    51         : public OIS::KeyListener, public OIS::MouseListener
    52   {
    53   public:
    54     InputHandlerGame ();
    55     ~InputHandlerGame();
     46  namespace KeybindSetting
     47  {
     48    enum KeybindSetting
     49    {
     50      None,
     51      OnPress,
     52      OnRelease,
     53      Continuous,
     54    };
     55  }
     56
     57  /**
     58    @brief Interface class used for key input listeners.
     59  */
     60  class _CoreExport KeyHandler : public OIS::KeyListener
     61  {
     62  public:
     63    virtual ~KeyHandler() { }
     64    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
     65  };
     66
     67  /**
     68    @brief Interface class used for mouse input listeners.
     69  */
     70  class _CoreExport MouseHandler : public OIS::MouseListener
     71  {
     72  public:
     73    virtual ~MouseHandler() { }
     74    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
     75  };
     76
     77  /**
     78    @brief Interface class used for joy stick input listeners.
     79  */
     80  class _CoreExport JoyStickHandler
     81  {
     82  public:
     83    virtual ~JoyStickHandler() { }
     84                virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     85                virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     86    virtual bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     87                virtual bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis)   = 0;
     88                virtual bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     89                virtual bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     90                virtual bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     91  };
     92
     93  struct _CoreExport KeyBinding
     94  {
     95    std::string commandStr;
     96    CommandEvaluation evaluation;
     97  };
     98 
     99
     100  /**
     101    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     102           Manages the key bindings.
     103  */
     104  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
     105  {
     106  public:
     107    KeyBinder ();
     108    ~KeyBinder();
    56109
    57110    bool loadBindings();
    58 
    59   private:
    60     // input events
    61                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    62                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    63     bool mouseMoved   (const OIS::MouseEvent &arg);
     111    void clearBindings();
     112
     113    void setConfigValues();
     114
     115    std::string testtest;
     116
     117  private: // functions
     118
     119    bool executeBinding(KeyBinding &binding);
     120
    64121                bool keyPressed   (const OIS::KeyEvent   &arg);
    65122                bool keyReleased  (const OIS::KeyEvent   &arg);
    66 
    67     // temporary hack
    68     void callListeners(InputEvent &evt);
    69 
    70     /** denotes the maximum number of different keys there are in OIS.
    71         256 should be ok since the highest number in the enum is 237. */
    72     static const int numberOfKeys_s = 256;
     123                bool keyHeld      (const OIS::KeyEvent   &arg);
     124
     125    bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     126                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     127                bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     128    bool mouseMoved   (const OIS::MouseEvent &arg);
     129
     130                bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     131                bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);
     132                bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     133                bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis);
     134                bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     135                bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     136                bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     137
     138  private: // variables
     139
     140    //! denotes the number of different keys there are in OIS.
     141    static const int numberOfKeys_s = 0xEE;
    73142    //! Array of input events for every pressed key
    74     std::string bindingsKeyPressed_[numberOfKeys_s];
     143    KeyBinding bindingsKeyPress_  [numberOfKeys_s];
    75144    //! Array of input events for every released key
    76     std::string bindingsKeyReleased_[numberOfKeys_s];
    77 
    78     /** denotes the maximum number of different buttons there are in OIS.
    79         16 should be ok since the highest number in the enum is 7. */
    80     static const int numberOfButtons_s = 16;
    81     //! Array of input events for every pressed key
    82     std::string bindingsButtonPressed_[numberOfButtons_s];
    83     //! Array of input events for every released key
    84     std::string bindingsButtonReleased_[numberOfButtons_s];
     145    KeyBinding bindingsKeyRelease_[numberOfKeys_s];
     146    //! Array of input events for every held key
     147    KeyBinding bindingsKeyHold_   [numberOfKeys_s];
     148    //! Names of the keys as strings
     149    std::string keyNames_[numberOfKeys_s];
     150
     151    //! denotes the number of different mouse buttons there are in OIS.
     152    static const int numberOfMouseButtons_s = 8;
     153    //! Array of input events for every pressed mouse button
     154    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
     155    //! Array of input events for every released mouse button
     156    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
     157    //! Array of input events for every held mouse button
     158    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
     159    //! Names of the mouse buttons as strings
     160    std::string mouseButtonNames_[numberOfMouseButtons_s];
     161
     162    //! denotes the number of different joy stick buttons there are in OIS.
     163    static const int numberOfJoyStickButtons_s = 32;
     164    //! Array of input events for every pressed joy stick button
     165    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
     166    //! Array of input events for every released joy stick button
     167    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
     168    //! Array of input events for every held joy stick button
     169    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
     170    //! Names of the joy stick buttons as strings
     171    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
    85172
    86173  };
     
    91178    GUI.
    92179  */
    93   class _CoreExport InputHandlerGUI
    94         : public OIS::KeyListener, public OIS::MouseListener
    95   {
    96   public:
    97     InputHandlerGUI ();
    98     ~InputHandlerGUI();
    99 
    100   private:
    101     // input events
    102                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    103                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    104     bool mouseMoved   (const OIS::MouseEvent &arg);
    105                 bool keyPressed   (const OIS::KeyEvent   &arg);
    106                 bool keyReleased  (const OIS::KeyEvent   &arg);
    107   };
     180  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
     181  //{
     182  //public:
     183  //  GUIInputHandler ();
     184  //  ~GUIInputHandler();
     185
     186  //private:
     187  //  // input events
     188                //bool keyPressed   (const OIS::KeyEvent   &arg);
     189                //bool keyReleased  (const OIS::KeyEvent   &arg);
     190                //bool keyHeld      (const OIS::KeyEvent   &arg);
     191
     192  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     193                //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     194                //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     195  //  bool mouseMoved   (const OIS::MouseEvent &arg);
     196
     197                //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     198                //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     199                //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
     200                //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     201                //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     202                //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     203  //};
    108204
    109205}
Note: See TracChangeset for help on using the changeset viewer.