Main Page | Modules | Data Structures | File List | Data Fields

Event Mapping Routines


Functions

DECLSPEC SDL_EventMap *SDLCALL SDLH_Create ()
 Creates an SDL_EventMap structure.

DECLSPEC void SDLCALL SDLH_Free (SDL_EventMap *)
 Frees an SDL_EventMap structure and it's contents.

DECLSPEC void SDLCALL SDLH_Clear (SDL_EventMap *)
 Removes all event associations fron an SDL_EventMap.

DECLSPEC int SDLCALL SDLH_RemoveEvent (SDL_EventMap *, Uint32 hash)
 Removes specified input association from an SDL_EventMap.

DECLSPEC int SDLCALL SDLH_RemoveID (SDL_EventMap *, int id)
 Removes specified output association from an SDL_EventMap.

DECLSPEC int SDLCALL SDLH_AddHashEvent (SDL_EventMap *, Uint32, int id)
 Adds an event association to an SDL_EventMap.

DECLSPEC int SDLCALL SDLH_AddEvent (SDL_EventMap *, SDL_Event *, int, Uint32 flag)
 Adds an event association to an SDL_EventMap directly.

DECLSPEC Uint32 SDLCALL SDLH_Learn (SDL_EventMap *, int eid, Uint32 flags)
 Adds an event to an SDL_EventMap based on input. Warning, blocks.

DECLSPEC int SDLCALL SDLH_TranslateEvent (SDL_EventMap *, SDL_Event *, Uint32 flag)
 Translates a SDL_Event to SDL_Events specified by the SDL_EventMap.

DECLSPEC int SDLCALL SDLH_Save (SDL_EventMap *, SDL_RWops *stream)
 Saves an SDL_EventMap to a SDL_RWops stream.

DECLSPEC SDL_EventMap *SDLCALL SDLH_Load (SDL_RWops *stream)
 Loads an SDL_EventMap from a SDL_RWops stream.


Function Documentation

DECLSPEC int SDLCALL SDLH_AddEvent SDL_EventMap eventmap,
SDL_Event *  event,
int  id,
Uint32  flag
 

Adds an event association to the SDL_EventMap if 'event' is a valid event given the filter flags.

Definition at line 188 of file SDL_eventmap.cpp.

References SDL_EventMap, SDLH_AddHashEvent(), and SDLH_HashEvent().

00189 {
00190   Uint32 hash=SDLH_HashEvent(event,flag);
00191 
00192   return(SDLH_AddHashEvent(eventmap,hash,id));
00193 }

DECLSPEC int SDLCALL SDLH_AddHashEvent SDL_EventMap eventmap,
Uint32  hash,
int  id
 

Adds a raw event hash to the SDL_EventMap.

Definition at line 199 of file SDL_eventmap.cpp.

References SDL_EventMap.

Referenced by SDLH_AddEvent(), and SDLH_Learn().

00200 {
00201   SDL_EM *em=(SDL_EM *)eventmap;
00202 
00203   if((eventmap==NULL)||(id<0)||(hash==0))
00204     return(-1);
00205 
00206   (*em)[hash]=(id+1);
00207 
00208   return(0);
00209 }

DECLSPEC Uint32 SDLCALL SDLH_Learn SDL_EventMap emap,
int  id,
Uint32  flag
 

Learns an event association from user input. Takes the event map, the SDL_UserEvent code, and filter flags.

It will wait for a valid event until one is received or an SDL_QUIT event occurs.

Definition at line 54 of file SDL_eventmap.cpp.

References SDL_EventMap, SDLH_AddHashEvent(), and SDLH_HashEvent().

Referenced by main().

00055 {
00056   int running=1;
00057   SDL_Event event;
00058   if((emap==NULL)||(id<0))
00059     return(0);
00060 
00061   while(running)
00062   {
00063     while(SDL_PollEvent(&event))
00064     {
00065       Uint32 hash=0;
00066       switch(event.type)
00067       {    
00068       case SDL_QUIT:
00069         return(0);
00070 
00071       default:
00072         hash=SDLH_HashEvent(&event,flag);
00073         break;
00074       }
00075 
00076       if(hash!=0)
00077       {
00078         if(SDLH_AddHashEvent(emap,hash,id)<0)
00079           return(0);
00080         else
00081           return(hash);
00082       }
00083     }
00084 
00085     SDL_Delay(10);
00086   }
00087   return(0);
00088 }

DECLSPEC int SDLCALL SDLH_RemoveEvent SDL_EventMap eventmap,
Uint32  hash
 

Removes the event association with the input hash 'hash' from the SDL_EventMap.

Definition at line 161 of file SDL_eventmap.cpp.

References SDL_EventMap.

00162 {
00163   SDL_EM *em=(SDL_EM *)eventmap;
00164 
00165   if((em==NULL)||(hash==0))
00166     return(-1);
00167 
00168   SDL_EM::iterator i=em->begin();
00169 
00170   while(i!=em->end())
00171   {
00172     if(i->first==hash)
00173     {
00174       em->erase(i);
00175       return(0);
00176     }
00177 
00178     i++;
00179   }
00180 
00181   return(-1);
00182 }

DECLSPEC int SDLCALL SDLH_RemoveID SDL_EventMap emap,
int  id
 

Removes event hashes attached to the output SDL_UserEvent 'id'. If

Definition at line 21 of file SDL_eventmap.cpp.

References SDL_EventMap.

00022 {
00023   SDL_EM *em=(SDL_EM *)emap;
00024   int removed=0;
00025 
00026   if((em==NULL)||(id<0))
00027     return(-1);
00028 
00029   SDL_EM::iterator i=em->begin();
00030 
00031   while(i!=em->end())
00032   {
00033     SDL_EM::iterator next=i;
00034     ++next;
00035 
00036     if((i->second)==(id+1))
00037     {
00038       em->erase(i);
00039       removed++;
00040     }
00041     i=next;
00042   }
00043 
00044   return(removed);
00045 }

DECLSPEC int SDLCALL SDLH_TranslateEvent SDL_EventMap emap,
SDL_Event *  event,
Uint32  flag
 

Given an event map and an event, it translates mapped SDL_Events to SDL_UserEvents. Returns -1 for unmapped events, 0 for mapped ones.

Definition at line 215 of file SDL_eventmap.cpp.

References SDL_EventMap, and SDLH_HashEvent().

Referenced by main().

00216 {
00217   int hash;
00218   SDL_EM *em=(SDL_EM *)emap;
00219 
00220   if((emap==NULL)||(event==NULL))
00221     return(-1);
00222 
00223   hash=SDLH_HashEvent(event,flag);
00224   if(hash==0)
00225     return(-1);
00226 
00227   if(!(*em)[hash])
00228     return(-1);
00229   else
00230   {
00231     SDL_Event uevent;
00232     uevent.type=SDL_USEREVENT;
00233     uevent.user.code=(*em)[hash]-1;
00234     uevent.user.data1=(void *)(long int)hash;
00235     uevent.user.data2=NULL;
00236     SDL_PushEvent(&uevent);
00237     return(0);
00238   }
00239 }


Generated on Tue Jun 22 16:25:25 2004 by doxygen 1.3.5