include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 18 May 2013 12:48:50 -0700
changeset 7190 11612d544fcd
parent 7104 4e4ca313000c
child 7191 75360622e65f
permissions -rw-r--r--
Added mobile application events, with implementations for iOS and Android
     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 
    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 /* *INDENT-OFF* */
    39 extern "C" {
    40 /* *INDENT-ON* */
    41 #endif
    42 
    43 typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    44 
    45 /**
    46  * \brief Cursor types for SDL_CreateSystemCursor.
    47  */
    48 typedef enum
    49 {
    50     SDL_SYSTEM_CURSOR_ARROW,     /**< Arrow */
    51     SDL_SYSTEM_CURSOR_IBEAM,     /**< I-beam */
    52     SDL_SYSTEM_CURSOR_WAIT,      /**< Wait */
    53     SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
    54     SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
    55     SDL_SYSTEM_CURSOR_SIZENWSE,  /**< Double arrow pointing northwest and southeast */
    56     SDL_SYSTEM_CURSOR_SIZENESW,  /**< Double arrow pointing northeast and southwest */
    57     SDL_SYSTEM_CURSOR_SIZEWE,    /**< Double arrow pointing west and east */
    58     SDL_SYSTEM_CURSOR_SIZENS,    /**< Double arrow pointing north and south */
    59     SDL_SYSTEM_CURSOR_SIZEALL,   /**< Four pointed arrow pointing north, south, east, and west */
    60     SDL_SYSTEM_CURSOR_NO,        /**< Slashed circle or crossbones */
    61     SDL_SYSTEM_CURSOR_HAND,      /**< Hand */
    62     SDL_NUM_SYSTEM_CURSORS
    63 } SDL_SystemCursor;
    64 
    65 /* Function prototypes */
    66 
    67 /**
    68  *  \brief Get the window which currently has mouse focus.
    69  */
    70 extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
    71 
    72 /**
    73  *  \brief Retrieve the current state of the mouse.
    74  *  
    75  *  The current button state is returned as a button bitmask, which can
    76  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    77  *  mouse cursor position relative to the focus window for the currently
    78  *  selected mouse.  You can pass NULL for either x or y.
    79  */
    80 extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
    81 
    82 /**
    83  *  \brief Retrieve the relative state of the mouse.
    84  *
    85  *  The current button state is returned as a button bitmask, which can
    86  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    87  *  mouse deltas since the last call to SDL_GetRelativeMouseState().
    88  */
    89 extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
    90 
    91 /**
    92  *  \brief Moves the mouse to the given position within the window.
    93  *  
    94  *  \param window The window to move the mouse into, or NULL for the current mouse focus
    95  *  \param x The x coordinate within the window
    96  *  \param y The y coordinate within the window
    97  *  
    98  *  \note This function generates a mouse motion event
    99  */
   100 extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
   101                                                    int x, int y);
   102 
   103 /**
   104  *  \brief Set relative mouse mode.
   105  *  
   106  *  \param enabled Whether or not to enable relative mode
   107  *
   108  *  \return 0 on success, or -1 if relative mode is not supported.
   109  *  
   110  *  While the mouse is in relative mode, the cursor is hidden, and the
   111  *  driver will try to report continuous motion in the current window.
   112  *  Only relative motion events will be delivered, the mouse position
   113  *  will not change.
   114  *  
   115  *  \note This function will flush any pending mouse motion.
   116  *  
   117  *  \sa SDL_GetRelativeMouseMode()
   118  */
   119 extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
   120 
   121 /**
   122  *  \brief Query whether relative mouse mode is enabled.
   123  *  
   124  *  \sa SDL_SetRelativeMouseMode()
   125  */
   126 extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
   127 
   128 /**
   129  *  \brief Create a cursor, using the specified bitmap data and
   130  *         mask (in MSB format).
   131  *  
   132  *  The cursor width must be a multiple of 8 bits.
   133  *  
   134  *  The cursor is created in black and white according to the following:
   135  *  <table>
   136  *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
   137  *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
   138  *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
   139  *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
   140  *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black 
   141  *                                         if not. </td></tr>
   142  *  </table>
   143  *  
   144  *  \sa SDL_FreeCursor()
   145  */
   146 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
   147                                                      const Uint8 * mask,
   148                                                      int w, int h, int hot_x,
   149                                                      int hot_y);
   150 
   151 /**
   152  *  \brief Create a color cursor.
   153  *  
   154  *  \sa SDL_FreeCursor()
   155  */
   156 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
   157                                                           int hot_x,
   158                                                           int hot_y);
   159 
   160 /**
   161  *  \brief Create a system cursor.
   162  *
   163  *  \sa SDL_FreeCursor()
   164  */
   165 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
   166 
   167 /**
   168  *  \brief Set the active cursor.
   169  */
   170 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
   171 
   172 /**
   173  *  \brief Return the active cursor.
   174  */
   175 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
   176 
   177 /**
   178  *  \brief Return the default cursor.
   179  */
   180 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
   181 
   182 /**
   183  *  \brief Frees a cursor created with SDL_CreateCursor().
   184  *  
   185  *  \sa SDL_CreateCursor()
   186  */
   187 extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
   188 
   189 /**
   190  *  \brief Toggle whether or not the cursor is shown.
   191  *  
   192  *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current 
   193  *                state.
   194  *  
   195  *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
   196  */
   197 extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
   198 
   199 /**
   200  *  Used as a mask when testing buttons in buttonstate.
   201  *   - Button 1:  Left mouse button
   202  *   - Button 2:  Middle mouse button
   203  *   - Button 3:  Right mouse button
   204  */
   205 #define SDL_BUTTON(X)		(1 << ((X)-1))
   206 #define SDL_BUTTON_LEFT		1
   207 #define SDL_BUTTON_MIDDLE	2
   208 #define SDL_BUTTON_RIGHT	3
   209 #define SDL_BUTTON_X1		4
   210 #define SDL_BUTTON_X2		5
   211 #define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
   212 #define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
   213 #define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
   214 #define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
   215 #define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
   216 
   217 
   218 /* Ends C function definitions when using C++ */
   219 #ifdef __cplusplus
   220 /* *INDENT-OFF* */
   221 }
   222 /* *INDENT-ON* */
   223 #endif
   224 #include "close_code.h"
   225 
   226 #endif /* _SDL_mouse_h */
   227 
   228 /* vi: set ts=4 sw=4 expandtab: */