src/video/winrt/SDL_winrtmouse.cpp
author David Ludwig <dludwig@pobox.com>
Thu, 29 Aug 2013 10:32:16 -0400
changeset 8513 0bcf3970deba
parent 8512 5b345a756965
child 8514 8ba600edd93f
permissions -rw-r--r--
WinRT: added touch-event support for Windows Phone devices

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