Panda3D
Loading...
Searching...
No Matches
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
20TypeHandle ButtonNode::_type_handle;
21
22/**
23 *
24 */
25ButtonNode::
26ButtonNode(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 */
54ButtonNode::
55ButtonNode(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 */
66ButtonNode::
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 */
76void ButtonNode::
77output(std::ostream &out) const {
79
80 if (_device != nullptr) {
81 out << " (";
82 _device->output_buttons(out);
83 out << ")";
84 }
85}
86
87/**
88 *
89 */
90void ButtonNode::
91write(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 */
107void ButtonNode::
108do_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}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Records a set of button events that happened recently.
bool is_valid() const
Returns true if the ButtonNode is valid and connected to a server, false otherwise.
Definition buttonNode.I:19
An abstract base class for a family of client device interfaces–including trackers,...
Definition clientBase.h:43
Any of a number of different devices that might be attached to a ClientBase, including trackers,...
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...
Encapsulates the data generated from (or sent into) any particular DataNode.
void set_data(int index, const EventParameter &data)
Sets the data for the indicated parameter.
The fundamental type of node for the data graph.
Definition dataNode.h:52
An optional parameter associated with an event.
This is a structure representing a single input device.
Definition inputDevice.h:53
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.