Use 'Messages' to handle the cursor functions so code is more portable.
This commit is contained in:
parent
e29c60cf7a
commit
769aceebb2
|
|
@ -15,7 +15,10 @@ int main(Platform::Array<Platform::String^>^)
|
|||
return 0;
|
||||
}
|
||||
|
||||
App::App() {}
|
||||
App::App()
|
||||
{
|
||||
SetConfigFlags(FLAG_SHOW_LOGO);
|
||||
}
|
||||
|
||||
static int posX = 100;
|
||||
static int posY = 100;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
74
src/core.c
74
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
|
||||
|
|
|
|||
69
src/raylib.h
69
src/raylib.h
|
|
@ -75,6 +75,7 @@
|
|||
#define RAYLIB_H
|
||||
|
||||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||
#include <stdlib.h> // 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user