src/video/windows/SDL_windowsmouse.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 24 Feb 2014 23:09:35 -0800
changeset 8254 f97b5166c158
parent 8252 3e4846dc97b1
child 8269 6e18328e25e0
permissions -rw-r--r--
Don't warp the mouse while we're doing a modal interaction
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5472
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5472
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: 5472
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: 5472
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5472
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: 5472
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: 5472
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5472
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: 5472
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: 5472
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: 5472
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5472
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: 5472
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: 5472
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8066
diff changeset
    21
#include "../../SDL_internal.h"
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINDOWS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
5472
674d45edfaeb We can assume ARGB surface format when creating cursors (enforced by higher level API)
Sam Lantinga <slouken@libsdl.org>
parents: 5421
diff changeset
    25
#include "SDL_assert.h"
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
    26
#include "SDL_windowsvideo.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:
diff changeset
    27
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    28
#include "../../events/SDL_mouse_c.h"
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    29
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    30
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    31
HCURSOR SDL_cursor = NULL;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    32
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    33
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    34
static SDL_Cursor *
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    35
WIN_CreateDefaultCursor()
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    36
{
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    37
    SDL_Cursor *cursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    38
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    39
    cursor = SDL_calloc(1, sizeof(*cursor));
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    40
    if (cursor) {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    41
        cursor->driverdata = LoadCursor(NULL, IDC_ARROW);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    42
    } else {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    43
        SDL_OutOfMemory();
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    44
    }
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    45
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    46
    return cursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    47
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    48
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    49
static SDL_Cursor *
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    50
WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    51
{
7489
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    52
    /* msdn says cursor mask has to be padded out to word alignment. Not sure
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    53
        if that means machine word or WORD, but this handles either case. */
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    54
    const size_t pad = (sizeof (size_t) * 8);  /* 32 or 64, or whatever. */
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    55
    SDL_Cursor *cursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    56
    HICON hicon;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    57
    HDC hdc;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    58
    BITMAPV4HEADER bmh;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    59
    LPVOID pixels;
7489
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    60
    LPVOID maskbits;
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    61
    size_t maskbitslen;
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    62
    ICONINFO ii;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    63
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    64
    SDL_zero(bmh);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    65
    bmh.bV4Size = sizeof(bmh);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    66
    bmh.bV4Width = surface->w;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    67
    bmh.bV4Height = -surface->h; /* Invert the image */
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    68
    bmh.bV4Planes = 1;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    69
    bmh.bV4BitCount = 32;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    70
    bmh.bV4V4Compression = BI_BITFIELDS;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    71
    bmh.bV4AlphaMask = 0xFF000000;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    72
    bmh.bV4RedMask   = 0x00FF0000;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    73
    bmh.bV4GreenMask = 0x0000FF00;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    74
    bmh.bV4BlueMask  = 0x000000FF;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    75
7489
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    76
    maskbitslen = ((surface->w + (pad - (surface->w % pad))) / 8) * surface->h;
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    77
    maskbits = SDL_stack_alloc(Uint8,maskbitslen);
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    78
    if (maskbits == NULL) {
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    79
        SDL_OutOfMemory();
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    80
        return NULL;
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    81
    }
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    82
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    83
    /* AND the cursor against full bits: no change. We already have alpha. */
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    84
    SDL_memset(maskbits, 0xFF, maskbitslen);
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    85
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    86
    hdc = GetDC(NULL);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    87
    SDL_zero(ii);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    88
    ii.fIcon = FALSE;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    89
    ii.xHotspot = (DWORD)hot_x;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    90
    ii.yHotspot = (DWORD)hot_y;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    91
    ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
7489
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    92
    ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, maskbits);
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    93
    ReleaseDC(NULL, hdc);
7489
30ec6dae748b Cursor mask was uninitialized data, causing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
    94
    SDL_stack_free(maskbits);
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    95
5472
674d45edfaeb We can assume ARGB surface format when creating cursors (enforced by higher level API)
Sam Lantinga <slouken@libsdl.org>
parents: 5421
diff changeset
    96
    SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
674d45edfaeb We can assume ARGB surface format when creating cursors (enforced by higher level API)
Sam Lantinga <slouken@libsdl.org>
parents: 5421
diff changeset
    97
    SDL_assert(surface->pitch == surface->w * 4);
674d45edfaeb We can assume ARGB surface format when creating cursors (enforced by higher level API)
Sam Lantinga <slouken@libsdl.org>
parents: 5421
diff changeset
    98
    SDL_memcpy(pixels, surface->pixels, surface->h * surface->pitch);
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
    99
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   100
    hicon = CreateIconIndirect(&ii);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   101
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   102
    DeleteObject(ii.hbmColor);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   103
    DeleteObject(ii.hbmMask);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   104
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   105
    if (!hicon) {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   106
        WIN_SetError("CreateIconIndirect()");
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   107
        return NULL;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   108
    }
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   109
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   110
    cursor = SDL_calloc(1, sizeof(*cursor));
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   111
    if (cursor) {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   112
        cursor->driverdata = hicon;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   113
    } else {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   114
        DestroyIcon(hicon);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   115
        SDL_OutOfMemory();
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   116
    }
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   117
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   118
    return cursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   119
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   120
6675
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   121
static SDL_Cursor *
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   122
WIN_CreateSystemCursor(SDL_SystemCursor id)
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   123
{
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   124
    SDL_Cursor *cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   125
    LPCTSTR name;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   126
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   127
    switch(id)
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   128
    {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   129
    default:
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   130
        SDL_assert(0);
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   131
        return NULL;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   132
    case SDL_SYSTEM_CURSOR_ARROW:     name = IDC_ARROW; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   133
    case SDL_SYSTEM_CURSOR_IBEAM:     name = IDC_IBEAM; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   134
    case SDL_SYSTEM_CURSOR_WAIT:      name = IDC_WAIT; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   135
    case SDL_SYSTEM_CURSOR_CROSSHAIR: name = IDC_CROSS; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   136
    case SDL_SYSTEM_CURSOR_WAITARROW: name = IDC_WAIT; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   137
    case SDL_SYSTEM_CURSOR_SIZENWSE:  name = IDC_SIZENWSE; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   138
    case SDL_SYSTEM_CURSOR_SIZENESW:  name = IDC_SIZENESW; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   139
    case SDL_SYSTEM_CURSOR_SIZEWE:    name = IDC_SIZEWE; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   140
    case SDL_SYSTEM_CURSOR_SIZENS:    name = IDC_SIZENS; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   141
    case SDL_SYSTEM_CURSOR_SIZEALL:   name = IDC_SIZEALL; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   142
    case SDL_SYSTEM_CURSOR_NO:        name = IDC_NO; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   143
    case SDL_SYSTEM_CURSOR_HAND:      name = IDC_HAND; break;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   144
    }
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   145
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   146
    cursor = SDL_calloc(1, sizeof(*cursor));
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   147
    if (cursor) {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   148
        HICON hicon;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   149
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   150
        hicon = LoadCursor(NULL, name);
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   151
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   152
        cursor->driverdata = hicon;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   153
    } else {
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   154
        SDL_OutOfMemory();
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   155
    }
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   156
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   157
    return cursor;
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   158
}
20f3cdea0fd2 Add SDL_CreateSystemCursor for Windows and Linux.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6350
diff changeset
   159
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   160
static void
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   161
WIN_FreeCursor(SDL_Cursor * cursor)
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   162
{
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   163
    HICON hicon = (HICON)cursor->driverdata;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   164
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   165
    DestroyIcon(hicon);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   166
    SDL_free(cursor);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   167
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   168
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   169
static int
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   170
WIN_ShowCursor(SDL_Cursor * cursor)
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   171
{
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   172
    if (cursor) {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   173
        SDL_cursor = (HCURSOR)cursor->driverdata;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   174
    } else {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   175
        SDL_cursor = NULL;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   176
    }
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   177
    if (SDL_GetMouseFocus() != NULL) {
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   178
        SetCursor(SDL_cursor);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   179
    }
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   180
    return 0;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   181
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   182
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   183
static void
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   184
WIN_WarpMouse(SDL_Window * window, int x, int y)
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   185
{
8254
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   186
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   187
    HWND hwnd = data->hwnd;
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   188
    POINT pt;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   189
8254
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   190
    /* Don't warp the mouse while we're doing a modal interaction */
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   191
    if (data->in_title_click || data->in_modal_loop) {
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   192
        return;
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   193
    }
f97b5166c158 Don't warp the mouse while we're doing a modal interaction
Sam Lantinga <slouken@libsdl.org>
parents: 8252
diff changeset
   194
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   195
    pt.x = x;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   196
    pt.y = y;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   197
    ClientToScreen(hwnd, &pt);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   198
    SetCursorPos(pt.x, pt.y);
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   199
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   200
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   201
static int
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   202
WIN_SetRelativeMouseMode(SDL_bool enabled)
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   203
{
6350
19545983ac76 Patrick Baggett implemented relative mouse mode on Win32
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   204
    RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
19545983ac76 Patrick Baggett implemented relative mouse mode on Win32
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   205
8252
3e4846dc97b1 Fixed relative mouse mode with multiple windows.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   206
    if (!enabled) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   207
        rawMouse.dwFlags |= RIDEV_REMOVE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   208
    }
6350
19545983ac76 Patrick Baggett implemented relative mouse mode on Win32
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   209
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   210
    /* (Un)register raw input for mice */
8036
d485906bd74a Fixed bug 2260 - SDL_SetCursorGrab() is buggy on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 7489
diff changeset
   211
    if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
6350
19545983ac76 Patrick Baggett implemented relative mouse mode on Win32
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   212
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   213
        /* Only return an error when registering. If we unregister and fail, then
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   214
        it's probably that we unregistered twice. That's OK. */
8252
3e4846dc97b1 Fixed relative mouse mode with multiple windows.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   215
        if (enabled) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   216
            return SDL_Unsupported();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   217
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   218
    }
6350
19545983ac76 Patrick Baggett implemented relative mouse mode on Win32
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   219
    return 0;
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   220
}
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   221
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
WIN_InitMouse(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
{
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   225
    SDL_Mouse *mouse = SDL_GetMouse();
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   226
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   227
    mouse->CreateCursor = WIN_CreateCursor;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7103
diff changeset
   228
    mouse->CreateSystemCursor = WIN_CreateSystemCursor;
5421
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   229
    mouse->ShowCursor = WIN_ShowCursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   230
    mouse->FreeCursor = WIN_FreeCursor;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   231
    mouse->WarpMouse = WIN_WarpMouse;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   232
    mouse->SetRelativeMouseMode = WIN_SetRelativeMouseMode;
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   233
f8588afb6486 Added support for Windows cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5336
diff changeset
   234
    SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
8066
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8036
diff changeset
   235
658b461d81be Added support for double-clicks, through a new "clicks" field in the mouse button event.
Sam Lantinga <slouken@libsdl.org>
parents: 8036
diff changeset
   236
    SDL_SetDoubleClickTime(GetDoubleClickTime());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
WIN_QuitMouse(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
{
7103
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   242
    SDL_Mouse *mouse = SDL_GetMouse();
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   243
    if ( mouse->def_cursor ) {
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   244
        SDL_free(mouse->def_cursor);
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   245
        mouse->def_cursor = NULL;
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   246
        mouse->cur_cursor = NULL;
9d146930d4f2 Bug 1787 - memory leak in WIN_InitMouse() by Marcel Bakker
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7037
diff changeset
   247
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   250
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   251
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
/* vi: set ts=4 sw=4 expandtab: */