src/events/SDL_mouse.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 15 Oct 2014 09:11:15 -0700
changeset 9161 6e34073ef024
parent 8983 21f5923cfd15
child 9257 6f41196c2d6b
permissions -rw-r--r--
Fixed spurious SDL error on shutdown if mouse capture isn't supported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5473
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8071
diff changeset
    21
#include "../SDL_internal.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* General mouse handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    25
#include "SDL_assert.h"
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
    26
#include "SDL_hints.h"
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    27
#include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include "SDL_events.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include "SDL_events_c.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    30
#include "default_cursor.h"
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3585
diff changeset
    31
#include "../video/SDL_sysvideo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    33
/* #define DEBUG_MOUSE */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    35
/* The mouse state */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    36
static SDL_Mouse SDL_mouse;
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    37
static Uint32 SDL_double_click_time = 500;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    38
static int SDL_double_click_radius = 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
    40
static int
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
    41
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    43
/* Public functions */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    44
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    45
SDL_MouseInit(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    46
{
5376
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    47
    SDL_Mouse *mouse = SDL_GetMouse();
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    48
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    49
    mouse->cursor_shown = SDL_TRUE;
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    50
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    51
    return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    52
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    53
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    54
void
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    55
SDL_SetDefaultCursor(SDL_Cursor * cursor)
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    56
{
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    57
    SDL_Mouse *mouse = SDL_GetMouse();
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    58
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    59
    mouse->def_cursor = cursor;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    60
    if (!mouse->cur_cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    61
        SDL_SetCursor(cursor);
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    62
    }
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    63
}
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    64
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    65
SDL_Mouse *
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    66
SDL_GetMouse(void)
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    67
{
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    68
    return &SDL_mouse;
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    69
}
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    70
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    71
void
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    72
SDL_SetDoubleClickTime(Uint32 interval)
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    73
{
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    74
    SDL_double_click_time = interval;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    75
}
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
    76
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    77
SDL_Window *
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    78
SDL_GetMouseFocus(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
    80
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    81
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    82
    return mouse->focus;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    83
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    84
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    85
void
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    86
SDL_ResetMouse(void)
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    87
{
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    88
    SDL_Mouse *mouse = SDL_GetMouse();
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    89
    Uint8 i;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    90
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    91
#ifdef DEBUG_MOUSE
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    92
    printf("Resetting mouse\n");
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    93
#endif
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    94
    for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    95
        if (mouse->buttonstate & SDL_BUTTON(i)) {
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    96
            SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    97
        }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    98
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    99
    SDL_assert(mouse->buttonstate == 0);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   100
}
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   101
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   102
void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   103
SDL_SetMouseFocus(SDL_Window * window)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   104
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   105
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   106
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   107
    if (mouse->focus == window) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   108
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   109
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   110
6829
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   111
    /* Actually, this ends up being a bad idea, because most operating
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   112
       systems have an implicit grab when you press the mouse button down
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   113
       so you can drag things out of the window and then get the mouse up
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   114
       when it happens.  So, #if 0...
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   115
    */
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   116
#if 0
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   117
    if (mouse->focus && !window) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   118
        /* We won't get anymore mouse messages, so reset mouse state */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   119
        SDL_ResetMouse();
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   120
    }
6829
36ce2e6166e7 Don't reset the mouse, that's actually bad behavior most of the time for windowed applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6755
diff changeset
   121
#endif
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   122
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   123
    /* See if the current window has lost focus */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   124
    if (mouse->focus) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   125
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   126
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   127
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3585
diff changeset
   128
    mouse->focus = window;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   129
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   130
    if (mouse->focus) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   131
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   132
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   133
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   134
    /* Update cursor visibility */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   135
    SDL_SetCursor(NULL);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   136
}
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   137
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   138
/* Check to see if we need to synthesize focus events */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   139
static SDL_bool
6673
78f18a929123 Nobody will EVER use more than 8 buttons. Oh wait... Nobody will EVER use more than 32 buttons...
Sam Lantinga <slouken@libsdl.org>
parents: 6667
diff changeset
   140
SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   141
{
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   142
    SDL_Mouse *mouse = SDL_GetMouse();
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   143
    SDL_bool inWindow = SDL_TRUE;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   144
8983
21f5923cfd15 Fixed compiler warnings on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   145
    if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   146
        int w, h;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   147
        SDL_GetWindowSize(window, &w, &h);
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   148
        if (x < 0 || y < 0 || x >= w || y >= h) {
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   149
            inWindow = SDL_FALSE;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   150
        }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   151
    }
6667
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   152
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   153
/* Linux doesn't give you mouse events outside your window unless you grab
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   154
   the pointer.
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   155
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   156
   Windows doesn't give you mouse events outside your window unless you call
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   157
   SetCapture().
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   158
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   159
   Both of these are slightly scary changes, so for now we'll punt and if the
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   160
   mouse leaves the window you'll lose mouse focus and reset button state.
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   161
*/
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   162
#ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   163
    if (!inWindow && !buttonstate) {
6667
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   164
#else
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   165
    if (!inWindow) {
243bfb5c31d6 Neither Windows nor Linux allow dragging out of the window without some sort of mouse capture, so for now punt on that behavior.
Sam Lantinga <slouken@libsdl.org>
parents: 6666
diff changeset
   166
#endif
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   167
        if (window == mouse->focus) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   168
#ifdef DEBUG_MOUSE
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   169
            printf("Mouse left window, synthesizing move & focus lost event\n");
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   170
#endif
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   171
            SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   172
            SDL_SetMouseFocus(NULL);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   173
        }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   174
        return SDL_FALSE;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   175
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   176
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   177
    if (window != mouse->focus) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   178
#ifdef DEBUG_MOUSE
7097
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   179
         printf("Mouse entered window, synthesizing focus gain & move event\n");
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   180
#endif
7097
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   181
         SDL_SetMouseFocus(window);
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   182
         SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   183
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   184
    return SDL_TRUE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   187
int
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   188
SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
{
7089
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   190
    if (window && !relative) {
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   191
        SDL_Mouse *mouse = SDL_GetMouse();
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   192
        if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   193
            return 0;
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   194
        }
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   195
    }
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   196
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   197
    return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   198
}
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   199
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   200
static int
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   201
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
257fc4e541e1 Send mouse leave updates for Windows and X11.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7037
diff changeset
   202
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   203
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   204
    int posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   205
    int xrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   206
    int yrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   207
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   208
    if (mouse->relative_mode_warp) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   209
        int center_x = 0, center_y = 0;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   210
        SDL_GetWindowSize(window, &center_x, &center_y);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   211
        center_x /= 2;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   212
        center_y /= 2;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   213
        if (x == center_x && y == center_y) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   214
            mouse->last_x = center_x;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   215
            mouse->last_y = center_y;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   216
            return 0;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   217
        }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   218
        SDL_WarpMouseInWindow(window, center_x, center_y);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   219
    }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   220
