Panda3D
clientButtonDevice.h
1 // Filename: clientButtonDevice.h
2 // Created by: drose (26Jan01)
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 
15 #ifndef CLIENTBUTTONDEVICE_H
16 #define CLIENTBUTTONDEVICE_H
17 
18 #include "pandabase.h"
19 
20 #include "clientDevice.h"
21 
22 #include "buttonHandle.h"
23 #include "buttonEvent.h"
24 #include "buttonEventList.h"
25 #include "pointerTo.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : ClientButtonDevice
29 // Description : A device, attached to the ClientBase by a
30 // ButtonNode, that records the data from a single
31 // named button device. The named device can contain
32 // any number of up/down style buttons, numbered in
33 // sequence beginning at zero; these are mapped by this
34 // class to a sequence of ButtonHandles specified by the
35 // user.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_DEVICE ClientButtonDevice : public ClientDevice {
38 protected:
39  ClientButtonDevice(ClientBase *client, const string &device_name);
40 
41 public:
42  INLINE int get_num_buttons() const;
43 
44  INLINE void set_button_map(int index, ButtonHandle button);
45  INLINE ButtonHandle get_button_map(int index) const;
46 
47  void set_button_state(int index, bool down);
48  INLINE bool get_button_state(int index) const;
49  INLINE bool is_button_known(int index) const;
50 
51  INLINE ButtonEventList *get_button_events() const;
52 
53  virtual void output(ostream &out) const;
54  virtual void write(ostream &out, int indent_level = 0) const;
55 
56  void output_buttons(ostream &out) const;
57  void write_buttons(ostream &out, int indent_level) const;
58 
59 private:
60  void ensure_button_index(int index);
61 
62 protected:
63  enum State {
64  S_unknown,
65  S_up,
66  S_down
67  };
68 
69  class ButtonState {
70  public:
71  INLINE ButtonState();
72 
73  ButtonHandle _handle;
74  State _state;
75  };
76 
78  Buttons _buttons;
79 
80  PT(ButtonEventList) _button_events;
81 
82 public:
83  static TypeHandle get_class_type() {
84  return _type_handle;
85  }
86  static void init_type() {
87  ClientDevice::init_type();
88  register_type(_type_handle, "ClientButtonDevice",
89  ClientDevice::get_class_type());
90  }
91  virtual TypeHandle get_type() const {
92  return get_class_type();
93  }
94  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
95 
96 private:
97  static TypeHandle _type_handle;
98  friend class ButtonState;
99 };
100 
101 #include "clientButtonDevice.I"
102 
103 #endif
A device, attached to the ClientBase by a ButtonNode, that records the data from a single named butto...
Records a set of button events that happened recently.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
An abstract base class for a family of client device interfaces–including trackers, buttons, dials, and other analog inputs.
Definition: clientBase.h:47
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Any of a number of different devices that might be attached to a ClientBase, including trackers...
Definition: clientDevice.h:35