src/events/SDL_mouse.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 09 May 2010 20:47:22 -0700
changeset 4465 3e69e077cb95
parent 4429 faa9fc8e7f67
child 4484 9322f7db8603
permissions -rw-r--r--
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.

Plus, this lets me start implementing cursor support.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* General mouse handling code for SDL */
slouken@0
    25
slouken@0
    26
#include "SDL_events.h"
slouken@0
    27
#include "SDL_events_c.h"
slouken@1895
    28
#include "default_cursor.h"
slouken@3685
    29
#include "../video/SDL_sysvideo.h"
slouken@0
    30
slouken@0
    31
slouken@4465
    32
/* Global mouse information */
slouken@4465
    33
slouken@4465
    34
typedef struct SDL_Mouse SDL_Mouse;
slouken@4465
    35
slouken@4465
    36
struct SDL_Mouse
slouken@4465
    37
{
slouken@4465
    38
    /* Create a cursor from a surface */
slouken@4465
    39
    SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
slouken@4465
    40
slouken@4465
    41
    /* Show the specified cursor, or hide if cursor is NULL */
slouken@4465
    42
    int (*ShowCursor) (SDL_Cursor * cursor);
slouken@4465
    43
slouken@4465
    44
    /* This is called when a mouse motion event occurs */
slouken@4465
    45
    void (*MoveCursor) (SDL_Cursor * cursor);
slouken@4465
    46
slouken@4465
    47
    /* Free a window manager cursor */
slouken@4465
    48
    void (*FreeCursor) (SDL_Cursor * cursor);
slouken@4465
    49
slouken@4465
    50
    /* Warp the mouse to (x,y) */
slouken@4465
    51
    void (*WarpMouse) (SDL_Mouse * mouse, SDL_Window * window, int x, int y);
slouken@4465
    52
slouken@4465
    53
    /* Data common to all mice */
slouken@4465
    54
    SDL_Window *focus;
slouken@4465
    55
    int x;
slouken@4465
    56
    int y;
slouken@4465
    57
    int xdelta;
slouken@4465
    58
    int ydelta;
slouken@4465
    59
    int last_x, last_y;         /* the last reported x and y coordinates */
slouken@4465
    60
    Uint8 buttonstate;
slouken@4465
    61
    SDL_bool relative_mode;
slouken@4465
    62
slouken@4465
    63
    SDL_Cursor *cursors;
slouken@4465
    64
    SDL_Cursor *def_cursor;
slouken@4465
    65
    SDL_Cursor *cur_cursor;
slouken@4465
    66
    SDL_bool cursor_shown;
slouken@4465
    67
};
slouken@4465
    68
slouken@4465
    69
static SDL_Mouse SDL_mouse;
slouken@0
    70
slouken@0
    71
slouken@0
    72
/* Public functions */
slouken@1895
    73
int
slouken@1895
    74
SDL_MouseInit(void)
slouken@0
    75
{
slouken@1895
    76
    return (0);
slouken@1123
    77
}
slouken@0
    78
slouken@4465
    79
void
slouken@4465
    80
SDL_ResetMouse(void)
slouken@460
    81
{
slouken@4465
    82
    /* FIXME */
slouken@460
    83
}
slouken@460
    84
slouken@4465
    85
SDL_Window *
slouken@4465
    86
SDL_GetMouseFocus(void)
slouken@2710
    87
{
slouken@4465
    88
    SDL_Mouse *mouse = &SDL_mouse;
slouken@2940
    89
slouken@4465
    90
    return mouse->focus;
slouken@0
    91
}
slouken@0
    92
slouken@1895
    93
void
slouken@4465
    94
