buttonNode.I 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file buttonNode.I
  10. * @author drose
  11. * @date 2002-03-12
  12. */
  13. /**
  14. * Returns true if the ButtonNode is valid and connected to a server, false
  15. * otherwise.
  16. */
  17. INLINE bool ButtonNode::
  18. is_valid() const {
  19. return (_device != nullptr) && _device->is_connected();
  20. }
  21. /**
  22. * Returns the number of buttons known to the ButtonNode. This includes those
  23. * buttons whose state has been seen, as well as buttons that have been
  24. * associated with a ButtonHandle even if their state is unknown. This number
  25. * may change as more buttons are discovered.
  26. */
  27. INLINE int ButtonNode::
  28. get_num_buttons() const {
  29. return _device->get_num_buttons();
  30. }
  31. /**
  32. * Associates the indicated ButtonHandle with the button of the indicated
  33. * index number. When the given button index changes state, a corresponding
  34. * ButtonEvent will be generated with the given ButtonHandle. Pass
  35. * ButtonHandle::none() to turn off any association.
  36. *
  37. * It is not necessary to call this if you simply want to query the state of
  38. * the various buttons by index number; this is only necessary in order to
  39. * generate ButtonEvents when the buttons change state.
  40. */
  41. INLINE void ButtonNode::
  42. set_button_map(int index, ButtonHandle button) {
  43. _device->map_button(index, button);
  44. }
  45. /**
  46. * Returns the ButtonHandle that was previously associated with the given
  47. * index number by a call to set_button_map(), or ButtonHandle::none() if no
  48. * button was associated.
  49. */
  50. INLINE ButtonHandle ButtonNode::
  51. get_button_map(int index) const {
  52. return _device->get_button_map(index);
  53. }
  54. /**
  55. * Returns true if the indicated button (identified by its index number) is
  56. * currently known to be down, or false if it is up or unknown.
  57. */
  58. INLINE bool ButtonNode::
  59. get_button_state(int index) const {
  60. return _device->is_button_pressed(index);
  61. }
  62. /**
  63. * Returns true if the state of the indicated button is known, or false if we
  64. * have never heard anything about this particular button.
  65. */
  66. INLINE bool ButtonNode::
  67. is_button_known(int index) const {
  68. return _device->is_button_known(index);
  69. }