Panda3D
|
00001 // Filename: modifierButtons.I 00002 // Created by: drose (01Mar00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ModifierButtons::Copy Assignment Operator 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE void ModifierButtons:: 00022 operator = (const ModifierButtons ©) { 00023 _button_list = copy._button_list; 00024 _state = copy._state; 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: ModifierButtons::Equality Operator 00029 // Access: Published 00030 // Description: The equality operator is an exact comparision: the 00031 // two ModifierButtons are equal if they share the same 00032 // button list--indeed, the same pointer--and they all 00033 // the buttons have the same state. Use matches() if a 00034 // less exact equality test is needed. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE bool ModifierButtons:: 00037 operator == (const ModifierButtons &other) const { 00038 return (_button_list == other._button_list && 00039 _state == other._state); 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: ModifierButtons::Inequality Operator 00044 // Access: Published 00045 // Description: 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE bool ModifierButtons:: 00048 operator != (const ModifierButtons &other) const { 00049 return !operator == (other); 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: ModifierButtons::Ordering Operator 00054 // Access: Published 00055 // Description: 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE bool ModifierButtons:: 00058 operator < (const ModifierButtons &other) const { 00059 if (_button_list != other._button_list) { 00060 return _button_list < other._button_list; 00061 } 00062 return _state < other._state; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: ModifierButtons::operator & 00067 // Access: Published 00068 // Description: Returns a new ModifierButtons object for which 00069 // is_down() will be true only if it is true on both 00070 // source objects. The set of buttons reported by 00071 // has_button() is not completely defined if both source 00072 // objects have a different set. 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE ModifierButtons ModifierButtons:: 00075 operator & (const ModifierButtons &other) const { 00076 ModifierButtons result = *this; 00077 result &= other; 00078 return result; 00079 } 00080 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: ModifierButtons::operator | 00084 // Access: Published 00085 // Description: Returns a new ModifierButtons object for which 00086 // is_down() will be true if it is true on either of the 00087 // source objects. The set of buttons reported by 00088 // has_button() is not completely defined if both source 00089 // objects have a different set. 00090 //////////////////////////////////////////////////////////////////// 00091 INLINE ModifierButtons ModifierButtons:: 00092 operator | (const ModifierButtons &other) const { 00093 ModifierButtons result = *this; 00094 result |= other; 00095 return result; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: ModifierButtons::get_num_buttons 00100 // Access: Published 00101 // Description: Returns the number of buttons that the 00102 // ModifierButtons object is monitoring (e.g. the number 00103 // of buttons passed to add_button()). 00104 //////////////////////////////////////////////////////////////////// 00105 INLINE int ModifierButtons:: 00106 get_num_buttons() const { 00107 return _button_list.size(); 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: ModifierButtons::get_button 00112 // Access: Published 00113 // Description: Returns the nth button that the ModifierButtons 00114 // object is monitoring (the nth button passed to 00115 // add_button()). This must be in the range 0 <= index 00116 // < get_num_buttons(). 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE ButtonHandle ModifierButtons:: 00119 get_button(int index) const { 00120 nassertr(index >= 0 && index < (int)_button_list.size(), ButtonHandle::none()); 00121 return _button_list[index]; 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: ModifierButtons::all_buttons_up 00126 // Access: Published 00127 // Description: Marks all monitored buttons as being in the "up" 00128 // state. 00129 //////////////////////////////////////////////////////////////////// 00130 INLINE void ModifierButtons:: 00131 all_buttons_up() { 00132 _state = 0; 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: ModifierButtons::is_down 00137 // Access: Published 00138 // Description: Returns true if the indicated button is known to be 00139 // down, or false if it is known to be up. 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE bool ModifierButtons:: 00142 is_down(int index) const { 00143 nassertr(index >= 0 && index < (int)_button_list.size(), false); 00144 return ((_state & ((BitmaskType)1 << index)) != 0); 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: ModifierButtons::is_any_down 00149 // Access: Published 00150 // Description: Returns true if any of the tracked button are known 00151 // to be down, or false if all of them are up. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE bool ModifierButtons:: 00154 is_any_down() const { 00155 return _state != 0; 00156 }