include/SDL_mouse.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 20 Mar 2015 21:57:15 -0400
changeset 9414 669bf9fb901e
parent 9257 6f41196c2d6b
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Several corrections to the CMake project files (thanks, Ozkan!).

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