include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 15 Feb 2013 08:47:44 -0800
changeset 6885 700f1b25f77f
parent 6677 c3202c29e352
child 6901 57dcaecb19e5
permissions -rw-r--r--
Happy New Year!
     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  *  Please note that this ONLY discusses "mice" with the notion of the
    28  *  desktop GUI. You (usually) have one system cursor, and the OS hides
    29  *  the hardware details from you. If you plug in 10 mice, all ten move that
    30  *  one cursor. For many applications and games, this is perfect, and this
    31  *  API has served hundreds of SDL programs well since its birth.
    32  *
    33  *  It's not the whole picture, though. If you want more lowlevel control,
    34  *  SDL offers a different API, that gives you visibility into each input
    35  *  device, multi-touch interfaces, etc.
    36  *
    37  *  Those two APIs are incompatible, and you usually should not use both
    38  *  at the same time. But for legacy purposes, this API refers to a "mouse"
    39  *  when it actually means the system pointer and not a physical mouse.
    40  *
    41  *  The other API is in SDL_input.h
    42  */
    43 
    44 #ifndef _SDL_mouse_h
    45 #define _SDL_mouse_h
    46 
    47 #include "SDL_stdinc.h"
    48 #include "SDL_error.h"
    49 #include "SDL_video.h"
    50 
    51 #include "begin_code.h"
    52 /* Set up for C function definitions, even when using C++ */
    53 #ifdef __cplusplus
    54 /* *INDENT-OFF* */
    55 extern "C" {
    56 /* *INDENT-ON* */
    57 #endif
    58 
    59 typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    60 
    61 /**
    62  * \brief Cursor types for SDL_CreateSystemCursor.
    63  */
    64 typedef enum
    65 {
    66     SDL_SYSTEM_CURSOR_ARROW,     // Arrow
    67     SDL_SYSTEM_CURSOR_IBEAM,     // I-beam
    68     SDL_SYSTEM_CURSOR_WAIT,      // Wait
    69     SDL_SYSTEM_CURSOR_CROSSHAIR, // Crosshair
    70     SDL_SYSTEM_CURSOR_WAITARROW, // Small wait cursor (or Wait if not available)
    71     SDL_SYSTEM_CURSOR_SIZENWSE,  // Double arrow pointing northwest and southeast
    72     SDL_SYSTEM_CURSOR_SIZENESW,  // Double arrow pointing northeast and southwest
    73     SDL_SYSTEM_CURSOR_SIZEWE,    // Double arrow pointing west and east
    74     SDL_SYSTEM_CURSOR_SIZENS,    // Double arrow pointing north and south
    75     SDL_SYSTEM_CURSOR_SIZEALL,   // Four pointed arrow pointing north, south, east, and west
    76     SDL_SYSTEM_CURSOR_NO,        // Slashed circle or crossbones
    77     SDL_SYSTEM_CURSOR_HAND,      // Hand
    78     SDL_NUM_SYSTEM_CURSORS
    79 } SDL_SystemCursor;
    80 
    81 /* Function prototypes */
    82 
    83 /**
    84  *  \brief Get the window which currently has mouse focus.
    85  */
    86 extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
    87 
    88 /**
    89  *  \brief Retrieve the current state of the mouse.
    90  *  
    91  *  The current button state is returned as a button bitmask, which can
    92  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    93  *  mouse cursor position relative to the focus window for the currently
    94  *  selected mouse.  You can pass NULL for either x or y.
    95  */
    96 extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
    97 
    98 /**
    99  *  \brief Retrieve the relative state of the mouse.
   100  *
   101  *  The current button state is returned as a button bitmask, which can
   102  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   103  *  mouse deltas since the last call to SDL_GetRelativeMouseState().
   104  */
   105 extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
   106 
   107 /**
   108  *  \brief Moves the mouse to the given position within the window.
   109  *  
   110  *  \param window The window to move the mouse into, or NULL for the current mouse focus
   111  *  \param x The x coordinate within the window
   112  *  \param y The y coordinate within the window
   113  *  
   114  *  \note This function generates a mouse motion event
   115  */
   116 extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
   117                                                    int x, int y);
   118 
   119 /**
   120  *  \brief Set relative mouse mode.
   121  *  
   122  *  \param enabled Whether or not to enable relative mode
   123  *
   124  *  \return 0 on success, or -1 if relative mode is not supported.
   125  *  
   126  *  While the mouse is in relative mode, the cursor is hidden, and the
   127  *  driver will try to report continuous motion in the current window.
   128  *  Only relative motion events will be delivered, the mouse position
   129  *  will not change.
   130  *  
   131  *  \note This function will flush any pending mouse motion.
   132  *  
   133  *  \sa SDL_GetRelativeMouseMode()
   134  */
   135 extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
   136 
   137 /**
   138  *  \brief Query whether relative mouse mode is enabled.
   139  *  
   140  *  \sa SDL_SetRelativeMouseMode()
   141  */
   142 extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
   143 
   144 /**
   145  *  \brief Create a cursor, using the specified bitmap data and
   146  *         mask (in MSB format).
   147  *  
   148  *  The cursor width must be a multiple of 8 bits.
   149  *  
   150  *  The cursor is created in black and white according to the following:
   151  *  <table>
   152  *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
   153  *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
   154  *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
   155  *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
   156  *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black 
   157  *                                         if not. </td></tr>
   158  *  </table>
   159  *  
   160  *  \sa SDL_FreeCursor()
   161  */
   162 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
   163                                                      const Uint8 * mask,
   164                                                      int w, int h, int hot_x,
   165                                                      int hot_y);
   166 
   167 /**
   168  *  \brief Create a color cursor.
   169  *  
   170  *  \sa SDL_FreeCursor()
   171  */
   172 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
   173                                                           int hot_x,
   174                                                           int hot_y);
   175 
   176 /**
   177  *  \brief Create a system cursor.
   178  *
   179  *  \sa SDL_FreeCursor()
   180  */
   181 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
   182 
   183 /**
   184  *  \brief Set the active cursor.
   185  */
   186 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
   187 
   188 /**
   189  *  \brief Return the active cursor.
   190  */
   191 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
   192 
   193 /**
   194  *  \brief Frees a cursor created with SDL_CreateCursor().
   195  *  
   196  *  \sa SDL_CreateCursor()
   197  */
   198 extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
   199 
   200 /**
   201  *  \brief Toggle whether or not the cursor is shown.
   202  *  
   203  *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current 
   204  *                state.
   205  *  
   206  *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
   207  */
   208 extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
   209 
   210 /**
   211  *  Used as a mask when testing buttons in buttonstate.
   212  *   - Button 1:  Left mouse button
   213  *   - Button 2:  Middle mouse button
   214  *   - Button 3:  Right mouse button
   215  */
   216 #define SDL_BUTTON(X)		(1 << ((X)-1))
   217 #define SDL_BUTTON_LEFT		1
   218 #define SDL_BUTTON_MIDDLE	2
   219 #define SDL_BUTTON_RIGHT	3
   220 #define SDL_BUTTON_X1		4
   221 #define SDL_BUTTON_X2		5
   222 #define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
   223 #define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
   224 #define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
   225 #define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
   226 #define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
   227 
   228 
   229 /* Ends C function definitions when using C++ */
   230 #ifdef __cplusplus
   231 /* *INDENT-OFF* */
   232 }
   233 /* *INDENT-ON* */
   234 #endif
   235 #include "close_code.h"
   236 
   237 #endif /* _SDL_mouse_h */
   238 
   239 /* vi: set ts=4 sw=4 expandtab: */