Panda3D
buttonNode.h
Go to the documentation of this file.
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.h
10  * @author drose
11  * @date 2002-03-12
12  */
13 
14 #ifndef BUTTONNODE_H
15 #define BUTTONNODE_H
16 
17 #include "pandabase.h"
18 
19 #include "clientBase.h"
20 #include "clientButtonDevice.h"
21 #include "dataNode.h"
22 
23 /**
24  * This is the primary interface to on/off button devices associated with a
25  * ClientBase. This creates a node that connects to the named button device,
26  * if it exists, and provides hooks to the user to read the state of any of
27  * the sequentially numbered buttons associated with that device.
28  *
29  * It also can associate an arbitrary ButtonHandle with each button; when
30  * buttons are associated with ButtonHandles, this node will put appropriate
31  * up and down events on the data graph for each button state change.
32  */
33 class EXPCL_PANDA_DEVICE ButtonNode : public DataNode {
34 PUBLISHED:
35  explicit ButtonNode(ClientBase *client, const std::string &device_name);
36  explicit ButtonNode(InputDevice *device);
37  virtual ~ButtonNode();
38 
39  INLINE bool is_valid() const;
40 
41  INLINE int get_num_buttons() const;
42 
43  INLINE void set_button_map(int index, ButtonHandle button);
44  INLINE ButtonHandle get_button_map(int index) const;
45 
46  INLINE bool get_button_state(int index) const;
47  INLINE bool is_button_known(int index) const;
48 
49 public:
50  virtual void output(std::ostream &out) const;
51  virtual void write(std::ostream &out, int indent_level = 0) const;
52 
53 private:
54  PT(InputDevice) _device;
55 
56 protected:
57  // Inherited from DataNode
58  virtual void do_transmit_data(DataGraphTraverser *trav,
59  const DataNodeTransmit &input,
60  DataNodeTransmit &output);
61 
62 private:
63  // outputs
64  int _button_events_output;
65 
66 public:
67  static TypeHandle get_class_type() {
68  return _type_handle;
69  }
70  static void init_type() {
71  DataNode::init_type();
72  register_type(_type_handle, "ButtonNode",
73  DataNode::get_class_type());
74  }
75  virtual TypeHandle get_type() const {
76  return get_class_type();
77  }
78  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
79 
80 private:
81  static TypeHandle _type_handle;
82 };
83 
84 #include "buttonNode.I"
85 
86 #endif
This is the primary interface to on/off button devices associated with a ClientBase.
Definition: buttonNode.h:33
The fundamental type of node for the data graph.
Definition: dataNode.h:52
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
This is a structure representing a single input device.
Definition: inputDevice.h:53
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An abstract base class for a family of client device interfaces–including trackers,...
Definition: clientBase.h:43
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...