src/video/winrt/SDL_winrtmouse.cpp
author David Ludwig <dludwig@pobox.com>
Wed, 28 Aug 2013 16:51:07 -0400
changeset 8512 5b345a756965
parent 8511 326b43e1276b
child 8513 0bcf3970deba
permissions -rw-r--r--
WinRT: corrected SDL_MOUSE* coordinates in non-Portrait modes

Thanks to Pierre-Yves Gueniffey for proper pointer geometry transform code!
dludwig@8500
     1
/*
dludwig@8500
     2
  Simple DirectMedia Layer
dludwig@8500
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
dludwig@8500
     4
dludwig@8500
     5
  This software is provided 'as-is', without any express or implied
dludwig@8500
     6
  warranty.  In no event will the authors be held liable for any damages
dludwig@8500
     7
  arising from the use of this software.
dludwig@8500
     8
dludwig@8500
     9
  Permission is granted to anyone to use this software for any purpose,
dludwig@8500
    10
  including commercial applications, and to alter it and redistribute it
dludwig@8500
    11
  freely, subject to the following restrictions:
dludwig@8500
    12
dludwig@8500
    13
  1. The origin of this software must not be misrepresented; you must not
dludwig@8500
    14
     claim that you wrote the original software. If you use this software
dludwig@8500
    15
     in a product, an acknowledgment in the product documentation would be
dludwig@8500
    16
     appreciated but is not required.
dludwig@8500
    17
  2. Altered source versions must be plainly marked as such, and must not be
dludwig@8500
    18
     misrepresented as being the original software.
dludwig@8500
    19
  3. This notice may not be removed or altered from any source distribution.
dludwig@8500
    20
*/
dludwig@8500
    21
dludwig@8500
    22
#include "SDL_config.h"
dludwig@8500
    23
dludwig@8500
    24
#if SDL_VIDEO_DRIVER_WINRT
dludwig@8500
    25
dludwig@8500
    26
/*
dludwig@8500
    27
 * Windows includes:
dludwig@8500
    28
 */
dludwig@8500
    29
#include <Windows.h>
dludwig@8500
    30
using namespace Windows::UI::Core;
dludwig@8500
    31
using Windows::UI::Core::CoreCursor;
dludwig@8500
    32
dludwig@8500
    33
/*
dludwig@8500
    34
 * SDL includes:
dludwig@8500
    35
 */
dludwig@8500
    36
extern "C" {
dludwig@8500
    37
#include "SDL_assert.h"
dludwig@8500
    38
#include "../../events/SDL_mouse_c.h"
dludwig@8500
    39
#include "../SDL_sysvideo.h"
dludwig@8500
    40
#include "SDL_events.h"
dludwig@8500
    41
#include "SDL_log.h"
dludwig@8500
    42
}
dludwig@8500
    43
dludwig@8500
    44
#include "../../core/winrt/SDL_winrtapp.h"
dludwig@8512
    45
#include "SDL_winrtvideo_cpp.h"
dludwig@8500
    46
#include "SDL_winrtmouse.h"
dludwig@8500
    47
dludwig@8500
    48
dludwig@8500
    49
static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
dludwig@8500
    50
dludwig@8500
    51
dludwig@8500
    52
static SDL_Cursor *
dludwig@8500
    53
