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