Panda3D
clientButtonDevice.I
1 // Filename: clientButtonDevice.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ClientButtonDevice::ButtonState::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ClientButtonDevice::ButtonState::
22 ButtonState() :
23  _handle(ButtonHandle::none()),
24  _state(S_unknown)
25 {
26 }
27 
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: ClientButtonDevice::get_num_buttons
31 // Access: Public
32 // Description: Returns the number of buttons known to the
33 // ClientButtonDevice. This includes those buttons
34 // whose state has been seen, as well as buttons that
35 // have been associated with a ButtonHandle even if
36 // their state is unknown. This number may change as
37 // more buttons are discovered.
38 ////////////////////////////////////////////////////////////////////
39 INLINE int ClientButtonDevice::
40 get_num_buttons() const {
41  return _buttons.size();
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: ClientButtonDevice::set_button_map
46 // Access: Public
47 // Description: Associates the indicated ButtonHandle with the button
48 // of the indicated index number. When the given button
49 // index changes state, a corresponding ButtonEvent will
50 // be generated with the given ButtonHandle. Pass
51 // ButtonHandle::none() to turn off any association.
52 //
53 // It is not necessary to call this if you simply want
54 // to query the state of the various buttons by index
55 // number; this is only necessary in order to generate
56 // ButtonEvents when the buttons change state.
57 ////////////////////////////////////////////////////////////////////
58 INLINE void ClientButtonDevice::
59 set_button_map(int index, ButtonHandle button) {
60  ensure_button_index(index);
61  nassertv(index >= 0 && index < (int)_buttons.size());
62  _buttons[index]._handle = button;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ClientButtonDevice::get_button_map
67 // Access: Public
68 // Description: Returns the ButtonHandle that was previously
69 // associated with the given index number by
70 // a call to set_button_map(), or ButtonHandle::none()
71 // if no button was associated.
72 ////////////////////////////////////////////////////////////////////
74 get_button_map(int index) const {
75  if (index >= 0 && index < (int)_buttons.size()) {
76  return _buttons[index]._handle;
77  } else {
78  return ButtonHandle::none();
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: ClientButtonDevice::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 ClientButtonDevice::
90 get_button_state(int index) const {
91  if (index >= 0 && index < (int)_buttons.size()) {
92  return (_buttons[index]._state == S_down);
93  } else {
94  return false;
95  }
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ClientButtonDevice::is_button_known
100 // Access: Public
101 // Description: Returns true if the state of the indicated button is
102 // known, or false if we have never heard anything about
103 // this particular button.
104 ////////////////////////////////////////////////////////////////////
105 INLINE bool ClientButtonDevice::
106 is_button_known(int index) const {
107  if (index >= 0 && index < (int)_buttons.size()) {
108  return _buttons[index]._state != S_unknown;
109  } else {
110  return false;
111  }
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: ClientButtonDevice::get_button_events
116 // Access: Public
117 // Description: Returns the list of recently-generated ButtonEvents.
118 // This must be periodically cleared, or the buttons
119 // will accumulate.
120 ////////////////////////////////////////////////////////////////////
123  return _button_events;
124 }
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
ButtonEventList * get_button_events() const
Returns the list of recently-generated ButtonEvents.
int get_num_buttons() const
Returns the number of buttons known to the ClientButtonDevice.
bool get_button_state(int index) const
Returns true if the indicated button (identified by its index number) is currently known to be down...
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
ButtonHandle get_button_map(int index) const
Returns the ButtonHandle that was previously associated with the given index number by a call to set_...
void set_button_map(int index, ButtonHandle button)
Associates the indicated ButtonHandle with the button of the indicated index number.
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 ...