Enable and Disable cursor support.

This commit is contained in:
Reece Mackie 2019-04-25 18:20:19 +01:00
parent d20041b8ae
commit 6a5cdbfbc3
3 changed files with 33 additions and 25 deletions

View File

@ -65,13 +65,13 @@ void App::Update()
if (IsKeyPressed(KEY_A)) if (IsKeyPressed(KEY_A))
{ {
posX -= 50; posX -= 50;
//UWPEnableCursor(); EnableCursor();
} }
if (IsKeyPressed(KEY_D)) if (IsKeyPressed(KEY_D))
{ {
posX += 50; posX += 50;
//UWPDisableCursor(); DisableCursor();
} }
if (IsKeyDown(KEY_LEFT_ALT)) //Unable to get working on my PC if (IsKeyDown(KEY_LEFT_ALT)) //Unable to get working on my PC

View File

@ -54,6 +54,8 @@ using namespace Windows::Graphics::Display;
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
using namespace Platform; using namespace Platform;
extern "C" { EGLNativeWindowType uwpWindow; };
/* /*
TODO list: TODO list:
- Cache reference to our CoreWindow? - 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 previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
//static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current 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 CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type
bool cursorHidden = false;
extern "C" { EGLNativeWindowType uwpWindow; };
bool isCursorHidden = false;
void ShowCursor() void ShowCursor()
{ {
CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor;
isCursorHidden = false; cursorHidden = false;
} }
void HideCursor() void HideCursor()
{ {
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
isCursorHidden = true; cursorHidden = true;
} }
bool IsCursorHidden() bool IsCursorHidden()
{ {
return isCursorHidden; return cursorHidden;
} }
void SetMousePosition(Vector2 position) void SetMousePosition(Vector2 position)
@ -101,19 +105,19 @@ void SetMousePosition(Vector2 position)
} }
// Enables cursor (unlock cursor) // Enables cursor (unlock cursor)
/*void UWPEnableCursor() void EnableCursor()
{ {
UWPShowCursor(); ShowCursor();
UWPSetMousePosition(GetMousePosition()); // The mouse is hidden in the center of the screen - move it to where it should appear SetMousePosition(GetMousePosition()); // The mouse is hidden in the center of the screen - move it to where it should appear
toggleCursorLock = false; cursorLocked = false;
}*/ }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
/*void UWPDisableCursor() void DisableCursor()
{ {
UWPHideCursor(); HideCursor();
toggleCursorLock = true; cursorLocked = true;
}*/ }
namespace raylibUWP namespace raylibUWP
{ {
@ -198,13 +202,15 @@ namespace raylibUWP
{ {
CoreWindow ^window = CoreWindow::GetForCurrentThread(); CoreWindow ^window = CoreWindow::GetForCurrentThread();
//TODO: Mouse locking logic (Library wide??) if (cursorLocked)
/*if (toggleCursorLock)
{ {
// Track cursor movement delta, recenter it on the client // Track cursor movement delta, recenter it on the client
mousePosition.x += mouseDelta.x; auto curMousePos = GetMousePosition();
mousePosition.y += mouseDelta.y;
auto x = curMousePos.x + mouseDelta.x;
auto y = curMousePos.y + mouseDelta.y;
UWPMousePosition(x, y);
// Why we're not using UWPSetMousePosition here... // Why we're not using UWPSetMousePosition here...
// UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. // 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) }; Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) };
window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y);
} }
else*/ else
{ {
// Record the cursor's position relative to the client // Record the cursor's position relative to the client
auto x = window->PointerPosition.X - window->Bounds.X; auto x = window->PointerPosition.X - window->Bounds.X;

View File

@ -921,6 +921,8 @@ RLAPI void UWPRegisterClick(int btn, char action);
RLAPI void UWPScrollWheel(int delta); RLAPI void UWPScrollWheel(int delta);
RLAPI void UWPMousePosition(float x, float y); 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? //Gamepad functionality?
#endif #endif