00001 // Filename: modifierButtons.I 00002 // Created by: drose (01Mar00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: ModifierButtons::Copy Assignment Operator 00022 // Access: Published 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE void ModifierButtons:: 00026 operator = (const ModifierButtons ©) { 00027 _button_list = copy._button_list; 00028 _state = copy._state; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: ModifierButtons::Equality Operator 00033 // Access: Published 00034 // Description: The equality operator is an exact comparision: the 00035 // two ModifierButtons are equal if they share the same 00036 // button list--indeed, the same pointer--and they all 00037 // the buttons have the same state. Use matches() if a 00038 // less exact equality test is needed. 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE bool ModifierButtons:: 00041 operator == (const ModifierButtons &other) const { 00042 return (_button_list == other._button_list && 00043 _state == other._state); 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: ModifierButtons::Inequality Operator 00048 // Access: Published 00049 // Description: 00050 //////////////////////////////////////////////////////////////////// 00051 INLINE bool ModifierButtons:: 00052 operator != (const ModifierButtons &other) const { 00053 return !operator == (other); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: ModifierButtons::Ordering Operator 00058 // Access: Published 00059 // Description: 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE bool ModifierButtons:: 00062 operator < (const ModifierButtons &other) const { 00063 if (_button_list != other._button_list) { 00064 return _button_list < other._button_list; 00065 } 00066 return _state < other._state; 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: ModifierButtons::get_num_buttons 00071 // Access: Published 00072 // Description: Returns the number of buttons that the 00073 // ModifierButtons object is monitoring (e.g. the number 00074 // of buttons passed to add_button()). 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE int ModifierButtons:: 00077 get_num_buttons() const { 00078 return _button_list.size(); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: ModifierButtons::get_button 00083 // Access: Published 00084 // Description: Returns the nth button that the ModifierButtons 00085 // object is monitoring (the nth button passed to 00086 // add_button()). This must be in the range 0 <= index 00087 // < get_num_buttons(). 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE ButtonHandle ModifierButtons:: 00090 get_button(int index) const { 00091 nassertr(index >= 0 && index < (int)_button_list.size(), ButtonHandle::none()); 00092 return _button_list[index]; 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: ModifierButtons::add_event 00097 // Access: Published 00098 // Description: Calls button_down() or button_up(), as appropriate, 00099 // according to the indicated ButtonEvent. 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE bool ModifierButtons:: 00102 add_event(const ButtonEvent &event) { 00103 switch (event._type) { 00104 case ButtonEvent::T_down: 00105 return button_down(event._button); 00106 00107 case ButtonEvent::T_up: 00108 return button_up(event._button); 00109 00110 default: 00111 return false; 00112 } 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: ModifierButtons::all_buttons_up 00117 // Access: Published 00118 // Description: Marks all monitored buttons as being in the "up" 00119 // state. 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE void ModifierButtons:: 00122 all_buttons_up() { 00123 _state = 0; 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: ModifierButtons::is_down 00128 // Access: Published 00129 // Description: Returns true if the indicated button is known to be 00130 // down, or false if it is known to be up. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE bool ModifierButtons:: 00133 is_down(int index) const { 00134 nassertr(index >= 0 && index < (int)_button_list.size(), false); 00135 return ((_state & ((BitmaskType)1 << index)) != 0); 00136 } 00137 00138 //////////////////////////////////////////////////////////////////// 00139 // Function: ModifierButtons::is_any_down 00140 // Access: Published 00141 // Description: Returns true if any of the tracked button are known 00142 // to be down, or false if all of them are up. 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE bool ModifierButtons:: 00145 is_any_down() const { 00146 return _state != 0; 00147 }