buttonNode.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Filename: ButtonNode.h
  2. // Created by: drose (12Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef BUTTONNODE_H
  15. #define BUTTONNODE_H
  16. #include "pandabase.h"
  17. #include "clientBase.h"
  18. #include "clientButtonDevice.h"
  19. #include "dataNode.h"
  20. #include "buttonEventList.h"
  21. ////////////////////////////////////////////////////////////////////
  22. // Class : ButtonNode
  23. // Description : This is the primary interface to on/off button
  24. // devices associated with a ClientBase. This creates a
  25. // node that connects to the named button device, if it
  26. // exists, and provides hooks to the user to read the
  27. // state of any of the sequentially numbered buttons
  28. // associated with that device.
  29. //
  30. // It also can associate an arbitrary ButtonHandle with
  31. // each button; when buttons are associated with
  32. // ButtonHandles, this node will put appropriate up and
  33. // down events on the data graph for each button state
  34. // change.
  35. ////////////////////////////////////////////////////////////////////
  36. class EXPCL_PANDA_DEVICE ButtonNode : public DataNode {
  37. PUBLISHED:
  38. ButtonNode(ClientBase *client, const string &device_name);
  39. virtual ~ButtonNode();
  40. INLINE bool is_valid() const;
  41. INLINE int get_num_buttons() const;
  42. INLINE void set_button_map(int index, ButtonHandle button);
  43. INLINE ButtonHandle get_button_map(int index) const;
  44. INLINE bool get_button_state(int index) const;
  45. INLINE bool is_button_known(int index) const;
  46. public:
  47. virtual void output(ostream &out) const;
  48. virtual void write(ostream &out, int indent_level = 0) const;
  49. private:
  50. PT(ClientButtonDevice) _button;
  51. protected:
  52. // Inherited from DataNode
  53. virtual void do_transmit_data(DataGraphTraverser *trav,
  54. const DataNodeTransmit &input,
  55. DataNodeTransmit &output);
  56. private:
  57. // outputs
  58. int _button_events_output;
  59. PT(ButtonEventList) _button_events;
  60. public:
  61. static TypeHandle get_class_type() {
  62. return _type_handle;
  63. }
  64. static void init_type() {
  65. DataNode::init_type();
  66. register_type(_type_handle, "ButtonNode",
  67. DataNode::get_class_type());
  68. }
  69. virtual TypeHandle get_type() const {
  70. return get_class_type();
  71. }
  72. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  73. private:
  74. static TypeHandle _type_handle;
  75. };
  76. #include "buttonNode.I"
  77. #endif