buttonNode.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Filename: buttonNode.h
  2. // Created by: drose (31Dec69)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef BUTTONNODE_H
  19. #define BUTTONNODE_H
  20. #include <pandabase.h>
  21. #include "clientBase.h"
  22. #include "clientButtonDevice.h"
  23. #include <dataNode.h>
  24. #include <nodeAttributes.h>
  25. ////////////////////////////////////////////////////////////////////
  26. // Class : ButtonNode
  27. // Description : This is the primary interface to on/off button
  28. // devices associated with a ClientBase. This creates a
  29. // node that connects to the named button device, if it
  30. // exists, and provides hooks to the user to read the
  31. // state of any of the sequentially numbered buttons
  32. // associated with that device.
  33. //
  34. // It also can associate an arbitrary ButtonHandle with
  35. // each button; when buttons are associated with
  36. // ButtonHandles, this node will put appropriate up and
  37. // down events on the data graph for each button state
  38. // change.
  39. ////////////////////////////////////////////////////////////////////
  40. class EXPCL_PANDA ButtonNode : public DataNode {
  41. PUBLISHED:
  42. ButtonNode(ClientBase *client, const string &device_name);
  43. virtual ~ButtonNode();
  44. INLINE bool is_valid() const;
  45. INLINE int get_num_buttons() const;
  46. INLINE void set_button_map(int index, ButtonHandle button);
  47. INLINE ButtonHandle get_button_map(int index) const;
  48. INLINE bool get_button_state(int index) const;
  49. INLINE bool is_button_known(int index) const;
  50. public:
  51. virtual void output(ostream &out) const;
  52. virtual void write(ostream &out, int indent_level = 0) const;
  53. ////////////////////////////////////////////////////////////////////
  54. // From parent class DataNode
  55. ////////////////////////////////////////////////////////////////////
  56. public:
  57. virtual void
  58. transmit_data(NodeAttributes &data);
  59. NodeAttributes _attrib;
  60. PT(ButtonEventDataAttribute) _button_events;
  61. // outputs
  62. static TypeHandle _button_events_type;
  63. private:
  64. PT(ClientButtonDevice) _button;
  65. public:
  66. virtual TypeHandle get_type() const {
  67. return get_class_type();
  68. }
  69. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  70. static TypeHandle get_class_type() {
  71. return _type_handle;
  72. }
  73. static void init_type();
  74. private:
  75. static TypeHandle _type_handle;
  76. };
  77. #include "buttonNode.I"
  78. #endif