Move messages to utils.h and use messages for everything. No more plat-specific code in raylib.h

This commit is contained in:
Reece Mackie 2019-04-26 13:20:30 +01:00
parent 51f5c8ed0b
commit 3ef5ad1a84
5 changed files with 389 additions and 302 deletions

View File

@ -41,6 +41,7 @@
#include <EGL/eglplatform.h>
#include "raylib.h"
#include "utils.h"
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
@ -163,39 +164,24 @@ protected:
//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 ShowMouse: //Do the same thing because of how UWP works...
case UnlockMouse:
{
//Bug: movement stops, for now we will lock...
CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor;
cursorLocked = false;
MoveMouse(GetMousePosition());
break;
}
case HideMouse: //Do the same thing because of how UWP works...
case LockMouse:
{
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
cursorLocked = true;
break;
}
case SetMouseLocation:
{
CoreWindow ^window = CoreWindow::GetForCurrentThread();
Point mousePosScreen = Point(msg->Vector0.x + window->Bounds.X, msg->Vector0.y + window->Bounds.Y);
window->PointerPosition = mousePosScreen;
MoveMouse(msg->Vector0);
break;
}
}
@ -217,7 +203,7 @@ protected:
auto x = curMousePos.x + mouseDelta.x;
auto y = curMousePos.y + mouseDelta.y;
UWPMousePosition(x, y);
UpdateMousePosition({ x, y });
// Why we're not using UWPSetMousePosition here...
// UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is.
@ -231,7 +217,7 @@ protected:
auto x = window->PointerPosition.X - window->Bounds.X;
auto y = window->PointerPosition.Y - window->Bounds.Y;
UWPMousePosition(x, y);
UpdateMousePosition({ x, y });
}
mouseDelta = { 0 ,0 };
@ -246,7 +232,11 @@ protected:
// connected gamepads with their spot in the list, but this has serious robustness problems
// e.g. player 1, 2, and 3 are playing a game - if player2 disconnects, p3's controller would now be mapped to p2's character since p3 is now second in the list.
UWPGamepadActive(i, i < Gamepad::Gamepads->Size);
UWPMessage* msg = CreateUWPMessage();
msg->Type = MarkGamepadActive;
msg->Int0 = i;
msg->Bool0 = i < Gamepad::Gamepads->Size;
UWPSendMessage(msg);
}
// Get current gamepad state
@ -259,27 +249,27 @@ protected:
GamepadReading reading = gamepad->GetCurrentReading();
// NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft));
UWPGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft));
RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP
// Get current axis state
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX);
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY);
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX);
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY);
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger);
UWPGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger);
RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger);
}
}
}
@ -316,15 +306,15 @@ protected:
{
if (args->CurrentPoint->Properties->IsLeftButtonPressed)
{
UWPRegisterClick(MOUSE_LEFT_BUTTON, 1);
RegisterClick(MOUSE_LEFT_BUTTON, 1);
}
if (args->CurrentPoint->Properties->IsRightButtonPressed)
{
UWPRegisterClick(MOUSE_RIGHT_BUTTON, 1);
RegisterClick(MOUSE_RIGHT_BUTTON, 1);
}
if (args->CurrentPoint->Properties->IsMiddleButtonPressed)
{
UWPRegisterClick(MOUSE_MIDDLE_BUTTON, 1);
RegisterClick(MOUSE_MIDDLE_BUTTON, 1);
}
}
@ -332,21 +322,24 @@ protected:
{
if (!(args->CurrentPoint->Properties->IsLeftButtonPressed))
{
UWPRegisterClick(MOUSE_LEFT_BUTTON, 0);
RegisterClick(MOUSE_LEFT_BUTTON, 0);
}
if (!(args->CurrentPoint->Properties->IsRightButtonPressed))
{
UWPRegisterClick(MOUSE_RIGHT_BUTTON, 0);
RegisterClick(MOUSE_RIGHT_BUTTON, 0);
}
if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed))
{
UWPRegisterClick(MOUSE_MIDDLE_BUTTON, 0);
RegisterClick(MOUSE_MIDDLE_BUTTON, 0);
}
}
void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args)
{
UWPScrollWheel(args->CurrentPoint->Properties->MouseWheelDelta);
UWPMessage* msg = CreateUWPMessage();
msg->Type = ScrollWheelUpdate;
msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta;
UWPSendMessage(msg);
}
void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args)
@ -357,17 +350,69 @@ protected:
void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args)
{
UWPRegisterKey((int)args->VirtualKey, 1);
UWPMessage* msg = CreateUWPMessage();
msg->Type = RegisterKey;
msg->Int0 = (int)args->VirtualKey;
msg->Char0 = 1;
UWPSendMessage(msg);
}
void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args)
{
//TODO: Fix hold errors
UWPRegisterKey((int)args->VirtualKey, 0);
UWPMessage* msg = CreateUWPMessage();
msg->Type = RegisterKey;
msg->Int0 = (int)args->VirtualKey;
msg->Char0 = 0;
UWPSendMessage(msg);
}
private:
void MoveMouse(Vector2 pos)
{
CoreWindow ^window = CoreWindow::GetForCurrentThread();
Point mousePosScreen = Point(pos.x + window->Bounds.X, pos.y + window->Bounds.Y);
window->PointerPosition = mousePosScreen;
}
void RegisterGamepadButton(int gamepad, int button, char status)
{
UWPMessage* msg = CreateUWPMessage();
msg->Type = MarkGamepadButton;
msg->Int0 = gamepad;
msg->Int1 = button;
msg->Char0 = status;
UWPSendMessage(msg);
}
void RegisterGamepadAxis(int gamepad, int axis, float value)
{
UWPMessage* msg = CreateUWPMessage();
msg->Type = MarkGamepadAxis;
msg->Int0 = gamepad;
msg->Int1 = axis;
msg->Float0 = value;
UWPSendMessage(msg);
}
void UpdateMousePosition(Vector2 pos)
{
UWPMessage* msg = CreateUWPMessage();
msg->Type = UpdateMouseLocation;
msg->Vector0 = pos;
UWPSendMessage(msg);
}
void RegisterClick(int button, char status)
{
UWPMessage* msg = CreateUWPMessage();
msg->Type = UWPMessageType::RegisterClick;
msg->Int0 = button;
msg->Char0 = status;
UWPSendMessage(msg);
}
bool mWindowClosed = false;
bool mWindowVisible = true;

