src/video/winrt/SDL_winrtmouse.cpp
author David Ludwig <dludwig@pobox.com>
Tue, 20 Aug 2013 21:22:32 -0400
changeset 8483 d403ded25942
parent 8437 src/video/windowsrt/SDL_winrtmouse.cpp@d6a6c3ebdf3e
child 8489 7fd62b320c31
permissions -rw-r--r--
WinRT: file naming and placement cleanup
- moved SDL_WinRTApp.* from src/video/windowsrt/ to src/core/winrt/, and renamed them to SDL_winrtapp.* (to mimick case-sensitivity used elsewhere in SDL)
- renamed all "windowsrt" directories (in src) to "winrt", as the shorthand name is used more often (and, IMO, "WinRT" != "Windows RT", not entirely at least)
dludwig@8374
     1
/*
dludwig@8374
     2
  Simple DirectMedia Layer
dludwig@8374
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
dludwig@8374
     4
dludwig@8374
     5
  This software is provided 'as-is', without any express or implied
dludwig@8374
     6
  warranty.  In no event will the authors be held liable for any damages
dludwig@8374
     7
  arising from the use of this software.
dludwig@8374
     8
dludwig@8374
     9
  Permission is granted to anyone to use this software for any purpose,
dludwig@8374
    10
  including commercial applications, and to alter it and redistribute it
dludwig@8374
    11
  freely, subject to the following restrictions:
dludwig@8374
    12
dludwig@8374
    13
  1. The origin of this software must not be misrepresented; you must not
dludwig@8374
    14
     claim that you wrote the original software. If you use this software
dludwig@8374
    15
     in a product, an acknowledgment in the product documentation would be
dludwig@8374
    16
     appreciated but is not required.
dludwig@8374
    17
  2. Altered source versions must be plainly marked as such, and must not be
dludwig@8374
    18
     misrepresented as being the original software.
dludwig@8374
    19
  3. This notice may not be removed or altered from any source distribution.
dludwig@8374
    20
*/
dludwig@8374
    21
dludwig@8374
    22
#include "SDL_config.h"
dludwig@8374
    23
dludwig@8374
    24
#if SDL_VIDEO_DRIVER_WINRT
dludwig@8374
    25
dludwig@8374
    26
extern "C" {
dludwig@8374
    27
#include "SDL_assert.h"
dludwig@8374
    28
#include "../../events/SDL_mouse_c.h"
dludwig@8374
    29
#include "../SDL_sysvideo.h"
dludwig@8374
    30
}
dludwig@8374
    31
dludwig@8483
    32
#include "../../core/winrt/SDL_winrtapp.h"
dludwig@8374
    33
#include "SDL_winrtmouse.h"
dludwig@8374
    34
dludwig@8437
    35
using namespace Windows::UI::Core;
dludwig@8374
    36
using Windows::UI::Core::CoreCursor;
dludwig@8374
    37
dludwig@8374
    38
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
dludwig@8374
    39
dludwig@8374
    40
dludwig@8374
    41
static SDL_Cursor *
dludwig@8374
    42
WINRT_CreateSystemCursor(SDL_SystemCursor id)
dludwig@8374
    43
{
dludwig@8374
    44
    SDL_Cursor *cursor;
dludwig@8374
    45
    CoreCursorType cursorType = CoreCursorType::Arrow;
dludwig@8374
    46
dludwig@8374
    47
    switch(id)
dludwig@8374
    48
    {
dludwig@8374
    49
    default:
dludwig@8374
    50
        SDL_assert(0);
dludwig@8374
    51
        return NULL;
dludwig@8374
    52
    case SDL_SYSTEM_CURSOR_ARROW:     cursorType = CoreCursorType::Arrow; break;
dludwig@8374
    53
    case SDL_SYSTEM_CURSOR_IBEAM:     cursorType = CoreCursorType::IBeam; break;
dludwig@8374
    54
    case SDL_SYSTEM_CURSOR_WAIT:      cursorType = CoreCursorType::Wait; break;
dludwig@8374
    55
    case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
dludwig@8374
    56
    case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
dludwig@8374
    57
    case SDL_SYSTEM_CURSOR_SIZENWSE:  cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
dludwig@8374
    58
    case SDL_SYSTEM_CURSOR_SIZENESW:  cursorType = CoreCursorType::SizeNortheastSouthwest; break;
dludwig@8374
    59
    case SDL_SYSTEM_CURSOR_SIZEWE:    cursorType = CoreCursorType::SizeWestEast; break;
dludwig@8374
    60
    case SDL_SYSTEM_CURSOR_SIZENS:    cursorType = CoreCursorType::SizeNorthSouth; break;
dludwig@8374
    61
    case SDL_SYSTEM_CURSOR_SIZEALL:   cursorType = CoreCursorType::SizeAll; break;
dludwig@8374
    62
    case SDL_SYSTEM_CURSOR_NO:        cursorType = CoreCursorType::UniversalNo; break;
dludwig@8374
    63
    case SDL_SYSTEM_CURSOR_HAND:      cursorType = CoreCursorType::Hand; break;
dludwig@8374
    64
    }
dludwig@8374
    65
dludwig@8374
    66
    cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
dludwig@8374
    67
    if (cursor) {
dludwig@8374
    68
        /* Create a pointer to a COM reference to a cursor.  The extra
dludwig@8374
    69
           pointer is used (on top of the COM reference) to allow the cursor
dludwig@8374
    70
           to be referenced by the SDL_cursor's driverdata field, which is
dludwig@8374
    71
           a void pointer.
dludwig@8374
    72
        */
dludwig@8374
    73
        CoreCursor ^* theCursor = new CoreCursor^(nullptr);
dludwig@8374
    74
        *theCursor = ref new CoreCursor(cursorType, 0);
dludwig@8374
    75
        cursor->driverdata = (void *) theCursor;
dludwig@8374
    76
    } else {
dludwig@8374
    77
        SDL_OutOfMemory();
dludwig@8374
    78
    }
dludwig@8374
    79
dludwig@8374
    80
    return cursor;
dludwig@8374
    81
}
dludwig@8374
    82
