00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef TEDDY__PHYSICAL_COMPONENTS__EVENT_LISTENER__H
00026 #define TEDDY__PHYSICAL_COMPONENTS__EVENT_LISTENER__H
00027
00028
00029 #include "Teddy/Signals/Functor.h"
00030 #include "Teddy/Maths/Vector2.h"
00031 #include "Teddy/SysSupport/StdSDL.h"
00032
00033
00034 namespace Teddy {
00035 namespace PhysicalComponents {
00036
00037
00038 struct Event {
00039 int type;
00040 SDL_keysym key;
00041 int item_id;
00042 int state;
00043 Teddy::Maths::TVector2<int> pos;
00044 Teddy::Maths::TVector2<int> delta;
00045
00046 static const int Event_ID ;
00047 static const int WindowEvent_ID ;
00048 static const int WindowFocusActiveEvent_ID ;
00049 static const int WindowPopupOpenEvent_ID ;
00050 static const int WindowPopupCloseEvent_ID ;
00051 static const int WindowMoveEvent_ID ;
00052 static const int WindowSizeEventEvent_ID ;
00053 static const int WindowToFrontEvent_ID ;
00054 static const int WindowToBackEvent_ID ;
00055 static const int WindowSplitUpdateEvent_ID ;
00056 static const int MouseButtonDownEvent_ID ;
00057 static const int MouseButtonUpEvent_ID ;
00058 static const int MouseMotionEvent_ID ;
00059 static const int MouseDragEvent_ID ;
00060 static const int MouseHoldDragEvent_ID ;
00061 static const int KeyEvent_ID ;
00062 static const int KeyDownEvent_ID ;
00063 static const int KeyUpEvent_ID ;
00064 static const int JoyEvent_ID ;
00065 static const int JoyButtonEvent_ID ;
00066 static const int JoyAxisEvent_ID ;
00067 static const int JoyHatEvent_ID ;
00068 static const int JoyBallEvent_ID ;
00069 };
00070
00071 struct WindowEvent : public Event {
00072 };
00073
00074 struct WindowFocusActiveEvent : public WindowEvent {
00075 WindowFocusActiveEvent( int active ){
00076 type = WindowFocusActiveEvent_ID;
00077 state = active;
00078 }
00079 };
00080
00081 struct WindowPopupOpenEvent : public WindowEvent {
00082 WindowPopupOpenEvent(){
00083 type = WindowPopupOpenEvent_ID;
00084 }
00085 };
00086
00087 struct WindowPopupCloseEvent : public WindowEvent {
00088 WindowPopupCloseEvent(){
00089 type = WindowPopupCloseEvent_ID;
00090 }
00091 };
00092
00093 struct WindowMoveEvent : public WindowEvent {
00094 WindowMoveEvent(){
00095 type = WindowMoveEvent_ID;
00096 }
00097 };
00098
00099 struct WindowSizeEventEvent : public WindowEvent {
00100 WindowSizeEventEvent(){
00101 type = WindowSizeEventEvent_ID;
00102 }
00103 };
00104
00105 struct WindowToFrontEvent : public WindowEvent {
00106 WindowToFrontEvent(){
00107 type = WindowToFrontEvent_ID;
00108 }
00109 };
00110
00111 struct WindowToBackEvent : public WindowEvent {
00112 WindowToBackEvent(){
00113 type = WindowToBackEvent_ID;
00114 }
00115 };
00116
00117 struct WindowSplitUpdateEvent : public WindowEvent {
00118 WindowSplitUpdateEvent(){
00119 type = WindowSplitUpdateEvent_ID;
00120 }
00121 };
00122
00123 struct MouseEvent : public Event {
00124 };
00125
00126 struct MouseButtonDownEvent : public MouseEvent {
00127 MouseButtonDownEvent( const int button, const int state, const Teddy::Maths::TVector2<int> &pos ){
00128 type = MouseButtonDownEvent_ID;
00129 item_id = button;
00130 this->state = state;
00131 this->pos = pos;
00132 }
00133 };
00134
00135 struct MouseButtonUpEvent : public MouseEvent {
00136 MouseButtonUpEvent( const int button, const int state, const Teddy::Maths::TVector2<int> &pos ){
00137 type = MouseButtonUpEvent_ID;
00138 item_id = button;
00139 this->state = state;
00140 this->pos = pos;
00141 }
00142 };
00143
00144 struct MouseMotionEvent : public MouseEvent {
00145 MouseMotionEvent( const Teddy::Maths::TVector2<int> &pos, const Teddy::Maths::TVector2<int> &delta ){
00146 type = MouseMotionEvent_ID;
00147 this->pos = pos;
00148 this->delta = delta;
00149 }
00150 };
00151
00152 struct MouseDragEvent : public MouseEvent {
00153 MouseDragEvent( const Teddy::Maths::TVector2<int> &pos, const Teddy::Maths::TVector2<int> &delta, const int button ){
00154 type = MouseDragEvent_ID;
00155 this->item_id = button;
00156 this->pos = pos;
00157 this->delta = delta;
00158 }
00159 };
00160
00161 struct MouseHoldDragEvent : public MouseEvent {
00162 MouseHoldDragEvent( const Teddy::Maths::TVector2<int> &pos, const Teddy::Maths::TVector2<int> &delta, const int button ){
00163 type = MouseHoldDragEvent_ID;
00164 this->item_id = button;
00165 this->pos = pos;
00166 this->delta = delta;
00167 }
00168 };
00169
00170 struct KeyEvent : public Event {
00171 };
00172
00173 struct KeyDownEvent : public KeyEvent {
00174 KeyDownEvent( const SDL_keysym key ){
00175 type = KeyDownEvent_ID;
00176 this->key = key;
00177 }
00178 };
00179
00180 struct KeyUpEvent : public KeyEvent {
00181 KeyUpEvent( const SDL_keysym key ){
00182 type = KeyUpEvent_ID;
00183 this->key = key;
00184 }
00185 };
00186
00187 struct JoyEvent : public Event {
00188 };
00189
00190 struct JoyButtonEvent : public JoyEvent {
00191 JoyButtonEvent( const int button_id, const int state ){
00192 type = JoyButtonEvent_ID;
00193 this->item_id = button_id;
00194 this->state = state;
00195 }
00196 };
00197
00198 struct JoyAxisEvent : public JoyEvent {
00199 JoyAxisEvent( const int axis_id, const int state ){
00200 type = JoyAxisEvent_ID;
00201 this->item_id = axis_id;
00202 this->state = state;
00203 }
00204 };
00205
00206 struct JoyHatEvent : public JoyEvent {
00207 JoyHatEvent( const int hat_id, const int value ){
00208 type = JoyHatEvent_ID;
00209 this->item_id = hat_id;
00210 this->state = value;
00211 }
00212 };
00213
00214 struct JoyBallEvent : public JoyEvent {
00215 JoyBallEvent( const int ball_id, const Teddy::Maths::TVector2<int> &delta ){
00216 type = JoyBallEvent_ID;
00217 this->item_id = ball_id;
00218 this->delta = delta;
00219 }
00220 };
00221
00222
00224 class EventListener {
00225 public:
00226 EventListener();
00227 virtual ~EventListener();
00228
00229 virtual void event ( const Event &e );
00230 virtual bool doesEvent ( int type );
00231 void bind ( int type, Teddy::Signals::Functor1<bool,const Event &> *f );
00232 void enableEvent ( int type );
00233 void disableEvent( int type );
00234
00235 unsigned long functor_mask;
00236 unsigned long anon_mask;
00237 Teddy::Signals::Holder1<bool,const Event &> holder[32];
00238 };
00239
00240
00241 #undef Vector2
00242 #define Vector2 TVector2<float>
00243
00244
00245 };
00246 };
00247
00248
00249 #endif // TEDDY__PHYSICAL_COMPONENTS__EVENT_LISTENER__H
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277