src/events/SDL_mouse.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 08 Nov 2012 02:26:40 -0800
changeset 6666 018f8019ce36
parent 6302 b0ae93a5b8d6
child 6667 243bfb5c31d6
permissions -rw-r--r--
Reset the mouse button state when losing mouse focus. Implemented mouse focus handling entirely using mouse motion events, with SetCapture() semantics, as long as the windowing system continues to provide mouse events.
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
     3
  Copyright (C) 1997-2012 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
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    21
#include "SDL_config.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"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#include "SDL_events.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#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
    28
#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
    29
#include "../video/SDL_sysvideo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    31
/*#define DEBUG_MOUSE*/
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
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
    33
/* 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
    34
static SDL_Mouse SDL_mouse;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
/* 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
    38
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
    39
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
    40
{
5376
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    41
    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
    42
183ec2d4485c Implemented cursor support and SDL_WarpMouseInWindow() on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    43
    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
    44
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
    45
    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
    46
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    47
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    48
void
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    49
SDL_SetDefaultCursor(SDL_Cursor * cursor)
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    50
{
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    51
    SDL_Mouse *mouse = SDL_GetMouse();
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    52
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    53
    mouse->def_cursor = cursor;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    54
    if (!mouse->cur_cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    55
        SDL_SetCursor(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
}
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
    58
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
    59
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
    60
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
    61
{
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
    62
    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
    63
}
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
    64
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
    65
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
    66
SDL_GetMouseFocus(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
{
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
    68
    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
    69
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
    70
    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
    71
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    72
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    73
void
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    74
SDL_ResetMouse(void)
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    75
{
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    76
    SDL_Mouse *mouse = SDL_GetMouse();
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    77
    Uint8 i;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    78
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    79
#ifdef DEBUG_MOUSE
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    80
    printf("Resetting mouse\n");
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    81
#endif
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    82
    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
    83
        if (mouse->buttonstate & SDL_BUTTON(i)) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    84
            SDL_SendMouseButton(mouse->focus, SDL_RELEASED, i);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    85
        }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    86
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    87
    SDL_assert(mouse->buttonstate == 0);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    88
}
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    89
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    90
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
    91
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
    92
{
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
    93
    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
    94
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
    95
    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
    96
        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
    97
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
    98
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
    99
    if (mouse->focus && !window) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   100
        /* 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
   101
        SDL_ResetMouse();
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   102
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   103
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
    /* 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
   105
    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
   106
        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
   107
    }
c121d94672cb SDL 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
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
   109
    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
   110
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   111
    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
   112
        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
   113
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   114
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   115
    /* Update cursor visibility */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   116
    SDL_SetCursor(NULL);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   117
}
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   118
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   119
/* 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
   120
static SDL_bool
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   121
SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint8 buttonstate)
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   122
{
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   123
    SDL_Mouse *mouse = SDL_GetMouse();
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   124
    int w, h;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   125
    SDL_bool inWindow;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   126
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   127
    SDL_GetWindowSize(window, &w, &h);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   128
    if (x < 0 || y < 0 || x >= w || y >= h) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   129
        inWindow = SDL_FALSE;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   130
    } else {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   131
        inWindow = SDL_TRUE;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   132
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   133
    if (!inWindow && !buttonstate) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   134
        if (window == mouse->focus) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   135
#ifdef DEBUG_MOUSE
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   136
            printf("Mouse left window, synthesizing focus lost event\n");
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   137
#endif
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   138
            SDL_SetMouseFocus(NULL);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   139
        }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   140
        return SDL_FALSE;
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
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   143
    if (window != mouse->focus) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   144
        mouse->last_x = x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   145
        mouse->last_y = y;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   146
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   147
#ifdef DEBUG_MOUSE
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   148
        printf("Mouse entered window, synthesizing focus gain event\n");
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   149
#endif
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   150
        SDL_SetMouseFocus(window);
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   151
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   152
    return SDL_TRUE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
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
   155
int
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
   156
SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
{
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
   158
    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
   159
    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
   160
    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
   161
    int yrel;
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   162
    int x_max = 0, y_max = 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
   163
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   164
    if (window && !relative) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   165
        if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   166
            return 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   167
        }
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
   168
    }
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
   169
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   170
    /* relative motion is calculated regarding the system cursor last position */
2842
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   171
    if (relative) {
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   172
        xrel = x;
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   173
        yrel = y;
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   174
        x = (mouse->last_x + x);
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   175
        y = (mouse->last_y + y);
2842
97ba0be8b565 Date: Sat, 06 Dec 2008 15:27:00 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2794
diff changeset
   176
    } else {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   177
        xrel = x - mouse->last_x;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   178
        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
   179
    }
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   180
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
   181
    /* 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
   182
    if (!xrel && !yrel) {
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   183
#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
   184
        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
   185
#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
   186
        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
   187
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   189
    /* Update internal mouse coordinates */
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   190
    if (mouse->relative_mode == SDL_FALSE) {
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
   191
        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
   192
        mouse->y = y;
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2152
diff changeset
   193
    } else {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   194
        mouse->x += xrel;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   195
        mouse->y += yrel;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   196
    }
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
   197
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   198
    SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
