Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 14, 2008, 11:44:17 AM (16 years ago)
Author:
rgrieder
Message:

merged input branch into merge branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/core/InputHandler.cc

    r1268 r1272  
    3333
    3434#include "InputHandler.h"
     35#include "util/Convert.h"
    3536#include "Debug.h"
    3637#include "ConfigValueIncludes.h"
    3738#include "CoreIncludes.h"
    38 #include "util/Convert.h"
    39 #include "core/CommandExecutor.h"
     39#include "CommandExecutor.h"
    4040
    4141namespace orxonox
     
    267267        switch (j)
    268268        {
    269           // note: the first element in the struct is the string, so the following pointer
    270           //       arithmetic works.
    271269          case 0:
    272270            cont->getValue(&bindingsKeyPress_[i].commandStr);
    273271            break;
    274272          case 1:
    275             cont->getValue(bindingsKeyRelease_ + i);
     273            cont->getValue(&bindingsKeyRelease_[i].commandStr);
    276274            break;
    277275          case 2:
    278             cont->getValue(bindingsKeyHold_ + i);
     276            cont->getValue(&bindingsKeyHold_[i].commandStr);
    279277        }
    280278      }
     
    295293        {
    296294          case 0:
    297             cont->getValue(bindingsMouseButtonPress_ + i);
     295            cont->getValue(&bindingsMouseButtonPress_[i].commandStr);
    298296            break;
    299297          case 1:
    300             cont->getValue(bindingsMouseButtonRelease_ + i);
     298            cont->getValue(&bindingsMouseButtonRelease_[i].commandStr);
    301299            break;
    302300          case 2:
    303             cont->getValue(bindingsMouseButtonHold_ + i);
     301            cont->getValue(&bindingsMouseButtonHold_[i].commandStr);
    304302        }
    305303      }
     
    320318        {
    321319          case 0:
    322             cont->getValue(bindingsJoyStickButtonPress_ + i);
     320            cont->getValue(&bindingsJoyStickButtonPress_[i].commandStr);
    323321            break;
    324322          case 1:
    325             cont->getValue(bindingsJoyStickButtonRelease_ + i);
     323            cont->getValue(&bindingsJoyStickButtonRelease_[i].commandStr);
    326324            break;
    327325          case 2:
    328             cont->getValue(bindingsJoyStickButtonHold_ + i);
     326            cont->getValue(&bindingsJoyStickButtonHold_[i].commandStr);
    329327        }
    330328      }
     
    345343    for (int i = 0; i < numberOfMouseButtons_s; i++)
    346344    {
    347       bindingsMouseButtonPress_  [i] = "";
    348       bindingsMouseButtonRelease_[i] = "";
    349       bindingsMouseButtonHold_   [i] = "";
     345      bindingsMouseButtonPress_  [i].commandStr = "";
     346      bindingsMouseButtonRelease_[i].commandStr = "";
     347      bindingsMouseButtonHold_   [i].commandStr = "";
    350348    }
    351349    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
    352350    {
    353       bindingsJoyStickButtonPress_  [i] = "";
    354       bindingsJoyStickButtonRelease_[i] = "";
    355       bindingsJoyStickButtonHold_   [i] = "";
     351      bindingsJoyStickButtonPress_  [i].commandStr = "";
     352      bindingsJoyStickButtonRelease_[i].commandStr = "";
     353      bindingsJoyStickButtonHold_   [i].commandStr = "";
    356354    }
    357355  }
     
    370368    // evaluate the key bindings
    371369    // TODO: what if binding is invalid?
    372     //for (int i = 0; i < numberOfKeys_s; i++)
    373     //{
    374     //  if (bindingsKeyPress_[i].commandStr != "")
    375     //  {
    376     //    bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);
    377     //    bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();
    378     //  }
    379     //}
     370    for (int i = 0; i < numberOfKeys_s; i++)
     371    {
     372      if (bindingsKeyPress_[i].commandStr != "")
     373      {
     374        bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);
     375        bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();
     376      }
     377    }
    380378
    381379    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
     
    383381  }
    384382
    385   bool KeyBinder::executeBinding(KeyBinding& binding)
     383  bool KeyBinder::executeSimpleBinding(KeyBinding& binding)
    386384  {
    387385    if (binding.commandStr != "")
    388386    {
    389       //if (binding.commandStr != binding.evaluation.getCommandString())
    390       //{
    391       //  // key binding has changed, reevaluate the command string.
    392       //  binding.evaluation = CommandExecutor::evaluate(binding.commandStr);
    393       //  binding.commandStr = binding.evaluation.getCommandString();
    394       //}
     387      if (binding.commandStr != binding.evaluation.getCommandString())
     388      {
     389        // key binding has changed, reevaluate the command string.
     390        binding.evaluation = CommandExecutor::evaluate(binding.commandStr);
     391        binding.commandStr = binding.evaluation.getCommandString();
     392      }
    395393      COUT(ORX_DEBUG) << "Keybinding: Executing command: " << binding.commandStr << std::endl;
    396394      CommandExecutor::execute(binding.commandStr);
     
    405403    @param e Event information
    406404  */
    407   bool KeyBinder::keyPressed(const OIS::KeyEvent &e)
    408   {
    409     //COUT(ORX_DEBUG) << "Key: " << e.key << std::endl;
    410     // find the appropriate key binding
    411     executeBinding(bindingsKeyPress_[int(e.key)]);
    412      
     405  bool KeyBinder::keyPressed(const KeyEvent& evt)
     406  {
     407    // find the appropriate key binding
     408    executeSimpleBinding(bindingsKeyPress_[int(evt.key)]);
     409
    413410    return true;
    414411  }
     
    418415    @param e Event information
    419416  */
    420   bool KeyBinder::keyReleased(const OIS::KeyEvent &e)
    421   {
    422     // find the appropriate key binding
    423     executeBinding(bindingsKeyRelease_[int(e.key)]);
     417  bool KeyBinder::keyReleased(const KeyEvent& evt)
     418  {
     419    // find the appropriate key binding
     420    executeSimpleBinding(bindingsKeyRelease_[int(evt.key)]);
    424421
    425422    return true;
     
    428425  /**
    429426    @brief Event handler for the keyHeld Event.
    430     @param e Event information
    431   */
    432   bool KeyBinder::keyHeld(const OIS::KeyEvent &e)
    433   {
    434     // find the appropriate key binding
    435     executeBinding(bindingsKeyHold_[int(e.key)]);
     427    @param e Mouse state information
     428  */
     429  bool KeyBinder::keyHeld(const KeyEvent& evt)
     430  {
     431    // find the appropriate key binding
     432    executeSimpleBinding(bindingsKeyHold_[int(evt.key)]);
    436433
    437434    return true;
     
    440437  /**
    441438    @brief Event handler for the mouseMoved Event.
    442     @param e Event information
    443   */
    444   bool KeyBinder::mouseMoved(const OIS::MouseEvent &e)
     439    @param e Mouse state information
     440  */
     441  bool KeyBinder::mouseMoved(const MouseState &evt)
     442  {
     443    /*if (bindingMouseMoved_.commandStr != "")
     444    {
     445      if (bindingMouseMoved_.commandStr != bindingMouseMoved_.evaluation.getCommandString())
     446      {
     447        // key binding has changed, reevaluate the command string.
     448        bindingMouseMoved_.evaluation = CommandExecutor::evaluate(bindingMouseMoved_.commandStr);
     449        bindingMouseMoved_.commandStr = bindingMouseMoved_.evaluation.getCommandString();
     450      }
     451      COUT(3) << "Executing command: " << bindingMouseMoved_.commandStr << std::endl;
     452
     453      bindingMouseMoved_.evaluation.setEvaluatedParameter(
     454      CommandExecutor::execute(bindingMouseMoved_.commandStr);
     455    }*/
     456
     457    return true;
     458  }
     459
     460  /**
     461    @brief Event handler for the mouseScrolled Event.
     462    @param e Mouse state information
     463  */
     464  bool KeyBinder::mouseScrolled(const MouseState &evt)
    445465  {
    446466    return true;
     
    452472    @param id The ID of the mouse button
    453473  */
    454   bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    455   {
    456     // find the appropriate key binding
    457     std::string cmdStr = bindingsMouseButtonPress_[int(id)];
    458     if (cmdStr != "")
    459     {
    460       CommandExecutor::execute(cmdStr);
    461       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    462     }
     474  bool KeyBinder::mouseButtonPressed(const MouseState& state, MouseButton::Enum id)
     475  {
     476    // find the appropriate key binding
     477    executeSimpleBinding(bindingsMouseButtonPress_[int(id)]);
    463478
    464479    return true;
     
    470485    @param id The ID of the mouse button
    471486  */
    472   bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    473   {
    474     // find the appropriate key binding
    475     std::string cmdStr = bindingsMouseButtonRelease_[int(id)];
    476     if (cmdStr != "")
    477     {
    478       CommandExecutor::execute(cmdStr);
    479       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    480     }
     487  bool KeyBinder::mouseButtonReleased(const MouseState& state, MouseButton::Enum id)
     488  {
     489    // find the appropriate key binding
     490    executeSimpleBinding(bindingsMouseButtonRelease_[int(id)]);
    481491
    482492    return true;
     
    488498    @param id The ID of the mouse button
    489499  */
    490   bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    491   {
    492     // find the appropriate key binding
    493     std::string cmdStr = bindingsMouseButtonHold_[int(id)];
    494     if (cmdStr != "")
    495     {
    496       CommandExecutor::execute(cmdStr);
    497       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    498     }
    499 
    500     return true;
    501   }
    502 
    503   bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    504   {
    505     // find the appropriate key binding
    506     std::string cmdStr = bindingsJoyStickButtonPress_[button];
    507     if (cmdStr != "")
    508     {
    509       CommandExecutor::execute(cmdStr);
    510       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    511     }
    512 
    513     return true;
    514   }
    515 
    516   bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    517   {
    518     // find the appropriate key binding
    519     std::string cmdStr = bindingsJoyStickButtonRelease_[button];
    520     if (cmdStr != "")
    521     {
    522       CommandExecutor::execute(cmdStr);
    523       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    524     }
    525 
    526     return true;
    527   }
    528 
    529   bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button)
    530   {
    531     // find the appropriate key binding
    532     std::string cmdStr = bindingsJoyStickButtonHold_[button];
    533     if (cmdStr != "")
    534     {
    535       CommandExecutor::execute(cmdStr);
    536       //COUT(3) << "Executing command: " << cmdStr << std::endl;
    537     }
    538 
    539     return true;
    540   }
    541 
    542   bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis)
    543   {
    544     return true;
    545   }
    546 
    547   bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
    548   {
    549     return true;
    550   }
    551 
    552   bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
    553   {
    554     return true;
    555   }
    556 
    557   bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     500  bool KeyBinder::mouseButtonHeld(const MouseState& state, MouseButton::Enum id)
     501  {
     502    // find the appropriate key binding
     503    executeSimpleBinding(bindingsMouseButtonHold_[int(id)]);
     504
     505    return true;
     506  }
     507
     508  bool KeyBinder::joyStickButtonPressed(const JoyStickState& state, int button)
     509  {
     510    // find the appropriate key binding
     511    executeSimpleBinding(bindingsJoyStickButtonPress_[button]);
     512
     513    return true;
     514  }
     515
     516  bool KeyBinder::joyStickButtonReleased(const JoyStickState& state, int button)
     517  {
     518    // find the appropriate key binding
     519    executeSimpleBinding(bindingsJoyStickButtonRelease_[button]);
     520
     521    return true;
     522  }
     523
     524  bool KeyBinder::joyStickButtonHeld(const JoyStickState& state, int button)
     525  {
     526    // find the appropriate key binding
     527    executeSimpleBinding(bindingsJoyStickButtonHold_[button]);
     528
     529    return true;
     530  }
     531
     532  bool KeyBinder::joyStickAxisMoved(const JoyStickState& state, int axis)
     533  {
     534    return true;
     535  }
     536
     537  bool KeyBinder::joyStickSliderMoved(const JoyStickState& state, int index)
     538  {
     539    return true;
     540  }
     541
     542  bool KeyBinder::joyStickPovMoved(const JoyStickState& state, int index)
     543  {
     544    return true;
     545  }
     546
     547  bool KeyBinder::joyStickVector3Moved(const JoyStickState& state, int index)
    558548  {
    559549    return true;
     
    616606  //  @param id The ID of the mouse button
    617607  //*/
    618   //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     608  //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton id)
    619609  //{
    620610    ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
     
    627617  //  @param id The ID of the mouse button
    628618  //*/
    629   //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     619  //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton id)
    630620  //{
    631621    ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
Note: See TracChangeset for help on using the changeset viewer.