src/video/winrt/SDL_winrtmouse.cpp
changeset 8582 c3e9a2b93517
parent 8522 3ae9dc9c439f
child 8600 092802455aed
     1.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Tue Mar 04 19:49:11 2014 -0500
     1.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Sun Mar 09 11:06:11 2014 -0700
     1.3 @@ -1,166 +1,166 @@
     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 -/*
    1.30 - * Windows includes:
    1.31 - */
    1.32 -#include <Windows.h>
    1.33 -using namespace Windows::UI::Core;
    1.34 -using Windows::UI::Core::CoreCursor;
    1.35 -
    1.36 -/*
    1.37 - * SDL includes:
    1.38 - */
    1.39 -extern "C" {
    1.40 -#include "SDL_assert.h"
    1.41 -#include "../../events/SDL_mouse_c.h"
    1.42 -#include "../../events/SDL_touch_c.h"
    1.43 -#include "../SDL_sysvideo.h"
    1.44 -#include "SDL_events.h"
    1.45 -#include "SDL_log.h"
    1.46 -}
    1.47 -
    1.48 -#include "../../core/winrt/SDL_winrtapp_direct3d.h"
    1.49 -#include "SDL_winrtvideo_cpp.h"
    1.50 -#include "SDL_winrtmouse_c.h"
    1.51 -
    1.52 -
    1.53 -extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
    1.54 -
    1.55 -
    1.56 -static SDL_Cursor *
    1.57 -WINRT_CreateSystemCursor(SDL_SystemCursor id)
    1.58 -{
    1.59 -    SDL_Cursor *cursor;
    1.60 -    CoreCursorType cursorType = CoreCursorType::Arrow;
    1.61 -
    1.62 -    switch(id)
    1.63 -    {
    1.64 -    default:
    1.65 -        SDL_assert(0);
    1.66 -        return NULL;
    1.67 -    case SDL_SYSTEM_CURSOR_ARROW:     cursorType = CoreCursorType::Arrow; break;
    1.68 -    case SDL_SYSTEM_CURSOR_IBEAM:     cursorType = CoreCursorType::IBeam; break;
    1.69 -    case SDL_SYSTEM_CURSOR_WAIT:      cursorType = CoreCursorType::Wait; break;
    1.70 -    case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
    1.71 -    case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
    1.72 -    case SDL_SYSTEM_CURSOR_SIZENWSE:  cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
    1.73 -    case SDL_SYSTEM_CURSOR_SIZENESW:  cursorType = CoreCursorType::SizeNortheastSouthwest; break;
    1.74 -    case SDL_SYSTEM_CURSOR_SIZEWE:    cursorType = CoreCursorType::SizeWestEast; break;
    1.75 -    case SDL_SYSTEM_CURSOR_SIZENS:    cursorType = CoreCursorType::SizeNorthSouth; break;
    1.76 -    case SDL_SYSTEM_CURSOR_SIZEALL:   cursorType = CoreCursorType::SizeAll; break;
    1.77 -    case SDL_SYSTEM_CURSOR_NO:        cursorType = CoreCursorType::UniversalNo; break;
    1.78 -    case SDL_SYSTEM_CURSOR_HAND:      cursorType = CoreCursorType::Hand; break;
    1.79 -    }
    1.80 -
    1.81 -    cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
    1.82 -    if (cursor) {
    1.83 -        /* Create a pointer to a COM reference to a cursor.  The extra
    1.84 -           pointer is used (on top of the COM reference) to allow the cursor
    1.85 -           to be referenced by the SDL_cursor's driverdata field, which is
    1.86 -           a void pointer.
    1.87 -        */
    1.88 -        CoreCursor ^* theCursor = new CoreCursor^(nullptr);
    1.89 -        *theCursor = ref new CoreCursor(cursorType, 0);
    1.90 -        cursor->driverdata = (void *) theCursor;
    1.91 -    } else {
    1.92 -        SDL_OutOfMemory();
    1.93 -    }
    1.94 -
    1.95 -    return cursor;
    1.96 -}
    1.97 -
    1.98 -static SDL_Cursor *
    1.99 -WINRT_CreateDefaultCursor()
   1.100 -{
   1.101 -    return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
   1.102 -}
   1.103 -
   1.104 -static void
   1.105 -WINRT_FreeCursor(SDL_Cursor * cursor)
   1.106 -{
   1.107 -    if (cursor->driverdata) {
   1.108 -        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
   1.109 -        *theCursor = nullptr;       // Release the COM reference to the CoreCursor
   1.110 -        delete theCursor;           // Delete the pointer to the COM reference
   1.111 -    }
   1.112 -    SDL_free(cursor);
   1.113 -}
   1.114 -
   1.115 -static int
   1.116 -WINRT_ShowCursor(SDL_Cursor * cursor)
   1.117 -{
   1.118 -    // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
   1.119 -    if ( ! CoreWindow::GetForCurrentThread()) {
   1.120 -        return 0;
   1.121 -    }
   1.122 -
   1.123 -    if (cursor) {
   1.124 -        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
   1.125 -        CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
   1.126 -    } else {
   1.127 -        CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
   1.128 -    }
   1.129 -    return 0;
   1.130 -}
   1.131 -
   1.132 -static int
   1.133 -WINRT_SetRelativeMouseMode(SDL_bool enabled)
   1.134 -{
   1.135 -    WINRT_UsingRelativeMouseMode = enabled;
   1.136 -    return 0;
   1.137 -}
   1.138 -
   1.139 -void
   1.140 -WINRT_InitMouse(_THIS)
   1.141 -{
   1.142 -    SDL_Mouse *mouse = SDL_GetMouse();
   1.143 -
   1.144 -    /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
   1.145 -       the following features, AFAIK:
   1.146 -        - custom cursors  (multiple system cursors are, however, available)
   1.147 -        - programmatically moveable cursors
   1.148 -    */
   1.149 -
   1.150 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   1.151 -    //mouse->CreateCursor = WINRT_CreateCursor;
   1.152 -    mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
   1.153 -    mouse->ShowCursor = WINRT_ShowCursor;
   1.154 -    mouse->FreeCursor = WINRT_FreeCursor;
   1.155 -    //mouse->WarpMouse = WINRT_WarpMouse;
   1.156 -    mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
   1.157 -
   1.158 -    SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
   1.159 -#endif
   1.160 -}
   1.161 -
   1.162 -void
   1.163 -WINRT_QuitMouse(_THIS)
   1.164 -{
   1.165 -}
   1.166 -
   1.167 -#endif /* SDL_VIDEO_DRIVER_WINRT */
   1.168 -
   1.169 -/* vi: set ts=4 sw=4 expandtab: */
   1.170 +/*
   1.171 +  Simple DirectMedia Layer
   1.172 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
   1.173 +
   1.174 +  This software is provided 'as-is', without any express or implied
   1.175 +  warranty.  In no event will the authors be held liable for any damages
   1.176 +  arising from the use of this software.
   1.177 +
   1.178 +  Permission is granted to anyone to use this software for any purpose,
   1.179 +  including commercial applications, and to alter it and redistribute it
   1.180 +  freely, subject to the following restrictions:
   1.181 +
   1.182 +  1. The origin of this software must not be misrepresented; you must not
   1.183 +     claim that you wrote the original software. If you use this software
   1.184 +     in a product, an acknowledgment in the product documentation would be
   1.185 +     appreciated but is not required.
   1.186 +  2. Altered source versions must be plainly marked as such, and must not be
   1.187 +     misrepresented as being the original software.
   1.188 +  3. This notice may not be removed or altered from any source distribution.
   1.189 +*/
   1.190 +
   1.191 +#include "SDL_config.h"
   1.192 +
   1.193 +#if SDL_VIDEO_DRIVER_WINRT
   1.194 +
   1.195 +/*
   1.196 + * Windows includes:
   1.197 + */
   1.198 +#include <Windows.h>
   1.199 +using namespace Windows::UI::Core;
   1.200 +using Windows::UI::Core::CoreCursor;
   1.201 +
   1.202 +/*
   1.203 + * SDL includes:
   1.204 + */
   1.205 +extern "C" {
   1.206 +#include "SDL_assert.h"
   1.207 +#include "../../events/SDL_mouse_c.h"
   1.208 +#include "../../events/SDL_touch_c.h"
   1.209 +#include "../SDL_sysvideo.h"
   1.210 +#include "SDL_events.h"
   1.211 +#include "SDL_log.h"
   1.212 +}
   1.213 +
   1.214 +#include "../../core/winrt/SDL_winrtapp_direct3d.h"
   1.215 +#include "SDL_winrtvideo_cpp.h"
   1.216 +#include "SDL_winrtmouse_c.h"
   1.217 +
   1.218 +
   1.219 +extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
   1.220 +
   1.221 +
   1.222 +static SDL_Cursor *
   1.223 +WINRT_CreateSystemCursor(SDL_SystemCursor id)
   1.224 +{
   1.225 +    SDL_Cursor *cursor;
   1.226 +    CoreCursorType cursorType = CoreCursorType::Arrow;
   1.227 +
   1.228 +    switch(id)
   1.229 +    {
   1.230 +    default:
   1.231 +        SDL_assert(0);
   1.232 +        return NULL;
   1.233 +    case SDL_SYSTEM_CURSOR_ARROW:     cursorType = CoreCursorType::Arrow; break;
   1.234 +    case SDL_SYSTEM_CURSOR_IBEAM:     cursorType = CoreCursorType::IBeam; break;
   1.235 +    case SDL_SYSTEM_CURSOR_WAIT:      cursorType = CoreCursorType::Wait; break;
   1.236 +    case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
   1.237 +    case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
   1.238 +    case SDL_SYSTEM_CURSOR_SIZENWSE:  cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
   1.239 +    case SDL_SYSTEM_CURSOR_SIZENESW:  cursorType = CoreCursorType::SizeNortheastSouthwest; break;
   1.240 +    case SDL_SYSTEM_CURSOR_SIZEWE:    cursorType = CoreCursorType::SizeWestEast; break;
   1.241 +    case SDL_SYSTEM_CURSOR_SIZENS:    cursorType = CoreCursorType::SizeNorthSouth; break;
   1.242 +    case SDL_SYSTEM_CURSOR_SIZEALL:   cursorType = CoreCursorType::SizeAll; break;
   1.243 +    case SDL_SYSTEM_CURSOR_NO:        cursorType = CoreCursorType::UniversalNo; break;
   1.244 +    case SDL_SYSTEM_CURSOR_HAND:      cursorType = CoreCursorType::Hand; break;
   1.245 +    }
   1.246 +
   1.247 +    cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
   1.248 +    if (cursor) {
   1.249 +        /* Create a pointer to a COM reference to a cursor.  The extra
   1.250 +           pointer is used (on top of the COM reference) to allow the cursor
   1.251 +           to be referenced by the SDL_cursor's driverdata field, which is
   1.252 +           a void pointer.
   1.253 +        */
   1.254 +        CoreCursor ^* theCursor = new CoreCursor^(nullptr);
   1.255 +        *theCursor = ref new CoreCursor(cursorType, 0);
   1.256 +        cursor->driverdata = (void *) theCursor;
   1.257 +    } else {
   1.258 +        SDL_OutOfMemory();
   1.259 +    }
   1.260 +
   1.261 +    return cursor;
   1.262 +}
   1.263 +
   1.264 +static SDL_Cursor *
   1.265 +WINRT_CreateDefaultCursor()
   1.266 +{
   1.267 +    return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
   1.268 +}
   1.269 +
   1.270 +static void
   1.271 +WINRT_FreeCursor(SDL_Cursor * cursor)
   1.272 +{
   1.273 +    if (cursor->driverdata) {
   1.274 +        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
   1.275 +        *theCursor = nullptr;       // Release the COM reference to the CoreCursor
   1.276 +        delete theCursor;           // Delete the pointer to the COM reference
   1.277 +    }
   1.278 +    SDL_free(cursor);
   1.279 +}
   1.280 +
   1.281 +static int
   1.282 +WINRT_ShowCursor(SDL_Cursor * cursor)
   1.283 +{
   1.284 +    // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
   1.285 +    if ( ! CoreWindow::GetForCurrentThread()) {
   1.286 +        return 0;
   1.287 +    }
   1.288 +
   1.289 +    if (cursor) {
   1.290 +        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
   1.291 +        CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
   1.292 +    } else {
   1.293 +        CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
   1.294 +    }
   1.295 +    return 0;
   1.296 +}
   1.297 +
   1.298 +static int
   1.299 +WINRT_SetRelativeMouseMode(SDL_bool enabled)
   1.300 +{
   1.301 +    WINRT_UsingRelativeMouseMode = enabled;
   1.302 +    return 0;
   1.303 +}
   1.304 +
   1.305 +void
   1.306 +WINRT_InitMouse(_THIS)
   1.307 +{
   1.308 +    SDL_Mouse *mouse = SDL_GetMouse();
   1.309 +
   1.310 +    /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
   1.311 +       the following features, AFAIK:
   1.312 +        - custom cursors  (multiple system cursors are, however, available)
   1.313 +        - programmatically moveable cursors
   1.314 +    */
   1.315 +
   1.316 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   1.317 +    //mouse->CreateCursor = WINRT_CreateCursor;
   1.318 +    mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
   1.319 +    mouse->ShowCursor = WINRT_ShowCursor;
   1.320 +    mouse->FreeCursor = WINRT_FreeCursor;
   1.321 +    //mouse->WarpMouse = WINRT_WarpMouse;
   1.322 +    mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
   1.323 +
   1.324 +    SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
   1.325 +#endif
   1.326 +}
   1.327 +
   1.328 +void
   1.329 +WINRT_QuitMouse(_THIS)
   1.330 +{
   1.331 +}
   1.332 +
   1.333 +#endif /* SDL_VIDEO_DRIVER_WINRT */
   1.334 +
   1.335 +/* vi: set ts=4 sw=4 expandtab: */