Lots of UWP work, added keyboard and mouse press support. Still need to finish scroll wheel, mouse position and cursor hiding, plus other stuff that I haven't seen yet.

This commit is contained in:
Reece Mackie 2019-04-24 20:54:42 +01:00
parent da3e498f2d
commit 47850c1e6d
4 changed files with 146 additions and 74 deletions

View File

@ -131,15 +131,15 @@ void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args)
{
if (args->CurrentPoint->Properties->IsLeftButtonPressed)
{
currentMouseState[MOUSE_LEFT_BUTTON] = 1;
UWPRegisterClick(MOUSE_LEFT_BUTTON, 1);
}
if (args->CurrentPoint->Properties->IsRightButtonPressed)
{
currentMouseState[MOUSE_RIGHT_BUTTON] = 1;
UWPRegisterClick(MOUSE_RIGHT_BUTTON, 1);
}
if (args->CurrentPoint->Properties->IsMiddleButtonPressed)
{
currentMouseState[MOUSE_MIDDLE_BUTTON] = 1;
UWPRegisterClick(MOUSE_MIDDLE_BUTTON, 1);
}
}
@ -147,15 +147,15 @@ void App::PointerReleased(CoreWindow ^window, PointerEventArgs^ args)
{
if (!(args->CurrentPoint->Properties->IsLeftButtonPressed))
{
currentMouseState[MOUSE_LEFT_BUTTON] = 0;
UWPRegisterClick(MOUSE_LEFT_BUTTON, 0);
}
if (!(args->CurrentPoint->Properties->IsRightButtonPressed))
{
currentMouseState[MOUSE_RIGHT_BUTTON] = 0;
UWPRegisterClick(MOUSE_RIGHT_BUTTON, 0);
}
if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed))
{
currentMouseState[MOUSE_MIDDLE_BUTTON] = 0;
UWPRegisterClick(MOUSE_MIDDLE_BUTTON, 0);
}
}
@ -173,19 +173,16 @@ void App::MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows:
void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args)
{
ProcessKeyEvent(args->VirtualKey, 1);
//ProcessKeyEvent(args->VirtualKey, 1);
UWPRegisterKey((int)args->VirtualKey, 1);
}
void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args)
{
ProcessKeyEvent(args->VirtualKey, 0);
}
//ProcessKeyEvent(args->VirtualKey, 0);
/* REIMPLEMENTED FROM CORE.C */
// Get one key state
static bool GetKeyStatus(int key)
{
return currentKeyState[key];
UWPRegisterKey((int)args->VirtualKey, 0);
}
// Show mouse cursor
@ -226,18 +223,9 @@ void UWPDisableCursor()
toggleCursorLock = true;
}
// Get one mouse button state
static bool UWPGetMouseButtonStatus(int button)
{
return currentMouseState[button];
}
// Poll (store) all input events
void UWP_PollInput()
{
// Register previous keyboard state
for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k];
// Process Mouse
{
// Register previous mouse states
@ -320,43 +308,6 @@ void UWP_PollInput()
}
// The following functions were ripped from core.c and have *no additional work done on them*
// Detect if a key has been pressed once
bool UWPIsKeyPressed(int key)
{
bool pressed = false;
if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true;
else pressed = false;
return pressed;
}
// Detect if a key is being pressed (key held down)
bool UWPIsKeyDown(int key)
{
if (GetKeyStatus(key) == 1) return true;
else return false;
}
// Detect if a key has been released once
bool UWPIsKeyReleased(int key)
{
bool released = false;
if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
else released = false;
return released;
}
// Detect if a key is NOT being pressed (key not held down)
bool UWPIsKeyUp(int key)
{
if (GetKeyStatus(key) == 0) return true;
else return false;
}
/* OTHER CODE */
// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
@ -461,23 +412,26 @@ void App::Run()
DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE);
if (UWPIsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE);
if (IsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE);
if (UWPIsKeyPressed(KEY_A))
if (IsKeyPressed(KEY_A))
{
posX -= 50;
UWPEnableCursor();
}
if (UWPIsKeyPressed(KEY_D))
if (IsKeyPressed(KEY_D))
{
posX += 50;
UWPDisableCursor();
}
if (currentKeyState[KEY_LEFT_ALT]) DrawRectangle(250, 250, 20, 20, BLACK);
if (currentKeyState[KEY_BACKSPACE]) DrawRectangle(280, 250, 20, 20, BLACK);
if (currentMouseState[MOUSE_LEFT_BUTTON]) DrawRectangle(280, 250, 20, 20, BLACK);
if (IsKeyDown(KEY_LEFT_ALT)) //Unable to get working on my PC
DrawRectangle(250, 250, 20, 20, BLACK);
if (IsKeyDown(KEY_BACKSPACE))
DrawRectangle(280, 250, 20, 20, BLACK);
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
DrawRectangle(280, 250, 20, 20, BLACK);
static int pos = 0;
pos -= currentMouseWheelY;