2842
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   221
    if (relative) {
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   222
        xrel = x;
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   223
        yrel = y;
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   224
        x = (mouse->last_x + xrel);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   225
        y = (mouse->last_y + yrel);
2842
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   226
    } else {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   227
        xrel = x - mouse->last_x;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   228
        yrel = y - mouse->last_y;
2842
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   229
    }
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   230
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   231
    /* Drop events that don't change state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   232
    if (!xrel && !yrel) {
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   233
#ifdef DEBUG_MOUSE
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   234
        printf("Mouse event didn't change state - dropped!\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   235
#endif
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   236
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   237
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   239
    /* Update internal mouse coordinates */
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   240
    if (!mouse->relative_mode) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   241
        mouse->x = x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   242
        mouse->y = y;
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   243
    } else {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   244
        mouse->x += xrel;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   245
        mouse->y += yrel;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   246
    }
2849
523b10db69f8 There's no reason to add extra code to notify the mice of window size changes.
Sam Lantinga <slouken@libsdl.org>
parents: 2842
diff changeset
   247
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   248
    /* make sure that the pointers find themselves inside the windows,
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   249
       unless we have the mouse captured. */
8983
21f5923cfd15 Fixed compiler warnings on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   250
    if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   251
        int x_max = 0, y_max = 0;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   252
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   253
        // !!! FIXME: shouldn't this be (window) instead of (mouse->focus)?
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   254
        SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   255
        --x_max;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   256
        --y_max;
