SDL_Event.3
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:6k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- .TH "SDL_Event" "3" "Tue 11 Sep 2001, 22:59" "SDL" "SDL API Reference"
- .SH "NAME"
- SDL_Event- General event structure
- .SH "STRUCTURE DEFINITION"
- .PP
- .nf
- f(CWtypedef union{
- Uint8 type;
- SDL_ActiveEvent active;
- SDL_KeyboardEvent key;
- SDL_MouseMotionEvent motion;
- SDL_MouseButtonEvent button;
- SDL_JoyAxisEvent jaxis;
- SDL_JoyBallEvent jball;
- SDL_JoyHatEvent jhat;
- SDL_JoyButtonEvent jbutton;
- SDL_ResizeEvent resize;
- SDL_ExposeEvent expose;
- SDL_QuitEvent quit;
- SDL_UserEvent user;
- SDL_SywWMEvent syswm;
- } SDL_Event;fR
- .fi
- .PP
- .SH "STRUCTURE DATA"
- .TP 20
- fBtypefR
- The type of event
- .TP 20
- fBactivefR
- fIActivation eventfR
- .TP 20
- fBkeyfR
- fIKeyboard eventfR
- .TP 20
- fBmotionfR
- fIMouse motion eventfR
- .TP 20
- fBbuttonfR
- fIMouse button eventfR
- .TP 20
- fBjaxisfR
- fIJoystick axis motion eventfR
- .TP 20
- fBjballfR
- fIJoystick trackball motion eventfR
- .TP 20
- fBjhatfR
- fIJoystick hat motion eventfR
- .TP 20
- fBjbuttonfR
- fIJoystick button eventfR
- .TP 20
- fBresizefR
- fIApplication window resize eventfR
- .TP 20
- fBexposefR
- fIApplication window expose eventfR
- .TP 20
- fBquitfR
- fIApplication quit request eventfR
- .TP 20
- fBuserfR
- fIUser defined eventfR
- .TP 20
- fBsyswmfR
- fIUndefined window manager eventfR
- .SH "DESCRIPTION"
- .PP
- The fBSDL_EventfR union is the core to all event handling is SDL, its probably the most important structure after fBSDL_SurfacefR&. fBSDL_EventfR is a union of all event structures used in SDL, using it is a simple matter of knowing which union member relates to which event fBtypefR&.
- .PP
- .TP 20
- fBEvent fBtypefRfR
- fBEvent StructurefR
- .TP 20
- fBSDL_ACTIVEEVENTfP
- fIfBSDL_ActiveEventfRfR
- .TP 20
- fBSDL_KEYDOWN/UPfP
- fIfBSDL_KeyboardEventfRfR
- .TP 20
- fBSDL_MOUSEMOTIONfP
- fIfBSDL_MouseMotionEventfRfR
- .TP 20
- fBSDL_MOUSEBUTTONDOWN/UPfP
- fIfBSDL_MouseButtonEventfRfR
- .TP 20
- fBSDL_JOYAXISMOTIONfP
- fIfBSDL_JoyAxisEventfRfR
- .TP 20
- fBSDL_JOYBALLMOTIONfP
- fIfBSDL_JoyBallEventfRfR
- .TP 20
- fBSDL_JOYHATMOTIONfP
- fIfBSDL_JoyHatEventfRfR
- .TP 20
- fBSDL_JOYBUTTONDOWN/UPfP
- fIfBSDL_JoyButtonEventfRfR
- .TP 20
- fBSDL_QUITfP
- fIfBSDL_QuitEventfRfR
- .TP 20
- fBSDL_SYSWMEVENTfP
- fIfBSDL_SysWMEventfRfR
- .TP 20
- fBSDL_VIDEORESIZEfP
- fIfBSDL_ResizeEventfRfR
- .TP 20
- fBSDL_VIDEOEXPOSEfP
- fIfBSDL_ExposeEventfRfR
- .TP 20
- fBSDL_USEREVENTfP
- fIfBSDL_UserEventfRfR
- .SH "USE"
- .PP
- The fBSDL_EventfR structure has two uses
- .IP " (bu" 6
- Reading events on the event queue
- .IP " (bu" 6
- Placing events on the event queue
- .PP
- Reading events from the event queue is done with either fIfBSDL_PollEventfPfR or fIfBSDL_PeepEventsfPfR&. We&'ll use fBSDL_PollEventfP and step through an example&.
- .PP
- First off, we create an empty fBSDL_EventfR structure&.
- .PP
- .nf
- f(CWSDL_Event test_event;fR
- .fi
- .PP
- fBSDL_PollEventfP removes the next event from the event queue, if there are no events on the queue it returns fB0fR otherwise it returns fB1fR&. We use a fBwhilefP loop to process each event in turn&.
- .PP
- .nf
- f(CWwhile(SDL_PollEvent(&test_event)) {fR
- .fi
- .PP
- The fBSDL_PollEventfP function take a pointer to an fBSDL_EventfR structure that is to be filled with event information&. We know that if fBSDL_PollEventfP removes an event from the queue then the event information will be placed in our fBtest_eventfR structure, but we also know that the fItypefP of event will be placed in the fBtypefR member of fBtest_eventfR&. So to handle each event fBtypefR seperately we use a fBswitchfP statement&.
- .PP
- .nf
- f(CW switch(test_event&.type) {fR
- .fi
- .PP
- We need to know what kind of events we&'re looking for fIandfP the event fBtypefR&'s of those events&. So lets assume we want to detect where the user is moving the mouse pointer within our application&. We look through our event types and notice that fBSDL_MOUSEMOTIONfP is, more than likely, the event we&'re looking for&. A little fImorefR research tells use that fBSDL_MOUSEMOTIONfP events are handled within the fIfBSDL_MouseMotionEventfRfR structure which is the fBmotionfR member of fBSDL_EventfR&. We can check for the fBSDL_MOUSEMOTIONfP event fBtypefR within our fBswitchfP statement like so:
- .PP
- .nf
- f(CW case SDL_MOUSEMOTION:fR
- .fi
- .PP
- All we need do now is read the information out of the fBmotionfR member of fBtest_eventfR&.
- .PP
- .nf
- f(CW printf("We got a motion event&.
- ");
- printf("Current mouse position is: (%d, %d)
- ", test_event&.motion&.x, test_event&.motion&.y);
- break;
- default:
- printf("Unhandled Event!
- ");
- break;
- }
- }
- printf("Event queue empty&.
- ");fR
- .fi
- .PP
- .PP
- It is also possible to push events onto the event queue and so use it as a two-way communication path&. Both fIfBSDL_PushEventfPfR and fIfBSDL_PeepEventsfPfR allow you to place events onto the event queue&. This is usually used to place a fBSDL_USEREVENTfP on the event queue, however you could use it to post fake input events if you wished&. Creating your own events is a simple matter of choosing the event type you want, setting the fBtypefR member and filling the appropriate member structure with information&.
- .PP
- .nf
- f(CWSDL_Event user_event;
- user_event&.type=SDL_USEREVENT;
- user_event&.user&.code=2;
- user_event&.user&.data1=NULL;
- user_event&.user&.data2=NULL;
- SDL_PushEvent(&user_event);fR
- .fi
- .PP
- .SH "SEE ALSO"
- .PP
- fIfBSDL_PollEventfPfR, fIfBSDL_PushEventfPfR, fIfBSDL_PeepEventsfPfR
- ..." created by instant / docbook-to-man, Tue 11 Sep 2001, 22:59