WINRT_CreateSystemCursor(SDL_SystemCursor id)
dludwig@8500
    54
{
dludwig@8500
    55
    SDL_Cursor *cursor;
dludwig@8500
    56
    CoreCursorType cursorType = CoreCursorType::Arrow;
dludwig@8500
    57
dludwig@8500
    58
    switch(id)
dludwig@8500
    59
    {
dludwig@8500
    60
    default:
dludwig@8500
    61
        SDL_assert(0);
dludwig@8500
    62
        return NULL;
dludwig@8500
    63
    case SDL_SYSTEM_CURSOR_ARROW:     cursorType = CoreCursorType::Arrow; break;
dludwig@8500
    64
    case SDL_SYSTEM_CURSOR_IBEAM:     cursorType = CoreCursorType::IBeam; break;
dludwig@8500
    65
    case SDL_SYSTEM_CURSOR_WAIT:      cursorType = CoreCursorType::Wait; break;
dludwig@8500
    66
    case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
dludwig@8500
    67
    case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
dludwig@8500
    68
    case SDL_SYSTEM_CURSOR_SIZENWSE:  cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
dludwig@8500
    69
    case SDL_SYSTEM_CURSOR_SIZENESW:  cursorType = CoreCursorType::SizeNortheastSouthwest; break;
dludwig@8500
    70
    case SDL_SYSTEM_CURSOR_SIZEWE:    cursorType = CoreCursorType::SizeWestEast; break;
dludwig@8500
    71
    case SDL_SYSTEM_CURSOR_SIZENS:    cursorType = CoreCursorType::SizeNorthSouth; break;
dludwig@8500
    72
    case SDL_SYSTEM_CURSOR_SIZEALL:   cursorType = CoreCursorType::SizeAll; break;
dludwig@8500
    73
    case SDL_SYSTEM_CURSOR_NO:        cursorType = CoreCursorType::UniversalNo; break;
dludwig@8500
    74
    case SDL_SYSTEM_CURSOR_HAND:      cursorType = CoreCursorType::Hand; break;
dludwig@8500
    75
    }
dludwig@8500
    76
dludwig@8500
    77
    cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
dludwig@8500
    78
    if (cursor) {
dludwig@8500
    79
        /* Create a pointer to a COM reference to a cursor.  The extra
dludwig@8500
    80
           pointer is used (on top of the COM reference) to allow the cursor
dludwig@8500
    81
           to be referenced by the SDL_cursor's driverdata field, which is
dludwig@8500
    82
           a void pointer.
dludwig@8500
    83
        */
dludwig@8500
    84
        CoreCursor ^* theCursor = new CoreCursor^(nullptr);
dludwig@8500
    85
        *theCursor = ref new CoreCursor(cursorType, 0);
dludwig@8500
    86
        cursor->driverdata = (void *) theCursor;
dludwig@8500
    87
    } else {
dludwig@8500
    88
        SDL_OutOfMemory();
dludwig@8500
    89
    }
dludwig@8500
    90
dludwig@8500
    91
    return cursor;
dludwig@8500
    92
}
dludwig@8500
    93
dludwig@8500
    94
static SDL_Cursor *
dludwig@8500
    95
WINRT_CreateDefaultCursor()
dludwig@8500
    96
{
dludwig@8500
    97
    return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
dludwig@8500
    98
}
dludwig@8500
    99
dludwig@8500
   100
static void
dludwig@8500
   101
WINRT_FreeCursor(SDL_Cursor * cursor)
dludwig@8500
   102
{
dludwig@8500
   103
    if (cursor->driverdata) {
dludwig@8500
   104
        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
dludwig@8500
   105
        *theCursor = nullptr;       // Release the COM reference to the CoreCursor
dludwig@8500
   106
        delete theCursor;           // Delete the pointer to the COM reference
dludwig@8500
   107
    }
dludwig@8500
   108
    SDL_free(cursor);
dludwig@8500
   109
}
dludwig@8500
   110
dludwig@8500
   111
static int
dludwig@8500
   112
WINRT_ShowCursor(SDL_Cursor * cursor)
dludwig@8500
   113
{
dludwig@8505
   114
    // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
dludwig@8505
   115
    if ( ! CoreWindow::GetForCurrentThread()) {
dludwig@8505
   116
        return 0;
dludwig@8505
   117
    }
dludwig@8505
   118
dludwig@8500
   119
    if (cursor) {
dludwig@8500
   120
        CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
dludwig@8500
   121
        CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
dludwig@8500
   122
    } else {
dludwig@8500
   123
        CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
dludwig@8500
   124
    }
dludwig@8500
   125
    return 0;
dludwig@8500
   126
}
dludwig@8500
   127
