include/SDL_mouse.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 05 Jun 2014 00:03:33 -0400
changeset 8945 04248c700ada
parent 8927 be64f5daf64b
child 8952 4bb098814ec4
permissions -rw-r--r--
Implemented SDL_GetAbsoluteMouseState().

X11 only for now, but this should be doable on every platform, I think.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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 
    22 /**
    23  *  \file SDL_mouse.h
    24  *
    25  *  Include file for SDL mouse event handling.
    26  */
    27 
    28 #ifndef _SDL_mouse_h
    29 #define _SDL_mouse_h
    30 
    31 #include "SDL_stdinc.h"
    32 #include "SDL_error.h"
    33 #include "SDL_video.h"
    34 
    35 #include "begin_code.h"
    36 /* Set up for C function definitions, even when using C++ */
    37 #ifdef __cplusplus
    38 extern "C" {
    39 #endif
    40 
    41 typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    42 
    43 /**
    44  * \brief Cursor types for SDL_CreateSystemCursor.
    45  */
    46 typedef enum
    47 {
    48     SDL_SYSTEM_CURSOR_ARROW,     /**< Arrow */
    49     SDL_SYSTEM_CURSOR_IBEAM,     /**< I-beam */
    50     SDL_SYSTEM_CURSOR_WAIT,      /**< Wait */
    51     SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
    52     SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
    53     SDL_SYSTEM_CURSOR_SIZENWSE,  /**< Double arrow pointing northwest and southeast */
    54     SDL_SYSTEM_CURSOR_SIZENESW,  /**< Double arrow pointing northeast and southwest */
    55     SDL_SYSTEM_CURSOR_SIZEWE,    /**< Double arrow pointing west and east */
    56     SDL_SYSTEM_CURSOR_SIZENS,    /**< Double arrow pointing north and south */
    57     SDL_SYSTEM_CURSOR_SIZEALL,   /**< Four pointed arrow pointing north, south, east, and west */
    58     SDL_SYSTEM_CURSOR_NO,        /**< Slashed circle or crossbones */
    59     SDL_SYSTEM_CURSOR_HAND,      /**< Hand */
    60     SDL_NUM_SYSTEM_CURSORS
    61 } SDL_SystemCursor;
    62 
    63 /* Function prototypes */
    64 
    65 /**
    66  *  \brief Get the window which currently has mouse focus.
    67  */
    68 extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
    69 
    70 /**
    71  *  \brief Retrieve the current state of the mouse.
    72  *
    73  *  The current button state is returned as a button bitmask, which can
    74  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    75  *  mouse cursor position relative to the focus window for the currently
    76  *  selected mouse.  You can pass NULL for either x or y.
    77  */
    78 extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
    79 
    80 /**
    81  *  \brief Get the current state of the mouse, in relation to the desktop
    82  *
    83  *  This works just like SDL_GetMouseState(), but the coordinates will be
    84  *  reported relative to the top-left of the desktop. This can be useful if
    85  *  you need to track the mouse outside of a specific window and
    86  *  SDL_CaptureMouse() doesn't fit your needs. For example, it could be
    87  *  useful if you need to track the mouse while dragging a window, where
    88  *  coordinates relative to a window might not be in sync at all times.
    89  *
    90  *  \note SDL_GetMouseState() returns the mouse position as SDL understands
    91  *        it from the last pump of the event queue. This function, however,
    92  *        queries the OS for the current mouse position, and as such, might
    93  *        be a slightly less efficient function. Unless you know what you're
    94  *        doing and have a good reason to use this function, you probably want
    95  *        SDL_GetMouseState() instead.
    96  *
    97  *  \param x Returns the current X coord, relative to the desktop. Can be NULL.
    98  *  \param y Returns the current Y coord, relative to the desktop. Can be NULL.
    99  *  \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
   100  *
   101  *  \sa SDL_GetMouseState
   102  */
   103 extern DECLSPEC Uint32 SDLCALL SDL_GetAbsoluteMouseState(int *x, int *y);
   104 
   105 /**
   106  *  \brief Retrieve the relative state of the mouse.
   107  *
   108  *  The current button state is returned as a button bitmask, which can
   109  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   110  *  mouse deltas since the last call to SDL_GetRelativeMouseState().
   111  */
   112 extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
   113 
   114 /**
   115  *  \brief Moves the mouse to the given position within the window.
   116  *
   117  *  \param window The window to move the mouse into, or NULL for the current mouse focus
   118  *  \param x The x coordinate within the window
   119  *  \param y The y coordinate within the window
   120  *
   121  *  \note This function generates a mouse motion event
   122  */
   123 extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
   124                                                    int x, int y);
   125 
   126 /**
   127  *  \brief Set relative mouse mode.
   128  *
   129  *  \param enabled Whether or not to enable relative mode
   130  *
   131  *  \return 0 on success, or -1 if relative mode is not supported.
   132  *
   133  *  While the mouse is in relative mode, the cursor is hidden, and the
   134  *  driver will try to report continuous motion in the current window.
   135  *  Only relative motion events will be delivered, the mouse position
   136  *  will not change.
   137  *
   138  *  \note This function will flush any pending mouse motion.
   139  *
   140  *  \sa SDL_GetRelativeMouseMode()
   141  */
   142 extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
   143 
   144 /**
   145  *  \brief Capture the mouse, to track input outside an SDL window.
   146  *
   147  *  \param enabled Whether or not to enable capturing
   148  *
   149  *  Capturing enables your app to obtain mouse events globally, instead of
   150  *  just within your window. Not all video targets support this function.
   151  *  When capturing is enabled, the current window will get all mouse events,
   152  *  but unlike relative mode, no change is made to the cursor and it is
   153  *  not restrained to your window.
   154  *
   155  *  This function may also deny mouse input to other windows--both those in
   156  *  your application and others on the system--so you should use this
   157  *  function sparingly, and in small bursts. For example, you might want to
   158  *  track the mouse while the user is dragging something, until the user
   159  *  releases a mouse button. It is not recommended that you capture the mouse
   160  *  for long periods of time, such as the entire time your app is running.
   161  *
   162  *  While captured, mouse events still report coordinates relative to the
   163  *  current (foreground) window, but those coordinates may be outside the
   164  *  bounds of the window (including negative values). Capturing is only
   165  *  allowed for the foreground window. If the window loses focus while
   166  *  capturing, the capture will be disabled automatically.
   167  *
   168  *  While capturing is enabled, the current window will have the
   169  *  SDL_WINDOW_MOUSE_CAPTURE flag set.
   170  *
   171  *  \return 0 on success, or -1 if not supported.
   172  */
   173 extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
   174 
   175 /**
   176  *  \brief Query whether relative mouse mode is enabled.
   177  *
   178  *  \sa SDL_SetRelativeMouseMode()
   179  */
   180 extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
   181 
   182 /**
   183  *  \brief Create a cursor, using the specified bitmap data and
   184  *         mask (in MSB format).
   185  *
   186  *  The cursor width must be a multiple of 8 bits.
   187  *
   188  *  The cursor is created in black and white according to the following:
   189  *  <table>
   190  *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
   191  *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
   192  *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
   193  *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
   194  *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black
   195  *                                         if not. </td></tr>
   196  *  </table>
   197  *
   198  *  \sa SDL_FreeCursor()
   199  */
   200 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
   201                                                      const Uint8 * mask,
   202                                                      int w, int h, int hot_x,
   203                                                      int hot_y);
   204 
   205 /**
   206  *  \brief Create a color cursor.
   207  *
   208  *  \sa SDL_FreeCursor()
   209  */
   210 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
   211                                                           int hot_x,
   212                                                           int hot_y);
   213 
   214 /**
   215  *  \brief Create a system cursor.
   216  *
   217  *  \sa SDL_FreeCursor()
   218  */
   219 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
   220 
   221 /**
   222  *  \brief Set the active cursor.
   223  */
   224 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
   225 
   226 /**
   227  *  \brief Return the active cursor.
   228  */
   229 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
   230 
   231 /**
   232  *  \brief Return the default cursor.
   233  */
   234 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
   235 
   236 /**
   237  *  \brief Frees a cursor created with SDL_CreateCursor().
   238  *
   239  *  \sa SDL_CreateCursor()
   240  */
   241 extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
   242 
   243 /**
   244  *  \brief Toggle whether or not the cursor is shown.
   245  *
   246  *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
   247  *                state.
   248  *
   249  *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
   250  */
   251 extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
   252 
   253 /**
   254  *  Used as a mask when testing buttons in buttonstate.
   255  *   - Button 1:  Left mouse button
   256  *   - Button 2:  Middle mouse button
   257  *   - Button 3:  Right mouse button
   258  */
   259 #define SDL_BUTTON(X)       (1 << ((X)-1))
   260 #define SDL_BUTTON_LEFT     1
   261 #define SDL_BUTTON_MIDDLE   2
   262 #define SDL_BUTTON_RIGHT    3
   263 #define SDL_BUTTON_X1       4
   264 #define SDL_BUTTON_X2       5
   265 #define SDL_BUTTON_LMASK    SDL_BUTTON(SDL_BUTTON_LEFT)
   266 #define SDL_BUTTON_MMASK    SDL_BUTTON(SDL_BUTTON_MIDDLE)
   267 #define SDL_BUTTON_RMASK    SDL_BUTTON(SDL_BUTTON_RIGHT)
   268 #define SDL_BUTTON_X1MASK   SDL_BUTTON(SDL_BUTTON_X1)
   269 #define SDL_BUTTON_X2MASK   SDL_BUTTON(SDL_BUTTON_X2)
   270 
   271 
   272 /* Ends C function definitions when using C++ */
   273 #ifdef __cplusplus
   274 }
   275 #endif
   276 #include "close_code.h"
   277 
   278 #endif /* _SDL_mouse_h */
   279 
   280 /* vi: set ts=4 sw=4 expandtab: */