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