From 6a5cdbfbc3504e05563d42a1168c6ce73a31141e Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Thu, 25 Apr 2019 18:20:19 +0100 Subject: [PATCH] Enable and Disable cursor support. --- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 4 +- projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 50 +++++++++++--------- src/raylib.h | 4 +- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index 845d2f809..e56c0e84c 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -65,13 +65,13 @@ void App::Update() if (IsKeyPressed(KEY_A)) { posX -= 50; - //UWPEnableCursor(); + EnableCursor(); } if (IsKeyPressed(KEY_D)) { posX += 50; - //UWPDisableCursor(); + DisableCursor(); } if (IsKeyDown(KEY_LEFT_ALT)) //Unable to get working on my PC diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index 65f28992d..813840581 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -54,6 +54,8 @@ using namespace Windows::Graphics::Display; using namespace Microsoft::WRL; using namespace Platform; +extern "C" { EGLNativeWindowType uwpWindow; }; + /* TODO list: - Cache reference to our CoreWindow? @@ -69,27 +71,29 @@ TODO list: //static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state //static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state +//Mouse cursor locking +bool cursorLocked = false; +Vector2 mouseDelta = {0, 0}; + +//Our mouse cursor CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type - -extern "C" { EGLNativeWindowType uwpWindow; }; - -bool isCursorHidden = false; +bool cursorHidden = false; void ShowCursor() { CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - isCursorHidden = false; + cursorHidden = false; } void HideCursor() { CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - isCursorHidden = true; + cursorHidden = true; } bool IsCursorHidden() { - return isCursorHidden; + return cursorHidden; } void SetMousePosition(Vector2 position) @@ -101,19 +105,19 @@ void SetMousePosition(Vector2 position) } // Enables cursor (unlock cursor) -/*void UWPEnableCursor() +void EnableCursor() { - UWPShowCursor(); - UWPSetMousePosition(GetMousePosition()); // The mouse is hidden in the center of the screen - move it to where it should appear - toggleCursorLock = false; -}*/ + ShowCursor(); + SetMousePosition(GetMousePosition()); // The mouse is hidden in the center of the screen - move it to where it should appear + cursorLocked = false; +} // Disables cursor (lock cursor) -/*void UWPDisableCursor() +void DisableCursor() { - UWPHideCursor(); - toggleCursorLock = true; -}*/ + HideCursor(); + cursorLocked = true; +} namespace raylibUWP { @@ -198,13 +202,15 @@ namespace raylibUWP { CoreWindow ^window = CoreWindow::GetForCurrentThread(); - //TODO: Mouse locking logic (Library wide??) - - /*if (toggleCursorLock) + if (cursorLocked) { // Track cursor movement delta, recenter it on the client - mousePosition.x += mouseDelta.x; - mousePosition.y += mouseDelta.y; + auto curMousePos = GetMousePosition(); + + auto x = curMousePos.x + mouseDelta.x; + auto y = curMousePos.y + mouseDelta.y; + + UWPMousePosition(x, y); // Why we're not using UWPSetMousePosition here... // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. @@ -212,7 +218,7 @@ namespace raylibUWP Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); } - else*/ + else { // Record the cursor's position relative to the client auto x = window->PointerPosition.X - window->Bounds.X; diff --git a/src/raylib.h b/src/raylib.h index 2e3d08cf6..e9b6e62d8 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -920,7 +920,9 @@ RLAPI void UWPRegisterKey(int key, char action); RLAPI void UWPRegisterClick(int btn, char action); RLAPI void UWPScrollWheel(int delta); RLAPI void UWPMousePosition(float x, float y); -RLAPI void UWPMarkCursor(bool hidden); +RLAPI void UWPMarkCursor(bool hidden); + +//Get task/input for allowing C to call UWP/cursor functions //Gamepad functionality? #endif