View File

@ -1,4 +1,5 @@
/**********************************************************************************************
/**********************************************************************************************
*
* raylib.core - Basic functions to manage windows, OpenGL context and input on multiple platforms
*
@ -392,22 +393,6 @@ 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
@ -1046,7 +1031,7 @@ void ShowCursor(void)
#if defined(PLATFORM_UWP)
UWPMessage* msg = CreateUWPMessage();
msg->Type = ShowMouse;
SendToUWP(msg);
SendMessageToUWP(msg);
#endif
cursorHidden = false;
}
@ -1060,7 +1045,7 @@ void HideCursor(void)
#if defined(PLATFORM_UWP)
UWPMessage* msg = CreateUWPMessage();
msg->Type = HideMouse;
SendToUWP(msg);
SendMessageToUWP(msg);
#endif
cursorHidden = true;
}
@ -1083,7 +1068,7 @@ void EnableCursor(void)
#if defined(PLATFORM_UWP)
UWPMessage* msg = CreateUWPMessage();
msg->Type = LockMouse;
SendToUWP(msg);
SendMessageToUWP(msg);
#endif
cursorHidden = false;
}
@ -1100,7 +1085,7 @@ void DisableCursor(void)
#if defined(PLATFORM_UWP)
UWPMessage* msg = CreateUWPMessage();
msg->Type = UnlockMouse;
SendToUWP(msg);
SendMessageToUWP(msg);
#endif
cursorHidden = true;
}
@ -2250,7 +2235,7 @@ void SetMousePosition(int x, int y)
msg->Type = SetMouseLocation;
msg->Vector0.x = mousePosition.x;
msg->Vector0.y = mousePosition.y;
SendToUWP(msg);
SendMessageToUWP(msg);
#endif
}
@ -3155,6 +3140,134 @@ static void PollInputEvents(void)
}
// Loop over pending messages
while (HasMessageFromUWP())
{
UWPMessage* msg = GetMessageFromUWP();
switch (msg->Type)
{
case RegisterKey:
{
//Convert from virtualKey
int actualKey = -1;
switch (msg->Int0)
{
case 0x08: actualKey = KEY_BACKSPACE; break;
case 0x20: actualKey = KEY_SPACE; break;
case 0x1B: actualKey = KEY_ESCAPE; break;
case 0x0D: actualKey = KEY_ENTER; break;
case 0x2E: actualKey = KEY_DELETE; break;
case 0x27: actualKey = KEY_RIGHT; break;
case 0x25: actualKey = KEY_LEFT; break;
case 0x28: actualKey = KEY_DOWN; break;
case 0x26: actualKey = KEY_UP; break;
case 0x70: actualKey = KEY_F1; break;
case 0x71: actualKey = KEY_F2; break;
case 0x72: actualKey = KEY_F3; break;
case 0x73: actualKey = KEY_F4; break;
case 0x74: actualKey = KEY_F5; break;
case 0x75: actualKey = KEY_F6; break;
case 0x76: actualKey = KEY_F7; break;
case 0x77: actualKey = KEY_F8; break;
case 0x78: actualKey = KEY_F9; break;
case 0x79: actualKey = KEY_F10; break;
case 0x7A: actualKey = KEY_F11; break;
case 0x7B: actualKey = KEY_F12; break;
case 0xA0: actualKey = KEY_LEFT_SHIFT; break;
case 0xA2: actualKey = KEY_LEFT_CONTROL; break;
case 0xA4: actualKey = KEY_LEFT_ALT; break;
case 0xA1: actualKey = KEY_RIGHT_SHIFT; break;
case 0xA3: actualKey = KEY_RIGHT_CONTROL; break;
case 0xA5: actualKey = KEY_RIGHT_ALT; break;
case 0x30: actualKey = KEY_ZERO; break;
case 0x31: actualKey = KEY_ONE; break;
case 0x32: actualKey = KEY_TWO; break;
case 0x33: actualKey = KEY_THREE; break;
case 0x34: actualKey = KEY_FOUR; break;
case 0x35: actualKey = KEY_FIVE; break;
case 0x36: actualKey = KEY_SIX; break;
case 0x37: actualKey = KEY_SEVEN; break;
case 0x38: actualKey = KEY_EIGHT; break;
case 0x39: actualKey = KEY_NINE; break;
case 0x41: actualKey = KEY_A; break;
case 0x42: actualKey = KEY_B; break;
case 0x43: actualKey = KEY_C; break;
case 0x44: actualKey = KEY_D; break;
case 0x45: actualKey = KEY_E; break;
case 0x46: actualKey = KEY_F; break;
case 0x47: actualKey = KEY_G; break;
case 0x48: actualKey = KEY_H; break;
case 0x49: actualKey = KEY_I; break;
case 0x4A: actualKey = KEY_J; break;
case 0x4B: actualKey = KEY_K; break;
case 0x4C: actualKey = KEY_L; break;
case 0x4D: actualKey = KEY_M; break;
case 0x4E: actualKey = KEY_N; break;
case 0x4F: actualKey = KEY_O; break;
case 0x50: actualKey = KEY_P; break;
case 0x51: actualKey = KEY_Q; break;
case 0x52: actualKey = KEY_R; break;
case 0x53: actualKey = KEY_S; break;
case 0x54: actualKey = KEY_T; break;
case 0x55: actualKey = KEY_U; break;
case 0x56: actualKey = KEY_V; break;
case 0x57: actualKey = KEY_W; break;
case 0x58: actualKey = KEY_X; break;
case 0x59: actualKey = KEY_Y; break;
case 0x5A: actualKey = KEY_Z; break;
}
if (actualKey > -1)
currentKeyState[actualKey] = msg->Char0;
break;
}
case RegisterClick:
{
currentMouseState[msg->Int0] = msg->Char0;
break;
}
case ScrollWheelUpdate:
{
currentMouseWheelY += msg->Int0;
break;
}
case UpdateMouseLocation:
{
mousePosition = msg->Vector0;
break;
}
case MarkGamepadActive:
{
if (msg->Int0 < MAX_GAMEPADS)
gamepadReady[msg->Int0] = msg->Bool0;
break;
}
case MarkGamepadButton:
{
if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_BUTTONS)
currentGamepadState[msg->Int0][msg->Int1] = msg->Char0;
break;
}
case MarkGamepadAxis:
{
if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_AXIS)
gamepadAxisState[msg->Int0][msg->Int1] = msg->Float0;
break;
}
}
DeleteUWPMessage(msg); //Delete, we are done
}
#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
@ -4641,150 +4754,6 @@ static void *GamepadThread(void *arg)
}
#endif // PLATFORM_RPI
#if defined(PLATFORM_UWP)
void UWPRegisterKey(int key, char action)
{
//Convert from virtualKey
int actualKey = -1;
switch (key)
{
case 0x08: actualKey = KEY_BACKSPACE; break;
case 0x20: actualKey = KEY_SPACE; break;
case 0x1B: actualKey = KEY_ESCAPE; break;
case 0x0D: actualKey = KEY_ENTER; break;
case 0x2E: actualKey = KEY_DELETE; break;
case 0x27: actualKey = KEY_RIGHT; break;
case 0x25: actualKey = KEY_LEFT; break;
case 0x28: actualKey = KEY_DOWN; break;
case 0x26: actualKey = KEY_UP; break;
case 0x70: actualKey = KEY_F1; break;
case 0x71: actualKey = KEY_F2; break;
case 0x72: actualKey = KEY_F3; break;
case 0x73: actualKey = KEY_F4; break;
case 0x74: actualKey = KEY_F5; break;
case 0x75: actualKey = KEY_F6; break;
case 0x76: actualKey = KEY_F7; break;
case 0x77: actualKey = KEY_F8; break;
case 0x78: actualKey = KEY_F9; break;
case 0x79: actualKey = KEY_F10; break;
case 0x7A: actualKey = KEY_F11; break;
case 0x7B: actualKey = KEY_F12; break;
case 0xA0: actualKey = KEY_LEFT_SHIFT; break;
case 0xA2: actualKey = KEY_LEFT_CONTROL; break;
case 0xA4: actualKey = KEY_LEFT_ALT; break;
case 0xA1: actualKey = KEY_RIGHT_SHIFT; break;
case 0xA3: actualKey = KEY_RIGHT_CONTROL; break;
case 0xA5: actualKey = KEY_RIGHT_ALT; break;
case 0x30: actualKey = KEY_ZERO; break;
case 0x31: actualKey = KEY_ONE; break;
case 0x32: actualKey = KEY_TWO; break;
case 0x33: actualKey = KEY_THREE; break;
case 0x34: actualKey = KEY_FOUR; break;
case 0x35: actualKey = KEY_FIVE; break;
case 0x36: actualKey = KEY_SIX; break;
case 0x37: actualKey = KEY_SEVEN; break;
case 0x38: actualKey = KEY_EIGHT; break;
case 0x39: actualKey = KEY_NINE; break;
case 0x41: actualKey = KEY_A; break;
case 0x42: actualKey = KEY_B; break;
case 0x43: actualKey = KEY_C; break;
case 0x44: actualKey = KEY_D; break;
case 0x45: actualKey = KEY_E; break;
case 0x46: actualKey = KEY_F; break;
case 0x47: actualKey = KEY_G; break;
case 0x48: actualKey = KEY_H; break;
case 0x49: actualKey = KEY_I; break;
case 0x4A: actualKey = KEY_J; break;
case 0x4B: actualKey = KEY_K; break;
case 0x4C: actualKey = KEY_L; break;
case 0x4D: actualKey = KEY_M; break;
case 0x4E: actualKey = KEY_N; break;
case 0x4F: actualKey = KEY_O; break;
case 0x50: actualKey = KEY_P; break;
case 0x51: actualKey = KEY_Q; break;
case 0x52: actualKey = KEY_R; break;
case 0x53: actualKey = KEY_S; break;
case 0x54: actualKey = KEY_T; break;
case 0x55: actualKey = KEY_U; break;
case 0x56: actualKey = KEY_V; break;
case 0x57: actualKey = KEY_W; break;
case 0x58: actualKey = KEY_X; break;
case 0x59: actualKey = KEY_Y; break;
case 0x5A: actualKey = KEY_Z; break;
}
if (actualKey > -1)
currentKeyState[actualKey] = action;
}
void UWPRegisterClick(int btn, char action)
{
currentMouseState[btn] = action;
}
void UWPScrollWheel(int delta)
{
currentMouseWheelY += delta;
}
void UWPMousePosition(float x, float y)
{
mousePosition.x = x;
mousePosition.y = y;
}
void UWPMarkCursor(bool hidden)
{
cursorHidden = hidden;
}
void UWPGamepadActive(int gamepad, bool active)
{
if (gamepad < MAX_GAMEPADS)
gamepadReady[gamepad] = active;
}
void UWPGamepadButton(int gamepad, int button, char action)
{
if (gamepad < MAX_GAMEPADS && button < MAX_GAMEPAD_BUTTONS)
currentGamepadState[gamepad][button] = action;
}
void UWPGamepadAxis(int gamepad, int axis, float value)
{
if (gamepad < MAX_GAMEPADS && axis < MAX_GAMEPAD_AXIS)
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
static void LogoAnimation(void)
{

View File

@ -872,68 +872,6 @@ 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
@ -976,24 +914,6 @@ RLAPI const char *GetMonitorName(int monitor); // Get the hum
RLAPI const char *GetClipboardText(void); // Get clipboard text content
RLAPI void SetClipboardText(const char *text); // Set clipboard text content
// UWP-related functions
#if defined(PLATFORM_UWP)
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 UWPGamepadActive(int gamepad, bool active);
RLAPI void UWPGamepadButton(int gamepad, int button, char action);
RLAPI void UWPGamepadAxis(int gamepad, int axis, float value);
RLAPI bool UWPHasMessages();
RLAPI UWPMessage* UWPGetMessage();
//RLAPI void UWPSendMessage(UWPMessage* msg); //Do we need to send messages?
#endif
// Cursor-related functions
RLAPI void ShowCursor(void); // Shows cursor
RLAPI void HideCursor(void); // Hides cursor

View File

@ -202,3 +202,88 @@ static int android_close(void *cookie)
return 0;
}
#endif
#if defined(PLATFORM_UWP)
#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 int UWPInMessageId = -1; //Stores the last index for the message
static UWPMessage* UWPInMessages[MAX_MESSAGES]; //Messages in from UWP
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->Bool0 = false;
return msg;
}
void DeleteUWPMessage(UWPMessage* msg)
{
RL_FREE(msg);
}
bool UWPHasMessages(void)
{
return UWPOutMessageId > -1;
}
UWPMessage* UWPGetMessage(void)
{
if (UWPHasMessages())
{
return UWPOutMessages[UWPOutMessageId--];
}
return NULL;
}
void UWPSendMessage(UWPMessage* msg)
{
if (UWPInMessageId + 1 < MAX_MESSAGES) {
UWPInMessageId++;
UWPInMessages[UWPInMessageId] = msg;
}
else
{
TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message.");
}
}
void SendMessageToUWP(UWPMessage* msg)
{
if (UWPOutMessageId + 1 < MAX_MESSAGES) {
UWPOutMessageId++;
UWPOutMessages[UWPOutMessageId] = msg;
}
else
{
TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message.");
}
}
bool HasMessageFromUWP(void)
{
return UWPInMessageId > -1;
}
UWPMessage* GetMessageFromUWP(void)
{
if (HasMessageFromUWP())
{
return UWPInMessages[UWPInMessageId--];
}
return NULL;
}
#endif

View File

@ -59,6 +59,74 @@ void InitAssetManager(AAssetManager *manager); // Initialize asset manager from
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen()
#endif
#if defined(PLATFORM_UWP)
// UWP Messages System
typedef enum
{
None = 0,
//Send
ShowMouse,
HideMouse,
LockMouse,
UnlockMouse,
SetMouseLocation, //Vector0 (pos)
//Recieve (Into C)
RegisterKey, //Int0 (key), Char0 (status)
RegisterClick, //Int0 (button), Char0 (status)
ScrollWheelUpdate, //Int0 (delta)
UpdateMouseLocation, //Vector0 (pos)
MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not)
MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status)
MarkGamepadAxis, //Int0 (gamepad), int1 (axis), Float0 (value)
} 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;
//Bool parameters
bool Bool0;
//More parameters can be added and fed to functions
} UWPMessage;
//Allocate UWP Message
RLAPI UWPMessage* CreateUWPMessage(void);
//Free UWP Message
RLAPI void DeleteUWPMessage(UWPMessage* msg);
//Get messages into C++
RLAPI bool UWPHasMessages(void);
RLAPI UWPMessage* UWPGetMessage(void);
RLAPI void UWPSendMessage(UWPMessage* msg);
//For C to call
#ifndef _cplusplus //Hide from C++ code
void SendMessageToUWP(UWPMessage* msg);
bool HasMessageFromUWP(void);
UWPMessage* GetMessageFromUWP(void);
#endif
#endif
#ifdef __cplusplus
}
#endif