include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 08 Dec 2008 00:27:32 +0000
changeset 2859 99210400e8b9
parent 2765 f55c87ae336b
child 3407 d3baf5ac4e37
permissions -rw-r--r--
Updated copyright date
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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  * \fn int SDL_GetNumMice(void)
    50  *
    51  * \brief Get the number of mouse input devices available.
    52  *
    53  * \sa SDL_SelectMouse()
    54  */
    55 extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
    56 
    57 /**
    58  * \fn char* SDL_GetMouseName(int index)
    59  *
    60  * \brief Gets the name of a mouse with the given index.
    61  *
    62  * \param index is the index of the mouse, which name is to be returned.
    63  *
    64  * \return the name of the mouse with the specified index
    65  */
    66 extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index);
    67 
    68 /**
    69  * \fn int SDL_SelectMouse(int index)
    70  *
    71  * \brief Set the index of the currently selected mouse.
    72  *
    73  * \return The index of the previously selected mouse.
    74  *
    75  * \note You can query the currently selected mouse by passing an index of -1.
    76  *
    77  * \sa SDL_GetNumMice()
    78  */
    79 extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
    80 
    81 /**
    82  * \fn SDL_WindowID SDL_GetMouseFocusWindow(int index)
    83  *
    84  * \brief Get the window which currently has focus for the currently selected mouse.
    85  */
    86 extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(int index);
    87 
    88 /**
    89  * \fn int SDL_SetRelativeMouseMode(int index, SDL_bool enabled)
    90  *
    91  * \brief Set relative mouse mode for the currently selected mouse.
    92  *
    93  * \param enabled Whether or not to enable relative mode
    94  *
    95  * \return 0 on success, or -1 if relative mode is not supported.
    96  *
    97  * While the mouse is in relative mode, the cursor is hidden, and the
    98  * driver will try to report continuous motion in the current window.
    99  * Only relative motion events will be delivered, the mouse position
   100  * will not change.
   101  *
   102  * \note This function will flush any pending mouse motion.
   103  *
   104  * \sa SDL_GetRelativeMouseMode()
   105  */
   106 extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(int index,
   107                                                      SDL_bool enabled);
   108 
   109 /**
   110  * \fn SDL_bool SDL_GetRelativeMouseMode(int index)
   111  *
   112  * \brief Query whether relative mouse mode is enabled for the currently selected mouse.
   113  *
   114  * \sa SDL_SetRelativeMouseMode()
   115  */
   116 extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(int index);
   117 
   118 /**
   119  * \fn Uint8 SDL_GetMouseState(int index, int *x, int *y)
   120  *
   121  * \brief Retrieve the current state of the currently selected mouse.
   122  *
   123  * The current button state is returned as a button bitmask, which can
   124  * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   125  * mouse cursor position relative to the focus window for the currently
   126  * selected mouse.  You can pass NULL for either x or y.
   127  */
   128 extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int index, int *x, int *y);
   129 
   130 /**
   131  * \fn Uint8 SDL_GetRelativeMouseState(int index, int *x, int *y)
   132  *
   133  * \brief Retrieve the state of the currently selected mouse.
   134  *
   135  * The current button state is returned as a button bitmask, which can
   136  * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
   137  * mouse deltas since the last call to SDL_GetRelativeMouseState().
   138  */
   139 extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int index, int *x,
   140                                                         int *y);
   141 
   142 /**
   143  * \fn void SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
   144  *
   145  * \brief Moves the currently selected mouse to the given position within the window.
   146  *
   147  * \param windowID The window to move the mouse into, or 0 for the current mouse focus
   148  * \param x The x coordinate within the window
   149  * \param y The y coordinate within the window
   150  *
   151  * \note This function generates a mouse motion event
   152  */
   153 extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
   154                                                    int x, int y);
   155 
   156 /**
   157  * \fn SDL_Cursor *SDL_CreateCursor (const Uint8 * data, const Uint8 * mask, int w, int h, int hot_x, int hot_y)
   158  *
   159  * \brief Create a cursor for the currently selected mouse, using the
   160  *        specified bitmap data and mask (in MSB format).
   161  *
   162  * The cursor width must be a multiple of 8 bits.
   163  *
   164  * The cursor is created in black and white according to the following:
   165  * data  mask    resulting pixel on screen
   166  *  0     1       White
   167  *  1     1       Black
   168  *  0     0       Transparent
   169  *  1     0       Inverted color if possible, black if not.
   170  *
   171  * \sa SDL_FreeCursor()
   172  */
   173 extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
   174                                                      const Uint8 * mask,
   175                                                      int w, int h, int hot_x,
   176                                                      int hot_y);
   177 
   178 /**
   179  * \fn void SDL_SetCursor(SDL_Cursor * cursor)
   180  *
   181  * \brief Set the active cursor for the currently selected mouse.
   182  *
   183  * \note The cursor must have been created for the selected mouse.
   184  */
   185 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
   186 
   187 /**
   188  * \fn SDL_Cursor *SDL_GetCursor(void)
   189  *
   190  * \brief Return the active cursor for the currently selected mouse.
   191  */
   192 extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
   193 
   194 /**
   195  * \fn void SDL_FreeCursor(SDL_Cursor * cursor)
   196  *
   197  * \brief Frees a cursor created with SDL_CreateCursor().
   198  *
   199  * \sa SDL_CreateCursor()
   200  */
   201 extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
   202 
   203 /**
   204  * \fn int SDL_ShowCursor(int toggle)
   205  *
   206  * \brief Toggle whether or not the cursor is shown for the currently selected mouse.
   207  *
   208  * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current state.
   209  *
   210  * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
   211  */
   212 extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
   213 
   214 /* Used as a mask when testing buttons in buttonstate
   215    Button 1:	Left mouse button
   216    Button 2:	Middle mouse button
   217    Button 3:	Right mouse button
   218  */
   219 
   220 /**
   221  * \fn int SDL_GetCursorsNumber(int index)
   222  *
   223  * \brief Gets the number of cursors a pointing device supports.
   224  * Useful for tablet users. Useful only under Windows.
   225  *
   226  * \param index is the index of the pointing device, which number of cursors we
   227  * want to receive.
   228  *
   229  * \return the number of cursors supported by the pointing device. On Windows
   230  * if a device is a tablet it returns a number >=1. Normal mice always return 1.
   231  * On Linux every device reports one cursor.
   232  */
   233 extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index);
   234 
   235 /**
   236  * \fn int SDL_GetCurrentCursor(int index)
   237  *
   238  * \brief Returns the index of the current cursor used by a specific pointing
   239  * device. Useful only under Windows.
   240  *
   241  * \param index is the index of the pointing device, which cursor index we want
   242  * to receive.
   243  *
   244  * \return the index of the cursor currently used by a specific pointing device.
   245  * Always 0 under Linux. On Windows if the device isn't a tablet it returns 0.
   246  * If the device is the tablet it returns the cursor index.
   247  * 0 - stylus, 1 - eraser, 2 - cursor.
   248  */
   249 extern DECLSPEC int SDLCALL SDL_GetCurrentCursor(int index);
   250 
   251 #define SDL_BUTTON(X)		(1 << ((X)-1))
   252 #define SDL_BUTTON_LEFT		1
   253 #define SDL_BUTTON_MIDDLE	2
   254 #define SDL_BUTTON_RIGHT	3
   255 #define SDL_BUTTON_X1		4
   256 #define SDL_BUTTON_X2		5
   257 #define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
   258 #define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
   259 #define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
   260 #define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
   261 #define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
   262 
   263 
   264 /* Ends C function definitions when using C++ */
   265 #ifdef __cplusplus
   266 /* *INDENT-OFF* */
   267 }
   268 /* *INDENT-ON* */
   269 #endif
   270 #include "close_code.h"
   271 
   272 #endif /* _SDL_mouse_h */
   273 
   274 /* vi: set ts=4 sw=4 expandtab: */