diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index 79e278a4f..84eb99e5c 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -403,14 +404,19 @@ void App::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { auto props = args->CurrentPoint->Properties; + auto device = args->CurrentPoint->PointerDevice; - // TODO: UWP Touch input/simulation. - if (args->CurrentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Mouse) + if (device->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Mouse) { if (props->IsLeftButtonPressed) UWPMouseButtonEvent(MOUSE_LEFT_BUTTON, true); if (props->IsMiddleButtonPressed) UWPMouseButtonEvent(MOUSE_MIDDLE_BUTTON, true); if (props->IsRightButtonPressed) UWPMouseButtonEvent(MOUSE_RIGHT_BUTTON, true); } + else if (device->PointerDeviceType == PointerDeviceType::Touch) + { + auto pos = args->CurrentPoint->Position; + UWPGestureTouch(args->CurrentPoint->PointerId, pos.X, pos.Y, true); + } args->Handled = true; } @@ -418,14 +424,19 @@ void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::C void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { auto props = args->CurrentPoint->Properties; + auto device = args->CurrentPoint->PointerDevice; - // TODO: UWP Touch input. - if (args->CurrentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Mouse) + if (device->PointerDeviceType == PointerDeviceType::Mouse) { if (!props->IsLeftButtonPressed) UWPMouseButtonEvent(MOUSE_LEFT_BUTTON, false); if (!props->IsMiddleButtonPressed) UWPMouseButtonEvent(MOUSE_MIDDLE_BUTTON, false); if (!props->IsRightButtonPressed) UWPMouseButtonEvent(MOUSE_RIGHT_BUTTON, false); } + else if (device->PointerDeviceType == PointerDeviceType::Touch) + { + auto pos = args->CurrentPoint->Position; + UWPGestureTouch(args->CurrentPoint->PointerId, pos.X, pos.Y, false); + } args->Handled = true; } @@ -439,8 +450,15 @@ void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows:: void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { auto pos = args->CurrentPoint->Position; - UWPMousePosEvent((double)pos.X, (double)pos.Y); - args->Handled = true; + if (args->CurrentPoint->PointerDevice->PointerDeviceType == PointerDeviceType::Mouse) + { + UWPMousePosEvent((double)pos.X, (double)pos.Y); + args->Handled = true; + } + else if (args->CurrentPoint->PointerDevice->PointerDeviceType == PointerDeviceType::Touch) + { + UWPGestureMove(args->CurrentPoint->PointerId, pos.X, pos.Y); + } } int App::GetRaylibKey(Windows::System::VirtualKey kVey) diff --git a/src/core.c b/src/core.c index e83065d31..7fa2856cc 100644 --- a/src/core.c +++ b/src/core.c @@ -2687,9 +2687,9 @@ int GetMouseWheelMove(void) // Returns touch position X for touch point 0 (relative to screen size) int GetTouchX(void) { -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP) return (int)CORE.Input.Touch.position[0].x; -#else // PLATFORM_DESKTOP, PLATFORM_RPI +#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_UWP return GetMouseX(); #endif } @@ -2697,9 +2697,9 @@ int GetTouchX(void) // Returns touch position Y for touch point 0 (relative to screen size) int GetTouchY(void) { -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP) return (int)CORE.Input.Touch.position[0].y; -#else // PLATFORM_DESKTOP, PLATFORM_RPI +#else // PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_UWP return GetMouseY(); #endif } @@ -2710,7 +2710,7 @@ Vector2 GetTouchPosition(int index) { Vector2 position = { -1.0f, -1.0f }; -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP) if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index]; else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS); @@ -5442,7 +5442,7 @@ void UWPMousePosEvent(double x, double y) gestureEvent.pointCount = 1; // Register touch points position, only one point registered - gestureEvent.position[0] = CORE.Input.Touch.position[0]; + gestureEvent.position[0] = CORE.Input.Mouse.position; // Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height gestureEvent.position[0].x /= (float)GetScreenWidth(); @@ -5496,4 +5496,54 @@ void UWPRegisterGamepadAxis(int gamepad, int axis, float value) } } +void UWPGestureMove(int pointer, float x, float y) +{ +#if defined(SUPPORT_GESTURES_SYSTEM) + GestureEvent gestureEvent = { 0 }; + + // Assign the pointer ID and touch action + gestureEvent.pointerId[0] = pointer; + gestureEvent.touchAction = TOUCH_MOVE; + + // Register touch points count + gestureEvent.pointCount = 1; + + // Register touch points position, only one point registered + gestureEvent.position[0].x = x; + gestureEvent.position[0].y = y; + + // Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + + // Gesture data is sent to gestures system for processing + ProcessGestureEvent(gestureEvent); +#endif +} + +void UWPGestureTouch(int pointer, float x, float y, bool touch) +{ +#if defined(SUPPORT_GESTURES_SYSTEM) + GestureEvent gestureEvent = { 0 }; + + // Assign the pointer ID and touch action + gestureEvent.pointerId[0] = pointer; + gestureEvent.touchAction = touch ? TOUCH_DOWN : TOUCH_UP; + + // Register touch points count + gestureEvent.pointCount = 1; + + // Register touch points position, only one point registered + gestureEvent.position[0].x = x; + gestureEvent.position[0].y = y; + + // Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height + gestureEvent.position[0].x /= (float)GetScreenWidth(); + gestureEvent.position[0].y /= (float)GetScreenHeight(); + + // Gesture data is sent to gestures system for processing + ProcessGestureEvent(gestureEvent); +#endif +} + #endif // PLATFORM_UWP diff --git a/src/uwp_events.h b/src/uwp_events.h index 84d18986d..af28da510 100644 --- a/src/uwp_events.h +++ b/src/uwp_events.h @@ -100,6 +100,12 @@ void UWPRegisterGamepadButton(int gamepad, int button, bool down); // Call when a gamepad axis state changes void UWPRegisterGamepadAxis(int gamepad, int axis, float value); +// Call when the touch point moves +void UWPGestureMove(int pointer, float x, float y); + +// Call when there is a touch down or up +void UWPGestureTouch(int pointer, float x, float y, bool touch); + // Set the core window pointer so that we can pass it to EGL. void* UWPGetCoreWindowPtr(); void UWPSetCoreWindowPtr(void* ptr);