Subversion Repositories Games.Rick Dangerous

Rev

Rev 7 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * src/sysevt.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. /*
  15.  * 20021010 SDLK_n replaced by SDLK_Fn because some non-US keyboards
  16.  *               requires that SHIFT be pressed to input numbers.
  17.  */
  18.  
  19. #include <SDL.h>
  20.  
  21. #include "system.h"
  22. #include "game.h"
  23.  
  24. #include "control.h"
  25. #include "draw.h"
  26.  
  27. #define SYSJOY_RANGE 3280
  28.  
  29. static SDL_Event event;
  30. extern U8 want_filter;
  31. extern U8 want_fullscreen;
  32. extern U8 redraw_screen;
  33.  
  34.  
  35. /*
  36.  * Process an event
  37.  */
  38. static void processEvent (void)
  39. {
  40.    static U8 alt_pressed = FALSE;
  41.  
  42.    U16 key = event.key.keysym.sym;
  43.  
  44.    switch (event.type)
  45.    {
  46.    case SDL_KEYDOWN:
  47.       if (key == SDLK_LALT)
  48.          alt_pressed = TRUE;
  49.       else if (alt_pressed && key == SDLK_RETURN)
  50.       {
  51.          want_fullscreen ^= TRUE;
  52.          redraw_screen = TRUE;
  53.       }
  54.       else if (alt_pressed && key == SDLK_F4)
  55.       {
  56.          control_status |= CONTROL_EXIT;
  57.          control_last = CONTROL_EXIT;
  58.       }
  59.       else if (key == SDLK_o || key == SDLK_UP)
  60.       {
  61.          control_status |= CONTROL_UP;
  62.          control_last = CONTROL_UP;
  63.       }
  64.       else if (key == SDLK_k || key == SDLK_DOWN)
  65.       {
  66.          control_status |= CONTROL_DOWN;
  67.          control_last = CONTROL_DOWN;
  68.       }
  69.       else if (key == SDLK_z || key == SDLK_LEFT)
  70.       {
  71.          control_status |= CONTROL_LEFT;
  72.          control_last = CONTROL_LEFT;
  73.       }
  74.       else if (key == SDLK_x || key == SDLK_RIGHT)
  75.       {
  76.          control_status |= CONTROL_RIGHT;
  77.          control_last = CONTROL_RIGHT;
  78.       }
  79.       else if (key == SDLK_PAUSE)
  80.       {
  81.          control_status |= CONTROL_PAUSE;
  82.          control_last = CONTROL_PAUSE;
  83.       }
  84.       else if (key == SDLK_END)
  85.       {
  86.          control_status |= CONTROL_END;
  87.          control_last = CONTROL_END;
  88.       }
  89.       else if (key == SDLK_ESCAPE)
  90.       {
  91.          control_status |= CONTROL_EXIT;
  92.          control_last = CONTROL_EXIT;
  93.       }
  94.       else if (key == SDLK_SPACE)
  95.       {
  96.          control_status |= CONTROL_FIRE;
  97.          control_last = CONTROL_FIRE;
  98.       }
  99.       else if (key == SDLK_F4)
  100.          syssnd_toggleMute();
  101.       else if (key == SDLK_F5)
  102.          syssnd_vol(-1);
  103.       else if (key == SDLK_F6)
  104.          syssnd_vol(+1);
  105.       else if (key == SDLK_F7)
  106.       {
  107.          want_filter ^= TRUE;
  108.          redraw_screen = TRUE;
  109.       }
  110.       else if (key == SDLK_F10)
  111.       {
  112.          control_status &= ~CONTROL_EXIT;
  113.          control_last = CONTROL_EXIT;
  114.       }
  115.       break;
  116.    case SDL_KEYUP:
  117.       if (key == SDLK_LALT)
  118.          alt_pressed = FALSE;
  119.       else if (key == SDLK_o || key == SDLK_UP)
  120.       {
  121.          control_status &= ~CONTROL_UP;
  122.          control_last = CONTROL_UP;
  123.       }
  124.       else if (key == SDLK_k || key == SDLK_DOWN)
  125.       {
  126.          control_status &= ~CONTROL_DOWN;
  127.          control_last = CONTROL_DOWN;
  128.       }
  129.       else if (key == SDLK_z || key == SDLK_LEFT)
  130.       {
  131.          control_status &= ~CONTROL_LEFT;
  132.          control_last = CONTROL_LEFT;
  133.       }
  134.       else if (key == SDLK_x || key == SDLK_RIGHT)
  135.       {
  136.          control_status &= ~CONTROL_RIGHT;
  137.          control_last = CONTROL_RIGHT;
  138.       }
  139.       else if (key == SDLK_PAUSE)
  140.       {
  141.          control_status &= ~CONTROL_PAUSE;
  142.          control_last = CONTROL_PAUSE;
  143.       }
  144.       else if (key == SDLK_END)
  145.       {
  146.          control_status &= ~CONTROL_END;
  147.          control_last = CONTROL_END;
  148.       }
  149.       else if (key == SDLK_ESCAPE)
  150.       {
  151.          control_status &= ~CONTROL_EXIT;
  152.          control_last = CONTROL_EXIT;
  153.       }
  154.       else if (key == SDLK_SPACE)
  155.       {
  156.          control_status &= ~CONTROL_FIRE;
  157.          control_last = CONTROL_FIRE;
  158.       }
  159.       break;
  160.    case SDL_QUIT:
  161.       /* player tries to close the window -- this is the same as pressing ESC */
  162.       control_status |= CONTROL_EXIT;
  163.       control_last = CONTROL_EXIT;
  164.       break;
  165.    case SDL_JOYAXISMOTION:
  166.       if (event.jaxis.axis == 0)
  167.       {
  168.          /* left-right */
  169.          if (event.jaxis.value < -SYSJOY_RANGE)
  170.          {   /* left */
  171.             control_status |= CONTROL_LEFT;
  172.             control_status &= ~CONTROL_RIGHT;
  173.          }
  174.          else if (event.jaxis.value > SYSJOY_RANGE)
  175.          {   /* right */
  176.             control_status |= CONTROL_RIGHT;
  177.             control_status &= ~CONTROL_LEFT;
  178.          }
  179.          else
  180.          {   /* center */
  181.             control_status &= ~CONTROL_RIGHT;
  182.             control_status &= ~CONTROL_LEFT;
  183.          }
  184.       }
  185.       if (event.jaxis.axis == 1)
  186.       {
  187.          /* up-down */
  188.          if (event.jaxis.value < -SYSJOY_RANGE)
  189.          {   /* up */
  190.             control_status |= CONTROL_UP;
  191.             control_status &= ~CONTROL_DOWN;
  192.          }
  193.          else if (event.jaxis.value > SYSJOY_RANGE)
  194.          {   /* down */
  195.             control_status |= CONTROL_DOWN;
  196.             control_status &= ~CONTROL_UP;
  197.          }
  198.          else
  199.          {   /* center */
  200.             control_status &= ~CONTROL_DOWN;
  201.             control_status &= ~CONTROL_UP;
  202.          }
  203.       }
  204.       break;
  205.    case SDL_JOYBUTTONDOWN:
  206.       control_status |= CONTROL_FIRE;
  207.       break;
  208.    case SDL_JOYBUTTONUP:
  209.       control_status &= ~CONTROL_FIRE;
  210.       break;
  211.    default:
  212.       break;
  213.    }
  214. }
  215.  
  216.  
  217. /*
  218.  * Process events, if any, then return
  219.  */
  220. void sysevt_poll (void)
  221. {
  222.    while (SDL_PollEvent (&event))
  223.       processEvent ();
  224. }
  225.  
  226.  
  227. /*
  228.  * Wait for an event, then process it and return
  229.  */
  230. void sysevt_wait (void)
  231. {
  232.    SDL_WaitEvent (&event);
  233.    processEvent ();
  234. }
  235.