00001 // This is core/vgui/vgui_event.h 00002 #ifndef vgui_event_h_ 00003 #define vgui_event_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 00010 // \date 11 Sep 99 00011 // \brief vgui_event class encapsulates the events handled by the vgui system. 00012 // 00013 // \verbatim 00014 // Modifications 00015 // 16-Sep-1999 fsm. various. 00016 // 5-Oct-1999 fsm. replaced (x,y) by (wx,wy) and (ux,uy). 00017 // 10-Oct-1999 pcp added timestamp 00018 // 20-Oct-1999 awf Changed timestamp to int. 00019 // 19-Oct-1999 fsm. added pointer to adaptor. 00020 // 1-Nov-1999 fsm. events now use viewport, not window coordinates. 00021 // 28-Nov-1999 fsm. added vcl_string event. 00022 // 22-Aug-2000 Marko Bacic. added support for scroll bar events 00023 // 04-Oct-2002 K.Y.McGaul - Added set_key() to make sure vgui_key is now 00024 // always lower case to save confusion. 00025 // - Added ascii_char value to vgui_event. 00026 // \endverbatim 00027 00028 #include <vcl_string.h> 00029 #include <vcl_iosfwd.h> 00030 #include <vgui/vgui_key.h> 00031 #include <vgui/vgui_button.h> 00032 #include <vgui/vgui_modifier.h> 00033 class vgui_adaptor; 00034 00035 enum vgui_event_type 00036 { 00037 vgui_EVENT_NULL = 0, 00038 vgui_ENTER, 00039 vgui_LEAVE, 00040 vgui_BUTTON_DOWN, /* */ vgui_MOUSE_DOWN = vgui_BUTTON_DOWN, vgui_MOUSE_PRESS = vgui_BUTTON_DOWN, 00041 vgui_BUTTON_UP, /* */ vgui_MOUSE_UP = vgui_BUTTON_UP, vgui_MOUSE_RELEASE = vgui_BUTTON_UP, 00042 vgui_MOTION, /* */ vgui_MOUSE_MOTION = vgui_MOTION, 00043 vgui_KEY_PRESS, /* */ vgui_KEY_DOWN = vgui_KEY_PRESS, 00044 vgui_KEY_RELEASE, /* */ vgui_KEY_UP = vgui_KEY_RELEASE, 00045 vgui_RESHAPE, 00046 vgui_TIMER, 00047 vgui_DRAW, 00048 vgui_DRAW_OVERLAY, /* */ vgui_OVERLAY_DRAW = vgui_DRAW_OVERLAY, 00049 vgui_STRING, 00050 vgui_HSCROLL, 00051 vgui_VSCROLL, 00052 vgui_DESTROY, 00053 vgui_IDLE, 00054 vgui_OTHER, 00055 vgui_FOCUSGAINED, 00056 vgui_FOCUSLOST, 00057 vgui_WHEEL_UP, 00058 vgui_WHEEL_DOWN, 00059 vgui_EVENT_MAX // This must be the last entry in the list 00060 }; 00061 00062 vcl_ostream& operator<<(vcl_ostream& s, vgui_event_type e); 00063 00064 //: The vgui_event class encapsulates the events handled by the vgui system. 00065 // 00066 // For key presses with modifiers the following standards apply: 00067 // \verbatim 00068 // a modifier = vgui_NULL key = 'a' ascii_char = 'a' 00069 // CTRL+a modifier = vgui_CTRL key = 'a' ascii_char = '^A' 00070 // SHIFT+a modifier = vgui_SHIFT key = 'a' ascii_char = 'A' 00071 // \endverbatim 00072 // 00073 // We have decided to make it a standard that key is always lower case for 00074 // simplicity. In particular people have been defining impossible 00075 // vgui_event_conditions, eg key='A', modifier=NULL (where NULL is the 00076 // default modifier) and then wondering why SHIFT+a doesn't work. 00077 // 00078 // A new data type has been added (ascii_char) which holds the actual 00079 // key stroke pressed by the user. 00080 class vgui_event 00081 { 00082 public: 00083 //: Constructor - create a default event. 00084 vgui_event() { init(); } 00085 00086 //: Constructor - create an event of the given type. 00087 vgui_event(vgui_event_type); 00088 00089 //: The type of event (key press, mouse motion, etc). 00090 vgui_event_type type; 00091 00092 //: Mouse button used (if it is a mouse event). 00093 vgui_button button; 00094 00095 //: The key pressed in lower case (if it is a key event). 00096 vgui_key key; 00097 00098 //: Convert given key to lower case and use that to set key. 00099 void set_key(vgui_key c); 00100 00101 //: Which modifiers are pressed during the event (NULL, CTRL, SHIFT). 00102 vgui_modifier modifier; 00103 00104 //: The actual key stroke pressed by the user. 00105 vgui_key ascii_char; 00106 00107 //: Position of the mouse pointer in viewport coordinates when event occurred. 00108 int wx,wy; 00109 00110 //: Timestamp in milliseconds since app started. 00111 int timestamp; 00112 00113 //: The adaptor from which the event came. 00114 vgui_adaptor *origin; 00115 00116 //: If the event is a timer event, this holds the ID. 00117 // For an event of type vgui_TIMER, this field holds the name 00118 // that was given when the timer request was posted. 00119 int timer_id; 00120 00121 //: A vcl_string message, for an event of type vgui_STRING. 00122 // An event of type vgui_STRING implies that 00123 // this field contains some sort of textual message. The exact 00124 // encoding of these messages is unspecified; the sender and the 00125 // receiver may use any protocol they like. Caveat : as a 00126 // corollary there is no guarantee that one protocol will not 00127 // clash with another. 00128 vcl_string str; 00129 00130 //: Type and data for events of type vgui_OTHER. 00131 // The fields user and data are used only when the event type is vgui_OTHER. 00132 // The 'user' field must uniquely identify the type of event, in the 00133 // sense that once the user field is known, the 'data' field can be 00134 // safely cast to point to the client data (type). 00135 void const *user; 00136 void const *data; 00137 00138 // methods 00139 bool modifier_is_down(int) const; 00140 double secs_since(vgui_event const &) const; 00141 long usecs_since(vgui_event const &) const; 00142 00143 private: 00144 void init(); 00145 }; 00146 00147 bool operator==(vgui_event const& a, vgui_event const& b); 00148 vcl_ostream& operator<<(vcl_ostream&, vgui_event const&); 00149 00150 #endif // vgui_event_h_