Panda3D
buttonNode.cxx
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.cxx
10  * @author drose
11  * @date 2002-03-12
12  */
13 
14 #include "buttonNode.h"
15 #include "config_device.h"
16 #include "dataNodeTransmit.h"
17 #include "buttonEventList.h"
18 #include "dcast.h"
19 
20 TypeHandle ButtonNode::_type_handle;
21 
22 /**
23  *
24  */
25 ButtonNode::
26 ButtonNode(ClientBase *client, const std::string &device_name) :
27  DataNode(device_name)
28 {
29  _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
30 
31  nassertv(client != nullptr);
32  PT(ClientDevice) device =
33  client->get_device(ClientButtonDevice::get_class_type(), device_name);
34 
35  if (device == nullptr) {
36  device_cat.warning()
37  << "Unable to open button device " << device_name << "\n";
38  return;
39  }
40 
41  if (!device->is_of_type(ClientButtonDevice::get_class_type())) {
42  device_cat.error()
43  << "Inappropriate device type " << device->get_type()
44  << " created; expected a ClientButtonDevice.\n";
45  return;
46  }
47 
48  _device = device;
49 }
50 
51 /**
52  *
53  */
54 ButtonNode::
55 ButtonNode(InputDevice *device) :
56  DataNode(device->get_name()),
57  _device(device)
58 {
59  _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
60  _device = device;
61 }
62 
63 /**
64  *
65  */
66 ButtonNode::
67 ~ButtonNode() {
68  // When the _button pointer destructs, the ClientButtonDevice disconnects
69  // itself from the ClientBase, and everything that needs to get turned off
70  // does. Magic.
71 }
72 
73 /**
74  *
75  */
76 void ButtonNode::
77 output(std::ostream &out) const {
78  DataNode::output(out);
79 
80  if (_device != nullptr) {
81  out << " (";
82  _device->output_buttons(out);
83  out << ")";
84  }
85 }
86 
87 /**
88  *
89  */
90 void ButtonNode::
91 write(std::ostream &out, int indent_level) const {
92  DataNode::write(out, indent_level);
93 
94  if (_device != nullptr) {
95  _device->write_buttons(out, indent_level + 2);
96  }
97 }
98 
99 /**
100  * The virtual implementation of transmit_data(). This function receives an
101  * array of input parameters and should generate an array of output
102  * parameters. The input parameters may be accessed with the index numbers
103  * returned by the define_input() calls that were made earlier (presumably in
104  * the constructor); likewise, the output parameters should be set with the
105  * index numbers returned by the define_output() calls.
106  */
107 void ButtonNode::
108 do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
109  DataNodeTransmit &output) {
110  if (is_valid()) {
111  PT(ButtonEventList) bel = _device->get_button_events();
112  output.set_data(_button_events_output, EventParameter(bel));
113  }
114 }
buttonNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DataGraphTraverser
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...
Definition: dataGraphTraverser.h:32
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
InputDevice
This is a structure representing a single input device.
Definition: inputDevice.h:53
ClientDevice
Any of a number of different devices that might be attached to a ClientBase, including trackers,...
Definition: clientDevice.h:27
ClientBase
An abstract base class for a family of client device interfaces–including trackers,...
Definition: clientBase.h:43
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
ButtonEventList
Records a set of button events that happened recently.
Definition: buttonEventList.h:33
buttonEventList.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DataNode
The fundamental type of node for the data graph.
Definition: dataNode.h:52
DataNodeTransmit::set_data
void set_data(int index, const EventParameter &data)
Sets the data for the indicated parameter.
Definition: dataNodeTransmit.I:75
EventParameter
An optional parameter associated with an event.
Definition: eventParameter.h:35
DataNodeTransmit
Encapsulates the data generated from (or sent into) any particular DataNode.
Definition: dataNodeTransmit.h:32
config_device.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dataNodeTransmit.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonNode::is_valid
bool is_valid() const
Returns true if the ButtonNode is valid and connected to a server, false otherwise.
Definition: buttonNode.I:19