include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5473 5665ccbd6792
child 6138 4c64952a58fb
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 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
slouken@4465
    61
slouken@0
    62
/* Function prototypes */
slouken@1895
    63
slouken@1895
    64
/**
slouken@4465
    65
 *  \brief Get the window which currently has mouse focus.
slouken@1895
    66
 */
slouken@4465
    67
extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
slouken@1895
    68
slouken@1895
    69
/**
slouken@4465
    70
 *  \brief Retrieve the current state of the mouse.
slouken@3407
    71
 *  
slouken@4465
    72
 *  The current button state is returned as a button bitmask, which can
slouken@4465
    73
 *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
slouken@4465
    74
 *  mouse cursor position relative to the focus window for the currently
slouken@4465
    75
 *  selected mouse.  You can pass NULL for either x or y.
kazeuser@2718
    76
 */
slouken@4465
    77
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
kazeuser@2718
    78
kazeuser@2718
    79
/**
slouken@4465
    80
 *  \brief Retrieve the relative state of the mouse.
slouken@4465
    81
 *
slouken@4465
    82
 *  The current button state is returned as a button bitmask, which can
slouken@4465
    83
 *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
slouken@4465
    84
 *  mouse deltas since the last call to SDL_GetRelativeMouseState().
slouken@1895
    85
 */
slouken@4465
    86
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
slouken@1895
    87
slouken@1895
    88
/**
slouken@4465
    89
 *  \brief Moves the mouse to the given position within the window.
slouken@4465
    90
 *  
slouken@4465
    91
 *  \param window The window to move the mouse into, or NULL for the current mouse focus
slouken@4465
    92
 *  \param x The x coordinate within the window
slouken@4465
    93
 *  \param y The y coordinate within the window
slouken@4465
    94
 *  
slouken@4465
    95
 *  \note This function generates a mouse motion event
slouken@1895
    96
 */
slouken@4465
    97
extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
slouken@4465
    98
                                                   int x, int y);
slouken@1895
    99
slouken@1895
   100
/**
slouken@4465
   101
 *  \brief Set relative mouse mode.
slouken@3407
   102
 *  
slouken@3407
   103
 *  \param enabled Whether or not to enable relative mode
slouken@4465
   104
 *
slouken@3407
   105
 *  \return 0 on success, or -1 if relative mode is not supported.
slouken@3407
   106
 *  
slouken@3407
   107
 *  While the mouse is in relative mode, the cursor is hidden, and the
slouken@3407
   108
 *  driver will try to report continuous motion in the current window.
slouken@3407
   109
 *  Only relative motion events will be delivered, the mouse position
slouken@3407
   110
 *  will not change.
slouken@3407
   111
 *  
slouken@3407
   112
 *  \note This function will flush any pending mouse motion.
slouken@3407
   113
 *  
slouken@3407
   114
 *  \sa SDL_GetRelativeMouseMode()
slouken@1895
   115
 */
slouken@4465
   116
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
slouken@1895
   117
slouken@1895
   118
/**
slouken@4465
   119
 *  \brief Query whether relative mouse mode is enabled.
slouken@3407
   120
 *  
slouken@3407
   121
 *  \sa SDL_SetRelativeMouseMode()
slouken@1895
   122
 */
slouken@4465
   123
extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
slouken@1895
   124
slouken@1895
   125
/**
slouken@4465
   126
 *  \brief Create a cursor, using the specified bitmap data and
slouken@4465
   127
 *         mask (in MSB format).
slouken@3407
   128
 *  
slouken@3407
   129
 *  The cursor width must be a multiple of 8 bits.
slouken@3407
   130
 *  
slouken@3407
   131
 *  The cursor is created in black and white according to the following:
slouken@3407
   132
 *  <table>
slouken@3407
   133
 *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
slouken@3407
   134
 *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
slouken@3407
   135
 *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
slouken@3407
   136
 *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
slouken@3407
   137
 *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black 
slouken@4465
   138
 *                                         if not. </td></tr>
slouken@3407
   139
 *  </table>
slouken@3407
   140
 *  
slouken@3407
   141
 *  \sa SDL_FreeCursor()
slouken@0
   142
 */
slouken@1895
   143
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
slouken@1895
   144
                                                     const Uint8 * mask,
slouken@1895
   145
                                                     int w, int h, int hot_x,
slouken@1895
   146
                                                     int hot_y);
slouken@0
   147
slouken@1895
   148
/**
slouken@5473
   149
 *  \brief Create a color cursor.
slouken@5473
   150
 *  
slouken@5473
   151
 *  \sa SDL_FreeCursor()
slouken@5473
   152
 */
slouken@5473
   153
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
slouken@5473
   154
                                                          int hot_x,
slouken@5473
   155
                                                          int hot_y);
slouken@5473
   156
slouken@5473
   157
/**
slouken@4465
   158
 *  \brief Set the active cursor.
slouken@0
   159
 */
slouken@1895
   160
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
slouken@0
   161
slouken@1895
   162
/**
slouken@4465
   163
 *  \brief Return the active cursor.
slouken@0
   164
 */
slouken@1895
   165
extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
slouken@0
   166
slouken@1895
   167
/**
slouken@3407
   168
 *  \brief Frees a cursor created with SDL_CreateCursor().
slouken@3407
   169
 *  
slouken@3407
   170
 *  \sa SDL_CreateCursor()
slouken@0
   171
 */
slouken@1895
   172
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
slouken@0
   173
slouken@1895
   174
/**
slouken@4465
   175
 *  \brief Toggle whether or not the cursor is shown.
slouken@3407
   176
 *  
slouken@3407
   177
 *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current 
slouken@3407
   178
 *                state.
slouken@3407
   179
 *  
slouken@3407
   180
 *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
slouken@0
   181
 */
slouken@337
   182
extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
slouken@0
   183
kazeuser@2718
   184
/**
slouken@3407
   185
 *  Used as a mask when testing buttons in buttonstate.
slouken@3407
   186
 *   - Button 1:  Left mouse button
slouken@3407
   187
 *   - Button 2:  Middle mouse button
slouken@3407
   188
 *   - Button 3:  Right mouse button
slouken@3407
   189
 */
slouken@1330
   190
#define SDL_BUTTON(X)		(1 << ((X)-1))
slouken@0
   191
#define SDL_BUTTON_LEFT		1
slouken@0
   192
#define SDL_BUTTON_MIDDLE	2
slouken@0
   193
#define SDL_BUTTON_RIGHT	3
slouken@2284
   194
#define SDL_BUTTON_X1		4
slouken@2284
   195
#define SDL_BUTTON_X2		5
slouken@0
   196
#define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
slouken@0
   197
#define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
slouken@0
   198
#define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
slouken@2284
   199
#define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
slouken@2284
   200
#define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
slouken@0
   201
slouken@0
   202
slouken@0
   203
/* Ends C function definitions when using C++ */
slouken@0
   204
#ifdef __cplusplus
slouken@1895
   205
/* *INDENT-OFF* */
slouken@0
   206
}
slouken@1895
   207
/* *INDENT-ON* */
slouken@0
   208
#endif
slouken@0
   209
#include "close_code.h"
slouken@0
   210
slouken@0
   211
#endif /* _SDL_mouse_h */
slouken@1895
   212
slouken@1895
   213
/* vi: set ts=4 sw=4 expandtab: */