5370
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   199
    --x_max;
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   200
    --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
   201
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   202
    /* make sure that the pointers find themselves inside the windows */
5370
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   203
    if (mouse->x > x_max) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   204
        mouse->x = x_max;
5370
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   205
    }
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   206
    if (mouse->x < 0) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   207
        mouse->x = 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
   208
    }
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   209
5370
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   210
    if (mouse->y > y_max) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   211
        mouse->y = y_max;
5370
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   212
    }
cb219a294ebf The valid mouse coordinates actually range from 0 to w-1 and h-1
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   213
    if (mouse->y < 0) {
2860
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   214
        mouse->y = 0;
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   215
    }
6ce28e5287e9 Date: Sun, 07 Dec 2008 13:35:23 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   216
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
   217
    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
   218
    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
   219
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
   220
#if 0 /* FIXME */
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
   221
    /* 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
   222
    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
   223
        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
   224
        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
   225
    }
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
   226
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   227
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
   228
    /* 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
   229
    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
   230
    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
   231
        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
   232
        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
   233
        event.motion.windowID = mouse->focus ? mouse->focus->id : 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
   234
        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
   235
        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
   236
        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
   237
        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
   238
        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
   239
        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
   240
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   241
    /* Use unclamped values if we're getting events outside the window */
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   242
    mouse->last_x = x;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   243
    mouse->last_y = y;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   244
    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
   245
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   246
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   247
int
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
   248
SDL_SendMouseButton(SDL_Window * window, 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
   249
{
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
   250
    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
   251
    int posted;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   252
    Uint32 type;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   253
    Uint8 buttonstate = mouse->buttonstate;
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
   254
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
   255
    /* 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
   256
    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
   257
    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
   258
        type = SDL_MOUSEBUTTONDOWN;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   259
        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
   260
        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
   261
    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
   262
        type = SDL_MOUSEBUTTONUP;
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   263
        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
   264
        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
   265
    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
   266
        /* 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
   267
        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
   268
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   270
    /* 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
   271
    if (window && state == SDL_PRESSED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   272
        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
   273
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   274
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   275
    if (buttonstate == mouse->buttonstate) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   276
        /* 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
   277
        return 0;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   278
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   279
    mouse->buttonstate = buttonstate;
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   280
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
   281
    /* 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
   282
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   283
    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
   284
        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
   285
        event.type = type;
c121d94672cb SDL 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.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
   287
        event.button.button = button;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   288
        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
   289
        event.button.y = mouse->y;
3689
af25b5586af7 Fixed crash when there was no mouse focus for some reason (iPhone bug?)
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
   290
        event.button.windowID = mouse->focus ? mouse->focus->id : 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
   291
        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
   292
    }
6666
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   293
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   294
    /* 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
   295
    if (window && state == SDL_RELEASED) {
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   296
        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
   297
    }
018f8019ce36 Reset the mouse button state when losing mouse focus.
Sam Lantinga <slouken@libsdl.org>
parents: 6302
diff changeset
   298
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   299
    return posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   300
}
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
   301
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
   302
int
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
   303
SDL_SendMouseWheel(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
   304
{
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
   305
    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
   306
    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
   307
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
   308
    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
   309
        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
   310
    }
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
   311
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
   312
    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
   313
        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
   314
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   315
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
   316
    /* 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
   317
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   318
    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
   319
        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
   320
        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
   321
        event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
2152
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   322
        event.wheel.x = x;
003c1b5b07da Fixed bug #382
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
   323
        event.wheel.y = y;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   324
        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
   325
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   326
    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
   327
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   328
c121d94672cb SDL 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
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
   330
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
   331
{
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
   332
}
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
   333
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
   334
Uint8
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
   335
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
   336
{
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
   337
    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
   338
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
   339
    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
   340
        *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
   341
    }
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
   342
    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
   343
        *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
   344
    }
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
   345
    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
   346
}
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
   347
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
   348
Uint8
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
   349
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
   350
{
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
   351
    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
   352
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
   353
    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
   354
        *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
   355
    }
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
   356
    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
   357
        *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
   358
    }
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
   359
    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
   360
    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
   361
    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
   362
}
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
   363
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
   364
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
   365
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
   366
{
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
   367
    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
   368
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   369
    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
   370
        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
   371
    } else {
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
   372
        SDL_SendMouseMotion(window, 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
   373
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   374
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   375
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
   376
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
   377
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
   378
{
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
   379
    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
   380
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   381
    if (enabled == mouse->relative_mode) {
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   382
        return 0;
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   383
    }
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   384
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   385
    if (!mouse->SetRelativeMouseMode) {
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   386
        SDL_Unsupported();
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   387
        return -1;
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   388
    }
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   389
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   390
    if (mouse->SetRelativeMouseMode(enabled) < 0) {
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   391
        return -1;
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   392
    }
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
   393
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
   394
    /* Set the 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
   395
    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
   396
6302
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   397
    if (enabled) {
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   398
        /* Save the expected mouse position */
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   399
        mouse->original_x = mouse->x;
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   400
        mouse->original_y = mouse->y;
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   401
    } else 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
   402
        /* Restore the expected mouse position */
6302
b0ae93a5b8d6 Make mouse relative mode save the original co-ordinates to restore them
Wim Looman <ghostunderscore@gmail.com>
parents: 6301
diff changeset
   403
        SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
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
   404
    }
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
   405
