src/events/SDL_mouse.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
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
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9807
diff changeset
     3
  Copyright (C) 1997-2016 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
    }
9448
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   296
    if (relative) {
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   297
        mouse->last_x = mouse->x;
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   298
        mouse->last_y = mouse->y;
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   299
    } else {
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   300
        /* Use unclamped values if we're getting events outside the window */
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   301
        mouse->last_x = x;
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   302
        mouse->last_y = y;
3d3ed3a5ba8d Fixed relative mouse motion moving farther and farther off screen.
Sam Lantinga <slouken@libsdl.org>
parents: 9334
diff changeset
   303
    }
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
   304
    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
   305
}
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
   306
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
   307
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
   308
{
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
    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
   310
        int i, count = button + 1;
9334
5eb5ab33286e Fixed three memory leaks on failed allocation.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9257
diff changeset
   311
        SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
5eb5ab33286e Fixed three memory leaks on failed allocation.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9257
diff changeset
   312
        if (!clickstate) {
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
   313
            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
   314
        }
9334
5eb5ab33286e Fixed three memory leaks on failed allocation.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9257
diff changeset
   315
        mouse->clickstate = clickstate;
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
   316
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
        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
   318
            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
   319
        }
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
   320
        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
   321
    }
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
   322
    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
   323
}
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
   324
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
   325
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
   326
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
   327
{
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
   328
    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
   329
    int posted;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   330
    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
   331
    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
   332
    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
   333
    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
   334
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
   335
    /* 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
   336
    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
   337
    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
   338
        type = SDL_MOUSEBUTTONDOWN;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   339
        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
   340
        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
   341
    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
   342
        type = SDL_MOUSEBUTTONUP;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   343
        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
   344
        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
   345
    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
   346
        /* 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
   347
        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
   348
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   349
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   350
    /* 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
   351
    if (window && state == SDL_PRESSED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   352
        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
   353
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   354
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   355
    if (buttonstate == mouse->buttonstate) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   356
        /* 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
   357
        return 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   358
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   359
    mouse->buttonstate = buttonstate;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   360
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
   361
    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
   362
        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
   363
            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
   364
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
            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
   366
                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
   367
                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
   368
                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
   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
            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
   371
            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
   372
            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
   373
            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
   374
                ++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
   375
            }
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
   376
        }
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
   377
        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
   378
    } 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
   379
        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
   380
    }
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
   381
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
   382
    /* 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
   383
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   384
    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
   385
        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
   386
        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
   387
        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
   388
        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
   389
        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
   390
        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
   391
        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
   392
        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
   393
        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
   394
        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
   395
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   396
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   397
    /* 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
   398
    if (window && state == SDL_RELEASED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   399
        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
   400
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   401
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
   402
    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
   403
}
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
   404
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
   405
int
9257
6f41196c2d6b add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
Edward Rudd <urkle@outoforder.cc>
parents: 9161
diff changeset
   406
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
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
   407
{
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
   408
    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
   409
    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
   410
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
   411
    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
   412
        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
   413
    }
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
   414
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
   415
    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
   416
        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
   417
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   418
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
   419
    /* 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
   420
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   421
    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
   422
        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
   423
        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
   424
        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
   425
        event.wheel.which = mouseID;
2152
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   426
        event.wheel.x = x;
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   427
        event.wheel.y = y;
9257
6f41196c2d6b add in support for passing down the "natural" (or flipped) scrolling direction in the MouseWheelEvent event
Edward Rudd <urkle@outoforder.cc>
parents: 9161
diff changeset
   428
        event.wheel.direction = (Uint32)direction;
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
   429
        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
   430
    }
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
   431
    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
   432
}
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
   433
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
   434
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
   435
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
   436
{
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   437
    SDL_Cursor *cursor, *next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   438
    SDL_Mouse *mouse = SDL_GetMouse();
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   439
9161
6e34073ef024 Fixed spurious SDL error on shutdown if mouse capture isn't supported
Sam Lantinga <slouken@libsdl.org>
parents: 8983
diff changeset
   440
    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
   441
        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
   442
    }
8049
eac8f31e9bbd Clean up the cursor clipping area when quitting SDL.
Sam Lantinga <slouken@libsdl.org>
parents: 7753
diff changeset
   443
    SDL_SetRelativeMouseMode(SDL_FALSE);
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   444
    SDL_ShowCursor(1);
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
    cursor = mouse->cursors;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   447
    while (cursor) {
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   448
        next = cursor->next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   449
        SDL_FreeCursor(cursor);
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   450
        cursor = next;
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   451
    }
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   452
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   453
    if (mouse->def_cursor && mouse->FreeCursor) {
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   454
        mouse->FreeCursor(mouse->def_cursor);
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   455
    }
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   456
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
   457
    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
   458
        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
   459
    }
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
   460
7493
7bfda8f0bfdf Fixed cursor leak when quitting the mouse subsystem
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   461
    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
   462
}
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
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
   464
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
   465
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
   466
{
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
   467
    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
   468
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
    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
   470
        *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
   471
    }
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
    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
   473
        *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
   474
    }
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
    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
   476
}
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
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
   478
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
   479
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
   480
{
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
   481
    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
   482
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
    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
   484
        *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
   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
    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
   487
        *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
   488
    }
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
   489
    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
   490
    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
   491
    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
   492
}
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
   493
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   494
Uint32
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   495
SDL_GetGlobalMouseState(int *x, int *y)
8945
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
    SDL_Mouse *mouse = SDL_GetMouse();
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   498
    int tmpx, 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
    /* make sure these are never NULL for the backend implementations... */
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   501
    if (!x) {
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   502
        x = &tmpx;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   503
    }
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   504
    if (!y) {
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   505
        y = &tmpy;
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
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   508
    *x = *y = 0;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   509
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   510
    if (!mouse->GetGlobalMouseState) {
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   511
        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
   512
        return 0;
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   513
    }
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   514
8952
4bb098814ec4 Changed SDL_GetAbsoluteMouseState() to SDL_GetGlobalMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8945
diff changeset
   515
    return mouse->GetGlobalMouseState(x, y);
8945
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   516
}
04248c700ada Implemented SDL_GetAbsoluteMouseState().
Ryan C. Gordon <icculus@icculus.org>
parents: 8944
diff changeset
   517
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
   518
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
   519
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
   520
{
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
   521
    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
   522
8953
dc80dc0bd22e Merged Ryan's SDL-gui-backend branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 8815 8952
diff changeset
   523
    if (window == NULL) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   524
        window = mouse->focus;
8944
045aac36daac Added some (harmlessly) missing braces.
Ryan C. Gordon <icculus@icculus.org>
parents: 8927
diff changeset
   525
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   526
8953
dc80dc0bd22e Merged Ryan's SDL-gui-backend branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 8815 8952
diff changeset
   527
    if (window == NULL) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   528
        return;
8944
045aac36daac Added some (harmlessly) missing braces.
Ryan C. Gordon <icculus@icculus.org>
parents: 8927
diff changeset
   529
    }
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
   530
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
   531
    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
   532
        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
   533
    } 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
   534
        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
   535
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   536
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   537
9807
57b448735f48 SDL_WarpMouseGlobal() should return non-void.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   538
int
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
   539
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
   540
{
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
   541
    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
   542
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
   543
    if (mouse->WarpMouseGlobal) {
9807
57b448735f48 SDL_WarpMouseGlobal() should return non-void.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   544
        return mouse->WarpMouseGlobal(x, y);
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
   545
    }
9807
57b448735f48 SDL_WarpMouseGlobal() should return non-void.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   546
57b448735f48 SDL_WarpMouseGlobal() should return non-void.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   547
    return SDL_Unsupported();
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
   548
}
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
   549
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   550
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
   551
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
   552
{
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   553
    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
   554
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   555
    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
   556
        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
   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
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   559
    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
   560
    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
   561
        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
   562
            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
   563
        } else {
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   564
            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
   565
        }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   566
    }
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   567
    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
   568
}
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   569
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
   570
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
   571
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
   572
{
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
   573
    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
   574
    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
   575
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   576
    if (enabled == mouse->relative_mode) {
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   577
        return 0;
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   578
    }
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   579
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
   580
    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
   581
        /* 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
   582
         * 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
   583
         */
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
   584
        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
   585
        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
   586
    }
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
   587
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   588
    /* 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
   589
    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
   590
        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
   591
    } 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
   592
        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
   593
    } 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
   594
        if (enabled) {
8776
29aac8b813d9 Changed C++ style comments to fix pedantic warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8269
diff changeset
   595
            /* 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
   596
            mouse->relative_mode_warp = SDL_TRUE;
6e18328e25e0 Fixed bug 2368 - Security Software is blocking RegisterRawInputDevices()
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   597
        }
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
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
    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
   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
    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
   602
        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
   603
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   604
        /* 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
   605
        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
   606
            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
   607
        }
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
   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
8071
1ac2db4abe11 Added a relative mouse mode that uses mouse warping instead of raw input.
Sam Lantinga <slouken@libsdl.org>
parents: 8066
diff changeset
   610
    /* 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
   611
    SDL_FlushEvent(SDL_MOUSEMOTION);
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   612
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
   613
    /* 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
   614
    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
   615
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
    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
   617
}
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
   618
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
   619
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
   620
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
   621
{
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
   622
    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
   623
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
   624
    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
   625
}
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
   626
8955
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   627
int
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   628
SDL_CaptureMouse(SDL_bool enabled)
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   629
{
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   630
    SDL_Mouse *mouse = SDL_GetMouse();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   631
    SDL_Window *focusWindow;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   632
    SDL_bool isCaptured;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   633
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   634
    if (!mouse->CaptureMouse) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   635
        return SDL_Unsupported();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   636
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   637
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   638
    focusWindow = SDL_GetKeyboardFocus();
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   639
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   640
    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
   641
    if (isCaptured == enabled) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   642
        return 0;  /* already done! */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   643
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   644
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   645
    if (enabled) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   646
        if (!focusWindow) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   647
            return SDL_SetError("No window has focus");
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   648
        } else if (mouse->CaptureMouse(focusWindow) == -1) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   649
            return -1;  /* CaptureMouse() should call SetError */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   650
        }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   651
        focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   652
    } else {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   653
        if (mouse->CaptureMouse(NULL) == -1) {
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   654
            return -1;  /* CaptureMouse() should call SetError */
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   655
        }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   656
        focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   657
    }
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   658
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   659
    return 0;
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   660
}
7a74b402790c Whoops, lost this in the merge.
Ryan C. Gordon <icculus@icculus.org>
parents: 8953
diff changeset
   661
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
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
   663
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
   664
                 int w, int h, int hot_x, int hot_y)
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
    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
   667
    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
   668
    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
   669
    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
   670
    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
   671
    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
   672
    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
   673
    const Uint32 transparent = 0x00000000;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   674
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
    /* 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
   676
    w = ((w + 7) & ~7);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   677
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
   678
    /* 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
   679
    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
   680
                                   0x00FF0000,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   681
                                   0x0000FF00,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   682
                                   0x000000FF,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   683
                                   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
   684
    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
   685
        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
   686
    }
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
    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
   688
        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
   689
        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
   690
            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
   691
                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
   692
                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
   693
            }
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
   694
            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
   695
                *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
   696
            } 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
   697
                *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
   698
            }
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
   699
            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
   700
            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
   701
        }
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
   702
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   703
5473
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   704
    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
   705
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   706
    SDL_FreeSurface(surface);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   707
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   708
    return cursor;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   709
}
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   710
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   711
SDL_Cursor *
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   712
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
   713
{
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   714
    SDL_Mouse *mouse = SDL_GetMouse();
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   715
    SDL_Surface *temp = NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   716
    SDL_Cursor *cursor;
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
    if (!surface) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   719
        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
   720
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   721
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   722
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   723
    if (!mouse->CreateCursor) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   724
        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
   725
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   726
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   727
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   728
    /* Sanity check the hot spot */
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   729
    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
   730
        (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
   731
        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
   732
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   733
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   734
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   735
    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
   736
        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
   737
        if (!temp) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   738
            return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   739
        }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   740
        surface = temp;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   741
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   742
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
   743
    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
   744
    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
   745
        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
   746
        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
   747
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   748
7720
f9a649383362 Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   749
    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
   750
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
   751
    return cursor;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   752
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   753
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   754
SDL_Cursor *
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   755
SDL_CreateSystemCursor(SDL_SystemCursor id)
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   756
{
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   757
    SDL_Mouse *mouse = SDL_GetMouse();
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   758
    SDL_Cursor *cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   759
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   760
    if (!mouse->CreateSystemCursor) {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   761
        SDL_SetError("CreateSystemCursor is not currently supported");
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   762
        return NULL;
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
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   765
    cursor = mouse->CreateSystemCursor(id);
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   766
    if (cursor) {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   767
        cursor->next = mouse->cursors;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   768
        mouse->cursors = cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   769
    }
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   770
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7107
diff changeset
   771
    return cursor;
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   772
}
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6673
diff changeset
   773
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
   774
/* 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
   775
   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
   776
   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
   777
 */
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
   778
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
   779
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
   780
{
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
   781
    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
   782
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
    /* 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
   784
    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
   785
        /* 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
   786
        if (cursor != mouse->def_cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   787
            SDL_Cursor *found;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   788
            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
   789
                if (found == cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   790
                    break;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   791
                }
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
   792
            }
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   793
            if (!found) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   794
                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
   795
                return;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   796
            }
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
   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
        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
   799
    } 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
   800
        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
   801
            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
   802
        } 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
   803
            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
   804
        }
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
   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
    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
   808
        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
   809
            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
   810
        }
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
    } 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
   812
        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
   813
            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
   814
        }
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
    }
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
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
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
   819
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
   820
{
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
   821
    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
   822
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
   823
    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
   824
        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
   825
    }
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
   826
    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
   827
}
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
   828
7104
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   829
SDL_Cursor *
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   830
SDL_GetDefaultCursor(void)
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   831
{
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   832
    SDL_Mouse *mouse = SDL_GetMouse();
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   833
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   834
    if (!mouse) {
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   835
        return NULL;
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   836
    }
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   837
    return mouse->def_cursor;
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   838
}
4e4ca313000c Add SDL_GetDefaultCursor.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7097
diff changeset
   839
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
   840
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
   841
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
   842
{
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
   843
    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
   844
    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
   845
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
    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
   847
        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
   848
    }
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
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 (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
   851
        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
   852
    }
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
    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
   854
        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
   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
    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
   858
         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
   859
        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
   860
            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
   861
                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
   862
            } 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
   863
                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
   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
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
            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
   867
                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
   868
            }
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
            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
   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
    }
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
}
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
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
   875
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
   876
{
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
   877
    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
   878
    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
   879
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
    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
   881
        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
   882
    }
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
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
    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
   885
    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
   886
        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
   887
            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
   888
        } 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
   889
            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
   890
        }
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
   891
        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
   892
            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
   893
        }
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
   894
    }
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
   895
    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
   896
}
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
   897
7097
84bbd421d62f Make sure to send MOUSEMOTION on window enter.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7089
diff changeset
   898
/* vi: set ts=4 sw=4 expandtab: */