Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

EventListener.h

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: EventListener.h,v 1.5 2002/03/12 10:46:07 tksuoran Exp $
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 };  //  namespace PhysicalComponents'
00246 };  //  namespace Teddy
00247 
00248 
00249 #endif  //  TEDDY__PHYSICAL_COMPONENTS__EVENT_LISTENER__H
00250 
00251 
00252 /*
00253 const int Event_ID                  =  0;
00254 const int WindowEvent_ID            =  1;
00255 const int WindowFocusActiveEvent_ID =  2;
00256 const int WindowPopupOpenEvent_ID   =  3;
00257 const int WindowPopupCloseEvent_ID  =  4;
00258 const int WindowMoveEvent_ID        =  5;
00259 const int WindowSizeEventEvent_ID   =  6;
00260 const int WindowToFrontEvent_ID     =  7;
00261 const int WindowToBackEvent_ID      =  8;
00262 const int WindowSplitUpdateEvent_ID =  9;
00263 const int MouseEvent_ID             = 10;
00264 const int MouseButtonEvent_ID       = 11;
00265 const int MouseMotionEvent_ID       = 12;
00266 const int MouseDragEvent_ID         = 13;
00267 const int MouseHoldDragEvent_ID     = 14;
00268 const int KeyEvent_ID               = 15;
00269 const int KeyDownEvent_ID           = 16;
00270 const int KeyUpEvent_ID             = 17;
00271 const int JoyEvent_ID               = 18;
00272 const int JoyButtonEvent_ID         = 19;
00273 const int JoyAxisEvent_ID           = 20;
00274 const int JoyHatEvent_ID            = 21;
00275 const int JoyBallEvent_ID           = 22;
00276 */
00277