buttonNode.I 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Filename: buttonNode.I
  2. // Created by: drose (31Dec69)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. ////////////////////////////////////////////////////////////////////
  6. // Function: ButtonNode::is_valid
  7. // Access: Public
  8. // Description: Returns true if the ButtonNode is valid and
  9. // connected to a server, false otherwise.
  10. ////////////////////////////////////////////////////////////////////
  11. INLINE bool ButtonNode::
  12. is_valid() const {
  13. return (_button != (ClientButtonDevice *)NULL) && _button->is_connected();
  14. }
  15. ////////////////////////////////////////////////////////////////////
  16. // Function: ButtonNode::get_num_buttons
  17. // Access: Public
  18. // Description: Returns the number of buttons known to the
  19. // ButtonNode. This includes those buttons whose state
  20. // has been seen, as well as buttons that have been
  21. // associated with a ButtonHandle even if their state is
  22. // unknown. This number may change as more buttons are
  23. // discovered.
  24. ////////////////////////////////////////////////////////////////////
  25. INLINE int ButtonNode::
  26. get_num_buttons() const {
  27. _button->lock();
  28. int result = _button->get_num_buttons();
  29. _button->unlock();
  30. return result;
  31. }
  32. ////////////////////////////////////////////////////////////////////
  33. // Function: ButtonNode::set_button_map
  34. // Access: Public
  35. // Description: Associates the indicated ButtonHandle with the button
  36. // of the indicated index number. When the given button
  37. // index changes state, a corresponding ButtonEvent will
  38. // be generated with the given ButtonHandle. Pass
  39. // ButtonHandle::none() to turn off any association.
  40. //
  41. // It is not necessary to call this if you simply want
  42. // to query the state of the various buttons by index
  43. // number; this is only necessary in order to generate
  44. // ButtonEvents when the buttons change state.
  45. ////////////////////////////////////////////////////////////////////
  46. INLINE void ButtonNode::
  47. set_button_map(int index, ButtonHandle button) {
  48. _button->lock();
  49. _button->set_button_map(index, button);
  50. _button->unlock();
  51. }
  52. ////////////////////////////////////////////////////////////////////
  53. // Function: ButtonNode::get_button_map
  54. // Access: Public
  55. // Description: Returns the ButtonHandle that was previously
  56. // associated with the given index number by
  57. // a call to set_button_map(), or ButtonHandle::none()
  58. // if no button was associated.
  59. ////////////////////////////////////////////////////////////////////
  60. INLINE ButtonHandle ButtonNode::
  61. get_button_map(int index) const {
  62. _button->lock();
  63. ButtonHandle result = _button->get_button_map(index);
  64. _button->unlock();
  65. return result;
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: ButtonNode::get_button_state
  69. // Access: Public
  70. // Description: Returns true if the indicated button (identified by
  71. // its index number) is currently known to be down, or
  72. // false if it is up or unknown.
  73. ////////////////////////////////////////////////////////////////////
  74. INLINE bool ButtonNode::
  75. get_button_state(int index) const {
  76. _button->lock();
  77. bool result = _button->get_button_state(index);
  78. _button->unlock();
  79. return result;
  80. }
  81. ////////////////////////////////////////////////////////////////////
  82. // Function: ButtonNode::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 ButtonNode::
  89. is_button_known(int index) const {
  90. _button->lock();
  91. bool result = _button->is_button_known(index);
  92. _button->unlock();
  93. return result;
  94. }