include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 24 Jan 2010 21:10:53 +0000
changeset 3697 f7b03b6838cb
parent 3685 64ce267332c6
child 4465 3e69e077cb95
permissions -rw-r--r--
Fixed bug #926

Updated copyright to LGPL version 2.1 and year 2010
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_mouse.h
    25  *  
    26  *  Include file for SDL mouse event handling.
    27  */
    28 
    29 #ifndef _SDL_mouse_h
    30 #define _SDL_mouse_h
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 #include "SDL_video.h"
    35 
    36 #include "begin_code.h"
    37 /* Set up for C function definitions, even when using C++ */
    38 #ifdef __cplusplus
    39 /* *INDENT-OFF* */
    40 extern "C" {
    41 /* *INDENT-ON* */
    42 #endif
    43 
    44 typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    45 
    46 /* Function prototypes */
    47 
    48 /**
    49  *  \brief Get the number of mouse input devices available.
    50  *  
    51  *  \sa SDL_SelectMouse()
    52  */
    53 extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
    54 
    55 /**
    56  *  \brief Gets the name of a mouse with the given index.
    57  *  
    58  *  \param index is the index of the mouse, which name is to be returned.
    59  *  
    60  *  \return the name of the mouse with the specified index
    61  */
    62 extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index);
    63 
    64 /**
    65  *  \brief Set the index of the currently selected mouse.
    66  *  
    67  *  \return The index of the previously selected mouse.
    68  *  
    69  *  \note You can query the currently selected mouse by passing an index of -1.
    70  *  
    71  *  \sa SDL_GetNumMice()
    72  */
    73 extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
    74 
    75 /**
    76  *  \brief Get the window which currently has focus for the specified mouse.
    77  */
    78 extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocusWindow(int index);
    79 
    80 /**
    81  *  \brief Set relative mouse mode for the specified mouse.
    82  *  
    83  *  \param enabled Whether or not to enable relative mode
    84  *  
    85  *  \return 0 on success, or -1 if relative mode is not supported.
    86  *  
    87  *  While the mouse is in relative mode, the cursor is hidden, and the
    88  *  driver will try to report continuous motion in the current window.
    89  *  Only relative motion events will be delivered, the mouse position
    90  *  will not change.
    91  *  
    92  *  \note This function will flush any pending mouse motion.
    93  *  
    94  *  \sa SDL_GetRelativeMouseMode()
    95  */
    96 extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(int index,
    97                                                      SDL_bool enabled);
    98 
    99 /**
   100  *  \brief Query whether relative mouse mode is enabled for the specified mouse.
   101  *  
   102  *  \sa SDL_SetRelativeMouseMode()
   103  */
   104 extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(int index);
   105 
   106 /**
   107  *  \brief Retrieve the current state of the specified mouse.
   108  *  
   109  *  The current button state is returned as a button bitmask, which can
   110  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   111  *  mouse cursor position relative to the focus window for the currently
   112  *  selected mouse.  You can pass NULL for either x or y.
   113  */
   114 extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
   115 
   116 /**
   117  *  \brief Retrieve the state of the specified mouse.
   118  *
   119  *  The current button state is returned as a button bitmask, which can
   120  *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   121  *  mouse deltas since the last call to SDL_GetRelativeMouseState().
   122  */
   123 extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int index, int *x,
   124                                                         int *y);
   125 
   126 /**
   127  *  \brief Moves the currently selected mouse to the given position within the window.
   128  *  
   129  *  \param window The window to move the mouse into, or NULL for the current mouse focus
   130  *  \param x The x coordinate within the window
   131  *  \param y The y coordinate within the window
   132  *  
   133  *  \note This function generates a mouse motion event
   134  */
   135 extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
   136                                                    int x, int y);
   137 
   138 /**
   139  *  \brief Create a cursor for the currently selected mouse, using the
   140  *         specified bitmap data and mask (in MSB format).
   141  *  
   142  *  The cursor width must be a multiple of 8 bits.
   143  *  
   144  *  The cursor is created in black and white according to the following:
   145  *  <table>
   146  *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
   147  *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
   148  *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
   149  *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
   150  *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black 
   151                                            if not. </td></tr>
   152  *  </table>
   153  *  
   154  *  \sa SDL_FreeCursor()
   155  */
   156 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
   157                                                      const Uint8 * mask,
   158                                                      int w, int h, int hot_x,
   159                                                      int hot_y);
   160 
   161 /**
   162  *  \brief Set the active cursor for the currently selected mouse.
   163  *  
   164  *  \note The cursor must have been created for the selected mouse.
   165  */
   166 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
   167 
   168 /**
   169  *  \brief Return the active cursor for the currently selected mouse.
   170  */
   171 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
   172 
   173 /**
   174  *  \brief Frees a cursor created with SDL_CreateCursor().
   175  *  
   176  *  \sa SDL_CreateCursor()
   177  */
   178 extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
   179 
   180 /**
   181  *  \brief Toggle whether or not the cursor is shown for the currently selected 
   182  *         mouse.
   183  *  
   184  *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current 
   185  *                state.
   186  *  
   187  *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
   188  */
   189 extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
   190 
   191 /**
   192  *  \brief Gets the number of cursors a pointing device supports.
   193  *  
   194  *  Useful for tablet users. Useful only under Windows.
   195  *  
   196  *  \param index is the index of the pointing device, which number of cursors we
   197  *               want to receive.
   198  *  
   199  *  \return the number of cursors supported by the pointing device. On Windows
   200  *          if a device is a tablet it returns a number >=1. Normal mice always 
   201  *          return 1.
   202  *  
   203  *  On Linux every device reports one cursor.
   204  */
   205 extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index);
   206 
   207 /**
   208  *  \brief Returns the index of the current cursor used by a specific pointing
   209  *         device.
   210  *  
   211  *  Useful only under Windows.
   212  *  
   213  *  \param index is the index of the pointing device, which cursor index we want
   214  *               to receive.
   215  *  
   216  *  \return the index of the cursor currently used by a specific pointing 
   217  *          device.  Always 0 under Linux. On Windows if the device isn't a 
   218  *          tablet it returns 0.  If the device is the tablet it returns the 
   219  *          cursor index.  0 - stylus, 1 - eraser, 2 - cursor.
   220  */
   221 extern DECLSPEC int SDLCALL SDL_GetCurrentCursor(int index);
   222 
   223 /**
   224  *  Used as a mask when testing buttons in buttonstate.
   225  *   - Button 1:  Left mouse button
   226  *   - Button 2:  Middle mouse button
   227  *   - Button 3:  Right mouse button
   228  */
   229 #define SDL_BUTTON(X)		(1 << ((X)-1))
   230 #define SDL_BUTTON_LEFT		1
   231 #define SDL_BUTTON_MIDDLE	2
   232 #define SDL_BUTTON_RIGHT	3
   233 #define SDL_BUTTON_X1		4
   234 #define SDL_BUTTON_X2		5
   235 #define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
   236 #define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
   237 #define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
   238 #define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
   239 #define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
   240 
   241 
   242 /* Ends C function definitions when using C++ */
   243 #ifdef __cplusplus
   244 /* *INDENT-OFF* */
   245 }
   246 /* *INDENT-ON* */
   247 #endif
   248 #include "close_code.h"
   249 
   250 #endif /* _SDL_mouse_h */
   251 
   252 /* vi: set ts=4 sw=4 expandtab: */