Amiga Developer Site by i n n o i d e a | MorphOS | Amiga Developers | Compilers | Documents | Dev-HardFile v1.11 for UAE / real Amiga - readme - shot) | Unique/All Visitors: 77257/570053
Search manual for function in the   
SDL/SDL_Event
NAME 

SDL_Event- General event structure

STRUCTURE DEFINITION 




typedef 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_QuitEvent quit;
  SDL_UserEvent user;
  SDL_SywWMEvent syswm;
} SDL_Event;




STRUCTURE DATA 

type
The type of event
active
Activation event
key
Keyboard event
motion
Mouse motion event
button
Mouse button event
jaxis
Joystick axis motion event
jball
Joystick trackball motion event
jhat
Joystick hat motion event
jbutton
Joystick button event
resize
Application window resize event
quit
Application quit request event
user
User defined event
syswm
Undefined window manager event

DESCRIPTION 



The SDL_Event union is the core to all event handling is SDL, its probably the
most important structure after SDL_Surface. SDL_Event 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 type.


Event type
Event Structure
SDL_ACTIVEEVENT
SDL_ActiveEvent
SDL_KEYDOWN/UP
SDL_KeyboardEvent
SDL_MOUSEMOTION
SDL_MouseMotionEvent
SDL_MOUSEBUTTONDOWN/UP
SDL_MouseButtonEvent
SDL_JOYAXISMOTION
SDL_JoyAxisEvent
SDL_JOYBALLMOTION
SDL_JoyBallEvent
SDL_JOYHATMOTION
SDL_JoyHatEvent
SDL_JOYBUTTONDOWN/UP
SDL_JoyButtonEvent
SDL_QUIT
SDL_QuitEvent
SDL_SYSWMEVENT
SDL_SysWMEvent
SDL_VIDEORESIZE
SDL_ResizeEvent
SDL_USEREVENT
SDL_UserEvent

USE 



The SDL_Event structure has two uses
   Reading events on the event queue
   Placing events on the event queue


Reading events from the event queue is done with either SDL_PollEvent or
SDL_PeepEvents. We'll use SDL_PollEvent and step through an example.


First off, we create an empty SDL_Event structure. 



SDL_Event test_event;



 SDL_PollEvent removes the next event from the event queue, if there are no
events on the queue it returns 0 otherwise it returns 1. We use a while loop to
process each event in turn. 



