Panda3D
modifierButtons.I
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 modifierButtons.I
10  * @author drose
11  * @date 2000-03-01
12  */
13 
14 /**
15  *
16  */
17 INLINE void ModifierButtons::
18 operator = (const ModifierButtons &copy) {
19  _button_list = copy._button_list;
20  _state = copy._state;
21 }
22 
23 /**
24  * The equality operator is an exact comparision: the two ModifierButtons are
25  * equal if they share the same button list--indeed, the same pointer--and
26  * they all the buttons have the same state. Use matches() if a less exact
27  * equality test is needed.
28  */
29 INLINE bool ModifierButtons::
30 operator == (const ModifierButtons &other) const {
31  return (_button_list == other._button_list &&
32  _state == other._state);
33 }
34 
35 /**
36  *
37  */
38 INLINE bool ModifierButtons::
39 operator != (const ModifierButtons &other) const {
40  return !operator == (other);
41 }
42 
43 /**
44  *
45  */
46 INLINE bool ModifierButtons::
47 operator < (const ModifierButtons &other) const {
48  if (_button_list != other._button_list) {
49  return _button_list < other._button_list;
50  }
51  return _state < other._state;
52 }
53 
54 /**
55  * Returns a new ModifierButtons object for which is_down() will be true only
56  * if it is true on both source objects. The set of buttons reported by
57  * has_button() is not completely defined if both source objects have a
58  * different set.
59  */
61 operator & (const ModifierButtons &other) const {
62  ModifierButtons result = *this;
63  result &= other;
64  return result;
65 }
66 
67 
68 /**
69  * Returns a new ModifierButtons object for which is_down() will be true if it
70  * is true on either of the source objects. The set of buttons reported by
71  * has_button() is not completely defined if both source objects have a
72  * different set.
73  */
75 operator | (const ModifierButtons &other) const {
76  ModifierButtons result = *this;
77  result |= other;
78  return result;
79 }
80 
81 /**
82  * Returns the number of buttons that the ModifierButtons object is monitoring
83  * (e.g. the number of buttons passed to add_button()).
84  */
85 INLINE int ModifierButtons::
86 get_num_buttons() const {
87  return _button_list.size();
88 }
89 
90 /**
91  * Returns the nth button that the ModifierButtons object is monitoring (the
92  * nth button passed to add_button()). This must be in the range 0 <= index <
93  * get_num_buttons().
94  */
96 get_button(int index) const {
97  nassertr(index >= 0 && index < (int)_button_list.size(), ButtonHandle::none());
98  return _button_list[index];
99 }
100 
101 /**
102  * Marks all monitored buttons as being in the "up" state.
103  */
104 INLINE void ModifierButtons::
106  _state = 0;
107 }
108 
109 /**
110  * Returns true if the indicated button is known to be down, or false if it is
111  * known to be up.
112  */
113 INLINE bool ModifierButtons::
114 is_down(int index) const {
115  nassertr(index >= 0 && index < (int)_button_list.size(), false);
116  return ((_state & ((BitmaskType)1 << index)) != 0);
117 }
118 
119 /**
120  * Returns true if any of the tracked button are known to be down, or false if
121  * all of them are up.
122  */
123 INLINE bool ModifierButtons::
124 is_any_down() const {
125  return _state != 0;
126 }
bool operator==(const ModifierButtons &other) const
The equality operator is an exact comparision: the two ModifierButtons are equal if they share the sa...
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
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 ...
get_button
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 "up" state.
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.
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...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26