00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_EVENT_HPP_)
00012 #define _XRB_EVENT_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_key.hpp"
00017 #include "xrb_screencoord.hpp"
00018
00019 namespace Xrb
00020 {
00021
00053 class Event
00054 {
00055 public:
00056
00062 enum EventType
00063 {
00064 DUMMY = 0,
00065 KEYDOWN,
00066 KEYUP,
00067 KEYREPEAT,
00068 MOUSEBUTTONDOWN,
00069 MOUSEBUTTONUP,
00070 MOUSEWHEEL,
00071 MOUSEMOTION,
00072 JOYAXIS,
00073 JOYBALL,
00074 JOYBUTTONDOWN,
00075 JOYBUTTONUP,
00076 JOYHAT,
00077 FOCUS,
00078 MOUSEOVER,
00079 DELETE_CHILD_WIDGET,
00080 QUIT,
00081 STATE_MACHINE_INPUT,
00082 ENGINE2_DELETE_ENTITY,
00083 ENGINE2_REMOVE_ENTITY_FROM_WORLD,
00084 CUSTOM
00085 };
00086
00093 inline Event (Float time, EventType event_type)
00094 {
00095 ASSERT1(time >= 0.0);
00096 m_time = time;
00097 m_event_type = event_type;
00098 m_id = 0;
00099 m_is_scheduled_for_deletion = false;
00100 }
00106 virtual ~Event () = 0;
00107
00110 static std::string const &Name (EventType event_type);
00113 inline Float Time () const { return m_time; }
00116 inline EventType GetEventType () const { return m_event_type; }
00120 inline Uint32 ID () const { return m_id; }
00126 inline bool IsScheduledForDeletion () const { return m_is_scheduled_for_deletion; }
00131 virtual bool IsInputEvent () const { return false; }
00135 virtual bool IsKeyEvent () const { return false; }
00139 virtual bool IsMouseEvent () const { return false; }
00144 virtual bool IsMouseButtonEvent () const { return false; }
00149 virtual bool IsMouseMotionEvent () const { return false; }
00153 virtual bool IsJoyEvent () const { return false; }
00154
00155 private:
00156
00157 inline void SetID (Uint32 id) const { m_id = id; }
00158
00159 inline void ScheduleForDeletion () const { m_is_scheduled_for_deletion = true; }
00160
00161 Float m_time;
00162 EventType m_event_type;
00163 mutable Uint32 m_id;
00164 mutable bool m_is_scheduled_for_deletion;
00165
00166 friend class EventQueue;
00167 };
00168
00174 class EventStateMachineInput : public Event
00175 {
00176 public:
00177
00180 EventStateMachineInput (StateMachineInput input, Float time)
00181 :
00182 Event(time, STATE_MACHINE_INPUT),
00183 m_input(input)
00184 { }
00185
00186 inline StateMachineInput GetInput () const { return m_input; }
00187
00188 private:
00189
00190 StateMachineInput const m_input;
00191 };
00192
00198 class EventCustom : public Event
00199 {
00200 public:
00201
00202 typedef Uint16 CustomType;
00203
00206 EventCustom (CustomType custom_type, Float time)
00207 :
00208 Event(time, CUSTOM),
00209 m_custom_type(custom_type)
00210 { }
00213 virtual ~EventCustom () = 0;
00214
00215 inline CustomType GetCustomType () const { return m_custom_type; }
00216
00217 private:
00218
00219 CustomType const m_custom_type;
00220 };
00221
00223
00227 class EventDummy : public Event
00228 {
00229 private:
00230
00231 EventDummy (Float time) : Event(time, DUMMY) { }
00232 ~EventDummy () { }
00233
00234 friend class EventQueue;
00235 };
00237
00238
00239
00240
00241
00242 bool MatchEventType (Event const *event, Event::EventType event_type);
00243 bool MatchCustomType (Event const *event, EventCustom::CustomType custom_type);
00244
00245 }
00246
00247 #endif // !defined(_XRB_EVENT_HPP_)
00248