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