src/events/SDL_mouse.c
changeset 5371 fc3d3d580777
parent 5370 cb219a294ebf
child 5376 183ec2d4485c
     1.1 --- a/src/events/SDL_mouse.c	Sun Feb 20 23:51:59 2011 -0800
     1.2 +++ b/src/events/SDL_mouse.c	Mon Feb 21 10:50:53 2011 -0800
     1.3 @@ -29,43 +29,7 @@
     1.4  #include "../video/SDL_sysvideo.h"
     1.5  
     1.6  
     1.7 -/* Global mouse information */
     1.8 -
     1.9 -typedef struct SDL_Mouse SDL_Mouse;
    1.10 -
    1.11 -struct SDL_Mouse
    1.12 -{
    1.13 -    /* Create a cursor from a surface */
    1.14 -    SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
    1.15 -
    1.16 -    /* Show the specified cursor, or hide if cursor is NULL */
    1.17 -    int (*ShowCursor) (SDL_Cursor * cursor);
    1.18 -
    1.19 -    /* This is called when a mouse motion event occurs */
    1.20 -    void (*MoveCursor) (SDL_Cursor * cursor);
    1.21 -
    1.22 -    /* Free a window manager cursor */
    1.23 -    void (*FreeCursor) (SDL_Cursor * cursor);
    1.24 -
    1.25 -    /* Warp the mouse to (x,y) */
    1.26 -    void (*WarpMouse) (SDL_Mouse * mouse, SDL_Window * window, int x, int y);
    1.27 -
    1.28 -    /* Data common to all mice */
    1.29 -    SDL_Window *focus;
    1.30 -    int x;
    1.31 -    int y;
    1.32 -    int xdelta;
    1.33 -    int ydelta;
    1.34 -    int last_x, last_y;         /* the last reported x and y coordinates */
    1.35 -    Uint8 buttonstate;
    1.36 -    SDL_bool relative_mode;
    1.37 -
    1.38 -    SDL_Cursor *cursors;
    1.39 -    SDL_Cursor *def_cursor;
    1.40 -    SDL_Cursor *cur_cursor;
    1.41 -    SDL_bool cursor_shown;
    1.42 -};
    1.43 -
    1.44 +/* The mouse state */
    1.45  static SDL_Mouse SDL_mouse;
    1.46  
    1.47  
    1.48 @@ -76,6 +40,12 @@
    1.49      return (0);
    1.50  }
    1.51  
    1.52 +SDL_Mouse *
    1.53 +SDL_GetMouse(void)
    1.54 +{
    1.55 +    return &SDL_mouse;
    1.56 +}
    1.57 +
    1.58  void
    1.59  SDL_ResetMouse(void)
    1.60  {
    1.61 @@ -85,7 +55,7 @@
    1.62  SDL_Window *
    1.63  SDL_GetMouseFocus(void)
    1.64  {
    1.65 -    SDL_Mouse *mouse = &SDL_mouse;
    1.66 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.67  
    1.68      return mouse->focus;
    1.69  }
    1.70 @@ -93,7 +63,7 @@
    1.71  void
    1.72  SDL_SetMouseFocus(SDL_Window * window)
    1.73  {
    1.74 -    SDL_Mouse *mouse = &SDL_mouse;
    1.75 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.76  
    1.77      if (mouse->focus == window) {
    1.78          return;
    1.79 @@ -114,7 +84,7 @@
    1.80  int
    1.81  SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
    1.82  {
    1.83 -    SDL_Mouse *mouse = &SDL_mouse;
    1.84 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.85      int posted;
    1.86      int xrel;
    1.87      int yrel;
    1.88 @@ -204,7 +174,7 @@
    1.89  int
    1.90  SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
    1.91  {
    1.92 -    SDL_Mouse *mouse = &SDL_mouse;
    1.93 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.94      int posted;
    1.95      Uint32 type;
    1.96  
    1.97 @@ -253,7 +223,7 @@
    1.98  int
    1.99  SDL_SendMouseWheel(SDL_Window * window, int x, int y)
   1.100  {
   1.101 -    SDL_Mouse *mouse = &SDL_mouse;
   1.102 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.103      int posted;
   1.104  
   1.105      if (window) {
   1.106 @@ -285,7 +255,7 @@
   1.107  Uint8
   1.108  SDL_GetMouseState(int *x, int *y)
   1.109  {
   1.110 -    SDL_Mouse *mouse = &SDL_mouse;
   1.111 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.112  
   1.113      if (x) {
   1.114          *x = mouse->x;
   1.115 @@ -299,7 +269,7 @@
   1.116  Uint8
   1.117  SDL_GetRelativeMouseState(int *x, int *y)
   1.118  {
   1.119 -    SDL_Mouse *mouse = &SDL_mouse;
   1.120 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.121  
   1.122      if (x) {
   1.123          *x = mouse->xdelta;
   1.124 @@ -315,10 +285,10 @@
   1.125  void
   1.126  SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
   1.127  {
   1.128 -    SDL_Mouse *mouse = &SDL_mouse;
   1.129 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.130  
   1.131      if (mouse->WarpMouse) {
   1.132 -        mouse->WarpMouse(mouse, window, x, y);
   1.133 +        mouse->WarpMouse(window, x, y);
   1.134      } else {
   1.135          SDL_SendMouseMotion(window, 0, x, y);
   1.136      }
   1.137 @@ -327,7 +297,7 @@
   1.138  int
   1.139  SDL_SetRelativeMouseMode(SDL_bool enabled)
   1.140  {
   1.141 -    SDL_Mouse *mouse = &SDL_mouse;
   1.142 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.143  
   1.144      /* Flush pending mouse motion */
   1.145      SDL_FlushEvent(SDL_MOUSEMOTION);
   1.146 @@ -349,7 +319,7 @@
   1.147  SDL_bool
   1.148  SDL_GetRelativeMouseMode()
   1.149  {
   1.150 -    SDL_Mouse *mouse = &SDL_mouse;
   1.151 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.152  
   1.153      return mouse->relative_mode;
   1.154  }
   1.155 @@ -358,7 +328,7 @@
   1.156  SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
   1.157                   int w, int h, int hot_x, int hot_y)
   1.158  {
   1.159 -    SDL_Mouse *mouse = &SDL_mouse;
   1.160 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.161      SDL_Surface *surface;
   1.162      SDL_Cursor *cursor;
   1.163      int x, y;
   1.164 @@ -424,7 +394,7 @@
   1.165  void
   1.166  SDL_SetCursor(SDL_Cursor * cursor)
   1.167  {
   1.168 -    SDL_Mouse *mouse = &SDL_mouse;
   1.169 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.170  
   1.171      /* Set the new cursor */
   1.172      if (cursor) {
   1.173 @@ -458,7 +428,7 @@
   1.174  SDL_Cursor *
   1.175  SDL_GetCursor(void)
   1.176  {
   1.177 -    SDL_Mouse *mouse = &SDL_mouse;
   1.178 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.179  
   1.180      if (!mouse) {
   1.181          return NULL;
   1.182 @@ -469,7 +439,7 @@
   1.183  void
   1.184  SDL_FreeCursor(SDL_Cursor * cursor)
   1.185  {
   1.186 -    SDL_Mouse *mouse = &SDL_mouse;
   1.187 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.188      SDL_Cursor *curr, *prev;
   1.189  
   1.190      if (!cursor) {
   1.191 @@ -503,7 +473,7 @@
   1.192  int
   1.193  SDL_ShowCursor(int toggle)
   1.194  {
   1.195 -    SDL_Mouse *mouse = &SDL_mouse;
   1.196 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.197      SDL_bool shown;
   1.198  
   1.199      if (!mouse) {