src/video/winrt/SDL_winrtmouse.cpp
changeset 8483 d403ded25942
parent 8437 d6a6c3ebdf3e
child 8489 7fd62b320c31
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Tue Aug 20 21:22:32 2013 -0400
     1.3 @@ -0,0 +1,149 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#if SDL_VIDEO_DRIVER_WINRT
    1.28 +
    1.29 +extern "C" {
    1.30 +#include "SDL_assert.h"
    1.31 +#include "../../events/SDL_mouse_c.h"
    1.32 +#include "../SDL_sysvideo.h"
    1.33 +}
    1.34 +
    1.35 +#include "../../core/winrt/SDL_winrtapp.h"
    1.36 +#include "SDL_winrtmouse.h"
    1.37 +
    1.38 +using namespace Windows::UI::Core;
    1.39 +using Windows::UI::Core::CoreCursor;
    1.40 +
    1.41 +extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
    1.42 +
    1.43 +
    1.44 +static SDL_Cursor *
    1.45 +WINRT_CreateSystemCursor(SDL_SystemCursor id)
    1.46 +{
    1.47 +    SDL_Cursor *cursor;
    1.48 +    CoreCursorType cursorType = CoreCursorType::Arrow;
    1.49 +
    1.50 +    switch(id)
    1.51 +    {
    1.52 +    default:
    1.53 +        SDL_assert(0);
    1.54 +        return NULL;
    1.55 +    case SDL_SYSTEM_CURSOR_ARROW:     cursorType = CoreCursorType::Arrow; break;
    1.56 +    case SDL_SYSTEM_CURSOR_IBEAM:     cursorType = CoreCursorType::IBeam; break;
    1.57 +    case SDL_SYSTEM_CURSOR_WAIT:      cursorType = CoreCursorType::Wait; break;
    1.58 +    case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
    1.59 +    case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
    1.60 +    case SDL_SYSTEM_CURSOR_SIZENWSE:  cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
    1.61 +    case SDL_SYSTEM_CURSOR_SIZENESW:  cursorType = CoreCursorType::SizeNortheastSouthwest; break;
    1.62 +    case SDL_SYSTEM_CURSOR_SIZEWE:    cursorType = CoreCursorType::SizeWestEast; break;
    1.63 +    case SDL_SYSTEM_CURSOR_SIZENS:    cursorType = CoreCursorType::SizeNorthSouth; break;
    1.64 +    case SDL_SYSTEM_CURSOR_SIZEALL:   cursorType = CoreCursorType::SizeAll; break;
    1.65 +    case SDL_SYSTEM_CURSOR_NO:        cursorType = CoreCursorType::UniversalNo; break;
    1.66 +    case SDL_SYSTEM_CURSOR_HAND:      cursorType = CoreCursorType::Hand; break;
    1.67 +    }
    1.68 +
    1.69 +    cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
    1.70 +    if (cursor) {
    1.71 +        /* Create a pointer to a COM reference to a cursor.  The extra
    1.72 +           pointer is used (on top of the COM reference) to allow the cursor
    1.73 +           to be referenced by the SDL_cursor's driverdata field, which is
    1.74 +           a void pointer.
    1.75 +        */
    1.76 +        CoreCursor ^* theCursor = new CoreCursor^(nullptr);
    1.77 +        *theCursor = ref new CoreCursor(cursorType, 0);
    1.78 +        cursor->driverdata = (void *) theCursor;
    1.79 +    } else {
    1.80 +        SDL_OutOfMemory();
    1.81 +    }
    1.82 +
    1.83 +    return cursor;
    1.84 +}
    1.85 +
    1.86 +static SDL_Cursor *
    1.87 +WINRT_CreateDefaultCursor()
    1.88 +{
    1.89 +    return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
    1.90 +}
    1.91 +
    1.92 +static void
    1.93 +WINRT_FreeCursor(SDL_Cursor * cursor)
    1.94 +{
    1.95 +    if (cursor->driverdata) {
    1.96 +        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
    1.97 +        *theCursor = nullptr;       // Release the COM reference to the CoreCursor
    1.98 +        delete theCursor;           // Delete the pointer to the COM reference
    1.99 +    }
   1.100 +    SDL_free(cursor);
   1.101 +}
   1.102 +
   1.103 +static int
   1.104 +WINRT_ShowCursor(SDL_Cursor * cursor)
   1.105 +{
   1.106 +    if (cursor) {
   1.107 +        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
   1.108 +        CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
   1.109 +    } else {
   1.110 +        CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
   1.111 +    }
   1.112 +    return 0;
   1.113 +}
   1.114 +
   1.115 +static int
   1.116 +WINRT_SetRelativeMouseMode(SDL_bool enabled)
   1.117 +{
   1.118 +    SDL_WinRTGlobalApp->SetRelativeMouseMode(enabled ? true : false);
   1.119 +    return 0;
   1.120 +}
   1.121 +
   1.122 +void
   1.123 +WINRT_InitMouse(_THIS)
   1.124 +{
   1.125 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.126 +
   1.127 +    /* DLudwig, Dec 3, 2012: Windows RT does not currently provide APIs for
   1.128 +       the following features, AFAIK:
   1.129 +        - custom cursors  (multiple system cursors are, however, available)
   1.130 +        - programmatically moveable cursors
   1.131 +    */
   1.132 +
   1.133 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   1.134 +    //mouse->CreateCursor = WINRT_CreateCursor;
   1.135 +    mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
   1.136 +    mouse->ShowCursor = WINRT_ShowCursor;
   1.137 +    mouse->FreeCursor = WINRT_FreeCursor;
   1.138 +    //mouse->WarpMouse = WINRT_WarpMouse;
   1.139 +    mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
   1.140 +
   1.141 +    SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
   1.142 +#endif
   1.143 +}
   1.144 +
   1.145 +void
   1.146 +WINRT_QuitMouse(_THIS)
   1.147 +{
   1.148 +}
   1.149 +
   1.150 +#endif /* SDL_VIDEO_DRIVER_WINRT */
   1.151 +
   1.152 +/* vi: set ts=4 sw=4 expandtab: */