while(SDL_PollEvent(&test_event)) {



 The SDL_PollEvent function take a pointer to an SDL_Event structure that is to
be filled with event information. We know that if SDL_PollEvent removes an event
from the queue then the event information will be placed in our test_event
structure, but we also know that the type of event will be placed in the type
member of test_event. So to handle each event type seperately we use a switch
statement. 



  switch(test_event.type) {



 We need to know what kind of events we're looking for and the event type'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 SDL_MOUSEMOTION is, more than likely, the event we're looking for. A little
more research tells use that SDL_MOUSEMOTION events are handled within the
SDL_MouseMotionEvent structure which is the motion member of SDL_Event. We can
check for the SDL_MOUSEMOTION event type within our switch statement like so: 



    case SDL_MOUSEMOTION:



 All we need do now is read the information out of the motion member of
test_event. 



      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.
");





It is also possible to push events onto the event queue and so use it as a
two-way communication path. Both SDL_PushEvent and SDL_PeepEvents allow you to
place events onto the event queue. This is usually used to place a SDL_USEREVENT
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 type member and filling the appropriate member structure
with information. 



SDL_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);




SEE ALSO 



SDL_PollEvent, SDL_PushEvent, SDL_PeepEvents


20031117165007 - LouiSe - for (SDL/SDL_Event)
When programming in GUI enviroments, most of the action takes place on events:
the mouse moves, a key is pressed, a mouse click happens, a print job finishes,
a CD-ROM is inserted, and so forth. 

If you have ever programmed in Windows, the concept of events should be be
familiar to you. Most SDL programs will continously check to see if an event has
happened, and when one does, handle it. There are two methods of checking for
events in SDL: SDL_PollEvent and SDL_WaitEvent. SDL_PollEvent and SDL_WaitEvent
both take a parameter of a pointer to type SDL_Event.


SDL_PollEvent checks to see if any events are in the event queue. If there are
events in the event que, it will return nonzero to let the programmer know that
there are events ready to be handled and place the event data in its parameter.


SDL_WaitEvent waits for an event to happen, and then places the event data
inside its parameter. SDL_WaitEvent will always return non zero unless there is
an error. 

Passing a NULL pointer to either function will allow you to wait for, or check
to see, if there are any events. The event data itself however, will remain in
the queue. 

The event type is stored in the SDL event structure as 'type'. Most SDL programs
use a switch statement to determine the type of event and then perform whatever
procedure they wish. 

Now it is easy to see what the remainder of the main program was doing in the
last tutorial. 

	SDL_Event event;
...
	while(!exitkey) {
		DrawPicture(screen);
		while(SDL_PollEvent(&event)) {
		switch( event.type ) {
				case SDL_QUIT:
					exitkey = 1;
					printf("Got quit event!\\n");
					break;
				case SDL_KEYDOWN:
					printf("Key hit - exiting!\\n");
					exitkey = 1;
					break;
			}
		}
	}


Here, the program continuosly draws to the software surface using the
DrawPictures function. In between draws, the program will check to see if
anything interesting has happened. If a key is pressed or there is a quit
message, the program will exit. The code below the SDL_PollEvent function will
only execute after an event has occured.

Logo by Emeric/SH
SDL/SDL_Event

No examples found...


Functions with "S":
SDLKey
SDL_ActiveEvent
SDL_AddTimer
SDL_AudioCVT
SDL_AudioSpec
SDL_BlitSurface
SDL_BuildAudioCVT
SDL_CD
SDL_CDClose
SDL_CDEject
SDL_CDName
SDL_CDNumDrives
SDL_CDOpen
SDL_CDPause
SDL_CDPlay
SDL_CDPlayTracks
SDL_CDResume
SDL_CDStatus
SDL_CDStop
SDL_CDtrack
SDL_CloseAudio
SDL_Color
SDL_CondBroadcast
SDL_CondSignal
SDL_CondWait
SDL_CondWaitTimeout
SDL_ConvertAudio
SDL_ConvertSurface
SDL_CreateCond
SDL_CreateCursor
SDL_CreateMutex
SDL_CreateRGBSurface
SDL_CreateRGBSurfaceFrom
SDL_CreateSemaphore
SDL_CreateThread
SDL_CreateYUVOverlay
SDL_Delay
SDL_DestroyCond
SDL_DestroyMutex
SDL_DestroySemaphore
SDL_DisplayFormat
SDL_DisplayFormatAlpha
SDL_DisplayYUVOverlay
SDL_EnableKeyRepeat
SDL_EnableUNICODE
SDL_Event
SDL_EventState
SDL_FillRect
SDL_Flip
SDL_FreeCursor
SDL_FreeSurface
SDL_FreeWAV
SDL_FreeYUVOverlay
SDL_GL_GetAttribute
SDL_GL_GetProcAddress
SDL_GL_LoadLibrary
SDL_GL_SetAttribute
SDL_GL_SwapBuffers
SDL_GLattr
SDL_GetAppState
SDL_GetAudioStatus
SDL_GetClipRect
SDL_GetCursor
SDL_GetEventFilter
SDL_GetGamma
SDL_GetGammaRamp
SDL_GetKeyName
SDL_GetKeyState
SDL_GetModState
SDL_GetMouseState
SDL_GetRGB
SDL_GetRGBA
SDL_GetRelativeMouseState
SDL_GetThreadID
SDL_GetTicks
SDL_GetVideoInfo
SDL_GetVideoSurface
SDL_Init
SDL_InitSubSystem
SDL_JoyAxisEvent
SDL_JoyBallEvent
SDL_JoyButtonEvent
SDL_JoyHatEvent
SDL_JoystickClose
SDL_JoystickEventState
SDL_JoystickGetAxis
SDL_JoystickGetBall
SDL_JoystickGetButton
SDL_JoystickGetHat
SDL_JoystickIndex
SDL_JoystickName
SDL_JoystickNumAxes
SDL_JoystickNumBalls
SDL_JoystickNumButtons
SDL_JoystickNumHats
SDL_JoystickOpen
SDL_JoystickOpened
SDL_JoystickUpdate
SDL_KeyboardEvent
SDL_KillThread
SDL_ListModes
SDL_LoadBMP
SDL_LoadWAV
SDL_LockAudio
SDL_LockSurface
SDL_LockYUVOverlay
SDL_MapRGB
SDL_MapRGBA
SDL_MixAudio
SDL_MouseButtonEvent
SDL_MouseMotionEvent
SDL_NumJoysticks
SDL_OpenAudio
SDL_Overlay
SDL_Palette
SDL_PauseAudio
SDL_PeepEvents
SDL_PixelFormat
SDL_PollEvent
SDL_PumpEvents
SDL_PushEvent
SDL_Quit
SDL_QuitEvent
SDL_QuitSubSystem
SDL_RWFromFile
SDL_Rect
SDL_RemoveTimer
SDL_ResizeEvent
SDL_SaveBMP
SDL_SemPost
SDL_SemTryWait
SDL_SemValue
SDL_SemWait
SDL_SemWaitTimeout
SDL_SetAlpha
SDL_SetClipRect
SDL_SetColorKey
SDL_SetColors
SDL_SetCursor
SDL_SetEventFilter
SDL_SetGamma
SDL_SetGammaRamp
SDL_SetModState
SDL_SetPalette
SDL_SetTimer
SDL_SetVideoMode
SDL_ShowCursor
SDL_Surface
SDL_SysWMEvent
SDL_ThreadID
SDL_UnlockAudio
SDL_UnlockSurface
SDL_UnlockYUVOverlay
SDL_UpdateRect
SDL_UpdateRects
SDL_UserEvent
SDL_VideoDriverName
SDL_VideoInfo
SDL_VideoModeOK
SDL_WM_GetCaption
SDL_WM_GrabInput
SDL_WM_IconifyWindow
SDL_WM_SetCaption
SDL_WM_SetIcon
SDL_WM_ToggleFullScreen
SDL_WaitEvent
SDL_WaitThread
SDL_WarpMouse
SDL_WasInit
SDL_keysym
SDL_mutexP
SDL_mutexV

Last 15 uploaded Examples:

20071229151342 AmiSSL/X509_STORE_CTX_cleanup
20070708011052 GeekGadgets/getlogin
20060705053954 AmigaOS/OpenWorkbenchObjectA
20050801035639 SDL/SDL_Surface
20050727092732 BlitzBasic/LSL
20050718102843 SDL/SDL_WarpMouse
20050718072844 GeekGadgets/fread
20050714051528 SDL/SDL_ActiveEvent
20050714051514 SDL/SDL_ActiveEvent
20050701171401 GeekGadgets/errno
20050701171347 GeekGadgets/errno
20050627101951 SDL/SDL_FreeSurface
20050623152729 GeekGadgets/fork
20050619153102 GeekGadgets/tcdrain
20050615182849 AmigaOS/OpenScreen

Last 25 posts:

20050613235812 SDL/SDL_SetGammaRamp
20050526065000 AmiTCP/unistd.h
20050413041558 AmiSSL/X509_STORE_set_default_paths
20050409155750 AmigaDOS/Status
20050129230614 MUI/Calendar.mcc
20050128185620 GeekGadgets/hstrerror
20041126154558 BlitzBasic/LoadBank
20041123170704 GeekGadgets/gcvt
20041105222909 AmigaOS/CheckSignal
20040712190839 SDL/SDL_SetVideoMode
20040627090529 SDL/SDL_Init
20040519133228 GeekGadgets/fork
20040407124555 AmigaOS/AllocMem
20040403101120 GeekGadgets/inet_ntoa
20040327172814 GeekGadgets/random
20040327172714 GeekGadgets/srandom
20040313211937 BlitzBasic/ANALYZEDISK
20040303135237 GeekGadgets/mktemp
20040301131355 GeekGadgets/realpath
20040301123615 GeekGadgets/gcvt
20040301114000 GeekGadgets/htonl
20040301100209 GeekGadgets/realpath
20040229095437 GeekGadgets/time
20040211132618 GeekGadgets/getpid
20040209102818 AmigaOS/OpenWindow




Amiga.sf
AMIGIFT

Locations of visitors to this page

Page took 0.527538 seconds to load.