2849
523b10db69f8 There's no reason to add extra code to notify the mice of window size changes.
Sam Lantinga <slouken@libsdl.org>
parents: 2842
diff changeset
   257
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   258
        if (mouse->x > x_max) {
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   259
            mouse->x = x_max;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   260
        }
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   261
        if (mouse->x < 0) {
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   262
            mouse->x = 0;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   263
        }
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   264
8927
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   265
        if (mouse->y > y_max) {
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   266
            mouse->y = y_max;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   267
        }
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   268
        if (mouse->y < 0) {
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   269
            mouse->y = 0;
be64f5daf64b Implemented SDL_CaptureMouse().
Ryan C. Gordon <icculus@icculus.org>
parents: 8783
diff changeset
   270
        }
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   271
    }
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   272
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   273
    mouse->xdelta += xrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   274
    mouse->ydelta += yrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   275
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   276
    /* Move the mouse cursor, if needed */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   277
    if (mouse->cursor_shown && !mouse->relative_mode &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   278
        mouse->MoveCursor && mouse->cur_cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   279
        mouse->MoveCursor(mouse->cur_cursor);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   280
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   281
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   282
    /* Post the event, if desired */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   283
    posted = 0;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   284
    if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   285
        SDL_Event event;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   286
        event.motion.type = SDL_MOUSEMOTION;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   287
        event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   288
        event.motion.which = mouseID;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   289
        event.motion.state = mouse->buttonstate;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   290
        event.motion.x = mouse->x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   291
        event.motion.y = mouse->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   292
        event.motion.xrel = xrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   293
        event.motion.yrel = yrel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   294
        posted = (SDL_PushEvent(&event) > 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   295
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   296
    /* Use unclamped values if we're getting events outside the window */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   297
    mouse->last_x = x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   298
    mouse->last_y = y;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   299
    return posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   300
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   301
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   302
static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   303
{
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   304
    if (button >= mouse->num_clickstates) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   305
        int i, count = button + 1;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   306
        mouse->clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   307
        if (!mouse->clickstate) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   308
            return NULL;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   309
        }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   310
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   311
        for (i = mouse->num_clickstates; i < count; ++i) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   312
            SDL_zero(mouse->clickstate[i]);
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   313
        }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   314
        mouse->num_clickstates = count;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   315
    }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   316
    return &mouse->clickstate[button];
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   317
}
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   318
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   319
int
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   320
SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   321
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   322
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   323
    int posted;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   324
    Uint32 type;
