00001 // Filename: buttonNode.I 00002 // Created by: drose (12Mar02) 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: ButtonNode::is_valid 00018 // Access: Public 00019 // Description: Returns true if the ButtonNode is valid and 00020 // connected to a server, false otherwise. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE bool ButtonNode:: 00023 is_valid() const { 00024 return (_button != (ClientButtonDevice *)NULL) && _button->is_connected(); 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: ButtonNode::get_num_buttons 00029 // Access: Public 00030 // Description: Returns the number of buttons known to the 00031 // ButtonNode. This includes those buttons whose state 00032 // has been seen, as well as buttons that have been 00033 // associated with a ButtonHandle even if their state is 00034 // unknown. This number may change as more buttons are 00035 // discovered. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE int ButtonNode:: 00038 get_num_buttons() const { 00039 _button->acquire(); 00040 int result = _button->get_num_buttons(); 00041 _button->unlock(); 00042 return result; 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: ButtonNode::set_button_map 00047 // Access: Public 00048 // Description: Associates the indicated ButtonHandle with the button 00049 // of the indicated index number. When the given button 00050 // index changes state, a corresponding ButtonEvent will 00051 // be generated with the given ButtonHandle. Pass 00052 // ButtonHandle::none() to turn off any association. 00053 // 00054 // It is not necessary to call this if you simply want 00055 // to query the state of the various buttons by index 00056 // number; this is only necessary in order to generate 00057 // ButtonEvents when the buttons change state. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE void ButtonNode:: 00060 set_button_map(int index, ButtonHandle button) { 00061 _button->acquire(); 00062 _button->set_button_map(index, button); 00063 _button->unlock(); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: ButtonNode::get_button_map 00068 // Access: Public 00069 // Description: Returns the ButtonHandle that was previously 00070 // associated with the given index number by 00071 // a call to set_button_map(), or ButtonHandle::none() 00072 // if no button was associated. 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE ButtonHandle ButtonNode:: 00075 get_button_map(int index) const { 00076 _button->acquire(); 00077 ButtonHandle result = _button->get_button_map(index); 00078 _button->unlock(); 00079 return result; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: ButtonNode::get_button_state 00084 // Access: Public 00085 // Description: Returns true if the indicated button (identified by 00086 // its index number) is currently known to be down, or 00087 // false if it is up or unknown. 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE bool ButtonNode:: 00090 get_button_state(int index) const { 00091 _button->acquire(); 00092 bool result = _button->get_button_state(index); 00093 _button->unlock(); 00094 return result; 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: ButtonNode::is_button_known 00099 // Access: Public 00100 // Description: Returns true if the state of the indicated button is 00101 // known, or false if we have never heard anything about 00102 // this particular button. 00103 //////////////////////////////////////////////////////////////////// 00104 INLINE bool ButtonNode:: 00105 is_button_known(int index) const { 00106 _button->acquire(); 00107 bool result = _button->is_button_known(index); 00108 _button->unlock(); 00109 return result; 00110 }