Panda3D
buttonNode.I
1 // Filename: buttonNode.I
2 // Created by: drose (12Mar02)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ButtonNode::is_valid
18 // Access: Public
19 // Description: Returns true if the ButtonNode is valid and
20 // connected to a server, false otherwise.
21 ////////////////////////////////////////////////////////////////////
22 INLINE bool ButtonNode::
23 is_valid() const {
24  return (_button != (ClientButtonDevice *)NULL) && _button->is_connected();
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: ButtonNode::get_num_buttons
29 // Access: Public
30 // Description: Returns the number of buttons known to the
31 // ButtonNode. This includes those buttons whose state
32 // has been seen, as well as buttons that have been
33 // associated with a ButtonHandle even if their state is
34 // unknown. This number may change as more buttons are
35 // discovered.
36 ////////////////////////////////////////////////////////////////////
37 INLINE int ButtonNode::
38 get_num_buttons() const {
39  _button->acquire();
40  int result = _button->get_num_buttons();
41  _button->unlock();
42  return result;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: ButtonNode::set_button_map
47 // Access: Public
48 // Description: Associates the indicated ButtonHandle with the button
49 // of the indicated index number. When the given button
50 // index changes state, a corresponding ButtonEvent will
51 // be generated with the given ButtonHandle. Pass
52 // ButtonHandle::none() to turn off any association.
53 //
54 // It is not necessary to call this if you simply want
55 // to query the state of the various buttons by index
56 // number; this is only necessary in order to generate
57 // ButtonEvents when the buttons change state.
58 ////////////////////////////////////////////////////////////////////
59 INLINE void ButtonNode::
60 set_button_map(int index, ButtonHandle button) {
61  _button->acquire();
62  _button->set_button_map(index, button);
63  _button->unlock();
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: ButtonNode::get_button_map
68 // Access: Public
69 // Description: Returns the ButtonHandle that was previously
70 // associated with the given index number by
71 // a call to set_button_map(), or ButtonHandle::none()
72 // if no button was associated.
73 ////////////////////////////////////////////////////////////////////
75 get_button_map(int index) const {
76  _button->acquire();
77  ButtonHandle result = _button->get_button_map(index);
78  _button->unlock();
79  return result;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: ButtonNode::get_button_state
84 // Access: Public
85 // Description: Returns true if the indicated button (identified by
86 // its index number) is currently known to be down, or
87 // false if it is up or unknown.
88 ////////////////////////////////////////////////////////////////////
89 INLINE bool ButtonNode::
90 get_button_state(int index) const {
91  _button->acquire();
92  bool result = _button->get_button_state(index);
93  _button->unlock();
94  return result;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: ButtonNode::is_button_known
99 // Access: Public
100 // Description: Returns true if the state of the indicated button is
101 // known, or false if we have never heard anything about
102 // this particular button.
103 ////////////////////////////////////////////////////////////////////
104 INLINE bool ButtonNode::
105 is_button_known(int index) const {
106  _button->acquire();
107  bool result = _button->is_button_known(index);
108  _button->unlock();
109  return result;
110 }
int get_num_buttons() const
Returns the number of buttons known to the ButtonNode.
Definition: buttonNode.I:38
void set_button_map(int index, ButtonHandle button)
Associates the indicated ButtonHandle with the button of the indicated index number.
Definition: buttonNode.I:60
A device, attached to the ClientBase by a ButtonNode, that records the data from a single named butto...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
bool get_button_state(int index) const
Returns true if the indicated button (identified by its index number) is currently known to be down...
Definition: buttonNode.I:90
ButtonHandle get_button_map(int index) const
Returns the ButtonHandle that was previously associated with the given index number by a call to set_...
Definition: buttonNode.I:75
bool is_valid() const
Returns true if the ButtonNode is valid and connected to a server, false otherwise.
Definition: buttonNode.I:23
bool is_button_known(int index) const
Returns true if the state of the indicated button is known, or false if we have never heard anything ...
Definition: buttonNode.I:105