SDL_SetMouseFocus(SDL_Window * window)
slouken@0
    95
{
slouken@4465
    96
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
    97
slouken@4465
    98
    if (mouse->focus == window) {
slouken@1895
    99
        return;
slouken@1895
   100
    }
slouken@1895
   101
slouken@1895
   102
    /* See if the current window has lost focus */
slouken@1895
   103
    if (mouse->focus) {
slouken@4465
   104
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
slouken@1895
   105
    }
slouken@1895
   106
slouken@3685
   107
    mouse->focus = window;
slouken@1895
   108
slouken@1895
   109
    if (mouse->focus) {
slouken@4465
   110
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
slouken@1895
   111
    }
slouken@1895
   112
}
slouken@1895
   113
slouken@1895
   114
int
slouken@4465
   115
SDL_SendMouseMotion(int relative, int x, int y)
slouken@1895
   116
{
slouken@4465
   117
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   118
    int posted;
slouken@1895
   119
    int xrel;
slouken@1895
   120
    int yrel;
slouken@2860
   121
    int x_max = 0, y_max = 0;
slouken@1895
   122
slouken@2710
   123
    /* the relative motion is calculated regarding the system cursor last position */
slouken@2842
   124
    if (relative) {
slouken@2842
   125
        xrel = x;
slouken@2842
   126
        yrel = y;
slouken@2860
   127
        x = (mouse->last_x + x);
slouken@2860
   128
        y = (mouse->last_y + y);
slouken@2842
   129
    } else {
slouken@2860
   130
        xrel = x - mouse->last_x;
slouken@2860
   131
        yrel = y - mouse->last_y;
slouken@2842
   132
    }
slouken@2710
   133
slouken@1895
   134
    /* Drop events that don't change state */
slouken@1895
   135
    if (!xrel && !yrel) {
slouken@1895
   136
#if 0
slouken@1895
   137
        printf("Mouse event didn't change state - dropped!\n");
slouken@1895
   138
#endif
slouken@1895
   139
        return 0;
slouken@1895
   140
    }
slouken@1895
   141
slouken@2710
   142
    /* Update internal mouse coordinates */
slouken@2710
   143
    if (mouse->relative_mode == SDL_FALSE) {
slouken@1895
   144
        mouse->x = x;
slouken@1895
   145
        mouse->y = y;
slouken@2710
   146
    } else {
slouken@2860
   147
        mouse->x += xrel;
slouken@2860
   148
        mouse->y += yrel;
slouken@2860
   149
    }
slouken@2849
   150
slouken@2860
   151
    SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
slouken@2849
   152
slouken@2860
   153
    /* make sure that the pointers find themselves inside the windows */
slouken@2860
   154
    /* only check if mouse->xmax is set ! */
slouken@2860
   155
    if (x_max && mouse->x > x_max) {
slouken@2860
   156
        mouse->x = x_max;
slouken@2860
   157
    } else if (mouse->x < 0) {
slouken@2860
   158
        mouse->x = 0;
slouken@1895
   159
    }
slouken@2860
   160
slouken@2860
   161
    if (y_max && mouse->y > y_max) {
slouken@2860
   162
        mouse->y = y_max;
slouken@2860
   163
    } else if (mouse->y < 0) {
slouken@2860
   164
        mouse->y = 0;
slouken@2860
   165
    }
slouken@2860
   166
slouken@1895
   167
    mouse->xdelta += xrel;
slouken@1895
   168
    mouse->ydelta += yrel;
slouken@1895
   169
slouken@4465
   170
#if 0 /* FIXME */
slouken@1895
   171
    /* Move the mouse cursor, if needed */
slouken@1895
   172
    if (mouse->cursor_shown && !mouse->relative_mode &&
slouken@1895
   173
        mouse->MoveCursor && mouse->cur_cursor) {
slouken@1895
   174
        mouse->MoveCursor(mouse->cur_cursor);
slouken@1895
   175
    }
slouken@4465
   176
#endif
slouken@1895
   177
slouken@1895
   178
    /* Post the event, if desired */
slouken@1895
   179
    posted = 0;
slouken@4465
   180
    if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
slouken@1895
   181
        SDL_Event event;
slouken@1895
   182
        event.motion.type = SDL_MOUSEMOTION;
slouken@4465
   183
        event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
slouken@1895
   184
        event.motion.state = mouse->buttonstate;
slouken@1895
   185
        event.motion.x = mouse->x;
slouken@1895
   186
        event.motion.y = mouse->y;
slouken@1895
   187
        event.motion.xrel = xrel;
slouken@1895
   188
        event.motion.yrel = yrel;
slouken@1895
   189
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   190
    }
