include/SDL_mouse.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 15:42:26 -0800
changeset 4986 8431f59485d0
parent 4465 3e69e077cb95
child 5262 b530ef003506
permissions -rw-r--r--
Renderer didn't advertise texture format SDL_PIXELFORMAT_ABGR8888
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@4465
    27
 *
slouken@4465
    28
 *  Please note that this ONLY discusses "mice" with the notion of the
slouken@4465
    29
 *  desktop GUI. You (usually) have one system cursor, and the OS hides
slouken@4465
    30
 *  the hardware details from you. If you plug in 10 mice, all ten move that
slouken@4465
    31
 *  one cursor. For many applications and games, this is perfect, and this
slouken@4465
    32
 *  API has served hundreds of SDL programs well since its birth.
slouken@4465
    33
 *
slouken@4465
    34
 *  It's not the whole picture, though. If you want more lowlevel control,
slouken@4465
    35
 *  SDL offers a different API, that gives you visibility into each input
slouken@4465
    36
 *  device, multi-touch interfaces, etc.
slouken@4465
    37
 *
slouken@4465
    38
 *  Those two APIs are incompatible, and you usually should not use both
slouken@4465
    39
 *  at the same time. But for legacy purposes, this API refers to a "mouse"
slouken@4465
    40
 *  when it actually means the system pointer and not a physical mouse.
slouken@4465
    41
 *
slouken@4465
    42
 *  The other API is in SDL_input.h
slouken@1895
    43
 */
slouken@0
    44
slouken@0
    45
#ifndef _SDL_mouse_h
slouken@0
    46
#define _SDL_mouse_h
slouken@0
    47
slouken@1356
    48
#include "SDL_stdinc.h"
slouken@1358
    49
#include "SDL_error.h"
slouken@0
    50
#include "SDL_video.h"
slouken@0
    51
slouken@0
    52
#include "begin_code.h"
slouken@0
    53
/* Set up for C function definitions, even when using C++ */
slouken@0
    54
#ifdef __cplusplus
slouken@1895
    55
/* *INDENT-OFF* */
slouken@0
    56
extern "C" {
slouken@1895
    57
/* *INDENT-ON* */
slouken@0
    58
#endif
slouken@0
    59
slouken@1895
    60
typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
slouken@0
    61
slouken@4465
    62
slouken@0
    63
/* Function prototypes */
slouken@1895
    64
slouken@1895
    65
/**
slouken@4465
    66
 *  \brief Get the window which currently has mouse focus.
slouken@1895
    67
 */
slouken@4465
    68
extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
slouken@1895
    69
slouken@1895
    70
/**
slouken@4465
    71
 *  \brief Retrieve the current state of the mouse.
slouken@3407
    72
 *  
slouken@4465
    73
 *  The current button state is returned as a button bitmask, which can
slouken@4465
    74
 *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
slouken@4465
    75
 *  mouse cursor position relative to the focus window for the currently
slouken@4465
    76
 *  selected mouse.  You can pass NULL for either x or y.
kazeuser@2718
    77
 */
slouken@4465
    78
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
kazeuser@2718
    79
kazeuser@2718
    80
/**
slouken@4465
    81
 *  \brief Retrieve the relative state of the mouse.
slouken@4465
    82
 *
slouken@4465
    83
 *  The current button state is returned as a button bitmask, which can
slouken@4465
    84
 *  be tested using the SDL_BUTTON(X) macros, and x and y are set to the
slouken@4465
    85
 *  mouse deltas since the last call to SDL_GetRelativeMouseState().
slouken@1895
    86
 */
slouken@4465
    87
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
slouken@1895
    88
slouken@1895
    89
/**
slouken@4465
    90
 *  \brief Moves the mouse to the given position within the window.
slouken@4465
    91
 *  
slouken@4465
    92
 *  \param window The window to move the mouse into, or NULL for the current mouse focus
slouken@4465
    93
 *  \param x The x coordinate within the window
slouken@4465
    94
 *  \param y The y coordinate within the window
slouken@4465
    95
 *  
slouken@4465
    96
 *  \note This function generates a mouse motion event
slouken@1895
    97
 */
slouken@4465
    98
extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
slouken@4465
    99
                                                   int x, int y);
slouken@1895
   100
slouken@1895
   101
/**
slouken@4465
   102
 *  \brief Set relative mouse mode.
slouken@3407
   103
 *  
slouken@3407
   104
 *  \param enabled Whether or not to enable relative mode
slouken@4465
   105
 *
slouken@3407
   106
 *  \return 0 on success, or -1 if relative mode is not supported.
slouken@3407
   107
 *  
slouken@3407
   108
 *  While the mouse is in relative mode, the cursor is hidden, and the
slouken@3407
   109
 *  driver will try to report continuous motion in the current window.
slouken@3407
   110
 *  Only relative motion events will be delivered, the mouse position
slouken@3407
   111
 *  will not change.
slouken@3407
   112
 *  
slouken@3407
   113
 *  \note This function will flush any pending mouse motion.
slouken@3407
   114
 *  
slouken@3407
   115
 *  \sa SDL_GetRelativeMouseMode()
slouken@1895
   116
 */