View File

@ -87,7 +87,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>PLATFORM_UWP;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkLibraryDependencies>
@ -100,7 +100,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4453;28204</DisableSpecificWarnings>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>PLATFORM_UWP;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Default</CompileAs>
<OmitDefaultLibName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</OmitDefaultLibName>
</ClCompile>

View File

@ -486,10 +486,6 @@ static void InitGamepad(void); // Init raw gamepad inpu
static void *GamepadThread(void *arg); // Mouse reading thread
#endif
#if defined(PLATFORM_UWP)
// TODO: Define functions required to manage inputs
#endif
#if defined(_WIN32)
// NOTE: We include Sleep() function signature here to avoid windows.h inclusion
void __stdcall Sleep(unsigned long msTimeout); // Required for Wait()
@ -3028,7 +3024,7 @@ static bool GetKeyStatus(int key)
// NOTE: Android supports up to 260 keys
if (key < 0 || key > 260) return false;
else return currentKeyState[key];
#elif defined(PLATFORM_RPI)
#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
// NOTE: Keys states are filled in PollInputEvents()
if (key < 0 || key > 511) return false;
else return currentKeyState[key];
@ -3043,7 +3039,7 @@ static bool GetMouseButtonStatus(int button)
#elif defined(PLATFORM_ANDROID)
// TODO: Check for virtual mouse?
return false;
#elif defined(PLATFORM_RPI)
#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
// NOTE: Mouse buttons states are filled in PollInputEvents()
return currentMouseState[button];
#endif
@ -3089,6 +3085,22 @@ static void PollInputEvents(void)
}
#endif
#if defined(PLATFORM_UWP)
// Register previous keys states
for (int i = 0; i < 512; i++)previousKeyState[i] = currentKeyState[i];
// Register previous mouse states
previousMouseWheelY = currentMouseWheelY;
currentMouseWheelY = 0;
for (int i = 0; i < 3; i++)
{
previousMouseState[i] = currentMouseState[i];
}
#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// Mouse input polling
double mouseX;
@ -4573,6 +4585,102 @@ static void *GamepadThread(void *arg)
}
#endif // PLATFORM_RPI
#if defined(PLATFORM_UWP)
void UWPRegisterKey(int key, int 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 UWPMouseMovement(float x, float y) {
mousePosition.x += x;
mousePosition.y += y;
}
void UWPMarkCursor(bool hidden) {
cursorHidden = hidden;
}
#endif
// Plays raylib logo appearing animation
static void LogoAnimation(void)
{

View File

@ -913,6 +913,16 @@ 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, int action);
RLAPI void UWPRegisterClick(int btn, char action);
RLAPI void UWPScrollWheel(int delta);
RLAPI void UWPMouseMovement(float x, float y);
RLAPI void UWPMarkCursor(bool hidden);
//Gamepad functionality?
#endif
// Cursor-related functions
RLAPI void ShowCursor(void); // Shows cursor
RLAPI void HideCursor(void); // Hides cursor