lestat@3112
   191
    mouse->last_x = mouse->x;
lestat@3112
   192
    mouse->last_y = mouse->y;
slouken@1895
   193
    return posted;
slouken@1895
   194
}
slouken@1895
   195
slouken@1895
   196
int
slouken@4465
   197
SDL_SendMouseButton(Uint8 state, Uint8 button)
slouken@1895
   198
{
slouken@4465
   199
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   200
    int posted;
slouken@4429
   201
    Uint32 type;
slouken@1895
   202
slouken@1895
   203
    /* Figure out which event to perform */
slouken@1895
   204
    switch (state) {
slouken@1895
   205
    case SDL_PRESSED:
slouken@1895
   206
        if (mouse->buttonstate & SDL_BUTTON(button)) {
slouken@1895
   207
            /* Ignore this event, no state change */
slouken@1895
   208
            return 0;
slouken@1895
   209
        }
slouken@1895
   210
        type = SDL_MOUSEBUTTONDOWN;
slouken@1895
   211
        mouse->buttonstate |= SDL_BUTTON(button);
slouken@1895
   212
        break;
slouken@1895
   213
    case SDL_RELEASED:
slouken@2725
   214
        if (!(mouse->buttonstate & SDL_BUTTON(button))) {
kazeuser@2718
   215
            /* Ignore this event, no state change */
kazeuser@2718
   216
            return 0;
kazeuser@2718
   217
        }
slouken@1895
   218
        type = SDL_MOUSEBUTTONUP;
slouken@1895
   219
        mouse->buttonstate &= ~SDL_BUTTON(button);
slouken@1895
   220
        break;
slouken@1895
   221
    default:
slouken@1895
   222
        /* Invalid state -- bail */
slouken@1895
   223
        return 0;
slouken@1895
   224
    }
slouken@1895
   225
slouken@1895
   226
    /* Post the event, if desired */
slouken@1895
   227
    posted = 0;
slouken@4429
   228
    if (SDL_GetEventState(type) == SDL_ENABLE) {
slouken@1895
   229
        SDL_Event event;
slouken@1895
   230
        event.type = type;
slouken@1895
   231
        event.button.state = state;
slouken@1895
   232
        event.button.button = button;
slouken@1895
   233
        event.button.x = mouse->x;
slouken@1895
   234
        event.button.y = mouse->y;
slouken@3689
   235
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
slouken@1895
   236
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   237
    }
slouken@1895
   238
    return posted;
slouken@1895
   239
}
slouken@1895
   240
slouken@1895
   241
int
slouken@4465
   242
SDL_SendMouseWheel(int x, int y)
slouken@1895
   243
{
slouken@4465
   244
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   245
    int posted;
slouken@1895
   246
slouken@4465
   247
    if (!x && !y) {
slouken@1895
   248
        return 0;
slouken@1895
   249
    }
slouken@1895
   250
slouken@1895
   251
    /* Post the event, if desired */
slouken@1895
   252
    posted = 0;
slouken@4429
   253
    if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
slouken@1895
   254
        SDL_Event event;
slouken@1895
   255
        event.type = SDL_MOUSEWHEEL;
slouken@4465
   256
        event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
slouken@2152
   257
        event.wheel.x = x;
slouken@2152
   258
        event.wheel.y = y;
slouken@1895
   259
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   260
    }
slouken@1895
   261
    return posted;
slouken@1895
   262
}
slouken@1895
   263
