diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index d63d9f3c4..5db6df2d1 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -15,7 +15,10 @@ int main(Platform::Array^) return 0; } -App::App() {} +App::App() +{ + SetConfigFlags(FLAG_SHOW_LOGO); +} static int posX = 100; static int posY = 100; diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index ff6f2db41..4f842479f 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -73,47 +73,6 @@ Vector2 mouseDelta = {0, 0}; //Our mouse cursor CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type -bool cursorHidden = false; - -void ShowCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - cursorHidden = false; -} - -void HideCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - cursorHidden = true; -} - -bool IsCursorHidden() -{ - return cursorHidden; -} - -void SetMousePosition(Vector2 position) -{ - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - Point mousePosScreen = Point(position.x + window->Bounds.X, position.y + window->Bounds.Y); - window->PointerPosition = mousePosScreen; - UWPMousePosition(position.x, position.y); -} - -// Enables cursor (unlock cursor) -void EnableCursor() -{ - 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 DisableCursor() -{ - HideCursor(); - cursorLocked = true; -} //Base app implementation ref class BaseApp : public Windows::ApplicationModel::Core::IFrameworkView @@ -193,6 +152,59 @@ protected: // Input polling void PollInput() { + // Process Messages + { + //Loop over pending messages + while (UWPHasMessages()) + { + //Get the message + auto msg = UWPGetMessage(); + + //Carry out the command + switch(msg->Type) + { + case ShowMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + //Unlock due to below + cursorLocked = false; + break; + } + case HideMouse: + { + //Bug: movement stops, for now we will lock... + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorLocked = true; + break; + } + case LockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + //Unlock due to below + cursorLocked = false; + break; + } + case UnlockMouse: + { + //Bug: movement stops, for now we will lock... + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorLocked = true; + break; + } + case SetMouseLocation: + { + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(msg->Float0 + window->Bounds.X, msg->Float1 + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + break; + } + } + + //Delete the message + DeleteUWPMessage(msg); + } + } + // Process Mouse { CoreWindow ^window = CoreWindow::GetForCurrentThread(); diff --git a/src/camera.h b/src/camera.h index e0c0db696..414f3b884 100644 --- a/src/camera.h +++ b/src/camera.h @@ -253,17 +253,11 @@ void SetCameraMode(Camera camera, int mode) playerEyesPosition = camera.position.y; - //TODO: Tell UWP that cursor should be enabled/disabled - -#if !defined(PLATFORM_UWP) - // Lock cursor for first person and third person cameras if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor(); else EnableCursor(); -#endif - cameraMode = mode; } diff --git a/src/core.c b/src/core.c index 0ffacea69..19bd37163 100644 --- a/src/core.c +++ b/src/core.c @@ -391,6 +391,23 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto static pthread_t gamepadThreadId; // Gamepad reading thread id static char gamepadName[64]; // Gamepad name holder #endif + +#if defined(PLATFORM_UWP) +// UWP Messages + +#define MAX_MESSAGES 128 //If there are over 128 messages, I will cry... either way, this may be too much + +static int UWPOutMessageId = -1; //Stores the last index for the message +static UWPMessage* UWPOutMessages[MAX_MESSAGES]; //Messages out to UWP + +static void SendToUWP(UWPMessage* msg) +{ + UWPOutMessageId++; + UWPOutMessages[UWPOutMessageId] = msg; +} + +#endif + //----------------------------------------------------------------------------------- // Timming system variables @@ -626,11 +643,13 @@ void InitWindow(int width, int height, const char *title) mousePosition.y = (float)screenHeight/2.0f; // raylib logo appearing animation (if enabled) +#if !defined(PLATFORM_UWP) if (showLogo) { SetTargetFPS(60); LogoAnimation(); } +#endif //defined(PLATFORM_UWP) #endif // defined(PLATFORM_ANDROID) } @@ -1020,13 +1039,16 @@ void SetClipboardText(const char *text) #endif } -#if !defined(PLATFORM_UWP) - // Show mouse cursor void ShowCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ShowMouse; + SendToUWP(msg); #endif cursorHidden = false; } @@ -1036,6 +1058,11 @@ void HideCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HideMouse; + SendToUWP(msg); #endif cursorHidden = true; } @@ -1054,6 +1081,11 @@ void EnableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = LockMouse; + SendToUWP(msg); #endif cursorHidden = false; } @@ -1066,12 +1098,15 @@ void DisableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UnlockMouse; + SendToUWP(msg); #endif cursorHidden = true; } -#endif - // Set background color (framebuffer clear color) void ClearBackground(Color color) { @@ -2212,6 +2247,13 @@ void SetMousePosition(int x, int y) // NOTE: emscripten not implemented glfwSetCursorPos(window, mousePosition.x, mousePosition.y); #endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetMouseLocation; + msg->Float0 = mousePosition.x; + msg->Float1 = mousePosition.y; + SendToUWP(msg); +#endif } // Set mouse offset @@ -4715,6 +4757,30 @@ void UWPGamepadAxis(int gamepad, int axis, float value) gamepadAxisState[gamepad][axis] = value; } +bool UWPHasMessages() +{ + if (UWPOutMessageId > -1) + return true; + return false; +} + +UWPMessage* UWPGetMessage() +{ + if (UWPHasMessages()) + { + return UWPOutMessages[UWPOutMessageId--]; + } + + return CreateUWPMessage(); +} + +/*void UWPSendMessage(UWPMessage* msg) +{ + switch(msg->Type) + { + } +}*/ + #endif // Plays raylib logo appearing animation diff --git a/src/raylib.h b/src/raylib.h index 8080fb389..13604107a 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -75,6 +75,7 @@ #define RAYLIB_H #include // Required for: va_list - Only used by TraceLogCallback +#include // Required for: malloc #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED) #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 shared library (.dll) @@ -871,6 +872,68 @@ typedef enum { // Callbacks to be implemented by users typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); +#if defined(PLATFORM_UWP) + +// UWP Messages + +typedef enum +{ + None = 0, + + //Send + ShowMouse, + HideMouse, + LockMouse, + UnlockMouse, + SetMouseLocation, //Flaot0, Float1 +} UWPMessageType; + +typedef struct UWPMessage { + //The message type + UWPMessageType Type; + + //Vector parameters + Vector2 Vector0; + + //Int parameters + int Int0; + int Int1; + + //Char parameters + char Char0; + + //Float parameters + float Float0; + float Float1; + + //Bool parameters + bool Bool0; + + //More parameters can be added and fed to functions +} UWPMessage; + +inline UWPMessage* CreateUWPMessage(void) +{ + UWPMessage* msg = (UWPMessage*) RL_MALLOC(sizeof(UWPMessage)); + msg->Type = None; + Vector2 v0 = { 0, 0 }; + msg->Vector0 = v0; + msg->Int0 = 0; + msg->Int1 = 0; + msg->Char0 = 0; + msg->Float0 = 0; + msg->Float1 = 0; + msg->Bool0 = false; + return msg; +} + +inline void DeleteUWPMessage(UWPMessage* msg) +{ + RL_FREE(msg); +} + +#endif + #if defined(__cplusplus) extern "C" { // Prevents name mangling of functions #endif @@ -925,18 +988,18 @@ RLAPI void UWPGamepadActive(int gamepad, bool active); RLAPI void UWPGamepadButton(int gamepad, int button, char action); RLAPI void UWPGamepadAxis(int gamepad, int axis, float value); -//Get task/input for allowing C to call UWP/cursor functions +RLAPI bool UWPHasMessages(); +RLAPI UWPMessage* UWPGetMessage(); +//RLAPI void UWPSendMessage(UWPMessage* msg); //Do we need to send messages? #endif // Cursor-related functions -#if !defined(PLATFORM_UWP) //These are implemented by BaseApp.h RLAPI void ShowCursor(void); // Shows cursor RLAPI void HideCursor(void); // Hides cursor RLAPI bool IsCursorHidden(void); // Check if cursor is not visible RLAPI void EnableCursor(void); // Enables cursor (unlock cursor) RLAPI void DisableCursor(void); // Disables cursor (lock cursor) -#endif // Drawing-related functions RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color)