home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapterj / lj-4.c < prev   
Text File  |  1997-06-18  |  2KB  |  55 lines

  1. // functions to start up and shutdown the game configuration for
  2. // the mouse, and to accumulate mouse moves over multiple calls
  3. // during a frame and to calculate the total move for the frame
  4. #include <windows.h>
  5.  
  6. extern int window_center_x, window_center_y;
  7.  
  8. // the two 0 values disable the two acceleration thresholds, and the
  9. // 1 value specifies medium mouse speed
  10. static int     originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
  11. static int     mouse_x_accum, mouse_y_accum;
  12. static POINT   current_pos;
  13.  
  14. int StartGameMouse (void)
  15. {
  16.    if (!SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0))
  17.       return 0;
  18.  
  19.    if (!SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0))
  20.       return 0;
  21.  
  22.    ShowCursor (FALSE);
  23.    SetCursorPos (window_center_x, window_center_y);
  24.    return 1;
  25. }
  26.  
  27. void StopGameMouse (void)
  28. {
  29.    SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
  30.    ShowCursor (TRUE);
  31. }
  32.  
  33. void AccumulateGameMouseMove (void)
  34. {
  35.    GetCursorPos (¤t_pos);
  36.  
  37.    mouse_x_accum += current_pos.x - window_center_x;
  38.    mouse_y_accum += current_pos.y - window_center_y;
  39.  
  40.    // force the mouse to the center, so there's room to move
  41.    SetCursorPos (window_center_x, window_center_y);
  42. }
  43.  
  44. void GetGameMouseMoveForFrame (int * mouse_x_move, int * mouse_y_move)
  45. {
  46.    GetCursorPos (¤t_pos);
  47.    *mouse_x_move = current_pos.x - window_center_x + mouse_x_accum;
  48.    *mouse_y_move = current_pos.y - window_center_y + mouse_y_accum;
  49.    mouse_x_accum = 0;
  50.    mouse_y_accum = 0;
  51.  
  52.    // force the mouse to the center, so there's room to move
  53.    SetCursorPos (window_center_x, window_center_y);
  54. }
  55.