dludwig@8500
   128
static int
dludwig@8500
   129
WINRT_SetRelativeMouseMode(SDL_bool enabled)
dludwig@8500
   130
{
dludwig@8500
   131
    WINRT_UseRelativeMouseMode = enabled;
dludwig@8500
   132
    return 0;
dludwig@8500
   133
}
dludwig@8500
   134
dludwig@8500
   135
void
dludwig@8500
   136
WINRT_InitMouse(_THIS)
dludwig@8500
   137
{
dludwig@8500
   138
    SDL_Mouse *mouse = SDL_GetMouse();
dludwig@8500
   139
dludwig@8500
   140
    /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
dludwig@8500
   141
       the following features, AFAIK:
dludwig@8500
   142
        - custom cursors  (multiple system cursors are, however, available)
dludwig@8500
   143
        - programmatically moveable cursors
dludwig@8500
   144
    */
dludwig@8500
   145
dludwig@8500
   146
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
dludwig@8500
   147
    //mouse->CreateCursor = WINRT_CreateCursor;
dludwig@8500
   148
    mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
dludwig@8500
   149
    mouse->ShowCursor = WINRT_ShowCursor;
dludwig@8500
   150
    mouse->FreeCursor = WINRT_FreeCursor;
dludwig@8500
   151
    //mouse->WarpMouse = WINRT_WarpMouse;
dludwig@8500
   152
    mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
dludwig@8500
   153
dludwig@8500
   154
    SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
dludwig@8500
   155
#endif
dludwig@8500
   156
}
dludwig@8500
   157
dludwig@8500
   158
void
dludwig@8500
   159
WINRT_QuitMouse(_THIS)
dludwig@8500
   160
{
dludwig@8500
   161
}
dludwig@8500
   162
dludwig@8489
   163
// Applies necessary geometric transformations to raw cursor positions:
dludwig@8511
   164
Windows::Foundation::Point
dludwig@8511
   165
WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
dludwig@8489
   166
{
dludwig@8512
   167
    using namespace Windows::Graphics::Display;
dludwig@8512
   168
dludwig@8489
   169
    if (!window) {
dludwig@8489
   170
        return rawPosition;
dludwig@8489
   171
    }
dludwig@8512
   172
dludwig@8512
   173
    SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
dludwig@8512
   174
    if (windowData->coreWindow == nullptr) {
dludwig@8512
   175
        // For some reason, the window isn't associated with a CoreWindow.
dludwig@8512
   176
        // This might end up being the case as XAML support is extended.
dludwig@8512
   177
        // For now, if there's no CoreWindow attached to the SDL_Window,
dludwig@8512
   178
        // don't do any transforms.
dludwig@8512
   179
        return rawPosition;
dludwig@8512
   180
    }
dludwig@8512
   181
dludwig@8512
   182
    // The CoreWindow can only be accessed on certain thread(s).
dludwig@8512
   183
    SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
dludwig@8512
   184
dludwig@8512
   185
    CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
dludwig@8489
   186
    Windows::Foundation::Point outputPosition;
dludwig@8512
   187
dludwig@8512
   188
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
dludwig@8489
   189
    outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
dludwig@8489
   190
    outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
dludwig@8512
   191
#else
dludwig@8512
   192
    switch (DisplayProperties::CurrentOrientation)
dludwig@8512
   193
    {
dludwig@8512
   194
        case DisplayOrientations::Portrait:
dludwig@8512
   195
            outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
dludwig@8512
   196
            outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
dludwig@8512
   197
            break;
dludwig@8512
   198
        case DisplayOrientations::PortraitFlipped:
dludwig@8512
   199
            outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
dludwig@8512
   200
            outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
dludwig@8512
   201
            break;
dludwig@8512
   202
        case DisplayOrientations::Landscape:
dludwig@8512
   203
            outputPosition.X = rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
dludwig@8512
   204
            outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
dludwig@8512
   205
            break;
dludwig@8512
   206
        case DisplayOrientations::LandscapeFlipped:
dludwig@8512
   207
            outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
dludwig@8512
   208
            outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
dludwig@8512
   209
            break;
dludwig@8512
   210
        default:
dludwig@8512
   211
            break;
dludwig@8512
   212
    }
dludwig@8512
   213
#endif
dludwig@8512
   214
dludwig@8489
   215
    return outputPosition;
dludwig@8500
   216
}
dludwig@8500
   217
