Panda3D

buttonHandle.I

00001 // Filename: buttonHandle.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: ButtonHandle::Constructor
00018 //       Access: Published
00019 //  Description: The default constructor must do nothing, because we
00020 //               can't guarantee ordering of static initializers.  If
00021 //               the constructor tried to initialize its value, it
00022 //               might happen after the value had already been set
00023 //               previously by another static initializer!
00024 ////////////////////////////////////////////////////////////////////
00025 INLINE ButtonHandle::
00026 ButtonHandle() {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: ButtonHandle::Constructor
00031 //       Access: Published
00032 //  Description: Constructs a ButtonHandle with the corresponding
00033 //               index number, which may have been returned by an
00034 //               earlier call to ButtonHandle::get_index().
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE ButtonHandle::
00037 ButtonHandle(int index) : _index(index) {
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: ButtonHandle::Copy Constructor
00042 //       Access: Published
00043 //  Description:
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE ButtonHandle::
00046 ButtonHandle(const ButtonHandle &copy) : _index(copy._index) {
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: ButtonHandle::Equality Operator
00051 //       Access: Published
00052 //  Description:
00053 ////////////////////////////////////////////////////////////////////
00054 INLINE bool ButtonHandle::
00055 operator == (const ButtonHandle &other) const {
00056   return (_index == other._index);
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: ButtonHandle::Inequality Operator
00061 //       Access: Published
00062 //  Description:
00063 ////////////////////////////////////////////////////////////////////
00064 INLINE bool ButtonHandle::
00065 operator != (const ButtonHandle &other) const {
00066   return (_index != other._index);
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: ButtonHandle::Ordering Operator
00071 //       Access: Published
00072 //  Description:
00073 ////////////////////////////////////////////////////////////////////
00074 INLINE bool ButtonHandle::
00075 operator < (const ButtonHandle &other) const {
00076   return (_index < other._index);
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: ButtonHandle::has_ascii_equivalent
00081 //       Access: Published
00082 //  Description: Returns true if the button was created with an ASCII
00083 //               equivalent code (e.g. for a standard keyboard
00084 //               button).
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE bool ButtonHandle::
00087 has_ascii_equivalent() const {
00088   return (_index > 0 && _index < 128);
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: ButtonHandle::get_ascii_equivalent
00093 //       Access: Published
00094 //  Description: Returns the character code associated with the
00095 //               button, or '\0' if no ASCII code was associated.
00096 ////////////////////////////////////////////////////////////////////
00097 INLINE char ButtonHandle::
00098 get_ascii_equivalent() const {
00099   return has_ascii_equivalent() ? (char)_index : '\0';
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: ButtonHandle::matches
00104 //       Access: Published
00105 //  Description: Returns true if this ButtonHandle is the same as the
00106 //               other one, or if the other one is an alias for this
00107 //               one.  (Does not return true if this button is an
00108 //               alias for the other one, however.)
00109 //
00110 //               This is a more general comparison than operator ==.
00111 ////////////////////////////////////////////////////////////////////
00112 INLINE bool ButtonHandle::
00113 matches(const ButtonHandle &other) const {
00114   return ((*this) == other ||
00115           (other != ButtonHandle::none() &&
00116            get_alias() == other));
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: ButtonHandle::get_index
00121 //       Access: Published
00122 //  Description: Returns the integer index associated with this
00123 //               ButtonHandle. Each different ButtonHandle will have a
00124 //               different index.  However, you probably shouldn't be
00125 //               using this method; you should just treat the
00126 //               ButtonHandles as opaque classes.  This is provided
00127 //               for the convenience of non-C++ scripting languages to
00128 //               build a hashtable of ButtonHandles.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE int ButtonHandle::
00131 get_index() const {
00132   return _index;
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: ButtonHandle::output
00137 //       Access: Published
00138 //  Description: 
00139 ////////////////////////////////////////////////////////////////////
00140 INLINE void ButtonHandle::
00141 output(ostream &out) const {
00142   out << get_name();
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: ButtonHandle::none
00147 //       Access: Published, Static
00148 //  Description: Returns a special zero-valued ButtonHandle that is
00149 //               used to indicate no button.
00150 ////////////////////////////////////////////////////////////////////
00151 INLINE ButtonHandle ButtonHandle::
00152 none() {
00153   return _none;
00154 }
 All Classes Functions Variables Enumerations