00001 // Filename: clientButtonDevice.I 00002 // Created by: drose (26Jan01) 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: ClientButtonDevice::ButtonState::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE ClientButtonDevice::ButtonState:: 00026 ButtonState() : 00027 _handle(ButtonHandle::none()), 00028 _state(S_unknown) 00029 { 00030 } 00031 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: ClientButtonDevice::get_num_buttons 00035 // Access: Public 00036 // Description: Returns the number of buttons known to the 00037 // ClientButtonDevice. This includes those buttons 00038 // whose state has been seen, as well as buttons that 00039 // have been associated with a ButtonHandle even if 00040 // their state is unknown. This number may change as 00041 // more buttons are discovered. 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE int ClientButtonDevice:: 00044 get_num_buttons() const { 00045 return _buttons.size(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: ClientButtonDevice::set_button_map 00050 // Access: Public 00051 // Description: Associates the indicated ButtonHandle with the button 00052 // of the indicated index number. When the given button 00053 // index changes state, a corresponding ButtonEvent will 00054 // be generated with the given ButtonHandle. Pass 00055 // ButtonHandle::none() to turn off any association. 00056 // 00057 // It is not necessary to call this if you simply want 00058 // to query the state of the various buttons by index 00059 // number; this is only necessary in order to generate 00060 // ButtonEvents when the buttons change state. 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE void ClientButtonDevice:: 00063 set_button_map(int index, ButtonHandle button) { 00064 ensure_button_index(index); 00065 nassertv(index >= 0 && index < (int)_buttons.size()); 00066 _buttons[index]._handle = button; 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: ClientButtonDevice::get_button_map 00071 // Access: Public 00072 // Description: Returns the ButtonHandle that was previously 00073 // associated with the given index number by 00074 // a call to set_button_map(), or ButtonHandle::none() 00075 // if no button was associated. 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE ButtonHandle ClientButtonDevice:: 00078 get_button_map(int index) const { 00079 if (index >= 0 && index < (int)_buttons.size()) { 00080 return _buttons[index]._handle; 00081 } else { 00082 return ButtonHandle::none(); 00083 } 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: ClientButtonDevice::get_button_state 00088 // Access: Public 00089 // Description: Returns true if the indicated button (identified by 00090 // its index number) is currently known to be down, or 00091 // false if it is up or unknown. 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE bool ClientButtonDevice:: 00094 get_button_state(int index) const { 00095 if (index >= 0 && index < (int)_buttons.size()) { 00096 return (_buttons[index]._state == S_down); 00097 } else { 00098 return false; 00099 } 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: ClientButtonDevice::is_button_known 00104 // Access: Public 00105 // Description: Returns true if the state of the indicated button is 00106 // known, or false if we have never heard anything about 00107 // this particular button. 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE bool ClientButtonDevice:: 00110 is_button_known(int index) const { 00111 if (index >= 0 && index < (int)_buttons.size()) { 00112 return _buttons[index]._state != S_unknown; 00113 } else { 00114 return false; 00115 } 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: ClientButtonDevice::get_button_events 00120 // Access: Public 00121 // Description: Returns the list of recently-generated ButtonEvents. 00122 // This must be periodically cleared, or the buttons 00123 // will accumulate. 00124 //////////////////////////////////////////////////////////////////// 00125 INLINE ButtonEventList *ClientButtonDevice:: 00126 get_button_events() const { 00127 return _button_events; 00128 }