dludwig@8489
   218
static inline int
dludwig@8489
   219
_lround(float arg)
dludwig@8489
   220
{
dludwig@8489
   221
    if (arg >= 0.0f) {
dludwig@8489
   222
        return (int)floor(arg + 0.5f);
dludwig@8489
   223
    } else {
dludwig@8489
   224
        return (int)ceil(arg - 0.5f);
dludwig@8489
   225
    }
dludwig@8500
   226
}
dludwig@8500
   227
dludwig@8500
   228
void
dludwig@8500
   229
WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
dludwig@8500
   230
{
dludwig@8500
   231
    if (!window || !WINRT_UseRelativeMouseMode) {
dludwig@8500
   232
        return;
dludwig@8500
   233
    }
dludwig@8500
   234
dludwig@8489
   235
    // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
dludwig@8489
   236
    // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
dludwig@8489
   237
    // MouseDelta field often reports very large values.  More information
dludwig@8489
   238
    // on this can be found at the following pages on MSDN:
dludwig@8489
   239
    //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
dludwig@8489
   240
    //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
dludwig@8489
   241
    //
dludwig@8489
   242
    // The values do not appear to be as large when running on some systems,
dludwig@8489
   243
    // most notably a Surface RT.  Furthermore, the values returned by
dludwig@8489
   244
    // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
dludwig@8489
   245
    // method, do not ever appear to be large, even when MouseEventArgs'
dludwig@8489
   246
    // MouseDelta is reporting to the contrary.
dludwig@8489
   247
    //
dludwig@8489
   248
    // On systems with the large-values behavior, it appears that the values
dludwig@8489
   249
    // get reported as if the screen's size is 65536 units in both the X and Y
dludwig@8489
   250
    // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
dludwig@8489
   251
    // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
dludwig@8489
   252
    //
dludwig@8489
   253
    // MSDN's documentation on MouseEventArgs' MouseDelta field (at
dludwig@8489
   254
    // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
dludwig@8489
   255
    // does not seem to indicate (to me) that its values should be so large.  It
dludwig@8489
   256
    // says that its values should be a "change in screen location".  I could
dludwig@8489
   257
    // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
dludwig@8489
   258
    // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
dludwig@8489
   259
    // indicates that these values are in DIPs, which is the same unit used
dludwig@8489
   260
    // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
dludwig@8489
   261
    // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
dludwig@8489
   262
    // for details.)
dludwig@8489
   263
    //
dludwig@8489
   264
    // To note, PointerMoved events are sent a 'RawPosition' value (via the
dludwig@8489
   265
    // CurrentPoint property in MouseEventArgs), however these do not seem
dludwig@8489
   266
    // to exhibit the same large-value behavior.
dludwig@8489
   267
    //
dludwig@8489
   268
    // The values passed via PointerMoved events can't always be used for relative
dludwig@8489
   269
    // mouse motion, unfortunately.  Its values are bound to the cursor's position,
dludwig@8489
   270
    // which stops when it hits one of the screen's edges.  This can be a problem in
dludwig@8489
   271
    // first person shooters, whereby it is normal for mouse motion to travel far
dludwig@8489
   272
    // along any one axis for a period of time.  MouseMoved events do not have the
dludwig@8489
   273
    // screen-bounding limitation, and can be used regardless of where the system's
dludwig@8489
   274
    // cursor is.
dludwig@8489
   275
    //
dludwig@8489
   276
    // One possible workaround would be to programmatically set the cursor's
dludwig@8489
   277
    // position to the screen's center (when SDL's relative mouse mode is enabled),
dludwig@8500
   278
    // however WinRT does not yet seem to have the ability to set the cursor's
dludwig@8489
   279
    // position via a public API.  Win32 did this via an API call, SetCursorPos,
dludwig@8489
   280
    // however WinRT makes this function be private.  Apps that use it won't get
dludwig@8489
   281
    // approved for distribution in the Windows Store.  I've yet to be able to find
dludwig@8489
   282
    // a suitable, store-friendly counterpart for WinRT.
dludwig@8489
   283
    //
dludwig@8489
   284
    // There may be some room for a workaround whereby OnPointerMoved's values
dludwig@8489
   285
    // are compared to the values from OnMouseMoved in order to detect
dludwig@8489
   286
    // when this bug is active.  A suitable transformation could then be made to
dludwig@8489
   287
    // OnMouseMoved's values.  For now, however, the system-reported values are sent
dludwig@8489
   288
    // to SDL with minimal transformation: from native screen coordinates (in DIPs)
dludwig@8489
   289
    // to SDL window coordinates.
dludwig@8489
   290
    //
dludwig@8489
   291
    const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
dludwig@8511
   292
    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs);