slouken@1895
   264
void
slouken@4465
   265
SDL_MouseQuit(void)
slouken@4465
   266
{
slouken@4465
   267
}
slouken@4465
   268
slouken@4465
   269
Uint8
slouken@4465
   270
SDL_GetMouseState(int *x, int *y)
slouken@4465
   271
{
slouken@4465
   272
    SDL_Mouse *mouse = &SDL_mouse;
slouken@4465
   273
slouken@4465
   274
    if (x) {
slouken@4465
   275
        *x = mouse->x;
slouken@4465
   276
    }
slouken@4465
   277
    if (y) {
slouken@4465
   278
        *y = mouse->y;
slouken@4465
   279
    }
slouken@4465
   280
    return mouse->buttonstate;
slouken@4465
   281
}
slouken@4465
   282
slouken@4465
   283
Uint8
slouken@4465
   284
SDL_GetRelativeMouseState(int *x, int *y)
slouken@4465
   285
{
slouken@4465
   286
    SDL_Mouse *mouse = &SDL_mouse;
slouken@4465
   287
slouken@4465
   288
    if (x) {
slouken@4465
   289
        *x = mouse->xdelta;
slouken@4465
   290
    }
slouken@4465
   291
    if (y) {
slouken@4465
   292
        *y = mouse->ydelta;
slouken@4465
   293
    }
slouken@4465
   294
    mouse->xdelta = 0;
slouken@4465
   295
    mouse->ydelta = 0;
slouken@4465
   296
    return mouse->buttonstate;
slouken@4465
   297
}
slouken@4465
   298
slouken@4465
   299
void
slouken@3685
   300
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
slouken@1895
   301
{
slouken@4465
   302
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   303
slouken@1895
   304
    if (mouse->WarpMouse) {
slouken@3685
   305
        mouse->WarpMouse(mouse, window, x, y);
slouken@1895
   306
    } else {
slouken@4465
   307
        SDL_SetMouseFocus(window);
slouken@4465
   308
        SDL_SendMouseMotion(0, x, y);
slouken@1895
   309
    }
slouken@1895
   310
}
slouken@1895
   311
slouken@4465
   312
int
slouken@4465
   313
SDL_SetRelativeMouseMode(SDL_bool enabled)
slouken@4465
   314
{
slouken@4465
   315
    SDL_Mouse *mouse = &SDL_mouse;
slouken@4465
   316
slouken@4465
   317
    /* Flush pending mouse motion */
slouken@4465
   318
    SDL_FlushEvent(SDL_MOUSEMOTION);
slouken@4465
   319
slouken@4465
   320
    /* Set the relative mode */
slouken@4465
   321
    mouse->relative_mode = enabled;
slouken@4465
   322
slouken@4465
   323
    if (!enabled) {
slouken@4465
   324
        /* Restore the expected mouse position */
slouken@4465
   325
        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
slouken@4465
   326
    }
slouken@4465
   327
slouken@4465
   328
    /* Update cursor visibility */
slouken@4465
   329
    SDL_SetCursor(NULL);
slouken@4465
   330
slouken@4465
   331
    return 0;
slouken@4465
   332
}
slouken@4465
   333
slouken@4465
   334
SDL_bool
slouken@4465
   335
SDL_GetRelativeMouseMode()
slouken@4465
   336
{
slouken@4465
   337
    SDL_Mouse *mouse = &SDL_mouse;
slouken@4465
   338
slouken@4465
   339
    return mouse->relative_mode;
slouken@4465
   340
}
slouken@4465
   341
slouken@1895
   342
SDL_Cursor *
slouken@1895
   343
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
slouken@1895
   344
                 int w, int h, int hot_x, int hot_y)
