Panda3D
 All Classes Functions Variables Enumerations
buttonEvent.I
00001 // Filename: buttonEvent.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: ButtonEvent::Default Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE ButtonEvent::
00022 ButtonEvent() :
00023   _button(ButtonHandle::none()),
00024   _keycode(0),
00025   _type(T_down),
00026   _time(0.0)
00027 {
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: ButtonEvent::Constructor
00032 //       Access: Public
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE ButtonEvent::
00036 ButtonEvent(ButtonHandle button, ButtonEvent::Type type, double time) :
00037   _button(button),
00038   _keycode(0),
00039   _highlight_start(0),
00040   _highlight_end(0),
00041   _type(type),
00042   _time(time)
00043 {
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: ButtonEvent::Constructor
00048 //       Access: Public
00049 //  Description:
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE ButtonEvent::
00052 ButtonEvent(short keycode, double time) :
00053   _button(ButtonHandle::none()),
00054   _keycode(keycode),
00055   _highlight_start(0),
00056   _highlight_end(0),
00057   _type(T_keystroke),
00058   _time(time)
00059 {
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: ButtonEvent::Constructor
00064 //       Access: Public
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE ButtonEvent::
00068 ButtonEvent(const wstring &candidate_string, size_t highlight_start, 
00069             size_t highlight_end, size_t cursor_pos) :
00070   _button(ButtonHandle::none()),
00071   _keycode(0),
00072   _candidate_string(candidate_string),
00073   _highlight_start(highlight_start),
00074   _highlight_end(highlight_end),
00075   _cursor_pos(cursor_pos),
00076   _type(T_candidate),
00077   _time(ClockObject::get_global_clock()->get_frame_time())
00078 {
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: ButtonEvent::Copy Constructor
00083 //       Access: Public
00084 //  Description:
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE ButtonEvent::
00087 ButtonEvent(const ButtonEvent &copy) :
00088   _button(copy._button),
00089   _keycode(copy._keycode),
00090   _candidate_string(copy._candidate_string),
00091   _highlight_start(copy._highlight_start),
00092   _highlight_end(copy._highlight_end),
00093   _cursor_pos(copy._cursor_pos),
00094   _type(copy._type),
00095   _time(copy._time)
00096 {
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: ButtonEvent::Copy Assignment Operator
00101 //       Access: Public
00102 //  Description:
00103 ////////////////////////////////////////////////////////////////////
00104 INLINE void ButtonEvent::
00105 operator = (const ButtonEvent &copy) {
00106   _button = copy._button;
00107   _keycode = copy._keycode;
00108   _candidate_string = copy._candidate_string;
00109   _highlight_start = copy._highlight_start;
00110   _highlight_end = copy._highlight_end;
00111   _cursor_pos = copy._cursor_pos;
00112   _type = copy._type;
00113   _time = copy._time;
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: ButtonEvent::Equality Operator
00118 //       Access: Public
00119 //  Description: The equality operator does not consider time
00120 //               significant.
00121 ////////////////////////////////////////////////////////////////////
00122 INLINE bool ButtonEvent::
00123 operator == (const ButtonEvent &other) const {
00124   return (_button == other._button &&
00125           _keycode == other._keycode &&
00126           _type == other._type);
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: ButtonEvent::Inequality Operator
00131 //       Access: Public
00132 //  Description:
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE bool ButtonEvent::
00135 operator != (const ButtonEvent &other) const {
00136   return !operator == (other);
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: ButtonEvent::Ordering Operator
00141 //       Access: Public
00142 //  Description:
00143 ////////////////////////////////////////////////////////////////////
00144 INLINE bool ButtonEvent::
00145 operator < (const ButtonEvent &other) const {
00146   if (_button != other._button) {
00147     return _button < other._button;
00148   }
00149   if (_keycode != other._keycode) {
00150     return _keycode < other._keycode;
00151   }
00152 
00153   return _type < other._type;
00154 }
00155 
00156 ////////////////////////////////////////////////////////////////////
00157 //     Function: ButtonEvent::update_mods
00158 //       Access: Published
00159 //  Description: Calls button_down() or button_up(), as appropriate,
00160 //               according to the ButtonEvent.
00161 ////////////////////////////////////////////////////////////////////
00162 INLINE bool ButtonEvent::
00163 update_mods(ModifierButtons &mods) const {
00164   switch (_type) {
00165   case T_down:
00166     return mods.button_down(_button);
00167 
00168   case T_up:
00169     return mods.button_up(_button);
00170 
00171   default:
00172     return false;
00173   }
00174 }
 All Classes Functions Variables Enumerations