dludwig@8374
    83
static SDL_Cursor *
dludwig@8374
    84
WINRT_CreateDefaultCursor()
dludwig@8374
    85
{
dludwig@8374
    86
    return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
dludwig@8374
    87
}
dludwig@8374
    88
dludwig@8374
    89
static void
dludwig@8374
    90
WINRT_FreeCursor(SDL_Cursor * cursor)
dludwig@8374
    91
{
dludwig@8374
    92
    if (cursor->driverdata) {
dludwig@8374
    93
        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
dludwig@8374
    94
        *theCursor = nullptr;       // Release the COM reference to the CoreCursor
dludwig@8374
    95
        delete theCursor;           // Delete the pointer to the COM reference
dludwig@8374
    96
    }
dludwig@8374
    97
    SDL_free(cursor);
dludwig@8374
    98
}
dludwig@8374
    99
dludwig@8374
   100
static int
dludwig@8374
   101
WINRT_ShowCursor(SDL_Cursor * cursor)
dludwig@8374
   102
{
dludwig@8374
   103
    if (cursor) {
dludwig@8374
   104
        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
dludwig@8374
   105
        CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
dludwig@8374
   106
    } else {
dludwig@8374
   107
        CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
dludwig@8374
   108
    }
dludwig@8374
   109
    return 0;
dludwig@8374
   110
}
dludwig@8374
   111
dludwig@8378
   112
static int
dludwig@8378
   113
WINRT_SetRelativeMouseMode(SDL_bool enabled)
dludwig@8378
   114
{
dludwig@8378
   115
    SDL_WinRTGlobalApp->SetRelativeMouseMode(enabled ? true : false);
dludwig@8378
   116
    return 0;
dludwig@8378
   117
}
dludwig@8374
   118
dludwig@8374
   119
void
dludwig@8374
   120
WINRT_InitMouse(_THIS)
dludwig@8374
   121
{
dludwig@8374
   122
    SDL_Mouse *mouse = SDL_GetMouse();
dludwig@8374
   123
dludwig@8374
   124
    /* DLudwig, Dec 3, 2012: Windows RT does not currently provide APIs for
dludwig@8374
   125
       the following features, AFAIK:
dludwig@8374
   126
        - custom cursors  (multiple system cursors are, however, available)
dludwig@8374
   127
        - programmatically moveable cursors
dludwig@8374
   128
    */
dludwig@8374
   129
dludwig@8399
   130
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
dludwig@8374
   131
    //mouse->CreateCursor = WINRT_CreateCursor;
dludwig@8374
   132
    mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
dludwig@8374
   133
    mouse->ShowCursor = WINRT_ShowCursor;
dludwig@8374
   134
    mouse->FreeCursor = WINRT_FreeCursor;
dludwig@8374
   135
    //mouse->WarpMouse = WINRT_WarpMouse;
dludwig@8378
   136
    mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
dludwig@8374
   137
dludwig@8374
   138
    SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
dludwig@8399
   139
#endif
dludwig@8374
   140
}
dludwig@8374
   141
dludwig@8374
   142
void
dludwig@8374
   143
WINRT_QuitMouse(_THIS)
dludwig@8374
   144
{
dludwig@8374
   145
}
dludwig@8374
   146
dludwig@8374
   147
#endif /* SDL_VIDEO_DRIVER_WINRT */
dludwig@8374
   148
dludwig@8374
   149
/* vi: set ts=4 sw=4 expandtab: */