home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !SDL / man / SDL_Event.3 < prev    next >
Encoding:
Text File  |  2006-09-20  |  6.8 KB  |  249 lines

  1. <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
  2. <!-- available at http://polyglotman.sourceforge.net/ -->
  3.  
  4. <html>
  5. <head>
  6. <title>"SDL_Event"("3") manual page</title>
  7. </head>
  8. <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
  9. <a href='#toc'>Table of Contents</a><p>
  10.  
  11. <h2><a name='sect0' href='#toc0'>Name</a></h2>
  12. SDL_Event- General event structure 
  13. <h2><a name='sect1' href='#toc1'>Structure Definition</a></h2>
  14. <p>
  15. <br>
  16. <pre>CWtypedef union{
  17.   Uint8 type;
  18.   SDL_ActiveEvent active;
  19.   SDL_KeyboardEvent key;
  20.   SDL_MouseMotionEvent motion;
  21.   SDL_MouseButtonEvent button;
  22.   SDL_JoyAxisEvent jaxis;
  23.   SDL_JoyBallEvent jball;
  24.   SDL_JoyHatEvent jhat;
  25.   SDL_JoyButtonEvent jbutton;
  26.   SDL_ResizeEvent resize;
  27.   SDL_ExposeEvent expose;
  28.   SDL_QuitEvent quit;
  29.   SDL_UserEvent user;
  30.   SDL_SywWMEvent syswm;
  31. } SDL_Event;
  32. </pre><p>
  33.  
  34. <h2><a name='sect2' href='#toc2'>Structure Data</a></h2>
  35.  
  36. <dl>
  37.  
  38. <dt><b>type</b> </dt>
  39. <dd>The type of event </dd>
  40.  
  41. <dt><b>active</b> </dt>
  42. <dd><i>Activation event</i> </dd>
  43.  
  44. <dt><b>key</b> </dt>
  45. <dd><i>Keyboard
  46. event</i> </dd>
  47.  
  48. <dt><b>motion</b> </dt>
  49. <dd><i>Mouse motion event</i> </dd>
  50.  
  51. <dt><b>button</b> </dt>
  52. <dd><i>Mouse button event</i> </dd>
  53.  
  54. <dt><b>jaxis</b> </dt>
  55. <dd><i>Joystick
  56. axis motion event</i> </dd>
  57.  
  58. <dt><b>jball</b> </dt>
  59. <dd><i>Joystick trackball motion event</i> </dd>
  60.  
  61. <dt><b>jhat</b> </dt>
  62. <dd><i>Joystick hat
  63. motion event</i> </dd>
  64.  
  65. <dt><b>jbutton</b> </dt>
  66. <dd><i>Joystick button event</i> </dd>
  67.  
  68. <dt><b>resize</b> </dt>
  69. <dd><i>Application window resize
  70. event</i> </dd>
  71.  
  72. <dt><b>expose</b> </dt>
  73. <dd><i>Application window expose event</i> </dd>
  74.  
  75. <dt><b>quit</b> </dt>
  76. <dd><i>Application quit request
  77. event</i> </dd>
  78.  
  79. <dt><b>user</b> </dt>
  80. <dd><i>User defined event</i> </dd>
  81.  
  82. <dt><b>syswm</b> </dt>
  83. <dd><i>Undefined window manager event</i> </dd>
  84. </dl>
  85.  
  86. <h2><a name='sect3' href='#toc3'>Description</a></h2>
  87. <p>
  88. The
  89. <b>SDL_Event</b> union is the core to all event handling is SDL, its probably
  90. the most important structure after <b>SDL_Surface</b>. <b>SDL_Event</b> is a union of
  91. all event structures used in SDL, using it is a simple matter of knowing
  92. which union member relates to which event <b>type</b>. <p>
  93.  
  94. <dl>
  95.  
  96. <dt><b>Event <b>type</b></b> </dt>
  97. <dd><b>Event Structure</b>
  98. </dd>
  99.  
  100. <dt><b>SDL_ACTIVEEVENT</b> </dt>
  101. <dd><i><b>SDL_ActiveEvent</b></i> </dd>
  102.  
  103. <dt><b>SDL_KEYDOWN/UP</b> </dt>
  104. <dd><i><b>SDL_KeyboardEvent</b></i> </dd>
  105.  
  106. <dt><b>SDL_MOUSEMOTION</b>
  107. </dt>
  108. <dd><i><b>SDL_MouseMotionEvent</b></i> </dd>
  109.  
  110. <dt><b>SDL_MOUSEBUTTONDOWN/UP</b> </dt>
  111. <dd><i><b>SDL_MouseButtonEvent</b></i> </dd>
  112.  
  113. <dt><b>SDL_JOYAXISMOTION</b>
  114. </dt>
  115. <dd><i><b>SDL_JoyAxisEvent</b></i> </dd>
  116.  
  117. <dt><b>SDL_JOYBALLMOTION</b> </dt>
  118. <dd><i><b>SDL_JoyBallEvent</b></i> </dd>
  119.  
  120. <dt><b>SDL_JOYHATMOTION</b> </dt>
  121. <dd><i><b>SDL_JoyHatEvent</b></i>
  122. </dd>
  123.  
  124. <dt><b>SDL_JOYBUTTONDOWN/UP</b> </dt>
  125. <dd><i><b>SDL_JoyButtonEvent</b></i> </dd>
  126.  
  127. <dt><b>SDL_QUIT</b> </dt>
  128. <dd><i><b>SDL_QuitEvent</b></i> </dd>
  129.  
  130. <dt><b>SDL_SYSWMEVENT</b>
  131. </dt>
  132. <dd><i><b>SDL_SysWMEvent</b></i> </dd>
  133.  
  134. <dt><b>SDL_VIDEORESIZE</b> </dt>
  135. <dd><i><b>SDL_ResizeEvent</b></i> </dd>
  136.  
  137. <dt><b>SDL_VIDEOEXPOSE</b> </dt>
  138. <dd><i><b>SDL_ExposeEvent</b></i>
  139. </dd>
  140.  
  141. <dt><b>SDL_USEREVENT</b> </dt>
  142. <dd><i><b>SDL_UserEvent</b></i> </dd>
  143. </dl>
  144.  
  145. <h2><a name='sect4' href='#toc4'>Use</a></h2>
  146. <p>
  147. The <b>SDL_Event</b> structure has two uses 
  148. <dl>
  149.  
  150. <dt>  
  151. </dt>
  152. <dd>Reading events on the event queue </dd>
  153.  
  154. <dt>   </dt>
  155. <dd>Placing events on the event queue
  156. </dd>
  157. </dl>
  158. <p>
  159. Reading events from the event queue is done with either <i><b>SDL_PollEvent</b></i> or
  160. <i><b>SDL_PeepEvents</b></i>. We'll use <b>SDL_PollEvent</b> and step through an example. <p>
  161. First
  162. off, we create an empty <b>SDL_Event</b> structure.  <p>
  163. <br>
  164. <pre>CWSDL_Event test_event;
  165. </pre><p>
  166.  <b>SDL_PollEvent</b> removes the next event from the event queue, if there are
  167. no events on the queue it returns <b>0</b> otherwise it returns <b>1</b>. We use a <b>while</b>
  168. loop to process each event in turn. <br>
  169.  <p>
  170. <br>
  171. <pre>CWwhile(SDL_PollEvent(&test_event)) {
  172. </pre><p>
  173.  The <b>SDL_PollEvent</b> function take a pointer to an <b>SDL_Event</b> structure that
  174. is to be filled with event information. We know that if <b>SDL_PollEvent</b> removes
  175. an event from the queue then the event information will be placed in our
  176. <b>test_event</b> structure, but we also know that the <i>type</i> of event will be placed
  177. in the <b>type</b> member of <b>test_event</b>. So to handle each event <b>type</b> seperately
  178. we use a <b>switch</b> statement. <br>
  179.  <p>
  180. <br>
  181. <pre>CW  switch(test_event.type) {
  182. </pre><p>
  183.  We need to know what kind of events we're looking for <i>and</i> the event <b>type</b>'s
  184. of those events. So lets assume we want to detect where the user is moving
  185. the mouse pointer within our application. We look through our event types
  186. and notice that <b>SDL_MOUSEMOTION</b> is, more than likely, the event we're looking
  187. for. A little <i>more</i> research tells use that <b>SDL_MOUSEMOTION</b> events are handled
  188. within the <i><b>SDL_MouseMotionEvent</b></i> structure which is the <b>motion</b> member of
  189. <b>SDL_Event</b>. We can check for the <b>SDL_MOUSEMOTION</b> event <b>type</b> within our <b>switch</b>
  190. statement like so: <br>
  191.  <p>
  192. <br>
  193. <pre>CW    case SDL_MOUSEMOTION:
  194. </pre><p>
  195.  All we need do now is read the information out of the <b>motion</b> member of
  196. <b>test_event</b>. <br>
  197.  <p>
  198. <br>
  199. <pre>CW      printf("We got a motion event.
  200. ");
  201.       printf("Current mouse position is: (%d, %d)
  202. ", test_event.motion.x, test_event.motion.y);
  203.       break;
  204.     default:
  205.       printf("Unhandled Event!
  206. ");
  207.       break;
  208.   }
  209. }
  210. printf("Event queue empty.
  211. ");
  212. </pre><p>
  213. <p>
  214. It is also possible to push events onto the event queue and so use it as
  215. a two-way communication path. Both <i><b>SDL_PushEvent</b></i> and <i><b>SDL_PeepEvents</b></i> allow
  216. you to place events onto the event queue. This is usually used to place
  217. a <b>SDL_USEREVENT</b> on the event queue, however you could use it to post fake
  218. input events if you wished. Creating your own events is a simple matter
  219. of choosing the event type you want, setting the <b>type</b> member and filling
  220. the appropriate member structure with information.  <p>
  221. <br>
  222. <pre>CWSDL_Event user_event;
  223. user_event.type=SDL_USEREVENT;
  224. user_event.user.code=2;
  225. user_event.user.data1=NULL;
  226. user_event.user.data2=NULL;
  227. SDL_PushEvent(&user_event);
  228. </pre><p>
  229.  
  230. <h2><a name='sect5' href='#toc5'>See Also</a></h2>
  231. <p>
  232. <i><b>SDL_PollEvent</b></i>, <i><b>SDL_PushEvent</b></i>, <i><b>SDL_PeepEvents</b></i> 
  233. <!--
  234.   
  235.  <p>
  236.  
  237. <hr><p>
  238. <a name='toc'><b>Table of Contents</b></a><p>
  239. <ul>
  240. <li><a name='toc0' href='#sect0'>Name</a></li>
  241. <li><a name='toc1' href='#sect1'>Structure Definition</a></li>
  242. <li><a name='toc2' href='#sect2'>Structure Data</a></li>
  243. <li><a name='toc3' href='#sect3'>Description</a></li>
  244. <li><a name='toc4' href='#sect4'>Use</a></li>
  245. <li><a name='toc5' href='#sect5'>See Also</a></li>
  246. </ul>
  247. </body>
  248. </html>
  249.