clientButtonDevice.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Filename: clientButtonDevice.h
  2. // Created by: drose (26Jan01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #ifndef CLIENTBUTTONDEVICE_H
  6. #define CLIENTBUTTONDEVICE_H
  7. #include <pandabase.h>
  8. #include "clientDevice.h"
  9. #include <buttonHandle.h>
  10. #include <buttonEvent.h>
  11. #include <buttonEventDataAttribute.h>
  12. #include <pointerTo.h>
  13. ////////////////////////////////////////////////////////////////////
  14. // Class : ClientButtonDevice
  15. // Description : A device, attached to the ClientBase by a
  16. // ButtonNode, that records the data from a single
  17. // named button device. The named device can contain
  18. // any number of up/down style buttons, numbered in
  19. // sequence beginning at zero; these are mapped by this
  20. // class to a sequence of ButtonHandles specified by the
  21. // user.
  22. ////////////////////////////////////////////////////////////////////
  23. class EXPCL_PANDA ClientButtonDevice : public ClientDevice {
  24. protected:
  25. ClientButtonDevice(ClientBase *client, const string &device_name);
  26. public:
  27. INLINE int get_num_buttons() const;
  28. INLINE void set_button_map(int index, ButtonHandle button);
  29. INLINE ButtonHandle get_button_map(int index) const;
  30. void set_button_state(int index, bool down);
  31. INLINE bool get_button_state(int index) const;
  32. INLINE bool is_button_known(int index) const;
  33. INLINE ButtonEventDataAttribute *get_button_events() const;
  34. virtual void output(ostream &out) const;
  35. virtual void write(ostream &out, int indent_level = 0) const;
  36. void output_buttons(ostream &out) const;
  37. void write_buttons(ostream &out, int indent_level) const;
  38. private:
  39. void ensure_button_index(int index);
  40. protected:
  41. enum State {
  42. S_unknown,
  43. S_up,
  44. S_down
  45. };
  46. class ButtonState {
  47. public:
  48. INLINE ButtonState();
  49. ButtonHandle _handle;
  50. State _state;
  51. };
  52. typedef vector<ButtonState> Buttons;
  53. Buttons _buttons;
  54. PT(ButtonEventDataAttribute) _button_events;
  55. public:
  56. static TypeHandle get_class_type() {
  57. return _type_handle;
  58. }
  59. static void init_type() {
  60. ClientDevice::init_type();
  61. register_type(_type_handle, "ClientButtonDevice",
  62. ClientDevice::get_class_type());
  63. }
  64. virtual TypeHandle get_type() const {
  65. return get_class_type();
  66. }
  67. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  68. private:
  69. static TypeHandle _type_handle;
  70. friend class ButtonState;
  71. };
  72. #include "clientButtonDevice.I"
  73. #endif