Panda3D
|
00001 // Filename: buttonEvent.h 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 #ifndef BUTTONEVENT_H 00016 #define BUTTONEVENT_H 00017 00018 #include "pandabase.h" 00019 00020 #include "buttonHandle.h" 00021 #include "clockObject.h" 00022 #include "modifierButtons.h" 00023 00024 class Datagram; 00025 class DatagramIterator; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : ButtonEvent 00029 // Description : Records a button event of some kind. This is either 00030 // a keyboard or mouse button (or some other kind of 00031 // button) changing state from up to down, or 00032 // vice-versa, or it is a single "keystroke". 00033 // 00034 // A keystroke is different than a button event in that 00035 // (a) it does not necessarily correspond to a physical 00036 // button on a keyboard, but might be the result of a 00037 // combination of buttons (e.g. "A" is the result of 00038 // shift + "a"); and (b) it does not manage separate 00039 // "up" and "down" events, but is itself an 00040 // instantaneous event. 00041 // 00042 // Normal up/down button events can be used to track the 00043 // state of a particular button on the keyboard, while 00044 // keystroke events are best used to monitor what a user 00045 // is attempting to type. 00046 // 00047 // Button up/down events are defined across all the 00048 // physical keys on the keyboard (and other buttons for 00049 // which there is a corresponding ButtonHandle object), 00050 // while keystroke events are defined across the entire 00051 // Unicode character set. 00052 //////////////////////////////////////////////////////////////////// 00053 class EXPCL_PANDA_EVENT ButtonEvent { 00054 public: 00055 enum Type { 00056 // T_down and T_up represent a button changing state 00057 // correspondingly. T_resume_down is a special event that is only 00058 // thrown when focus is returned to a window and a button is 00059 // detected as being held down at that point; it indicates that 00060 // the button should be considered down now (if it wasn't 00061 // already), but it didn't just get pressed down at this moment, 00062 // it was depressed some time ago. It's mainly used for correct 00063 // tracking of modifier keys like shift and control, and can be 00064 // ignored for other keys. 00065 T_down, 00066 T_resume_down, 00067 T_up, 00068 00069 // T_repeat is sent for each a keyrepeat event generated by the 00070 // system, for a button that is continually held down. If you 00071 // want to respect keyrepeat, treat T_down and T_repeat 00072 // equivalently. 00073 T_repeat, 00074 00075 // T_keystroke is a special keystroke event, and is sent along 00076 // with a Unicode keycode value, not a ButtonHandle. 00077 T_keystroke, 00078 00079 // T_candidate is used to indicate that the user is using the IME 00080 // and has in the process of selecting some possible text to type 00081 // from a menu. 00082 T_candidate, 00083 00084 // T_move is used to indicate that the mouse has moved within the 00085 // current region. Button drag mode needs this, others may ignore 00086 // this event 00087 T_move, 00088 }; 00089 00090 INLINE ButtonEvent(); 00091 INLINE ButtonEvent(ButtonHandle button, Type type, double time = ClockObject::get_global_clock()->get_frame_time()); 00092 INLINE ButtonEvent(short keycode, double time = ClockObject::get_global_clock()->get_frame_time()); 00093 INLINE ButtonEvent(const wstring &candidate_string, size_t highlight_start, 00094 size_t highlight_end, size_t cursor_pos); 00095 INLINE ButtonEvent(const ButtonEvent ©); 00096 INLINE void operator = (const ButtonEvent ©); 00097 00098 INLINE bool operator == (const ButtonEvent &other) const; 00099 INLINE bool operator != (const ButtonEvent &other) const; 00100 INLINE bool operator < (const ButtonEvent &other) const; 00101 00102 INLINE bool update_mods(ModifierButtons &mods) const; 00103 00104 void output(ostream &out) const; 00105 00106 void write_datagram(Datagram &dg) const; 00107 void read_datagram(DatagramIterator &scan); 00108 00109 public: 00110 // _button will be filled in if type is T_down, T_resume_down, or 00111 // T_up. 00112 ButtonHandle _button; 00113 00114 // _keycode will be filled in if type is T_keystroke. It will be 00115 // the Unicode character that was typed. 00116 short _keycode; 00117 00118 // _candidate_string will be filled in if type is T_candidate. 00119 wstring _candidate_string; 00120 size_t _highlight_start; 00121 size_t _highlight_end; 00122 size_t _cursor_pos; 00123 00124 // This is the type of the button event (see above). 00125 Type _type; 00126 00127 // This is the time the event occurred, as recorded from the OS if 00128 // that information is available. It is in seconds elapsed from an 00129 // arbitrary epoch, and it matches the time reported by 00130 // ClockObject::get_global_clock(). 00131 double _time; 00132 }; 00133 00134 INLINE ostream &operator << (ostream &out, const ButtonEvent &be) { 00135 be.output(out); 00136 return out; 00137 } 00138 00139 #include "buttonEvent.I" 00140 00141 #endif 00142