6673
78f18a929123 Nobody will EVER use more than 8 buttons. Oh wait... Nobody will EVER use more than 32 buttons...
Sam Lantinga <slouken@libsdl.org>
parents: 6667
diff changeset
   325
    Uint32 buttonstate = mouse->buttonstate;
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   326
    SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   327
    Uint8 click_count;
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   328
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   329
    /* Figure out which event to perform */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   330
    switch (state) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   331
    case SDL_PRESSED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   332
        type = SDL_MOUSEBUTTONDOWN;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   333
        buttonstate |= SDL_BUTTON(button);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   334
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   335
    case SDL_RELEASED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   336
        type = SDL_MOUSEBUTTONUP;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   337
        buttonstate &= ~SDL_BUTTON(button);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   338
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   339
    default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   340
        /* Invalid state -- bail */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   341
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   342
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   343
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   344
    /* We do this after calculating buttonstate so button presses gain focus */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   345
    if (window && state == SDL_PRESSED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   346
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   347
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   348
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   349
    if (buttonstate == mouse->buttonstate) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   350
        /* Ignore this event, no state change */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   351
        return 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   352
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   353
    mouse->buttonstate = buttonstate;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   354
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   355
    if (clickstate) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   356
        if (state == SDL_PRESSED) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   357
            Uint32 now = SDL_GetTicks();
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   358
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   359
            if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   360
                SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   361
                SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   362
                clickstate->click_count = 0;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   363
            }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   364
            clickstate->last_timestamp = now;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   365
            clickstate->last_x = mouse->x;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   366
            clickstate->last_y = mouse->y;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   367
            if (clickstate->click_count < 255) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   368
                ++clickstate->click_count;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   369
            }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   370
        }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   371
        click_count = clickstate->click_count;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   372
    } else {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   373
        click_count = 1;
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   374
    }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   375
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   376
    /* Post the event, if desired */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   377
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   378
    if (SDL_GetEventState(type) == SDL_ENABLE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   379
        SDL_Event event;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   380
        event.type = type;
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   381
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   382
        event.button.which = mouseID;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   383
        event.button.state = state;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   384
        event.button.button = button;
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   385
        event.button.clicks = click_count;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   386
        event.button.x = mouse->x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   387
        event.button.y = mouse->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   388
        posted = (SDL_PushEvent(&event) > 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   389
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   390
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   391
    /* We do this after dispatching event so button releases can lose focus */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   392
    if (window && state == SDL_RELEASED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   393
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   394
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   395
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   396
    return posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   397
}
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
   398
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   399
int
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   400
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   401
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   402
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   403
    int posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   404
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   405
    if (window) {
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   406
        SDL_SetMouseFocus(window);
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   407
    }
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   408
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   409
    if (!x && !y) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   410
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   411
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   412
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   413
    /* Post the event, if desired */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   414
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   415
    if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   416
        SDL_Event event;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   417
        event.type = SDL_MOUSEWHEEL;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   418
        event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   419
        event.wheel.which = mouseID;
2152
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   420
        event.wheel.x = x;
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   421
        event.wheel.y = y;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   422
        posted = (SDL_PushEvent(&event) > 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   423
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   424
    return posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   425
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   426
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   427
void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   428
SDL_MouseQuit(void)
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   429
{
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   430
    SDL_Cursor *cursor, *next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   431
    SDL_Mouse *mouse = SDL_GetMouse();
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   432
9161
6e34073ef024 Fixed spurious SDL error on shutdown if mouse capture isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 8983
diff changeset
   433
    if (mouse->CaptureMouse) {
6e34073ef024 Fixed spurious SDL error on shutdown if mouse capture isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 8983
diff changeset
   434
        SDL_CaptureMouse(SDL_FALSE);
6e34073ef024 Fixed spurious SDL error on shutdown if mouse capture isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 8983
diff changeset
   435
    }
8049
eac8f31e9bbd Clean up the cursor clipping area when quitting SDL.
Sam Lantinga <slouken@libsdl.org>
parents: 7753
diff changeset
   436
    SDL_SetRelativeMouseMode(SDL_FALSE);
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   437
    SDL_ShowCursor(1);
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   438
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   439
    cursor = mouse->cursors;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   440
    while (cursor) {
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   441
        next = cursor->next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   442
        SDL_FreeCursor(cursor);
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   443
        cursor = next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   444
    }
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   445
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   446
    if (mouse->def_cursor && mouse->FreeCursor) {
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   447
        mouse->FreeCursor(mouse->def_cursor);
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   448
    }
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   449
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   450
    if (mouse->clickstate) {
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   451
        SDL_free(mouse->clickstate);
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   452
    }
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8049
diff changeset
   453
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   454
    SDL_zerop(mouse);
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   455
}
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   456
6673
78f18a929123 Nobody will EVER use more than 8 buttons. Oh wait... Nobody will EVER use more than 32 buttons...
Sam Lantinga <slouken@libsdl.org>
parents: 6667
diff changeset
   457
Uint32
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   458
SDL_GetMouseState(int *x, int *y)
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   459
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   460
    SDL_Mouse *mouse = SDL_GetMouse();
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   461
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   462
    if (x) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   463
        *x = mouse->x;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   464
    }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   465
    if (y) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   466
        *y = mouse->y;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   467
    }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   468
    return mouse->buttonstate;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   469
}
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   470
6673
78f18a929123 Nobody will EVER use more than 8 buttons. Oh wait... Nobody will EVER use more than 32 buttons...
Sam Lantinga <slouken@libsdl.org>
parents: 6667
diff changeset
   471