slouken@4465
   117
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
slouken@1895
   118
slouken@1895
   119
/**
slouken@4465
   120
 *  \brief Query whether relative mouse mode is enabled.
slouken@3407
   121
 *  
slouken@3407
   122
 *  \sa SDL_SetRelativeMouseMode()
slouken@1895
   123
 */
slouken@4465
   124
extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
slouken@1895
   125
slouken@1895
   126
/**
slouken@4465
   127
 *  \brief Create a cursor, using the specified bitmap data and
slouken@4465
   128
 *         mask (in MSB format).
slouken@3407
   129
 *  
slouken@3407
   130
 *  The cursor width must be a multiple of 8 bits.
slouken@3407
   131
 *  
slouken@3407
   132
 *  The cursor is created in black and white according to the following:
slouken@3407
   133
 *  <table>
slouken@3407
   134
 *  <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
slouken@3407
   135
 *  <tr><td>  0   </td><td>  1   </td><td> White </td></tr>
slouken@3407
   136
 *  <tr><td>  1   </td><td>  1   </td><td> Black </td></tr>
slouken@3407
   137
 *  <tr><td>  0   </td><td>  0   </td><td> Transparent </td></tr>
slouken@3407
   138
 *  <tr><td>  1   </td><td>  0   </td><td> Inverted color if possible, black 
slouken@4465
   139
 *                                         if not. </td></tr>
slouken@3407
   140
 *  </table>
slouken@3407
   141
 *  
slouken@3407
   142
 *  \sa SDL_FreeCursor()
slouken@0
   143
 */
slouken@1895
   144
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
slouken@1895
   145
                                                     const Uint8 * mask,
slouken@1895
   146
                                                     int w, int h, int hot_x,
slouken@1895
   147
                                                     int hot_y);
slouken@0
   148
slouken@1895
   149
/**
slouken@4465
   150
 *  \brief Set the active cursor.
slouken@0
   151
 */
slouken@1895
   152
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
slouken@0
   153
slouken@1895
   154
/**
slouken@4465
   155
 *  \brief Return the active cursor.
slouken@0
   156
 */
slouken@1895
   157
extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
slouken@0
   158
slouken@1895
   159
/**
slouken@3407
   160
 *  \brief Frees a cursor created with SDL_CreateCursor().
slouken@3407
   161
 *  
slouken@3407
   162
 *  \sa SDL_CreateCursor()
slouken@0
   163
 */
slouken@1895
   164
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
slouken@0
   165
slouken@1895
   166
/**
slouken@4465
   167
 *  \brief Toggle whether or not the cursor is shown.
slouken@3407
   168
 *  
slouken@3407
   169
 *  \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current 
slouken@3407
   170
 *                state.
slouken@3407
   171
 *  
slouken@3407
   172
 *  \return 1 if the cursor is shown, or 0 if the cursor is hidden.
slouken@0
   173
 */
slouken@337
   174
extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
slouken@0
   175
kazeuser@2718
   176
/**
slouken@3407
   177
 *  Used as a mask when testing buttons in buttonstate.
slouken@3407
   178
 *   - Button 1:  Left mouse button
slouken@3407
   179
 *   - Button 2:  Middle mouse button
slouken@3407
   180
 *   - Button 3:  Right mouse button
slouken@3407
   181
 */
slouken@1330
   182
#define SDL_BUTTON(X)		(1 << ((X)-1))
slouken@0
   183
#define SDL_BUTTON_LEFT		1
slouken@0
   184
#define SDL_BUTTON_MIDDLE	2
slouken@0
   185
#define SDL_BUTTON_RIGHT	3
slouken@2284
   186
#define SDL_BUTTON_X1		4
slouken@2284
   187
#define SDL_BUTTON_X2		5
slouken@0
   188
#define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
slouken@0
   189
#define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
slouken@0
   190
#define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
slouken@2284
   191
#define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
slouken@2284
   192
#define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
slouken@0
   193
slouken@0
   194
slouken@0
   195
/* Ends C function definitions when using C++ */
slouken@0
   196
#ifdef __cplusplus
slouken@1895
   197
/* *INDENT-OFF* */
slouken@0
   198
}
slouken@1895
   199
/* *INDENT-ON* */
slouken@0
   200
#endif
slouken@0
   201
#include "close_code.h"
slouken@0
   202
slouken@0
   203
#endif /* _SDL_mouse_h */
slouken@1895
   204
slouken@1895
   205
/* vi: set ts=4 sw=4 expandtab: */