Panda3D
 All Classes Functions Variables Enumerations
modifierButtons.I
1 // Filename: modifierButtons.I
2 // Created by: drose (01Mar00)
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: ModifierButtons::Copy Assignment Operator
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE void ModifierButtons::
22 operator = (const ModifierButtons &copy) {
23  _button_list = copy._button_list;
24  _state = copy._state;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: ModifierButtons::Equality Operator
29 // Access: Published
30 // Description: The equality operator is an exact comparision: the
31 // two ModifierButtons are equal if they share the same
32 // button list--indeed, the same pointer--and they all
33 // the buttons have the same state. Use matches() if a
34 // less exact equality test is needed.
35 ////////////////////////////////////////////////////////////////////
36 INLINE bool ModifierButtons::
37 operator == (const ModifierButtons &other) const {
38  return (_button_list == other._button_list &&
39  _state == other._state);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ModifierButtons::Inequality Operator
44 // Access: Published
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 INLINE bool ModifierButtons::
48 operator != (const ModifierButtons &other) const {
49  return !operator == (other);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: ModifierButtons::Ordering Operator
54 // Access: Published
55 // Description:
56 ////////////////////////////////////////////////////////////////////
57 INLINE bool ModifierButtons::
58 operator < (const ModifierButtons &other) const {
59  if (_button_list != other._button_list) {
60  return _button_list < other._button_list;
61  }
62  return _state < other._state;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ModifierButtons::operator &
67 // Access: Published
68 // Description: Returns a new ModifierButtons object for which
69 // is_down() will be true only if it is true on both
70 // source objects. The set of buttons reported by
71 // has_button() is not completely defined if both source
72 // objects have a different set.
73 ////////////////////////////////////////////////////////////////////
75 operator & (const ModifierButtons &other) const {
76  ModifierButtons result = *this;
77  result &= other;
78  return result;
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: ModifierButtons::operator |
84 // Access: Published
85 // Description: Returns a new ModifierButtons object for which
86 // is_down() will be true if it is true on either of the
87 // source objects. The set of buttons reported by
88 // has_button() is not completely defined if both source
89 // objects have a different set.
90 ////////////////////////////////////////////////////////////////////
92 operator | (const ModifierButtons &other) const {
93  ModifierButtons result = *this;
94  result |= other;
95  return result;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ModifierButtons::get_num_buttons
100 // Access: Published
101 // Description: Returns the number of buttons that the
102 // ModifierButtons object is monitoring (e.g. the number
103 // of buttons passed to add_button()).
104 ////////////////////////////////////////////////////////////////////
105 INLINE int ModifierButtons::
107  return _button_list.size();
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: ModifierButtons::get_button
112 // Access: Published
113 // Description: Returns the nth button that the ModifierButtons
114 // object is monitoring (the nth button passed to
115 // add_button()). This must be in the range 0 <= index
116 // < get_num_buttons().
117 ////////////////////////////////////////////////////////////////////
119 get_button(int index) const {
120  nassertr(index >= 0 && index < (int)_button_list.size(), ButtonHandle::none());
121  return _button_list[index];
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: ModifierButtons::all_buttons_up
126 // Access: Published
127 // Description: Marks all monitored buttons as being in the "up"
128 // state.
129 ////////////////////////////////////////////////////////////////////
130 INLINE void ModifierButtons::
132  _state = 0;
133 }
134 
135 ////////////////////////////////////////////////////////////////////
136 // Function: ModifierButtons::is_down
137 // Access: Published
138 // Description: Returns true if the indicated button is known to be
139 // down, or false if it is known to be up.
140 ////////////////////////////////////////////////////////////////////
141 INLINE bool ModifierButtons::
142 is_down(int index) const {
143  nassertr(index >= 0 && index < (int)_button_list.size(), false);
144  return ((_state & ((BitmaskType)1 << index)) != 0);
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ModifierButtons::is_any_down
149 // Access: Published
150 // Description: Returns true if any of the tracked button are known
151 // to be down, or false if all of them are up.
152 ////////////////////////////////////////////////////////////////////
153 INLINE bool ModifierButtons::
154 is_any_down() const {
155  return _state != 0;
156 }
bool operator==(const ModifierButtons &other) const
The equality operator is an exact comparision: the two ModifierButtons are equal if they share the sa...
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
bool is_any_down() const
Returns true if any of the tracked button are known to be down, or false if all of them are up...
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
ButtonHandle get_button(int index) const
Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_bu...
ModifierButtons operator&(const ModifierButtons &other) const
Returns a new ModifierButtons object for which is_down() will be true only if it is true on both sour...
void all_buttons_up()
Marks all monitored buttons as being in the &quot;up&quot; state.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
int get_num_buttons() const
Returns the number of buttons that the ModifierButtons object is monitoring (e.g. ...
ModifierButtons operator|(const ModifierButtons &other) const
Returns a new ModifierButtons object for which is_down() will be true if it is true on either of the ...
bool is_down(ButtonHandle button) const
Returns true if the indicated button is known to be down, or false if it is known to be up or if it i...