Uint32
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   472
SDL_GetRelativeMouseState(int *x, int *y)
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   473
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   474
    SDL_Mouse *mouse = SDL_GetMouse();
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   475
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   476
    if (x) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   477
        *x = mouse->xdelta;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   478
    }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   479
    if (y) {
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   480
        *y = mouse->ydelta;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   481
    }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   482
    mouse->xdelta = 0;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   483
    mouse->ydelta = 0;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   484
    return mouse->buttonstate;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   485
}
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   486
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   487
Uint32
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   488
SDL_GetGlobalMouseState(int *x, int *y)
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   489
{
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   490
    SDL_Mouse *mouse = SDL_GetMouse();
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   491
    int tmpx, tmpy;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   492
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   493
    /* make sure these are never NULL for the backend implementations... */
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   494
    if (!x) {
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   495
        x = &tmpx;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   496
    }
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   497
    if (!y) {
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   498
        y = &tmpy;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   499
    }
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   500
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   501
    *x = *y = 0;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   502
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   503
    if (!mouse->GetGlobalMouseState) {
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   504
        SDL_assert(0 && "This should really be implemented for every target.");
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   505
        return 0;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   506
    }
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   507
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   508
    return mouse->GetGlobalMouseState(x, y);
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   509
}
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   510
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   511
void
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3585
diff changeset
   512
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   513
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   514
    SDL_Mouse *mouse = SDL_GetMouse();
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   515
8953
dc80dc0bd22e Merged Ryan's SDL-gui-backend branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 8815 8952
diff changeset
   516
    if (window == NULL) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   517
        window = mouse->focus;
8944
045aac36daac Added some (harmlessly) missing braces.
Ryan C. Gordon <icculus@icculus.org>
parents: 8927
diff changeset
   518
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   519
8953
dc80dc0bd22e Merged Ryan's SDL-gui-backend branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 8815 8952
diff changeset
   520
    if (window == NULL) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   521
        return;
8944
045aac36daac Added some (harmlessly) missing braces.
Ryan C. Gordon <icculus@icculus.org>
parents: 8927
diff changeset
   522
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   523
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   524
    if (mouse->WarpMouse) {
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   525
        mouse->WarpMouse(window, x, y);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   526
    } else {
6950
1ddb72193079 Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   527
        SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   528
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   529
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   530
8815
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   531
void
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   532
SDL_WarpMouseGlobal(int x, int y)
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   533
{
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   534
    SDL_Mouse *mouse = SDL_GetMouse();
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   535
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   536
    if (mouse->WarpMouseGlobal) {
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   537
        mouse->WarpMouseGlobal(x, y);
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   538
    }
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   539
}
c6d0a457f3b2 Added an API function to warp the mouse cursor in global screen space: SDL_WarpMouseGlobal()
Sam Lantinga <slouken@libsdl.org>
parents: 8783
diff changeset
   540
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   541
static SDL_bool
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   542
ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   543
{
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   544
    const char *hint;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   545
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   546
    if (!mouse->SetRelativeMouseMode) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   547
        return SDL_TRUE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   548
    }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   549
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   550
    hint = SDL_GetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   551
    if (hint) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   552
        if (*hint == '0') {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   553
            return SDL_FALSE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   554
        } else {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   555
            return SDL_TRUE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   556
        }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   557
    }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   558
    return SDL_FALSE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   559
}
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   560
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   561
int
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   562
SDL_SetRelativeMouseMode(SDL_bool enabled)
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   563
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   564
    SDL_Mouse *mouse = SDL_GetMouse();
