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/SysSupport/StdSDL.h"
00030 #include "Teddy/SysSupport/Signals.h"
00031
00032
00033 namespace Teddy {
00034 namespace PhysicalComponents {
00035
00036
00037 struct Event {
00038 int type;
00039 SDL_keysym key;
00040 int item_id;
00041 int state;
00042 int x;
00043 int y;
00044 int dx;
00045 int dy;
00046 };
00047
00048 const int Event_ID = 0;
00049
00050 const int WindowEvent_ID = 1;
00051 struct WindowEvent : public Event {
00052 };
00053
00054 const int WindowEvent_ID = 2;
00055 struct WindowFocusActiveEvent : public WindowEvent {
00056 WindowFocusActiveEvent( int active ){
00057 type = WindowEvent_ID;
00058 state = active;
00059 }
00060 };
00061
00062 const int WindowPopupOpenEvent_ID = 3;
00063 struct WindowPopupOpenEvent : public WindowEvent {
00064 WindowPopupOpenEvent(){
00065 type = WindowPopupOpenEvent_ID;
00066 }
00067 };
00068
00069 const int WindowPopupCloseEvent_ID = 4;
00070 struct WindowPopupCloseEvent : public WindowEvent {
00071 WindowPopupCloseEvent(){
00072 type = WindowPopupCloseEvent_ID;
00073 }
00074 };
00075
00076 const int WindowMoveEvent_ID = 5;
00077 struct WindowMoveEvent : public WindowEvent {
00078 WindowMoveEvent(){
00079 type = WindowMoveEvent_ID;
00080 }
00081 }:
00082
00083 const int WindowSizeEventEvent_ID = 6;
00084 struct WindowSizeEventEvent : public WindowEvent {
00085 WindowSizeEventEvent(){
00086 type = WindowSizeEventEvent_ID;
00087 }
00088 };
00089
00090 const int WindowToFrontEvent_ID = 7;
00091 struct WindowToFrontEvent : public WindowEvent {
00092 WindowToFrontEvent(){
00093 type = WindowToFrontEvent_ID;
00094 }
00095 };
00096
00097 const int WindowToBackEvent_ID = 8;
00098 struct WindowToBackEvent : public WindowEvent {
00099 WindowToBackEvent(){
00100 type = WindowToBackEvent_ID;
00101 }
00102 };
00103
00104 const int WindowSplitUpdateEvent_ID = 9;
00105 struct WindowSplitUpdateEvent : public WindowEvent {
00106 WindowSplitUpdateEvent(){
00107 type = WindowSplitUpdateEvent_ID;
00108 }
00109 };
00110
00111 const int MouseEvent_ID = 10;
00112 struct MouseEvent : public Event {
00113 };
00114
00115 const int MouseButtonEvent_ID = 11;
00116 struct MouseButtonEvent : public MouseEvent {
00117 MouseButtonEvent( int button, int state, int x, int y ){
00118 type = MouseButtonEvent_ID;
00119 item_id = button;
00120 this->state = state;
00121 this->x = x;
00122 this->y = y;
00123 }
00124 };
00125
00126 const int MouseMotionEvent_ID = 12;
00127 struct MouseMotionEvent : public MouseEvent {
00128 MouseMotionEvent( int x, int y, int dx, int dy ){
00129 type = MouseMotionEvent_ID;
00130 this->x = x;
00131 this->y = y;
00132 this->dx = dx;
00133 this->dy = dy;
00134 }
00135 };
00136
00137 const int MouseDragEvent_ID = 13;
00138 struct MouseDragEvent : public MouseMotionEvent {
00139 MouseDragEvent( int x, int y, int dx, int dy,int button ){
00140 type = MouseDragEvent_ID;
00141 this->item_id = button;
00142 this->x = x;
00143 this->y = y;
00144 this->dx = dx;
00145 this->dy = dy;
00146 }
00147 };
00148
00149 const int MouseHoldDragEvent_ID = 14;
00150 struct MouseHoldDragEvent : public MouseDragEvent {
00151 MouseHoldDragEvent( int x, int y, int dx, int dy, int button ){
00152 type = MouseHoldDragEvent_ID;
00153 this->item_id = button;
00154 this->x = x;
00155 this->y = y;
00156 this->dx = dx;
00157 this->dy = dy;
00158 }
00159 };
00160
00161 const int KeyEvent_ID = 15;
00162 struct KeyEvent : public Event {
00163 };
00164
00165 const int KeyDownEvent_ID = 16;
00166 struct KeyDownEvent : public KeyEvent {
00167 KeyDownEvent( SDL_keysym key ){
00168 type = KeyDownEvent_ID;
00169 this->key = key;
00170 }
00171 };
00172
00173 const int KeyUpEvent_ID = 17;
00174 struct KeyUpEvent : public KeyEvent {
00175 KeyUpEvent( SDL_keysym key ){
00176 type = KeyUpEvent_ID;
00177 this->key = key;
00178 }
00179 };
00180
00181 const int JoyEvent_ID = 18;
00182 struct JoyEvent : public Event {
00183 };
00184
00185 const int JoyButtonEvent_ID = 19;
00186 struct JoyButtonEvent : public JoyEvent {
00187 JoyButtonEvent( int button_id, int state ){
00188 type = JoyButtonEvent_ID;
00189 this->item_id = button_id;
00190 this->state = state;
00191 }
00192 };
00193
00194 const int JoyAxisEvent_ID = 20;
00195 struct JoyAxisEvent : public JoyEvent {
00196 JoyAxisEvent( int axis_id, int state ){
00197 type = JoyAxisEvent_ID;
00198 this->item_id = axis_id;
00199 this->state = state;
00200
00201 }
00202 };
00203
00204 const int JoyHatEvent_ID = 21;
00205 struct JoyHatEvent : public JoyEvent {
00206 JoyHatEvent( int hat_id,int value ){
00207 type = JoyHatEvent_ID;
00208 this->item_id = hat_id;
00209 this->state = value;
00210 }
00211 };
00212
00213 const int JoyBallEvent_ID = 22;
00214 struct JoyBallEvent : public JoyEvent {
00215 JoyBallEvent( int ball_id, int xrel, int yrel ){
00216 type = JoyBallEvent_ID;
00217 this->item_id = ball_id;
00218 this->dx = xrel;
00219 this->dy = yrel;
00220 }
00221 };
00222
00223
00225 class EventListener {
00226 public:
00227 EventListener();
00228 virtual ~EventListener();
00229
00230 void bind ( int type, const SigC::Signal1<void,const Event &> &s ){ signal[type] = s; }
00231 void event( const Event &e ){ signal[e.type]( e ); }
00232
00233 unsigned long signal_mask;
00234 SigC::Signal1<void,const Event &> signal[32];
00235 };
00236
00237
00238 };
00239 };
00240
00241
00242 #endif // TEDDY__PHYSICAL_COMPONENTS__EVENT_LISTENER__H
00243