Changeset 3285 for code/branches/core4
- Timestamp:
- Jul 13, 2009, 6:41:58 PM (15 years ago)
- Location:
- code/branches/core4/src/core/input
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/InputDevice.h
r3279 r3285 138 138 std::string getClassName() 139 139 { 140 return InputDeviceNames::values[OISDeviceValue];140 return DeviceClass::getClassNameImpl(); 141 141 } 142 142 -
code/branches/core4/src/core/input/InputHandler.h
r3274 r3285 41 41 namespace orxonox 42 42 { 43 namespace ButtonEvent 44 { 45 //! Helper enum to deploy events with the help of templates 46 enum Value 47 { 48 Press, 49 Release, 50 Hold 51 }; 52 53 //! Enables function overloading with integer values 54 template <ButtonEvent::Value Event> 55 struct EnumToType { }; 56 typedef EnumToType<Press> TPress; 57 typedef EnumToType<Release> TRelease; 58 typedef EnumToType<Hold> THold; 59 } 60 61 namespace KeyboardModifier 62 { 63 //! Keyboard modifiers (shift, ctrl and alt) 64 enum Enum 65 { 66 Shift = 0x0000001, 67 Ctrl = 0x0000010, 68 Alt = 0x0000100 69 }; 70 } 71 72 //! Event argument for key events 73 class _CoreExport KeyEvent 74 { 75 public: 76 KeyEvent(const OIS::KeyEvent& evt) 77 : key_(static_cast<KeyCode::ByEnum>(evt.key)) 78 , text_(evt.text) 79 , modifiers_(0) 80 { } 81 bool operator==(const KeyEvent& rhs) const 82 { return rhs.key_ == key_; } 83 bool operator!=(const KeyEvent& rhs) const 84 { return rhs.key_ != key_; } 85 void setModifiers(int modifiers) 86 { modifiers_ = modifiers; } 87 88 bool isModifierDown(KeyboardModifier::Enum modifier) const 89 { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); } 90 KeyCode::ByEnum getKeyCode() const 91 { return key_; } 92 unsigned int getText() const { return text_; } 93 94 private: 95 KeyCode::ByEnum key_; 96 unsigned int text_; 97 int modifiers_; 98 }; 99 43 100 /** 44 101 @brief -
code/branches/core4/src/core/input/InputPrereqs.h
r3274 r3285 442 442 }; 443 443 } 444 445 namespace ButtonEvent446 {447 enum Value448 {449 Press,450 Release,451 Hold452 };453 454 template <ButtonEvent::Value Event>455 struct EnumToType { };456 typedef EnumToType<Press> TPress;457 typedef EnumToType<Release> TRelease;458 typedef EnumToType<Hold> THold;459 }460 461 462 namespace KeyboardModifier463 {464 enum Enum465 {466 Shift = 0x0000001,467 Ctrl = 0x0000010,468 Alt = 0x0000100469 };470 }471 472 class _CoreExport KeyEvent473 {474 public:475 KeyEvent(const OIS::KeyEvent& evt)476 : key_(static_cast<KeyCode::ByEnum>(evt.key))477 , text_(evt.text)478 , modifiers_(0)479 { }480 bool operator==(const KeyEvent& rhs) const481 { return rhs.key_ == key_; }482 bool operator!=(const KeyEvent& rhs) const483 { return rhs.key_ != key_; }484 void setModifiers(int modifiers)485 { modifiers_ = modifiers; }486 487 bool isModifierDown(KeyboardModifier::Enum modifier) const488 { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); }489 KeyCode::ByEnum getKeyCode() const490 { return key_; }491 unsigned int getText() const { return text_; }492 493 private:494 KeyCode::ByEnum key_;495 unsigned int text_;496 int modifiers_;497 };498 499 500 //-----------------------------------------------------------------------501 // Device type traits502 //-----------------------------------------------------------------------503 504 struct KeyboardTraits505 {506 typedef Keyboard DeviceClass;507 typedef OIS::Keyboard OISDeviceClass;508 typedef KeyEvent ButtonType;509 typedef KeyEvent& ButtonTypeParam;510 static const OIS::Type OISDeviceValue = OIS::OISKeyboard;511 };512 513 struct MouseTraits514 {515 typedef Mouse DeviceClass;516 typedef OIS::Mouse OISDeviceClass;517 typedef MouseButtonCode::ByEnum ButtonType;518 typedef MouseButtonCode::ByEnum ButtonTypeParam;519 static const OIS::Type OISDeviceValue = OIS::OISMouse;520 };521 522 struct JoyStickTraits523 {524 typedef JoyStick DeviceClass;525 typedef OIS::JoyStick OISDeviceClass;526 typedef JoyStickButtonCode::ByEnum ButtonType;527 typedef JoyStickButtonCode::ByEnum ButtonTypeParam;528 static const OIS::Type OISDeviceValue = OIS::OISJoyStick;529 };530 531 // Note: Entries correspond to OIS::Type enum532 namespace InputDeviceNames533 {534 const char* const values[] = { "", "Keyboard", "Mouse", "JoyStick" };535 }536 444 } 537 445 -
code/branches/core4/src/core/input/JoyStick.h
r3274 r3285 38 38 namespace orxonox 39 39 { 40 struct JoyStickTraits 41 { 42 typedef JoyStick DeviceClass; 43 typedef OIS::JoyStick OISDeviceClass; 44 typedef JoyStickButtonCode::ByEnum ButtonType; 45 typedef JoyStickButtonCode::ByEnum ButtonTypeParam; 46 static const OIS::Type OISDeviceValue = OIS::OISJoyStick; 47 }; 48 40 49 /** 41 50 @brief … … 93 102 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } 94 103 104 static std::string getClassNameImpl() { return "JoyStick"; } 105 95 106 std::string idString_; //!< ID string generated by the number of knobs and the device name 96 107 int povStates_[4]; //!< Internal states for the POVs -
code/branches/core4/src/core/input/Keyboard.h
r3275 r3285 31 31 32 32 #include "InputPrereqs.h" 33 #include "InputHandler.h" 33 34 #include "InputDevice.h" 34 35 35 36 namespace orxonox 36 37 { 38 struct KeyboardTraits 39 { 40 typedef Keyboard DeviceClass; 41 typedef OIS::Keyboard OISDeviceClass; 42 typedef KeyEvent ButtonType; 43 typedef KeyEvent& ButtonTypeParam; 44 static const OIS::Type OISDeviceValue = OIS::OISKeyboard; 45 }; 46 37 47 /** 38 48 @brief … … 63 73 bool keyReleased(const OIS::KeyEvent& arg); 64 74 75 static std::string getClassNameImpl() { return "Keyboard"; } 76 65 77 //! Bit mask representing keyboard modifiers 66 78 int modifiers_; -
code/branches/core4/src/core/input/Mouse.h
r3276 r3285 35 35 namespace orxonox 36 36 { 37 struct MouseTraits 38 { 39 typedef Mouse DeviceClass; 40 typedef OIS::Mouse OISDeviceClass; 41 typedef MouseButtonCode::ByEnum ButtonType; 42 typedef MouseButtonCode::ByEnum ButtonTypeParam; 43 static const OIS::Type OISDeviceValue = OIS::OISMouse; 44 }; 45 37 46 /** 38 47 @brief … … 92 101 bool mouseMoved(const OIS::MouseEvent &arg); 93 102 103 static std::string getClassNameImpl() { return "Mouse"; } 104 94 105 // HACK: 95 106 static Mouse* instancePointer_s;
Note: See TracChangeset
for help on using the changeset viewer.