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