dludwig@8489
   293
    SDL_SendMouseMotion(
dludwig@8489
   294
        window,
dludwig@8489
   295
        0,
dludwig@8489
   296
        1,
dludwig@8489
   297
        _lround(mouseDeltaInSDLWindowCoords.X),
dludwig@8489
   298
        _lround(mouseDeltaInSDLWindowCoords.Y));
dludwig@8500
   299
}
dludwig@8500
   300
dludwig@8511
   301
Uint8
dludwig@8489
   302
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
dludwig@8489
   303
{
dludwig@8489
   304
    using namespace Windows::UI::Input;
dludwig@8489
   305
dludwig@8511
   306
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
dludwig@8511
   307
    return SDL_BUTTON_LEFT;
dludwig@8511
   308
#else
dludwig@8489
   309
    switch (pt->Properties->PointerUpdateKind)
dludwig@8489
   310
    {
dludwig@8489
   311
        case PointerUpdateKind::LeftButtonPressed:
dludwig@8489
   312
        case PointerUpdateKind::LeftButtonReleased:
dludwig@8489
   313
            return SDL_BUTTON_LEFT;
dludwig@8489
   314
dludwig@8489
   315
        case PointerUpdateKind::RightButtonPressed:
dludwig@8489
   316
        case PointerUpdateKind::RightButtonReleased:
dludwig@8489
   317
            return SDL_BUTTON_RIGHT;
dludwig@8489
   318
dludwig@8489
   319
        case PointerUpdateKind::MiddleButtonPressed:
dludwig@8489
   320
        case PointerUpdateKind::MiddleButtonReleased:
dludwig@8489
   321
            return SDL_BUTTON_MIDDLE;
dludwig@8489
   322
dludwig@8489
   323
        case PointerUpdateKind::XButton1Pressed:
dludwig@8489
   324
        case PointerUpdateKind::XButton1Released:
dludwig@8489
   325
            return SDL_BUTTON_X1;
dludwig@8489
   326
dludwig@8489
   327
        case PointerUpdateKind::XButton2Pressed:
dludwig@8489
   328
        case PointerUpdateKind::XButton2Released:
dludwig@8489
   329
            return SDL_BUTTON_X2;
dludwig@8489
   330
dludwig@8489
   331
        default:
dludwig@8489
   332
            break;
dludwig@8489
   333
    }
dludwig@8511
   334
#endif
dludwig@8489
   335
dludwig@8489
   336
    return 0;
dludwig@8489
   337
}
dludwig@8489
   338
dludwig@8511
   339
//const char *
dludwig@8511
   340
//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
dludwig@8511
   341
//{
dludwig@8511
   342
//    using namespace Windows::UI::Input;
dludwig@8511
   343
//
dludwig@8511
   344