slouken@1895
   345
{
slouken@4465
   346
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   347
    SDL_Surface *surface;
slouken@1895
   348
    SDL_Cursor *cursor;
slouken@1895
   349
    int x, y;
slouken@1895
   350
    Uint32 *pixel;
slouken@4465
   351
    Uint8 datab = 0, maskb = 0;
slouken@1895
   352
    const Uint32 black = 0xFF000000;
slouken@1895
   353
    const Uint32 white = 0xFFFFFFFF;
slouken@1895
   354
    const Uint32 transparent = 0x00000000;
slouken@1895
   355
slouken@1895
   356
    if (!mouse->CreateCursor) {
slouken@4465
   357
        SDL_SetError("Cursors are not currently supported");
slouken@1895
   358
        return NULL;
slouken@1895
   359
    }
slouken@1895
   360
slouken@1895
   361
    /* Sanity check the hot spot */
slouken@1895
   362
    if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
slouken@1895
   363
        SDL_SetError("Cursor hot spot doesn't lie within cursor");
slouken@1895
   364
        return NULL;
slouken@1895
   365
    }
slouken@1895
   366
slouken@1895
   367
    /* Make sure the width is a multiple of 8 */
slouken@1895
   368
    w = ((w + 7) & ~7);
slouken@1895
   369
slouken@1895
   370
    /* Create the surface from a bitmap */
slouken@1895
   371
    surface =
slouken@1895
   372
        SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
slouken@1895
   373
                             0xFF000000);
slouken@1895
   374
    if (!surface) {
slouken@1895
   375
        return NULL;
slouken@1895
   376
    }
slouken@1895
   377
    for (y = 0; y < h; ++y) {
slouken@1895
   378
        pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
slouken@1895
   379
        for (x = 0; x < w; ++x) {
slouken@1895
   380
            if ((x % 8) == 0) {
slouken@1895
   381
                datab = *data++;
slouken@1895
   382
                maskb = *mask++;
slouken@1895
   383
            }
slouken@1895
   384
            if (maskb & 0x80) {
slouken@1895
   385
                *pixel++ = (datab & 0x80) ? black : white;
slouken@1895
   386
            } else {
slouken@1895
   387
                *pixel++ = (datab & 0x80) ? black : transparent;
slouken@1895
   388
            }
slouken@1895
   389
            datab <<= 1;
slouken@1895
   390
            maskb <<= 1;
slouken@1895
   391
        }
slouken@1895
   392
    }
slouken@1895
   393
slouken@1895
   394
    cursor = mouse->CreateCursor(surface, hot_x, hot_y);
slouken@1895
   395
    if (cursor) {
slouken@1895
   396
        cursor->next = mouse->cursors;
slouken@1895
   397
        mouse->cursors = cursor;
slouken@1895
   398
    }
slouken@1895
   399
slouken@1895
   400
    SDL_FreeSurface(surface);
slouken@1895
   401
slouken@1895
   402
    return cursor;
slouken@1895
   403
}
slouken@1895
   404
slouken@1895
   405
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
slouken@1895
   406
   if this is desired for any reason.  This is used when setting
slouken@1895
   407
   the video mode and when the SDL window gains the mouse focus.
slouken@1895
   408
 */
slouken@1895
   409
void
slouken@1895
   410
SDL_SetCursor(SDL_Cursor * cursor)
slouken@1895
   411
{
slouken@4465
   412
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   413
slouken@1895
   414
    /* Set the new cursor */
slouken@1895
   415
    if (cursor) {
slouken@1895
   416
        /* Make sure the cursor is still valid for this mouse */
slouken@1895
   417
        SDL_Cursor *found;
slouken@1895
   418
        for (found = mouse->cursors; found; found = found->next) {
slouken@1895
   419
            if (found == cursor) {
slouken@1895
   420
                break;
slouken@1895
   421
            }
slouken@1895
   422
        }
slouken@1895
   423
        if (!found) {
slouken@1895
   424
            SDL_SetError("Cursor not associated with the current mouse");
slouken@1895
   425
            return;
slouken@1895
   426
        }
slouken@1895
   427
        mouse->cur_cursor = cursor;
slouken@1895
   428
    } else {
slouken@1895
   429
        cursor = mouse->cur_cursor;
slouken@1895
   430
    }
slouken@1895
   431
slouken@1895
   432
    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
slouken@1895
   433
        if (mouse->ShowCursor) {
slouken@1895
   434
            mouse->ShowCursor(cursor);
slouken@1895
   435
        }
slouken@1895
   436
    } else {
slouken@1895
   437
        if (mouse->ShowCursor) {
slouken@1895
   438
            mouse->ShowCursor(NULL);
slouken@1895
   439
        }
slouken@1895
   440
    }
