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