Panda3D
 All Classes Functions Variables Enumerations
mouseWatcherParameter.I
00001 // Filename: mouseWatcherParameter.I
00002 // Created by:  drose (06Jul01)
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: MouseWatcherParameter::Constructor
00018 //       Access: Public
00019 //  Description: 
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE MouseWatcherParameter::
00022 MouseWatcherParameter() {
00023   _keycode = 0;
00024   _flags = 0;
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: MouseWatcherParameter::Copy Constructor
00029 //       Access: Public
00030 //  Description: 
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE MouseWatcherParameter::
00033 MouseWatcherParameter(const MouseWatcherParameter &copy) :
00034   _button(copy._button),
00035   _keycode(copy._keycode),
00036   _mods(copy._mods),
00037   _mouse(copy._mouse),
00038   _flags(copy._flags)
00039 {
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: MouseWatcherParameter::Copy Assignment Operator
00044 //       Access: Public
00045 //  Description: 
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE void MouseWatcherParameter::
00048 operator = (const MouseWatcherParameter &copy) {
00049   _button = copy._button;
00050   _keycode = copy._keycode;
00051   _mods = copy._mods;
00052   _mouse = copy._mouse;
00053   _flags = copy._flags;
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: MouseWatcherParameter::Destructor
00058 //       Access: Public
00059 //  Description: 
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE MouseWatcherParameter::
00062 ~MouseWatcherParameter() {
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: MouseWatcherParameter::set_button
00067 //       Access: Public
00068 //  Description: Sets the mouse or keyboard button that generated this
00069 //               event, if any.
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE void MouseWatcherParameter::
00072 set_button(const ButtonHandle &button) {
00073   _button = button;
00074   _flags |= F_has_button;
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: MouseWatcherParameter::set_keyrepeat
00079 //       Access: Public
00080 //  Description: Sets the state of the "keyrepeat" flag.  This is true
00081 //               if a button-press event was generated due to
00082 //               keyrepeat, or false if it is an original button
00083 //               press.
00084 ////////////////////////////////////////////////////////////////////
00085 INLINE void MouseWatcherParameter::
00086 set_keyrepeat(bool flag) {
00087   if (flag) {
00088     _flags |= F_is_keyrepeat;
00089   } else {
00090     _flags &= ~F_is_keyrepeat;
00091   }
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: MouseWatcherParameter::set_keycode
00096 //       Access: Public
00097 //  Description: Sets the keycode associated with this event, if any.
00098 ////////////////////////////////////////////////////////////////////
00099 INLINE void MouseWatcherParameter::
00100 set_keycode(int keycode) {
00101   _keycode = keycode;
00102   _flags |= F_has_keycode;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: MouseWatcherParameter::set_candidate
00107 //       Access: Public
00108 //  Description: Sets the candidate string associated with this event,
00109 //               if any.
00110 ////////////////////////////////////////////////////////////////////
00111 INLINE void MouseWatcherParameter::
00112 set_candidate(const wstring &candidate_string,
00113               size_t highlight_start, size_t highlight_end,
00114               size_t cursor_pos) {
00115   _candidate_string = candidate_string;
00116   _highlight_start = highlight_start;
00117   _highlight_end = highlight_end;
00118   _cursor_pos = cursor_pos;
00119   _flags |= F_has_candidate;
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////
00123 //     Function: MouseWatcherParameter::set_modifier_buttons
00124 //       Access: Public
00125 //  Description: Sets the modifier buttons that were being held while
00126 //               this event was generated.
00127 ////////////////////////////////////////////////////////////////////
00128 INLINE void MouseWatcherParameter::
00129 set_modifier_buttons(const ModifierButtons &mods) {
00130   _mods = mods;
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: MouseWatcherParameter::set_mouse
00135 //       Access: Public
00136 //  Description: Sets the mouse position that was current at the time
00137 //               the event was generated.
00138 ////////////////////////////////////////////////////////////////////
00139 INLINE void MouseWatcherParameter::
00140 set_mouse(const LPoint2 &mouse) {
00141   _mouse = mouse;
00142   _flags |= F_has_mouse;
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: MouseWatcherParameter::set_outside
00147 //       Access: Public
00148 //  Description: Sets the state of the "outside" flag.  This is true
00149 //               if the mouse was outside the region at the time the
00150 //               event was generated, false otherwise.  This only has
00151 //               meaning for "release" events.
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE void MouseWatcherParameter::
00154 set_outside(bool flag) {
00155   if (flag) {
00156     _flags |= F_is_outside;
00157   } else {
00158     _flags &= ~F_is_outside;
00159   }
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: MouseWatcherParameter::has_button
00164 //       Access: Published
00165 //  Description: Returns true if this parameter has an associated
00166 //               mouse or keyboard button, false otherwise.
00167 ////////////////////////////////////////////////////////////////////
00168 INLINE bool MouseWatcherParameter::
00169 has_button() const {
00170   return (_flags & F_has_button) != 0;
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: MouseWatcherParameter::get_button
00175 //       Access: Published
00176 //  Description: Returns the mouse or keyboard button associated with
00177 //               this event.  If has_button(), above, returns false,
00178 //               this returns ButtonHandle::none().
00179 ////////////////////////////////////////////////////////////////////
00180 INLINE ButtonHandle MouseWatcherParameter::
00181 get_button() const {
00182   return _button;
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: MouseWatcherParameter::is_keyrepeat
00187 //       Access: Published
00188 //  Description: Returns true if the button-down even was generated
00189 //               due to keyrepeat, or false if it was an original
00190 //               button down.
00191 ////////////////////////////////////////////////////////////////////
00192 INLINE bool MouseWatcherParameter::
00193 is_keyrepeat() const {
00194   return (_flags & F_is_keyrepeat) != 0;
00195 }
00196 
00197 ////////////////////////////////////////////////////////////////////
00198 //     Function: MouseWatcherParameter::has_keycode
00199 //       Access: Published
00200 //  Description: Returns true if this parameter has an associated
00201 //               keycode, false otherwise.
00202 ////////////////////////////////////////////////////////////////////
00203 INLINE bool MouseWatcherParameter::
00204 has_keycode() const {
00205   return (_flags & F_has_keycode) != 0;
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: MouseWatcherParameter::get_keycode
00210 //       Access: Published
00211 //  Description: Returns the keycode associated with this event.  If
00212 //               has_keycode(), above, returns false, this returns 0.
00213 ////////////////////////////////////////////////////////////////////
00214 INLINE int MouseWatcherParameter::
00215 get_keycode() const {
00216   return _keycode;
00217 }
00218 
00219 ////////////////////////////////////////////////////////////////////
00220 //     Function: MouseWatcherParameter::has_candidate
00221 //       Access: Published
00222 //  Description: Returns true if this parameter has an associated
00223 //               candidate string, false otherwise.
00224 ////////////////////////////////////////////////////////////////////
00225 INLINE bool MouseWatcherParameter::
00226 has_candidate() const {
00227   return (_flags & F_has_candidate) != 0;
00228 }
00229 
00230 ////////////////////////////////////////////////////////////////////
00231 //     Function: MouseWatcherParameter::get_candidate_string
00232 //       Access: Published
00233 //  Description: Returns the candidate string associated with this
00234 //               event.  If has_candidate(), above, returns false,
00235 //               this returns the empty string.
00236 ////////////////////////////////////////////////////////////////////
00237 INLINE const wstring &MouseWatcherParameter::
00238 get_candidate_string() const {
00239   return _candidate_string;
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: MouseWatcherParameter::get_candidate_string_encoded
00244 //       Access: Published
00245 //  Description: Returns the candidate string associated with this
00246 //               event.  If has_candidate(), above, returns false,
00247 //               this returns the empty string.
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE string MouseWatcherParameter::
00250 get_candidate_string_encoded() const {
00251   return get_candidate_string_encoded(TextEncoder::get_default_encoding());
00252 }
00253 
00254 ////////////////////////////////////////////////////////////////////
00255 //     Function: MouseWatcherParameter::get_candidate_string_encoded
00256 //       Access: Published
00257 //  Description: Returns the candidate string associated with this
00258 //               event.  If has_candidate(), above, returns false,
00259 //               this returns the empty string.
00260 ////////////////////////////////////////////////////////////////////
00261 INLINE string MouseWatcherParameter::
00262 get_candidate_string_encoded(TextEncoder::Encoding encoding) const {
00263   return TextEncoder::encode_wtext(_candidate_string, encoding);
00264 }
00265 
00266 ////////////////////////////////////////////////////////////////////
00267 //     Function: MouseWatcherParameter::get_highlight_start
00268 //       Access: Published
00269 //  Description: Returns the first highlighted character in the
00270 //               candidate string.
00271 ////////////////////////////////////////////////////////////////////
00272 INLINE size_t MouseWatcherParameter::
00273 get_highlight_start() const {
00274   return _highlight_start;
00275 }
00276 
00277 ////////////////////////////////////////////////////////////////////
00278 //     Function: MouseWatcherParameter::get_highlight_end
00279 //       Access: Published
00280 //  Description: Returns one more than the last highlighted character
00281 //               in the candidate string.
00282 ////////////////////////////////////////////////////////////////////
00283 INLINE size_t MouseWatcherParameter::
00284 get_highlight_end() const {
00285   return _highlight_end;
00286 }
00287 
00288 ////////////////////////////////////////////////////////////////////
00289 //     Function: MouseWatcherParameter::get_cursor_pos
00290 //       Access: Published
00291 //  Description: Returns the position of the user's edit cursor within
00292 //               the candidate string.
00293 ////////////////////////////////////////////////////////////////////
00294 INLINE size_t MouseWatcherParameter::
00295 get_cursor_pos() const {
00296   return _cursor_pos;
00297 }
00298 
00299 ////////////////////////////////////////////////////////////////////
00300 //     Function: MouseWatcherParameter::get_modifier_buttons
00301 //       Access: Published
00302 //  Description: Returns the set of modifier buttons that were being
00303 //               held down while the event was generated.
00304 ////////////////////////////////////////////////////////////////////
00305 INLINE const ModifierButtons &MouseWatcherParameter::
00306 get_modifier_buttons() const {
00307   return _mods;
00308 }
00309 
00310 ////////////////////////////////////////////////////////////////////
00311 //     Function: MouseWatcherParameter::has_mouse
00312 //       Access: Published
00313 //  Description: Returns true if this parameter has an associated
00314 //               mouse position, false otherwise.
00315 ////////////////////////////////////////////////////////////////////
00316 INLINE bool MouseWatcherParameter::
00317 has_mouse() const {
00318   return (_flags & F_has_mouse) != 0;
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: MouseWatcherParameter::get_mouse
00323 //       Access: Published
00324 //  Description: Returns the mouse position at the time the event was
00325 //               generated, in the normalized range (-1 .. 1).  It is
00326 //               valid to call this only if has_mouse() returned true.
00327 ////////////////////////////////////////////////////////////////////
00328 INLINE const LPoint2 &MouseWatcherParameter::
00329 get_mouse() const {
00330   nassertr(has_mouse(), _mouse);
00331   return _mouse;
00332 }
00333 
00334 ////////////////////////////////////////////////////////////////////
00335 //     Function: MouseWatcherParameter::is_outside
00336 //       Access: Published
00337 //  Description: Returns true if the mouse was outside the region at
00338 //               the time the event was generated, false otherwise.
00339 //               This is only valid for "release" type events.
00340 ////////////////////////////////////////////////////////////////////
00341 INLINE bool MouseWatcherParameter::
00342 is_outside() const {
00343   return (_flags & F_is_outside) != 0;
00344 }
00345 
00346 INLINE ostream &
00347 operator << (ostream &out, const MouseWatcherParameter &parm) {
00348   parm.output(out);
00349   return out;
00350 }
 All Classes Functions Variables Enumerations