slouken@1895
   441
}
slouken@1895
   442
slouken@1895
   443
SDL_Cursor *
slouken@1895
   444
SDL_GetCursor(void)
slouken@1895
   445
{
slouken@4465
   446
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   447
slouken@1895
   448
    if (!mouse) {
slouken@1895
   449
        return NULL;
slouken@1895
   450
    }
slouken@1895
   451
    return mouse->cur_cursor;
slouken@1895
   452
}
slouken@1895
   453
slouken@1895
   454
void
slouken@1895
   455
SDL_FreeCursor(SDL_Cursor * cursor)
slouken@1895
   456
{
slouken@4465
   457
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   458
    SDL_Cursor *curr, *prev;
slouken@1895
   459
slouken@1895
   460
    if (!cursor) {
slouken@1895
   461
        return;
slouken@1895
   462
    }
slouken@1895
   463
slouken@1895
   464
    if (cursor == mouse->def_cursor) {
slouken@1895
   465
        return;
slouken@1895
   466
    }
slouken@1895
   467
    if (cursor == mouse->cur_cursor) {
slouken@1895
   468
        SDL_SetCursor(mouse->def_cursor);
slouken@1895
   469
    }
slouken@1895
   470
slouken@1895
   471
    for (prev = NULL, curr = mouse->cursors; curr;
slouken@1895
   472
         prev = curr, curr = curr->next) {
slouken@1895
   473
        if (curr == cursor) {
slouken@1895
   474
            if (prev) {
slouken@1895
   475
                prev->next = curr->next;
slouken@1895
   476
            } else {
slouken@1895
   477
                mouse->cursors = curr->next;
slouken@1895
   478
            }
slouken@1895
   479
slouken@1895
   480
            if (mouse->FreeCursor) {
slouken@1895
   481
                mouse->FreeCursor(curr);
slouken@1895
   482
            }
slouken@1895
   483
            return;
slouken@1895
   484
        }
slouken@1895
   485
    }
slouken@1895
   486
}
slouken@1895
   487
slouken@1895
   488
int
slouken@1895
   489
SDL_ShowCursor(int toggle)
slouken@1895
   490
{
slouken@4465
   491
    SDL_Mouse *mouse = &SDL_mouse;
slouken@1895
   492
    SDL_bool shown;
slouken@1895
   493
slouken@1895
   494
    if (!mouse) {
slouken@1895
   495
        return 0;
slouken@1895
   496
    }
slouken@1895
   497
slouken@1895
   498
    shown = mouse->cursor_shown;
slouken@1895
   499
    if (toggle >= 0) {
slouken@1895
   500
        if (toggle) {
slouken@1895
   501
            mouse->cursor_shown = SDL_TRUE;
slouken@1895
   502
        } else {
slouken@1895
   503
            mouse->cursor_shown = SDL_FALSE;
slouken@1895
   504
        }
slouken@1895
   505
        if (mouse->cursor_shown != shown) {
slouken@1895
   506
            SDL_SetCursor(NULL);
slouken@1895
   507
        }
slouken@1895
   508
    }
slouken@1895
   509
    return shown;
slouken@1895
   510
}
slouken@1895
   511
slouken@1895
   512
/* vi: set ts=4 sw=4 expandtab: */