clientButtonDevice.I 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Filename: clientButtonDevice.I
  2. // Created by: drose (26Jan01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. ////////////////////////////////////////////////////////////////////
  6. // Function: ClientButtonDevice::ButtonState::Constructor
  7. // Access: Public
  8. // Description:
  9. ////////////////////////////////////////////////////////////////////
  10. INLINE ClientButtonDevice::ButtonState::
  11. ButtonState() :
  12. _handle(ButtonHandle::none()),
  13. _state(S_unknown)
  14. {
  15. }
  16. ////////////////////////////////////////////////////////////////////
  17. // Function: ClientButtonDevice::get_num_buttons
  18. // Access: Public
  19. // Description: Returns the number of buttons known to the
  20. // ClientButtonDevice. This includes those buttons
  21. // whose state has been seen, as well as buttons that
  22. // have been associated with a ButtonHandle even if
  23. // their state is unknown. This number may change as
  24. // more buttons are discovered.
  25. ////////////////////////////////////////////////////////////////////
  26. INLINE int ClientButtonDevice::
  27. get_num_buttons() const {
  28. return _buttons.size();
  29. }
  30. ////////////////////////////////////////////////////////////////////
  31. // Function: ClientButtonDevice::set_button_map
  32. // Access: Public
  33. // Description: Associates the indicated ButtonHandle with the button
  34. // of the indicated index number. When the given button
  35. // index changes state, a corresponding ButtonEvent will
  36. // be generated with the given ButtonHandle. Pass
  37. // ButtonHandle::none() to turn off any association.
  38. //
  39. // It is not necessary to call this if you simply want
  40. // to query the state of the various buttons by index
  41. // number; this is only necessary in order to generate
  42. // ButtonEvents when the buttons change state.
  43. ////////////////////////////////////////////////////////////////////
  44. INLINE void ClientButtonDevice::
  45. set_button_map(int index, ButtonHandle button) {
  46. ensure_button_index(index);
  47. nassertv(index >= 0 && index < (int)_buttons.size());
  48. _buttons[index]._handle = button;
  49. }
  50. ////////////////////////////////////////////////////////////////////
  51. // Function: ClientButtonDevice::get_button_map
  52. // Access: Public
  53. // Description: Returns the ButtonHandle that was previously
  54. // associated with the given index number by
  55. // a call to set_button_map(), or ButtonHandle::none()
  56. // if no button was associated.
  57. ////////////////////////////////////////////////////////////////////
  58. INLINE ButtonHandle ClientButtonDevice::
  59. get_button_map(int index) const {
  60. if (index >= 0 && index < (int)_buttons.size()) {
  61. return _buttons[index]._handle;
  62. } else {
  63. return ButtonHandle::none();
  64. }
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: ClientButtonDevice::get_button_state
  68. // Access: Public
  69. // Description: Returns true if the indicated button (identified by
  70. // its index number) is currently known to be down, or
  71. // false if it is up or unknown.
  72. ////////////////////////////////////////////////////////////////////
  73. INLINE bool ClientButtonDevice::
  74. get_button_state(int index) const {
  75. if (index >= 0 && index < (int)_buttons.size()) {
  76. return (_buttons[index]._state == S_down);
  77. } else {
  78. return false;
  79. }
  80. }
  81. ////////////////////////////////////////////////////////////////////
  82. // Function: ClientButtonDevice::is_button_known
  83. // Access: Public
  84. // Description: Returns true if the state of the indicated button is
  85. // known, or false if we have never heard anything about
  86. // this particular button.
  87. ////////////////////////////////////////////////////////////////////
  88. INLINE bool ClientButtonDevice::
  89. is_button_known(int index) const {
  90. if (index >= 0 && index < (int)_buttons.size()) {
  91. return _buttons[index]._state != S_unknown;
  92. } else {
  93. return false;
  94. }
  95. }
  96. ////////////////////////////////////////////////////////////////////
  97. // Function: ClientButtonDevice::get_button_events
  98. // Access: Public
  99. // Description: Returns the list of recently-generated ButtonEvents.
  100. // This must be periodically cleared, or the buttons
  101. // will accumulate.
  102. ////////////////////////////////////////////////////////////////////
  103. INLINE ButtonEventDataAttribute *ClientButtonDevice::
  104. get_button_events() const {
  105. return _button_events;
  106. }