5406
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   406
    /* Flush pending mouse motion */
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   407
    SDL_FlushEvent(SDL_MOUSEMOTION);
1517da4ab6b1 Implemented mouse relative mode on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5405
diff changeset
   408
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   409
    /* 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
   410
    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
   411
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
   412
    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
   413
}
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
   414
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
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
   416
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
   417
{
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
   418
    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
   419
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
   420
    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
   421
}
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
   422
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
   423
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
   424
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
   425
                 int w, int h, int hot_x, int hot_y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   426
{
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
   427
    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
   428
    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
   429
    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
   430
    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
   431
    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
   432
    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
   433
    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
   434
    const Uint32 transparent = 0x00000000;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   435
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
   436
    /* 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
   437
    w = ((w + 7) & ~7);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   438
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
   439
    /* 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
   440
    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
   441
                                   0x00FF0000,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   442
                                   0x0000FF00,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   443
                                   0x000000FF,
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   444
                                   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
   445
    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
   446
        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
   447
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   448
    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
   449
        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
   450
        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
   451
            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
   452
                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
   453
                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
   454
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   455
            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
   456
                *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
   457
            } 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
   458
                *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
   459
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   460
            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
   461
            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
   462
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   463
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   464
5473
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   465
    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
   466
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   467
    SDL_FreeSurface(surface);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   468
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   469
    return cursor;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   470
}
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   471
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   472
SDL_Cursor *
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   473
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
   474
{
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   475
    SDL_Mouse *mouse = SDL_GetMouse();
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   476
    SDL_Surface *temp = NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   477
    SDL_Cursor *cursor;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   478
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   479
    if (!surface) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   480
        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
   481
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   482
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   483
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   484
    if (!mouse->CreateCursor) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   485
        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
   486
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   487
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   488
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   489
    /* Sanity check the hot spot */
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   490
    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
   491
        (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
   492
        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
   493
        return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   494
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   495
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   496
    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
   497
        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
   498
        if (!temp) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   499
            return NULL;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   500
        }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   501
        surface = temp;
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   502
    }
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   503
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
   504
    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
   505
    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
   506
        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
   507
        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
   508
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
5473
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   510
    if (temp) {
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   511
        SDL_FreeSurface(temp);
5665ccbd6792 Added a function to create color cursors: SDL_CreateColorCursor()
Sam Lantinga <slouken@libsdl.org>
parents: 5406
diff changeset
   512
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   513
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   514
    return cursor;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   515
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   516
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
   517
/* 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
   518
   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
   519
   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
   520
 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   521
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
   522
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
   523
{
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
   524
    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
   525
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   526
    /* 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
   527
    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
   528
        /* 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
   529
        if (cursor != mouse->def_cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   530
            SDL_Cursor *found;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   531
            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
   532
                if (found == cursor) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   533
                    break;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   534
                }
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
            }
5405
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   536
            if (!found) {
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   537
                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
   538
                return;
64fa8526e1ce Added a cleaner way to set the default cursor.
Sam Lantinga <slouken@libsdl.org>
parents: 5376
diff changeset
   539
            }
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
   540
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   541
        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
   542
    } 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
   543
        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
   544
            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
   545
        } 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
   546
            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
   547
        }
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
   548
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   549
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   550
    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
   551
        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
   552
            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
   553
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   554
    } 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
   555
        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
   556
            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
   557
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   558
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   559
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   560
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   561
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
   562
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
   563
{
5371
fc3d3d580777 Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 5370
diff changeset
   564
    SDL_Mouse *mouse = SDL_GetMouse();
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
   565
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   566
    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
   567
        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
   568
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   569
    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
   570
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   571
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   572
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
   573
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
   574
{
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
   575
    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
   576
    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
   577
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   578
    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
   579
        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
   580
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   581
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   582
    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
   583
        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
   584
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   585
    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
   586
        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
   587
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   588
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   589
    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
   590
         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
   591
        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
   592
            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
   593
                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
   594
            } 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
   595
                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
   596
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   597
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   598
            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
   599
                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
   600
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   601
            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
   602
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   603
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   604
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   605
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   606
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
   607
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
   608
{
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
   609
    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
   610
    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
   611
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   612
    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
   613
        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
   614
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   615
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   616
    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
   617
    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
   618
        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
   619
            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
   620
        } 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
   621
            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
   622
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   623
        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
   624
            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
   625
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   626
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   627
    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
   628
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   629
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
   630
/* vi: set ts=4 sw=4 expandtab: */