7107
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   565
    SDL_Window *focusWindow = SDL_GetKeyboardFocus();
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   566
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   567
    if (enabled == mouse->relative_mode) {
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   568
        return 0;
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   569
    }
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   570
7107
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   571
    if (enabled && focusWindow) {
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   572
        /* Center it in the focused window to prevent clicks from going through
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   573
         * to background windows.
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   574
         */
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   575
        SDL_SetMouseFocus(focusWindow);
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   576
        SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   577
    }
2fcf7bf1d2b2 Move cursor into window when enabling relative mode or gaining focus in relative mode.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7104
diff changeset
   578
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   579
    /* Set the relative mode */
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   580
    if (!enabled && mouse->relative_mode_warp) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   581
        mouse->relative_mode_warp = SDL_FALSE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   582
    } else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   583
        mouse->relative_mode_warp = SDL_TRUE;
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   584
    } else if (mouse->SetRelativeMouseMode(enabled) < 0) {
8269
6e18328e25e0 Fixed bug 2368 - Security Software is blocking RegisterRawInputDevices()
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   585
        if (enabled) {
8776
29aac8b813d9 Changed C++ style comments to fix pedantic warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8269
diff changeset
   586
            /* Fall back to warp mode if native relative mode failed */
8269
6e18328e25e0 Fixed bug 2368 - Security Software is blocking RegisterRawInputDevices()
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   587
            mouse->relative_mode_warp = SDL_TRUE;
6e18328e25e0 Fixed bug 2368 - Security Software is blocking RegisterRawInputDevices()
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   588
        }
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   589
    }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   590
    mouse->relative_mode = enabled;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   591
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   592
    if (mouse->focus) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   593
        SDL_UpdateWindowGrab(mouse->focus);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   594
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   595
        /* Put the cursor back to where the application expects it */
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   596
        if (!enabled) {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   597
            SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   598
        }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   599
    }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   600
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   601
    /* Flush pending mouse motion - ideally we would pump events, but that's not always safe */
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   602
    SDL_FlushEvent(SDL_MOUSEMOTION);
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   603
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   604
    /* Update cursor visibility */
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   605
    SDL_SetCursor(NULL);
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   606
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   607
    return 0;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   608
}
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   609
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   610
SDL_bool
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   611
SDL_GetRelativeMouseMode()
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   612
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   613
    SDL_Mouse *mouse = SDL_GetMouse();
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   614
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   615
    return mouse->relative_mode;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   616
}
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   617
8955
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   618
int
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   619
SDL_CaptureMouse(SDL_bool enabled)
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   620
{
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   621
    SDL_Mouse *mouse = SDL_GetMouse();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   622
    SDL_Window *focusWindow;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   623
    SDL_bool isCaptured;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   624
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   625
    if (!mouse->CaptureMouse) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   626
        return SDL_Unsupported();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   627
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   628
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   629
    focusWindow = SDL_GetKeyboardFocus();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   630
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   631
    isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   632
    if (isCaptured == enabled) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   633
        return 0;  /* already done! */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   634
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   635
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   636
    if (enabled) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   637
        if (!focusWindow) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   638
            return SDL_SetError("No window has focus");
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   639
        } else if (mouse->CaptureMouse(focusWindow) == -1) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   640
            return -1;  /* CaptureMouse() should call SetError */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   641
        }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   642
        focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   643
    } else {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   644
        if (mouse->CaptureMouse(NULL) == -1) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   645
            return -1;  /* CaptureMouse() should call SetError */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   646
        }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   647
        focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   648
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   649
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   650
    return 0;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   651
}
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   652
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   653
SDL_Cursor *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   654
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   655
                 int w, int h, int hot_x, int hot_y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   657
    SDL_Surface *surface;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   658
    SDL_Cursor *cursor;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   659
    int x, y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   660
    Uint32 *pixel;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   661
    Uint8 datab = 0, maskb = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   662
    const Uint32 black = 0xFF000000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   663
    const Uint32 white = 0xFFFFFFFF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   664
    const Uint32 transparent = 0x00000000;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   665
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   666
    /* Make sure the width is a multiple of 8 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   667
    w = ((w + 7) & ~7);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   668
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   669
    /* Create the surface from a bitmap */
