src/events/SDL_mouse_c.h
author Sam Lantinga
Mon, 23 Dec 2013 17:37:22 -0800
changeset 8071 1ac2db4abe11
parent 8066 658b461d81be
child 8093 b43765095a6f
permissions -rw-r--r--
Added a relative mouse mode that uses mouse warping instead of raw input.
To enable this, set the environment variable SDL_MOUSE_RELATIVE_MODE_WARP to "1"

When mouse relative mode is disabled, put the cursor back where the application expects it to be, instead of where it was when relative mode was enabled.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #ifndef _SDL_mouse_c_h
    24 #define _SDL_mouse_c_h
    25 
    26 #include "SDL_mouse.h"
    27 
    28 typedef Uint32 SDL_MouseID;
    29 
    30 struct SDL_Cursor
    31 {
    32     struct SDL_Cursor *next;
    33     void *driverdata;
    34 };
    35 
    36 typedef struct
    37 {
    38     int last_x, last_y;
    39     Uint32 last_timestamp;
    40     Uint8 click_count;
    41 } SDL_MouseClickState;
    42 
    43 typedef struct
    44 {
    45     /* Create a cursor from a surface */
    46     SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
    47 
    48     /* Create a system cursor */
    49     SDL_Cursor *(*CreateSystemCursor) (SDL_SystemCursor id);
    50 
    51     /* Show the specified cursor, or hide if cursor is NULL */
    52     int (*ShowCursor) (SDL_Cursor * cursor);
    53 
    54     /* This is called when a mouse motion event occurs */
    55     void (*MoveCursor) (SDL_Cursor * cursor);
    56 
    57     /* Free a window manager cursor */
    58     void (*FreeCursor) (SDL_Cursor * cursor);
    59 
    60     /* Warp the mouse to (x,y) */
    61     void (*WarpMouse) (SDL_Window * window, int x, int y);
    62 
    63     /* Set relative mode */
    64     int (*SetRelativeMouseMode) (SDL_bool enabled);
    65 
    66     /* Data common to all mice */
    67     SDL_MouseID mouseID;
    68     SDL_Window *focus;
    69     int x;
    70     int y;
    71     int xdelta;
    72     int ydelta;
    73     int last_x, last_y;         /* the last reported x and y coordinates */
    74     Uint32 buttonstate;
    75     SDL_bool relative_mode;
    76     SDL_bool relative_mode_warp;
    77 
    78     /* Data for double-click tracking */
    79     int num_clickstates;
    80     SDL_MouseClickState *clickstate;
    81 
    82     SDL_Cursor *cursors;
    83     SDL_Cursor *def_cursor;
    84     SDL_Cursor *cur_cursor;
    85     SDL_bool cursor_shown;
    86 
    87     /* Driver-dependent data. */
    88     void *driverdata;
    89 } SDL_Mouse;
    90 
    91 
    92 /* Initialize the mouse subsystem */
    93 extern int SDL_MouseInit(void);
    94 
    95 /* Get the mouse state structure */
    96 SDL_Mouse *SDL_GetMouse(void);
    97 
    98 /* Set the default double-click interval */
    99 extern void SDL_SetDoubleClickTime(Uint32 interval);
   100 
   101 /* Set the default mouse cursor */
   102 extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
   103 
   104 /* Set the mouse focus window */
   105 extern void SDL_SetMouseFocus(SDL_Window * window);
   106 
   107 /* Send a mouse motion event */
   108 extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
   109 
   110 /* Send a mouse button event */
   111 extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
   112 
   113 /* Send a mouse wheel event */
   114 extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);
   115 
   116 /* Shutdown the mouse subsystem */
   117 extern void SDL_MouseQuit(void);
   118 
   119 #endif /* _SDL_mouse_c_h */
   120 
   121 /* vi: set ts=4 sw=4 expandtab: */