//    switch (kind)
dludwig@8511
   345
//    {
dludwig@8511
   346
//        case PointerUpdateKind::Other:
dludwig@8511
   347
//            return "Other";
dludwig@8511
   348
//        case PointerUpdateKind::LeftButtonPressed:
dludwig@8511
   349
//            return "LeftButtonPressed";
dludwig@8511
   350
//        case PointerUpdateKind::LeftButtonReleased:
dludwig@8511
   351
//            return "LeftButtonReleased";
dludwig@8511
   352
//        case PointerUpdateKind::RightButtonPressed:
dludwig@8511
   353
//            return "RightButtonPressed";
dludwig@8511
   354
//        case PointerUpdateKind::RightButtonReleased:
dludwig@8511
   355
//            return "RightButtonReleased";
dludwig@8511
   356
//        case PointerUpdateKind::MiddleButtonPressed:
dludwig@8511
   357
//            return "MiddleButtonPressed";
dludwig@8511
   358
//        case PointerUpdateKind::MiddleButtonReleased:
dludwig@8511
   359
//            return "MiddleButtonReleased";
dludwig@8511
   360
//        case PointerUpdateKind::XButton1Pressed:
dludwig@8511
   361
//            return "XButton1Pressed";
dludwig@8511
   362
//        case PointerUpdateKind::XButton1Released:
dludwig@8511
   363
//            return "XButton1Released";
dludwig@8511
   364
//        case PointerUpdateKind::XButton2Pressed:
dludwig@8511
   365
//            return "XButton2Pressed";
dludwig@8511
   366
//        case PointerUpdateKind::XButton2Released:
dludwig@8511
   367
//            return "XButton2Released";
dludwig@8511
   368
//    }
dludwig@8511
   369
//
dludwig@8511
   370
//    return "";
dludwig@8511
   371
//}
dludwig@8500
   372
dludwig@8500
   373
void
dludwig@8505
   374
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
dludwig@8489
   375
{
dludwig@8489
   376
    if (!window || WINRT_UseRelativeMouseMode) {
dludwig@8489
   377
        return;
dludwig@8489
   378
    }
dludwig@8489
   379
dludwig@8511
   380
    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
dludwig@8489
   381
    SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
dludwig@8500
   382
}
dludwig@8500
   383
dludwig@8500
   384
void
dludwig@8505
   385
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
dludwig@8489
   386
{
dludwig@8489
   387
    if (!window) {
dludwig@8489
   388
        return;
dludwig@8489
   389
    }
dludwig@8489
   390
dludwig@8489
   391
    // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
dludwig@8505
   392
    short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
dludwig@8489
   393
    SDL_SendMouseWheel(window, 0, 0, motion);
dludwig@8500
   394
}
dludwig@8500
   395
dludwig@8505
   396
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
dludwig@8489
   397
{
dludwig@8489
   398
    if (!window) {
dludwig@8489
   399
        return;
dludwig@8489
   400
    }
dludwig@8489
   401
dludwig@8505
   402
    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
dludwig@8489
   403
    if (button) {
dludwig@8489
   404
        SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
dludwig@8489
   405
    }
dludwig@8500
   406
}
dludwig@8500
   407
dludwig@8505
   408
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
dludwig@8489
   409
{
dludwig@8489
   410
    if (!window) {
dludwig@8489
   411
        return;
dludwig@8489
   412
    }
dludwig@8489
   413
dludwig@8505
   414
    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
dludwig@8489
   415
    if (button) {
dludwig@8511
   416
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
dludwig@8511
   417
        Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
dludwig@8511
   418
        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
dludwig@8511
   419
#endif
dludwig@8489
   420
        SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
dludwig@8489
   421
    }
dludwig@8500
   422
}
dludwig@8500
   423
dludwig@8500
   424
#endif /* SDL_VIDEO_DRIVER_WINRT */
dludwig@8500
   425
dludwig@8500
   426
/* vi: set ts=4 sw=4 expandtab: */