5473
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   670
    surface = SDL_CreateRGBSurface(0, w, h, 32,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   671
                                   0x00FF0000,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   672
                                   0x0000FF00,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   673
                                   0x000000FF,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   674
                                   0xFF000000);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   675
    if (!surface) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   676
        return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   677
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   678
    for (y = 0; y < h; ++y) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   679
        pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   680
        for (x = 0; x < w; ++x) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   681
            if ((x % 8) == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   682
                datab = *data++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   683
                maskb = *mask++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   684
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   685
            if (maskb & 0x80) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   686
                *pixel++ = (datab & 0x80) ? black : white;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   687
            } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   688
                *pixel++ = (datab & 0x80) ? black : transparent;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   689
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   690
            datab <<= 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   691
            maskb <<= 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   692
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   693
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   694
5473
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   695
    cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   696
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   697
    SDL_FreeSurface(surface);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   698
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   699
    return cursor;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   700
}
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   701
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   702
SDL_Cursor *
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   703
SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   704
{
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   705
    SDL_Mouse *mouse = SDL_GetMouse();
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   706
    SDL_Surface *temp = NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   707
    SDL_Cursor *cursor;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   708
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   709
    if (!surface) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   710
        SDL_SetError("Passed NULL cursor surface");
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   711
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   712
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   713
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   714
    if (!mouse->CreateCursor) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   715
        SDL_SetError("Cursors are not currently supported");
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   716
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   717
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   718
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   719
    /* Sanity check the hot spot */
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   720
    if ((hot_x < 0) || (hot_y < 0) ||
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   721
        (hot_x >= surface->w) || (hot_y >= surface->h)) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   722
        SDL_SetError("Cursor hot spot doesn't lie within cursor");
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   723
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   724
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   725
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   726
    if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   727
        temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   728
        if (!temp) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   729
            return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   730
        }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   731
        surface = temp;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   732
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   733
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   734
    cursor = mouse->CreateCursor(surface, hot_x, hot_y);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   735
    if (cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   736
        cursor->next = mouse->cursors;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   737
        mouse->cursors = cursor;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   738
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   739
7720
f9a649383362 Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   740
    SDL_FreeSurface(temp);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   741
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   742
    return cursor;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   743
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   744
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   745
SDL_Cursor *
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   746
SDL_CreateSystemCursor(SDL_SystemCursor id)
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   747
{
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   748
    SDL_Mouse *mouse = SDL_GetMouse();
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   749
    SDL_Cursor *cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   750
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   751
    if (!mouse->CreateSystemCursor) {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   752
        SDL_SetError("CreateSystemCursor is not currently supported");
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   753
        return NULL;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   754
    }
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   755
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   756
    cursor = mouse->CreateSystemCursor(id);
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   757
    if (cursor) {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   758
        cursor->next = mouse->cursors;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   759
        mouse->cursors = cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   760
    }
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   761
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   762
    return cursor;
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   763
}
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   764
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   765
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   766
   if this is desired for any reason.  This is used when setting
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   767
   the video mode and when the SDL window gains the mouse focus.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   768
 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   769
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   770
SDL_SetCursor(SDL_Cursor * cursor)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   771
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   772
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   773
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   774
    /* Set the new cursor */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   775
    if (cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   776
        /* Make sure the cursor is still valid for this mouse */
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   777
        if (cursor != mouse->def_cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   778
            SDL_Cursor *found;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   779
            for (found = mouse->cursors; found; found = found->next) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   780
                if (found == cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   781
                    break;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   782
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   783
            }
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   784
            if (!found) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   785
                SDL_SetError("Cursor not associated with the current mouse");
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   786
                return;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   787
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   788
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   789
        mouse->cur_cursor = cursor;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   790
    } else {
6301
e8a69c5378e7 Change SDL_SetCursor to set the cursor back to the default cursor when the
Wim Looman <ghostunderscore@gmail.com>
parents: 6300
diff changeset
   791
        if (mouse->focus) {
e8a69c5378e7 Change SDL_SetCursor to set the cursor back to the default cursor when the
Wim Looman <ghostunderscore@gmail.com>
parents: 6300
diff changeset
   792
            cursor = mouse->cur_cursor;
e8a69c5378e7 Change SDL_SetCursor to set the cursor back to the default cursor when the
Wim Looman <ghostunderscore@gmail.com>
parents: 6300
diff changeset
   793
        } else {
e8a69c5378e7 Change SDL_SetCursor to set the cursor back to the default cursor when the
Wim Looman <ghostunderscore@gmail.com>
parents: 6300
diff changeset
   794
            cursor = mouse->def_cursor;
e8a69c5378e7 Change SDL_SetCursor to set the cursor back to the default cursor when the
Wim Looman <ghostunderscore@gmail.com>
parents: 6300
diff changeset
   795
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   796
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   797
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   798
    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   799
        if (mouse->ShowCursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   800
            mouse->ShowCursor(cursor);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   801
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   802
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   803
        if (mouse->ShowCursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   804
            mouse->ShowCursor(NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   805
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   806
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   807
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   808
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   809
SDL_Cursor *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   810
SDL_GetCursor(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   811
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   812
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   813
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   814
    if (!mouse) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   815
        return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   816
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   817
    return mouse->cur_cursor;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   818
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   819
7104
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   820
SDL_Cursor *
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   821
SDL_GetDefaultCursor(void)
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   822
{
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   823
    SDL_Mouse *mouse = SDL_GetMouse();
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   824
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   825
    if (!mouse) {
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   826
        return NULL;
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   827
    }
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   828
    return mouse->def_cursor;
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   829
}
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   830
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   831
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   832
SDL_FreeCursor(SDL_Cursor * cursor)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   833
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   834
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   835
    SDL_Cursor *curr, *prev;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   836
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   837
    if (!cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   838
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   839
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   840
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   841
    if (cursor == mouse->def_cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   842
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   843
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   844
    if (cursor == mouse->cur_cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   845
        SDL_SetCursor(mouse->def_cursor);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   846
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   847
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   848
    for (prev = NULL, curr = mouse->cursors; curr;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   849
         prev = curr, curr = curr->next) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   850
        if (curr == cursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   851
            if (prev) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   852
                prev->next = curr->next;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   853
            } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   854
                mouse->cursors = curr->next;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   855
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   856
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   857
            if (mouse->FreeCursor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   858
                mouse->FreeCursor(curr);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   859
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   860
            return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   861
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   862
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   863
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   864
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   865
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   866
SDL_ShowCursor(int toggle)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   867
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   868
    SDL_Mouse *mouse = SDL_GetMouse();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   869
    SDL_bool shown;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   870
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   871
    if (!mouse) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   872
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   873
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   874
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   875
    shown = mouse->cursor_shown;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   876
    if (toggle >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   877
        if (toggle) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   878
            mouse->cursor_shown = SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   879
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   880
            mouse->cursor_shown = SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   881
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   882
        if (mouse->cursor_shown != shown) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   883
            SDL_SetCursor(NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   884
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   885
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   886
    return shown;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   887
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   888
7097
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   889
/* vi: set ts=4 sw=4 expandtab: */