From b6b58991e689d9f5a6fa18ff8ea9b2162d1f7d62 Mon Sep 17 00:00:00 2001 From: Ray San Date: Fri, 10 Nov 2017 12:37:53 +0100 Subject: Working on UWP support Support Universal Windows Platform (UWP): - Windows 10 App - Windows Phone - Xbox One --- project/vs2015.UWP/raylib.App.UWP/App.cpp | 174 ++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 project/vs2015.UWP/raylib.App.UWP/App.cpp (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp new file mode 100644 index 00000000..7d98d707 --- /dev/null +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -0,0 +1,174 @@ + +#include "pch.h" +#include "app.h" + +#include "raylib.h" + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Graphics::Display; +using namespace Microsoft::WRL; +using namespace Platform; + +using namespace raylibUWP; + +// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. +inline float ConvertDipsToPixels(float dips, float dpi) +{ + static const float dipsPerInch = 96.0f; + return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. +} + +// Implementation of the IFrameworkViewSource interface, necessary to run our app. +ref class SimpleApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() + { + return ref new App(); + } +}; + +// The main function creates an IFrameworkViewSource for our app, and runs the app. +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto simpleApplicationSource = ref new SimpleApplicationSource(); + CoreApplication::Run(simpleApplicationSource); + + return 0; +} + +App::App() : + mWindowClosed(false), + mWindowVisible(true) +{ +} + +// The first method called when the IFrameworkView is being created. +void App::Initialize(CoreApplicationView^ applicationView) +{ + // Register event handlers for app lifecycle. This example includes Activated, so that we + // can make the CoreWindow active and start rendering on the window. + applicationView->Activated += ref new TypedEventHandler(this, &App::OnActivated); + + // Logic for other event handlers could go here. + // Information about the Suspending and Resuming event handlers can be found here: + // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx + + CoreApplication::Resuming += ref new EventHandler(this, &App::OnResuming); +} + +// Called when the CoreWindow object is created (or re-created). +void App::SetWindow(CoreWindow^ window) +{ + window->SizeChanged += ref new TypedEventHandler(this, &App::OnWindowSizeChanged); + window->VisibilityChanged += ref new TypedEventHandler(this, &App::OnVisibilityChanged); + window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); + currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); + + + // The CoreWindow has been created, so EGL can be initialized. + InitWindow(800, 450, (EGLNativeWindowType)window); +} + +// Initializes scene resources +void App::Load(Platform::String^ entryPoint) +{ + // InitWindow() --> rlglInit() +} + +// This method is called after the window becomes active. +void App::Run() +{ + while (!mWindowClosed) + { + if (mWindowVisible) + { + // Update + + // Draw + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangle(100, 100, 400, 100, RED); + + DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + + EndDrawing(); + + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + } + else + { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + } + + CloseWindow(); +} + +// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView +// class is torn down while the app is in the foreground. +void App::Uninitialize() +{ + // CloseWindow(); +} + +// Application lifecycle event handler. +void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) +{ + // Run() won't start until the CoreWindow is activated. + CoreWindow::GetForCurrentThread()->Activate(); +} + +void App::OnResuming(Object^ sender, Object^ args) +{ + // Restore any data or state that was unloaded on suspend. By default, data + // and state are persisted when resuming from suspend. Note that this event + // does not occur if the app was previously terminated. +} + +void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) +{ + // TODO: Update window and render area size + //m_deviceResources->SetLogicalSize(Size(sender->Bounds.Width, sender->Bounds.Height)); + //m_main->UpdateForWindowSizeChange(); +} + +// Window event handlers. +void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) +{ + mWindowVisible = args->Visible; + + // raylib core has the variable windowMinimized to register state, + // it should be modifyed by this event... +} + +void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) +{ + mWindowClosed = true; + + // raylib core has the variable windowShouldClose to register state, + // it should be modifyed by this event... +} + +void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) +{ + //m_deviceResources->SetDpi(sender->LogicalDpi); + //m_main->UpdateForWindowSizeChange(); +} + +void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) +{ + //m_deviceResources->SetCurrentOrientation(sender->CurrentOrientation); + //m_main->UpdateForWindowSizeChange(); +} -- cgit v1.2.3 From 9dbd30c44bd64fbefc78dce32128e196cb7f0da5 Mon Sep 17 00:00:00 2001 From: Sam C Date: Wed, 29 Nov 2017 20:43:41 -0800 Subject: Add UWP gamepad input polling Add a basic UWP gampead poll function with zero changes to code outside of App.cpp --- project/vs2015.UWP/raylib.App.UWP/App.cpp | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp index 7d98d707..8fe9bc19 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.cpp +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -10,12 +10,77 @@ using namespace Windows::UI::Core; using namespace Windows::UI::Input; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; +using namespace Windows::Gaming::Input; using namespace Windows::Graphics::Display; using namespace Microsoft::WRL; using namespace Platform; using namespace raylibUWP; +/* GAMEPAD CODE */ + +// Stand-ins for "core.c" variables +#define MAX_GAMEPADS 4 // Max number of gamepads supported +#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) +#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) + +static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready +static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis 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 + +void UWP_PollInput() +{ + // Check if gamepads are ready + for (int i = 0; i < MAX_GAMEPADS; i++) + { + // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of + // 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. + + gamepadReady[i] = (i < Gamepad::Gamepads->Size); + } + + // Get current gamepad state + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (gamepadReady[i]) + { + // Register previous gamepad states + for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; + + // Get current gamepad state + auto gamepad = Gamepad::Gamepads->GetAt(i); + 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 doing this + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP + + // Get current axis state + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; + } + } +} + +/* OTHER CODE*/ + // Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. inline float ConvertDipsToPixels(float dips, float dpi) { -- cgit v1.2.3 From c801830bcc55380a23a32d9d11be106f4c2e50b6 Mon Sep 17 00:00:00 2001 From: Sam C Date: Thu, 28 Dec 2017 10:44:03 -0800 Subject: Add keyboard input --- .../vs2015.UWP/raylib.App.UWP/ARM/Release/App.obj | Bin 0 -> 1568963 bytes .../vs2015.UWP/raylib.App.UWP/ARM/Release/pch.obj | Bin 0 -> 1413762 bytes .../vs2015.UWP/raylib.App.UWP/ARM/Release/pch.pch | Bin 0 -> 31522816 bytes .../Release/raylib.App.UWP.tlog/CL.command.1.tlog | Bin 0 -> 11934 bytes .../ARM/Release/raylib.App.UWP.tlog/CL.read.1.tlog | Bin 0 -> 48668 bytes .../Release/raylib.App.UWP.tlog/CL.write.1.tlog | Bin 0 -> 1254 bytes .../raylib.App.UWP.tlog/link.command.1.tlog | 1 + .../Release/raylib.App.UWP.tlog/link.read.1.tlog | 1 + .../Release/raylib.App.UWP.tlog/link.write.1.tlog | 1 + .../raylib.App.UWP.lastbuildstate | 2 + .../Release/raylib.App.UWP.tlog/unsuccessfulbuild | 0 project/vs2015.UWP/raylib.App.UWP/App.cpp | 169 ++++++++++++++++++++- project/vs2015.UWP/raylib.App.UWP/App.h | 4 + project/vs2015.UWP/raylib.App.UWP/packages.config | 2 +- .../raylib.App.UWP/raylib.App.UWP.vcxproj | 21 ++- project/vs2015.UWP/raylib.UWP.sln | 2 +- project/vs2015.UWP/raylib/Release/audio.obj | Bin 0 -> 253461 bytes project/vs2015.UWP/raylib/Release/core.obj | Bin 0 -> 244780 bytes project/vs2015.UWP/raylib/Release/models.obj | Bin 0 -> 313882 bytes project/vs2015.UWP/raylib/Release/raylib.lib | Bin 0 -> 2226394 bytes .../raylib/Release/raylib.tlog/CL.command.1.tlog | Bin 0 -> 9678 bytes .../raylib/Release/raylib.tlog/CL.read.1.tlog | Bin 0 -> 40304 bytes .../raylib/Release/raylib.tlog/CL.write.1.tlog | Bin 0 -> 5020 bytes .../Release/raylib.tlog/Lib-link.read.1.tlog | Bin 0 -> 3130 bytes .../Release/raylib.tlog/Lib-link.write.1.tlog | Bin 0 -> 1644 bytes .../raylib/Release/raylib.tlog/lib.command.1.tlog | Bin 0 -> 2008 bytes .../Release/raylib.tlog/raylib.lastbuildstate | 2 + project/vs2015.UWP/raylib/Release/rlgl.obj | Bin 0 -> 221449 bytes project/vs2015.UWP/raylib/Release/shapes.obj | Bin 0 -> 44106 bytes project/vs2015.UWP/raylib/Release/stb_vorbis.obj | Bin 0 -> 262532 bytes project/vs2015.UWP/raylib/Release/text.obj | Bin 0 -> 295910 bytes project/vs2015.UWP/raylib/Release/textures.obj | Bin 0 -> 395021 bytes project/vs2015.UWP/raylib/Release/utils.obj | Bin 0 -> 120783 bytes project/vs2015.UWP/raylib/raylib.vcxproj | 63 ++++++++ 34 files changed, 252 insertions(+), 16 deletions(-) create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/App.obj create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.obj create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.pch create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.command.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.read.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.write.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.command.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.read.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.write.1.tlog create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/raylib.App.UWP.lastbuildstate create mode 100644 project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/unsuccessfulbuild create mode 100644 project/vs2015.UWP/raylib/Release/audio.obj create mode 100644 project/vs2015.UWP/raylib/Release/core.obj create mode 100644 project/vs2015.UWP/raylib/Release/models.obj create mode 100644 project/vs2015.UWP/raylib/Release/raylib.lib create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/CL.command.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/CL.read.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/CL.write.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.read.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.write.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/lib.command.1.tlog create mode 100644 project/vs2015.UWP/raylib/Release/raylib.tlog/raylib.lastbuildstate create mode 100644 project/vs2015.UWP/raylib/Release/rlgl.obj create mode 100644 project/vs2015.UWP/raylib/Release/shapes.obj create mode 100644 project/vs2015.UWP/raylib/Release/stb_vorbis.obj create mode 100644 project/vs2015.UWP/raylib/Release/text.obj create mode 100644 project/vs2015.UWP/raylib/Release/textures.obj create mode 100644 project/vs2015.UWP/raylib/Release/utils.obj (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/App.obj b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/App.obj new file mode 100644 index 00000000..1307178b Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/App.obj differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.obj b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.obj new file mode 100644 index 00000000..66a2b475 Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.obj differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.pch b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.pch new file mode 100644 index 00000000..edd57b0f Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/pch.pch differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.command.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.command.1.tlog new file mode 100644 index 00000000..8ee21549 Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.command.1.tlog differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.read.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.read.1.tlog new file mode 100644 index 00000000..c7e85852 Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.read.1.tlog differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.write.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.write.1.tlog new file mode 100644 index 00000000..d9d745a6 Binary files /dev/null and b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/CL.write.1.tlog differ diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.command.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.command.1.tlog new file mode 100644 index 00000000..46b134b1 --- /dev/null +++ b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.command.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.read.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.read.1.tlog new file mode 100644 index 00000000..46b134b1 --- /dev/null +++ b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.read.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.write.1.tlog b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.write.1.tlog new file mode 100644 index 00000000..46b134b1 --- /dev/null +++ b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/link.write.1.tlog @@ -0,0 +1 @@ +ÿþ \ No newline at end of file diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/raylib.App.UWP.lastbuildstate b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/raylib.App.UWP.lastbuildstate new file mode 100644 index 00000000..a690e0ae --- /dev/null +++ b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/raylib.App.UWP.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.14393.0 +Release|ARM|C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\| diff --git a/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/unsuccessfulbuild b/project/vs2015.UWP/raylib.App.UWP/ARM/Release/raylib.App.UWP.tlog/unsuccessfulbuild new file mode 100644 index 00000000..e69de29b diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp index 8fe9bc19..2b3c2d9a 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.cpp +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -23,14 +23,23 @@ using namespace raylibUWP; #define MAX_GAMEPADS 4 // Max number of gamepads supported #define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) #define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) - static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis 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 +//#define MAX_KEYS 512 +static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state +static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state + void UWP_PollInput() { + // Register previous keyboard state + for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; + // NOTE: Since UWP updates key state while our game is processing, the current key state really is the CURRENT, most up to date key state - not the key state from last frame. + // If we register the current key state as the last key state right before processing the frame, prev and current keyboard states will nearly always be identical. + // In the future, we should either create a third cache for windows to write key changes into, or better yet, just poll the keyboard using CoreWindow's GetKeyState https://docs.microsoft.com/en-us/uwp/api/windows.ui.core.corewindow#Windows_UI_Core_CoreWindow_GetKeyState_Windows_System_VirtualKey_ + // Check if gamepads are ready for (int i = 0; i < MAX_GAMEPADS; i++) { @@ -77,9 +86,138 @@ void UWP_PollInput() gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; } } + +} + +// Stand-ins for "core.c" variables + + // NOTE(sam): We could also poll for all keys every frame using CoreWindow's GetKeyState https://docs.microsoft.com/en-us/uwp/api/windows.ui.core.corewindow#Windows_UI_Core_CoreWindow_GetKeyState_Windows_System_VirtualKey_ + // Helper to process key events +inline void ProcessKeyEvent(Windows::System::VirtualKey key, int action) +{ + using Windows::System::VirtualKey; + switch (key) + { + case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break; + case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break; + case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break; + case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break; + case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break; + case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break; + case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break; + case VirtualKey::Up: currentKeyState[KEY_UP] = action; break; + case VirtualKey::F1: currentKeyState[KEY_F1] = action; break; + case VirtualKey::F2: currentKeyState[KEY_F2] = action; break; + case VirtualKey::F3: currentKeyState[KEY_F4] = action; break; + case VirtualKey::F4: currentKeyState[KEY_F5] = action; break; + case VirtualKey::F5: currentKeyState[KEY_F6] = action; break; + case VirtualKey::F6: currentKeyState[KEY_F7] = action; break; + case VirtualKey::F7: currentKeyState[KEY_F8] = action; break; + case VirtualKey::F8: currentKeyState[KEY_F9] = action; break; + case VirtualKey::F9: currentKeyState[KEY_F10] = action; break; + case VirtualKey::F10: currentKeyState[KEY_F11] = action; break; + case VirtualKey::F11: currentKeyState[KEY_F12] = action; break; + case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break; + case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break; + case VirtualKey::LeftMenu: currentKeyState[KEY_LEFT_ALT] = action; break; // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown + case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break; + case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break; + case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break; + case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break; + case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break; + case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break; + case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break; + case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break; + case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break; + case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break; + case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break; + case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break; + case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break; + case VirtualKey::A: currentKeyState[KEY_A] = action; break; + case VirtualKey::B: currentKeyState[KEY_B] = action; break; + case VirtualKey::C: currentKeyState[KEY_C] = action; break; + case VirtualKey::D: currentKeyState[KEY_D] = action; break; + case VirtualKey::E: currentKeyState[KEY_E] = action; break; + case VirtualKey::F: currentKeyState[KEY_F] = action; break; + case VirtualKey::G: currentKeyState[KEY_G] = action; break; + case VirtualKey::H: currentKeyState[KEY_H] = action; break; + case VirtualKey::I: currentKeyState[KEY_I] = action; break; + case VirtualKey::J: currentKeyState[KEY_J] = action; break; + case VirtualKey::K: currentKeyState[KEY_K] = action; break; + case VirtualKey::L: currentKeyState[KEY_L] = action; break; + case VirtualKey::M: currentKeyState[KEY_M] = action; break; + case VirtualKey::N: currentKeyState[KEY_N] = action; break; + case VirtualKey::O: currentKeyState[KEY_O] = action; break; + case VirtualKey::P: currentKeyState[KEY_P] = action; break; + case VirtualKey::Q: currentKeyState[KEY_Q] = action; break; + case VirtualKey::R: currentKeyState[KEY_R] = action; break; + case VirtualKey::S: currentKeyState[KEY_S] = action; break; + case VirtualKey::T: currentKeyState[KEY_T] = action; break; + case VirtualKey::U: currentKeyState[KEY_U] = action; break; + case VirtualKey::V: currentKeyState[KEY_V] = action; break; + case VirtualKey::W: currentKeyState[KEY_W] = action; break; + case VirtualKey::X: currentKeyState[KEY_X] = action; break; + case VirtualKey::Y: currentKeyState[KEY_Y] = action; break; + case VirtualKey::Z: currentKeyState[KEY_Z] = action; break; + + } +} + +void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) +{ + ProcessKeyEvent(args->VirtualKey, 1); +} + +void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) +{ + ProcessKeyEvent(args->VirtualKey, 0); +} + +// The following functions were reimplemented for UWP from core.c +static bool GetKeyStatus(int key) +{ + return currentKeyState[key]; +} + +// The following functions were ripped from core.c +// 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; } -/* OTHER CODE*/ +// 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. inline float ConvertDipsToPixels(float dips, float dpi) @@ -139,6 +277,8 @@ void App::SetWindow(CoreWindow^ window) currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); + window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); + window->KeyUp += ref new TypedEventHandler(this, &App::OnKeyUp); // The CoreWindow has been created, so EGL can be initialized. InitWindow(800, 450, (EGLNativeWindowType)window); @@ -150,6 +290,8 @@ void App::Load(Platform::String^ entryPoint) // InitWindow() --> rlglInit() } +static int posX = 100; +static int posY = 100; // This method is called after the window becomes active. void App::Run() { @@ -157,18 +299,33 @@ void App::Run() { if (mWindowVisible) { - // Update - + // Draw BeginDrawing(); ClearBackground(RAYWHITE); - - DrawRectangle(100, 100, 400, 100, RED); + + + posX += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_X] * 5; + posY += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_Y] * -5; + DrawRectangle(posX, posY, 400, 100, RED); DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + + if(UWPIsKeyDown(KEY_S)) + { + DrawCircle(100, 100, 100, BLUE); + } + + if(UWPIsKeyPressed(KEY_A)) + { + posX -= 50; + } + EndDrawing(); + // Update + UWP_PollInput(); // TODO: Move to beginning of frame - currently at end of frame to accomodate keyboard callback CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); } diff --git a/project/vs2015.UWP/raylib.App.UWP/App.h b/project/vs2015.UWP/raylib.App.UWP/App.h index 3f27eeb0..66de6cc7 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.h +++ b/project/vs2015.UWP/raylib.App.UWP/App.h @@ -33,6 +33,10 @@ namespace raylibUWP void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + // Input Event Handlers + void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); + void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); + private: bool mWindowClosed; diff --git a/project/vs2015.UWP/raylib.App.UWP/packages.config b/project/vs2015.UWP/raylib.App.UWP/packages.config index 4a5c0b55..70c3dea0 100644 --- a/project/vs2015.UWP/raylib.App.UWP/packages.config +++ b/project/vs2015.UWP/raylib.App.UWP/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj index 307c7394..bc7f27d2 100644 --- a/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj +++ b/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj @@ -58,10 +58,14 @@ raylib.App.UWP.TemporaryKey.pfx + + C:\Users\Sam\Documents\GitHub\raylib\release\include;$(IncludePath) + C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\raylib\Debug;$(LibraryPath) + - mincore.lib; %(AdditionalDependencies) - %(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\arm; $(VCInstallDir)\lib\arm + mincore.lib;raylib.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\arm;$(VCInstallDir)\lib\arm @@ -73,7 +77,7 @@ mincore.lib;raylib.lib;%(AdditionalDependencies) - C:\Users\Alumno\Downloads\angle\UWP_OpenGLES2\raylib;%(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\amd64;$(VCInstallDir)\lib\amd64 + C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\x64\Debug;C:\Users\Alumno\Downloads\angle\UWP_OpenGLES2\raylib;%(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\amd64;$(VCInstallDir)\lib\amd64 @@ -85,6 +89,9 @@ 4453;28204 _DEBUG;%(PreprocessorDefinitions) + + true + @@ -122,19 +129,17 @@ Designer - - - + - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/project/vs2015.UWP/raylib.UWP.sln b/project/vs2015.UWP/raylib.UWP.sln index a2772604..b2f95ca2 100644 --- a/project/vs2015.UWP/raylib.UWP.sln +++ b/project/vs2015.UWP/raylib.UWP.sln @@ -36,7 +36,7 @@ Global {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Build.0 = Release|Win32 {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Deploy.0 = Release|Win32 {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|ARM.ActiveCfg = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x64.ActiveCfg = Debug|Win32 + {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x64.ActiveCfg = Debug|x64 {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.ActiveCfg = Debug|Win32 {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.Build.0 = Debug|Win32 {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|ARM.ActiveCfg = Release|Win32 diff --git a/project/vs2015.UWP/raylib/Release/audio.obj b/project/vs2015.UWP/raylib/Release/audio.obj new file mode 100644 index 00000000..78e1f5c6 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/audio.obj differ diff --git a/project/vs2015.UWP/raylib/Release/core.obj b/project/vs2015.UWP/raylib/Release/core.obj new file mode 100644 index 00000000..08f4371a Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/core.obj differ diff --git a/project/vs2015.UWP/raylib/Release/models.obj b/project/vs2015.UWP/raylib/Release/models.obj new file mode 100644 index 00000000..003236ca Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/models.obj differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.lib b/project/vs2015.UWP/raylib/Release/raylib.lib new file mode 100644 index 00000000..c4972753 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.lib differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.command.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.command.1.tlog new file mode 100644 index 00000000..8a9f8e58 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.command.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.read.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.read.1.tlog new file mode 100644 index 00000000..39238ed7 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.read.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.write.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.write.1.tlog new file mode 100644 index 00000000..378c0088 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/CL.write.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.read.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.read.1.tlog new file mode 100644 index 00000000..9800228d Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.read.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.write.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.write.1.tlog new file mode 100644 index 00000000..6960e948 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/Lib-link.write.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/lib.command.1.tlog b/project/vs2015.UWP/raylib/Release/raylib.tlog/lib.command.1.tlog new file mode 100644 index 00000000..1223d942 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/raylib.tlog/lib.command.1.tlog differ diff --git a/project/vs2015.UWP/raylib/Release/raylib.tlog/raylib.lastbuildstate b/project/vs2015.UWP/raylib/Release/raylib.tlog/raylib.lastbuildstate new file mode 100644 index 00000000..ec0d340b --- /dev/null +++ b/project/vs2015.UWP/raylib/Release/raylib.tlog/raylib.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.14393.0 +Release|Win32|C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\| diff --git a/project/vs2015.UWP/raylib/Release/rlgl.obj b/project/vs2015.UWP/raylib/Release/rlgl.obj new file mode 100644 index 00000000..8b711cc9 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/rlgl.obj differ diff --git a/project/vs2015.UWP/raylib/Release/shapes.obj b/project/vs2015.UWP/raylib/Release/shapes.obj new file mode 100644 index 00000000..17ed8470 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/shapes.obj differ diff --git a/project/vs2015.UWP/raylib/Release/stb_vorbis.obj b/project/vs2015.UWP/raylib/Release/stb_vorbis.obj new file mode 100644 index 00000000..f976b17c Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/stb_vorbis.obj differ diff --git a/project/vs2015.UWP/raylib/Release/text.obj b/project/vs2015.UWP/raylib/Release/text.obj new file mode 100644 index 00000000..80feccc5 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/text.obj differ diff --git a/project/vs2015.UWP/raylib/Release/textures.obj b/project/vs2015.UWP/raylib/Release/textures.obj new file mode 100644 index 00000000..5ccd62b7 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/textures.obj differ diff --git a/project/vs2015.UWP/raylib/Release/utils.obj b/project/vs2015.UWP/raylib/Release/utils.obj new file mode 100644 index 00000000..0ef1bbd9 Binary files /dev/null and b/project/vs2015.UWP/raylib/Release/utils.obj differ diff --git a/project/vs2015.UWP/raylib/raylib.vcxproj b/project/vs2015.UWP/raylib/raylib.vcxproj index 7e501995..d48e6260 100644 --- a/project/vs2015.UWP/raylib/raylib.vcxproj +++ b/project/vs2015.UWP/raylib/raylib.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {E89D61AC-55DE-4482-AFD4-DF7242EBC859} @@ -23,6 +31,12 @@ v140 Unicode + + StaticLibrary + true + v140 + Unicode + StaticLibrary false @@ -30,6 +44,13 @@ true Unicode + + StaticLibrary + false + v140 + true + Unicode + @@ -38,13 +59,20 @@ + + + + + + $(SolutionDir)$(ProjectName)\$(Configuration)\ + $(SolutionDir)$(ProjectName)\$(Configuration)\ $(SolutionDir)$(ProjectName)\$(Configuration)\temp @@ -66,6 +94,23 @@ %(AdditionalLibraryDirectories) + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP + CompileAsC + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\include\ANGLE + + + Windows + + + %(AdditionalLibraryDirectories) + + Level3 @@ -84,6 +129,24 @@ true + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP + $(SolutionDir)..\..\src\external\include\ANGLE;$(SolutionDir)..\..\release\include + CompileAsC + + + Windows + true + true + + -- cgit v1.2.3 From 9941a6f4aa32727ea9980ef37139cde26a956804 Mon Sep 17 00:00:00 2001 From: Sam C Date: Thu, 28 Dec 2017 13:00:03 -0800 Subject: Replace keyboard callbacks with polling --- project/vs2015.UWP/raylib.App.UWP/App.cpp | 266 +++++++++++++++--------------- project/vs2015.UWP/raylib.App.UWP/App.h | 4 - 2 files changed, 131 insertions(+), 139 deletions(-) (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp index 2b3c2d9a..19260e04 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.cpp +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -34,143 +34,130 @@ static char currentKeyState[512] = { 0 }; // Contains current frame keyboard s void UWP_PollInput() { - // Register previous keyboard state - for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; - // NOTE: Since UWP updates key state while our game is processing, the current key state really is the CURRENT, most up to date key state - not the key state from last frame. - // If we register the current key state as the last key state right before processing the frame, prev and current keyboard states will nearly always be identical. - // In the future, we should either create a third cache for windows to write key changes into, or better yet, just poll the keyboard using CoreWindow's GetKeyState https://docs.microsoft.com/en-us/uwp/api/windows.ui.core.corewindow#Windows_UI_Core_CoreWindow_GetKeyState_Windows_System_VirtualKey_ - - // Check if gamepads are ready - for (int i = 0; i < MAX_GAMEPADS; i++) + // Process Keyboard { - // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of - // 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. - - gamepadReady[i] = (i < Gamepad::Gamepads->Size); + // Register previous keyboard state + for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; + + // Poll keyboard input + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + using Windows::System::VirtualKey; + // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown + currentKeyState[KEY_SPACE] = (window->GetAsyncKeyState(VirtualKey::Space) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_ESCAPE] = (window->GetAsyncKeyState(VirtualKey::Escape) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_ENTER] = (window->GetAsyncKeyState(VirtualKey::Enter) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_BACKSPACE] = (window->GetAsyncKeyState(VirtualKey::Back) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_RIGHT] = (window->GetAsyncKeyState(VirtualKey::Right) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_LEFT] = (window->GetAsyncKeyState(VirtualKey::Left) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_DOWN] = (window->GetAsyncKeyState(VirtualKey::Down) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_UP] = (window->GetAsyncKeyState(VirtualKey::Up) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F1] = (window->GetAsyncKeyState(VirtualKey::F1) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F2] = (window->GetAsyncKeyState(VirtualKey::F2) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F3] = (window->GetAsyncKeyState(VirtualKey::F3) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F4] = (window->GetAsyncKeyState(VirtualKey::F4) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F5] = (window->GetAsyncKeyState(VirtualKey::F5) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F6] = (window->GetAsyncKeyState(VirtualKey::F6) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F7] = (window->GetAsyncKeyState(VirtualKey::F7) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F8] = (window->GetAsyncKeyState(VirtualKey::F8) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F9] = (window->GetAsyncKeyState(VirtualKey::F9) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F10] = (window->GetAsyncKeyState(VirtualKey::F10) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F11] = (window->GetAsyncKeyState(VirtualKey::F11) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F12] = (window->GetAsyncKeyState(VirtualKey::F12) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_LEFT_SHIFT] = (window->GetAsyncKeyState(VirtualKey::LeftShift) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_LEFT_CONTROL] = (window->GetAsyncKeyState(VirtualKey::LeftControl) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_LEFT_ALT] = (window->GetAsyncKeyState(VirtualKey::LeftMenu) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_RIGHT_SHIFT] = (window->GetAsyncKeyState(VirtualKey::RightShift) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_RIGHT_CONTROL] = (window->GetAsyncKeyState(VirtualKey::RightControl) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_RIGHT_ALT] = (window->GetAsyncKeyState(VirtualKey::RightMenu) == CoreVirtualKeyStates::Down); + + currentKeyState[KEY_ZERO] = (window->GetAsyncKeyState(VirtualKey::Number0) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_ONE] = (window->GetAsyncKeyState(VirtualKey::Number1) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_TWO] = (window->GetAsyncKeyState(VirtualKey::Number2) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_THREE] = (window->GetAsyncKeyState(VirtualKey::Number3) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_FOUR] = (window->GetAsyncKeyState(VirtualKey::Number4) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_FIVE] = (window->GetAsyncKeyState(VirtualKey::Number5) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_SIX] = (window->GetAsyncKeyState(VirtualKey::Number6) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_SEVEN] = (window->GetAsyncKeyState(VirtualKey::Number7) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_EIGHT] = (window->GetAsyncKeyState(VirtualKey::Number8) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_NINE] = (window->GetAsyncKeyState(VirtualKey::Number9) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_A] = (window->GetAsyncKeyState(VirtualKey::A) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_B] = (window->GetAsyncKeyState(VirtualKey::B) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_C] = (window->GetAsyncKeyState(VirtualKey::C) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_D] = (window->GetAsyncKeyState(VirtualKey::D) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_E] = (window->GetAsyncKeyState(VirtualKey::E) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_F] = (window->GetAsyncKeyState(VirtualKey::F) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_G] = (window->GetAsyncKeyState(VirtualKey::G) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_H] = (window->GetAsyncKeyState(VirtualKey::H) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_I] = (window->GetAsyncKeyState(VirtualKey::I) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_J] = (window->GetAsyncKeyState(VirtualKey::J) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_K] = (window->GetAsyncKeyState(VirtualKey::K) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_L] = (window->GetAsyncKeyState(VirtualKey::L) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_M] = (window->GetAsyncKeyState(VirtualKey::M) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_N] = (window->GetAsyncKeyState(VirtualKey::N) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_O] = (window->GetAsyncKeyState(VirtualKey::O) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_P] = (window->GetAsyncKeyState(VirtualKey::P) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_Q] = (window->GetAsyncKeyState(VirtualKey::Q) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_R] = (window->GetAsyncKeyState(VirtualKey::R) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_S] = (window->GetAsyncKeyState(VirtualKey::S) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_T] = (window->GetAsyncKeyState(VirtualKey::T) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_U] = (window->GetAsyncKeyState(VirtualKey::U) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_V] = (window->GetAsyncKeyState(VirtualKey::V) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_W] = (window->GetAsyncKeyState(VirtualKey::W) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_X] = (window->GetAsyncKeyState(VirtualKey::X) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_Y] = (window->GetAsyncKeyState(VirtualKey::Y) == CoreVirtualKeyStates::Down); + currentKeyState[KEY_Z] = (window->GetAsyncKeyState(VirtualKey::Z) == CoreVirtualKeyStates::Down); } - // Get current gamepad state - for (int i = 0; i < MAX_GAMEPADS; i++) + // Process Gamepads { - if (gamepadReady[i]) + // Check if gamepads are ready + for (int i = 0; i < MAX_GAMEPADS; i++) { - // Register previous gamepad states - for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; - - // Get current gamepad state - auto gamepad = Gamepad::Gamepads->GetAt(i); - 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 doing this - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP - - // Get current axis state - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; - } - } - -} - -// Stand-ins for "core.c" variables + // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of + // 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. - // NOTE(sam): We could also poll for all keys every frame using CoreWindow's GetKeyState https://docs.microsoft.com/en-us/uwp/api/windows.ui.core.corewindow#Windows_UI_Core_CoreWindow_GetKeyState_Windows_System_VirtualKey_ - // Helper to process key events -inline void ProcessKeyEvent(Windows::System::VirtualKey key, int action) -{ - using Windows::System::VirtualKey; - switch (key) - { - case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break; - case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break; - case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break; - case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break; - case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break; - case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break; - case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break; - case VirtualKey::Up: currentKeyState[KEY_UP] = action; break; - case VirtualKey::F1: currentKeyState[KEY_F1] = action; break; - case VirtualKey::F2: currentKeyState[KEY_F2] = action; break; - case VirtualKey::F3: currentKeyState[KEY_F4] = action; break; - case VirtualKey::F4: currentKeyState[KEY_F5] = action; break; - case VirtualKey::F5: currentKeyState[KEY_F6] = action; break; - case VirtualKey::F6: currentKeyState[KEY_F7] = action; break; - case VirtualKey::F7: currentKeyState[KEY_F8] = action; break; - case VirtualKey::F8: currentKeyState[KEY_F9] = action; break; - case VirtualKey::F9: currentKeyState[KEY_F10] = action; break; - case VirtualKey::F10: currentKeyState[KEY_F11] = action; break; - case VirtualKey::F11: currentKeyState[KEY_F12] = action; break; - case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break; - case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break; - case VirtualKey::LeftMenu: currentKeyState[KEY_LEFT_ALT] = action; break; // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown - case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break; - case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break; - case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break; - case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break; - case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break; - case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break; - case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break; - case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break; - case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break; - case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break; - case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break; - case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break; - case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break; - case VirtualKey::A: currentKeyState[KEY_A] = action; break; - case VirtualKey::B: currentKeyState[KEY_B] = action; break; - case VirtualKey::C: currentKeyState[KEY_C] = action; break; - case VirtualKey::D: currentKeyState[KEY_D] = action; break; - case VirtualKey::E: currentKeyState[KEY_E] = action; break; - case VirtualKey::F: currentKeyState[KEY_F] = action; break; - case VirtualKey::G: currentKeyState[KEY_G] = action; break; - case VirtualKey::H: currentKeyState[KEY_H] = action; break; - case VirtualKey::I: currentKeyState[KEY_I] = action; break; - case VirtualKey::J: currentKeyState[KEY_J] = action; break; - case VirtualKey::K: currentKeyState[KEY_K] = action; break; - case VirtualKey::L: currentKeyState[KEY_L] = action; break; - case VirtualKey::M: currentKeyState[KEY_M] = action; break; - case VirtualKey::N: currentKeyState[KEY_N] = action; break; - case VirtualKey::O: currentKeyState[KEY_O] = action; break; - case VirtualKey::P: currentKeyState[KEY_P] = action; break; - case VirtualKey::Q: currentKeyState[KEY_Q] = action; break; - case VirtualKey::R: currentKeyState[KEY_R] = action; break; - case VirtualKey::S: currentKeyState[KEY_S] = action; break; - case VirtualKey::T: currentKeyState[KEY_T] = action; break; - case VirtualKey::U: currentKeyState[KEY_U] = action; break; - case VirtualKey::V: currentKeyState[KEY_V] = action; break; - case VirtualKey::W: currentKeyState[KEY_W] = action; break; - case VirtualKey::X: currentKeyState[KEY_X] = action; break; - case VirtualKey::Y: currentKeyState[KEY_Y] = action; break; - case VirtualKey::Z: currentKeyState[KEY_Z] = action; break; + gamepadReady[i] = (i < Gamepad::Gamepads->Size); + } + // Get current gamepad state + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (gamepadReady[i]) + { + // Register previous gamepad states + for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; + + // Get current gamepad state + auto gamepad = Gamepad::Gamepads->GetAt(i); + 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 + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft); + currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP + + // Get current axis state + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger; + gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; + } + } } -} -void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 1); -} - -void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 0); } // The following functions were reimplemented for UWP from core.c @@ -277,9 +264,6 @@ void App::SetWindow(CoreWindow^ window) currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); - window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); - window->KeyUp += ref new TypedEventHandler(this, &App::OnKeyUp); - // The CoreWindow has been created, so EGL can be initialized. InitWindow(800, 450, (EGLNativeWindowType)window); } @@ -292,6 +276,7 @@ void App::Load(Platform::String^ entryPoint) static int posX = 100; static int posY = 100; +static int time = 0; // This method is called after the window becomes active. void App::Run() { @@ -299,7 +284,9 @@ void App::Run() { if (mWindowVisible) { - + // Update + UWP_PollInput(); + // Draw BeginDrawing(); @@ -322,11 +309,20 @@ void App::Run() { posX -= 50; } + if (UWPIsKeyPressed(KEY_D)) + { + posX += 50; + } - EndDrawing(); - // Update - UWP_PollInput(); // TODO: Move to beginning of frame - currently at end of frame to accomodate keyboard callback + if(currentKeyState[KEY_LEFT_ALT]) + DrawRectangle(250, 250, 20, 20, BLACK); + if (currentKeyState[KEY_BACKSPACE]) + DrawRectangle(280, 250, 20, 20, BLACK); + DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); + + EndDrawing(); + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); } else diff --git a/project/vs2015.UWP/raylib.App.UWP/App.h b/project/vs2015.UWP/raylib.App.UWP/App.h index 66de6cc7..3f27eeb0 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.h +++ b/project/vs2015.UWP/raylib.App.UWP/App.h @@ -33,10 +33,6 @@ namespace raylibUWP void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); - // Input Event Handlers - void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - private: bool mWindowClosed; -- cgit v1.2.3 From 1f70a8984a4bb7b97783838d8a3675a087ada33a Mon Sep 17 00:00:00 2001 From: Sam C Date: Fri, 12 Jan 2018 20:56:35 -0800 Subject: Add mouse input and revert keyboard to callback model Mouse input is implemented, with all bells-and-whistles. This includes cursor locking and scroll wheel support. Keyboard input is reverted to a callback model to better reflect the existing architecture in "core.c" --- project/vs2015.UWP/raylib.App.UWP/App.cpp | 334 ++++++++++++++++++++++-------- project/vs2015.UWP/raylib.App.UWP/App.h | 8 + 2 files changed, 258 insertions(+), 84 deletions(-) (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp index 19260e04..375b668c 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.cpp +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -1,5 +1,4 @@ - -#include "pch.h" +#include "pch.h" #include "app.h" #include "raylib.h" @@ -8,6 +7,7 @@ using namespace Windows::ApplicationModel::Core; using namespace Windows::ApplicationModel::Activation; using namespace Windows::UI::Core; using namespace Windows::UI::Input; +using namespace Windows::Devices::Input; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::Gaming::Input; @@ -17,8 +17,13 @@ using namespace Platform; using namespace raylibUWP; -/* GAMEPAD CODE */ +/* +To-do list + - Cache reference to our CoreWindow? + - Implement gestures +*/ +/* INPUT CODE */ // Stand-ins for "core.c" variables #define MAX_GAMEPADS 4 // Max number of gamepads supported #define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) @@ -28,84 +33,234 @@ static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state -//#define MAX_KEYS 512 static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state +//... +static char previousMouseState[3] = { 0 }; // Registers previous mouse button state +static char currentMouseState[3] = { 0 }; // Registers current mouse button state +static int previousMouseWheelY = 0; // Registers previous mouse wheel variation +static int currentMouseWheelY = 0; // Registers current mouse wheel variation + +static bool cursorOnScreen = false; // Tracks if cursor is inside client area +static bool cursorHidden = false; // Track if cursor is hidden + +static Vector2 mousePosition; +static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c" +static bool toggleCursorLock; + +CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type + +// Helper to process key events +void ProcessKeyEvent(Windows::System::VirtualKey key, int action) +{ + using Windows::System::VirtualKey; + switch (key) + { + case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break; + case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break; + case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break; + case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break; + case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break; + case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break; + case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break; + case VirtualKey::Up: currentKeyState[KEY_UP] = action; break; + case VirtualKey::F1: currentKeyState[KEY_F1] = action; break; + case VirtualKey::F2: currentKeyState[KEY_F2] = action; break; + case VirtualKey::F3: currentKeyState[KEY_F4] = action; break; + case VirtualKey::F4: currentKeyState[KEY_F5] = action; break; + case VirtualKey::F5: currentKeyState[KEY_F6] = action; break; + case VirtualKey::F6: currentKeyState[KEY_F7] = action; break; + case VirtualKey::F7: currentKeyState[KEY_F8] = action; break; + case VirtualKey::F8: currentKeyState[KEY_F9] = action; break; + case VirtualKey::F9: currentKeyState[KEY_F10] = action; break; + case VirtualKey::F10: currentKeyState[KEY_F11] = action; break; + case VirtualKey::F11: currentKeyState[KEY_F12] = action; break; + case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break; + case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break; + case VirtualKey::LeftMenu: currentKeyState[KEY_LEFT_ALT] = action; break; // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown + case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break; + case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break; + case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break; + case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break; + case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break; + case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break; + case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break; + case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break; + case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break; + case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break; + case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break; + case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break; + case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break; + case VirtualKey::A: currentKeyState[KEY_A] = action; break; + case VirtualKey::B: currentKeyState[KEY_B] = action; break; + case VirtualKey::C: currentKeyState[KEY_C] = action; break; + case VirtualKey::D: currentKeyState[KEY_D] = action; break; + case VirtualKey::E: currentKeyState[KEY_E] = action; break; + case VirtualKey::F: currentKeyState[KEY_F] = action; break; + case VirtualKey::G: currentKeyState[KEY_G] = action; break; + case VirtualKey::H: currentKeyState[KEY_H] = action; break; + case VirtualKey::I: currentKeyState[KEY_I] = action; break; + case VirtualKey::J: currentKeyState[KEY_J] = action; break; + case VirtualKey::K: currentKeyState[KEY_K] = action; break; + case VirtualKey::L: currentKeyState[KEY_L] = action; break; + case VirtualKey::M: currentKeyState[KEY_M] = action; break; + case VirtualKey::N: currentKeyState[KEY_N] = action; break; + case VirtualKey::O: currentKeyState[KEY_O] = action; break; + case VirtualKey::P: currentKeyState[KEY_P] = action; break; + case VirtualKey::Q: currentKeyState[KEY_Q] = action; break; + case VirtualKey::R: currentKeyState[KEY_R] = action; break; + case VirtualKey::S: currentKeyState[KEY_S] = action; break; + case VirtualKey::T: currentKeyState[KEY_T] = action; break; + case VirtualKey::U: currentKeyState[KEY_U] = action; break; + case VirtualKey::V: currentKeyState[KEY_V] = action; break; + case VirtualKey::W: currentKeyState[KEY_W] = action; break; + case VirtualKey::X: currentKeyState[KEY_X] = action; break; + case VirtualKey::Y: currentKeyState[KEY_Y] = action; break; + case VirtualKey::Z: currentKeyState[KEY_Z] = action; break; + + } +} + +/* CALLBACKS */ +void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args) +{ + if (args->CurrentPoint->Properties->IsLeftButtonPressed) + { + currentMouseState[MOUSE_LEFT_BUTTON] = 1; + } + if (args->CurrentPoint->Properties->IsRightButtonPressed) + { + currentMouseState[MOUSE_RIGHT_BUTTON] = 1; + } + if (args->CurrentPoint->Properties->IsMiddleButtonPressed) + { + currentMouseState[MOUSE_MIDDLE_BUTTON] = 1; + } +} + +void App::PointerReleased(CoreWindow ^window, PointerEventArgs^ args) +{ + if (!(args->CurrentPoint->Properties->IsLeftButtonPressed)) + { + currentMouseState[MOUSE_LEFT_BUTTON] = 0; + } + if (!(args->CurrentPoint->Properties->IsRightButtonPressed)) + { + currentMouseState[MOUSE_RIGHT_BUTTON] = 0; + } + if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed)) + { + currentMouseState[MOUSE_MIDDLE_BUTTON] = 0; + } +} + +void App::PointerWheelChanged(CoreWindow ^window, PointerEventArgs^ args) +{ + // TODO: Scale the MouseWheelDelta to match GLFW's mouse wheel sensitivity. + currentMouseWheelY += args->CurrentPoint->Properties->MouseWheelDelta; +} + +void App::MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) +{ + mouseDelta.x += args->MouseDelta.X; + mouseDelta.y += args->MouseDelta.Y; +} + +void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) +{ + ProcessKeyEvent(args->VirtualKey, 1); +} + +void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) +{ + ProcessKeyEvent(args->VirtualKey, 0); +} + +/* REIMPLEMENTED FROM CORE.C */ +// Get one key state +static bool GetKeyStatus(int key) +{ + return currentKeyState[key]; +} + +// Show mouse cursor +void UWPShowCursor() +{ + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + cursorHidden = false; +} + +// Hides mouse cursor +void UWPHideCursor() +{ + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorHidden = true; +} + +// Set mouse position XY +void UWPSetMousePosition(Vector2 position) +{ + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(position.x + window->Bounds.X, position.y + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + mousePosition = position; +} +// Enables cursor (unlock cursor) +void UWPEnableCursor() +{ + UWPShowCursor(); + UWPSetMousePosition(mousePosition); // The mouse is hidden in the center of the screen - move it to where it should appear + toggleCursorLock = false; +} + +// Disables cursor (lock cursor) +void UWPDisableCursor() +{ + UWPHideCursor(); + toggleCursorLock = true; +} + +// Get one mouse button state +static bool UWPGetMouseButtonStatus(int button) +{ + return currentMouseState[button]; +} + +// Poll (store) all input events void UWP_PollInput() { - // Process Keyboard + // Register previous keyboard state + for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; + + // Process Mouse { - // Register previous keyboard state - for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; + // Register previous mouse states + for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i]; + previousMouseWheelY = currentMouseWheelY; + currentMouseWheelY = 0; - // Poll keyboard input CoreWindow ^window = CoreWindow::GetForCurrentThread(); - using Windows::System::VirtualKey; - // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown - currentKeyState[KEY_SPACE] = (window->GetAsyncKeyState(VirtualKey::Space) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_ESCAPE] = (window->GetAsyncKeyState(VirtualKey::Escape) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_ENTER] = (window->GetAsyncKeyState(VirtualKey::Enter) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_BACKSPACE] = (window->GetAsyncKeyState(VirtualKey::Back) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_RIGHT] = (window->GetAsyncKeyState(VirtualKey::Right) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_LEFT] = (window->GetAsyncKeyState(VirtualKey::Left) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_DOWN] = (window->GetAsyncKeyState(VirtualKey::Down) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_UP] = (window->GetAsyncKeyState(VirtualKey::Up) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F1] = (window->GetAsyncKeyState(VirtualKey::F1) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F2] = (window->GetAsyncKeyState(VirtualKey::F2) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F3] = (window->GetAsyncKeyState(VirtualKey::F3) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F4] = (window->GetAsyncKeyState(VirtualKey::F4) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F5] = (window->GetAsyncKeyState(VirtualKey::F5) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F6] = (window->GetAsyncKeyState(VirtualKey::F6) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F7] = (window->GetAsyncKeyState(VirtualKey::F7) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F8] = (window->GetAsyncKeyState(VirtualKey::F8) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F9] = (window->GetAsyncKeyState(VirtualKey::F9) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F10] = (window->GetAsyncKeyState(VirtualKey::F10) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F11] = (window->GetAsyncKeyState(VirtualKey::F11) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F12] = (window->GetAsyncKeyState(VirtualKey::F12) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_LEFT_SHIFT] = (window->GetAsyncKeyState(VirtualKey::LeftShift) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_LEFT_CONTROL] = (window->GetAsyncKeyState(VirtualKey::LeftControl) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_LEFT_ALT] = (window->GetAsyncKeyState(VirtualKey::LeftMenu) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_RIGHT_SHIFT] = (window->GetAsyncKeyState(VirtualKey::RightShift) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_RIGHT_CONTROL] = (window->GetAsyncKeyState(VirtualKey::RightControl) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_RIGHT_ALT] = (window->GetAsyncKeyState(VirtualKey::RightMenu) == CoreVirtualKeyStates::Down); - - currentKeyState[KEY_ZERO] = (window->GetAsyncKeyState(VirtualKey::Number0) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_ONE] = (window->GetAsyncKeyState(VirtualKey::Number1) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_TWO] = (window->GetAsyncKeyState(VirtualKey::Number2) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_THREE] = (window->GetAsyncKeyState(VirtualKey::Number3) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_FOUR] = (window->GetAsyncKeyState(VirtualKey::Number4) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_FIVE] = (window->GetAsyncKeyState(VirtualKey::Number5) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_SIX] = (window->GetAsyncKeyState(VirtualKey::Number6) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_SEVEN] = (window->GetAsyncKeyState(VirtualKey::Number7) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_EIGHT] = (window->GetAsyncKeyState(VirtualKey::Number8) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_NINE] = (window->GetAsyncKeyState(VirtualKey::Number9) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_A] = (window->GetAsyncKeyState(VirtualKey::A) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_B] = (window->GetAsyncKeyState(VirtualKey::B) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_C] = (window->GetAsyncKeyState(VirtualKey::C) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_D] = (window->GetAsyncKeyState(VirtualKey::D) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_E] = (window->GetAsyncKeyState(VirtualKey::E) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_F] = (window->GetAsyncKeyState(VirtualKey::F) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_G] = (window->GetAsyncKeyState(VirtualKey::G) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_H] = (window->GetAsyncKeyState(VirtualKey::H) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_I] = (window->GetAsyncKeyState(VirtualKey::I) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_J] = (window->GetAsyncKeyState(VirtualKey::J) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_K] = (window->GetAsyncKeyState(VirtualKey::K) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_L] = (window->GetAsyncKeyState(VirtualKey::L) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_M] = (window->GetAsyncKeyState(VirtualKey::M) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_N] = (window->GetAsyncKeyState(VirtualKey::N) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_O] = (window->GetAsyncKeyState(VirtualKey::O) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_P] = (window->GetAsyncKeyState(VirtualKey::P) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_Q] = (window->GetAsyncKeyState(VirtualKey::Q) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_R] = (window->GetAsyncKeyState(VirtualKey::R) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_S] = (window->GetAsyncKeyState(VirtualKey::S) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_T] = (window->GetAsyncKeyState(VirtualKey::T) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_U] = (window->GetAsyncKeyState(VirtualKey::U) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_V] = (window->GetAsyncKeyState(VirtualKey::V) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_W] = (window->GetAsyncKeyState(VirtualKey::W) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_X] = (window->GetAsyncKeyState(VirtualKey::X) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_Y] = (window->GetAsyncKeyState(VirtualKey::Y) == CoreVirtualKeyStates::Down); - currentKeyState[KEY_Z] = (window->GetAsyncKeyState(VirtualKey::Z) == CoreVirtualKeyStates::Down); + if (toggleCursorLock) + { + // Track cursor movement delta, recenter it on the client + mousePosition.x += mouseDelta.x; + mousePosition.y += mouseDelta.y; + + // Why we're not using UWPSetMousePosition here... + // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. + // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition" + Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; + window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); + } + else + { + // Record the cursor's position relative to the client + mousePosition.x = window->PointerPosition.X - window->Bounds.X; + mousePosition.y = window->PointerPosition.Y - window->Bounds.Y; + } + + mouseDelta = { 0 ,0 }; } // Process Gamepads @@ -160,13 +315,7 @@ void UWP_PollInput() } -// The following functions were reimplemented for UWP from core.c -static bool GetKeyStatus(int key) -{ - return currentKeyState[key]; -} - -// The following functions were ripped from core.c +// 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) { @@ -260,6 +409,14 @@ void App::SetWindow(CoreWindow^ window) window->VisibilityChanged += ref new TypedEventHandler(this, &App::OnVisibilityChanged); window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); + window->PointerPressed += ref new TypedEventHandler(this, &App::PointerPressed); + window->PointerReleased += ref new TypedEventHandler(this, &App::PointerReleased); + window->PointerWheelChanged += ref new TypedEventHandler(this, &App::PointerWheelChanged); + window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); + window->KeyUp += ref new TypedEventHandler(this, &App::OnKeyUp); + + Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &App::MouseMoved); + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); @@ -284,9 +441,6 @@ void App::Run() { if (mWindowVisible) { - // Update - UWP_PollInput(); - // Draw BeginDrawing(); @@ -299,6 +453,7 @@ void App::Run() DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE); if(UWPIsKeyDown(KEY_S)) { @@ -308,10 +463,13 @@ void App::Run() if(UWPIsKeyPressed(KEY_A)) { posX -= 50; + UWPEnableCursor(); } if (UWPIsKeyPressed(KEY_D)) { posX += 50; + + UWPDisableCursor(); } if(currentKeyState[KEY_LEFT_ALT]) @@ -319,10 +477,18 @@ void App::Run() if (currentKeyState[KEY_BACKSPACE]) DrawRectangle(280, 250, 20, 20, BLACK); + if (currentMouseState[MOUSE_LEFT_BUTTON]) + DrawRectangle(280, 250, 20, 20, BLACK); + + static int pos = 0; + pos -= currentMouseWheelY; + DrawRectangle(280, pos + 50, 20, 20, BLACK); + DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); EndDrawing(); - + UWP_PollInput(); + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); } else diff --git a/project/vs2015.UWP/raylib.App.UWP/App.h b/project/vs2015.UWP/raylib.App.UWP/App.h index 3f27eeb0..5b58528b 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.h +++ b/project/vs2015.UWP/raylib.App.UWP/App.h @@ -33,6 +33,14 @@ namespace raylibUWP void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + // Input event handlers + void PointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void PointerReleased(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); + void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); + void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args); + void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); + void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); + private: bool mWindowClosed; -- cgit v1.2.3 From e18e8c62766491603d3fe3b52b16c2777ca1264f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 2 Apr 2018 14:49:27 +0200 Subject: Review UWP configuration --- project/vs2015.UWP/raylib.App.UWP/App.cpp | 46 +++++++++++----------- .../vs2015.UWP/raylib.App.UWP/Package.appxmanifest | 2 +- .../raylib.App.UWP/raylib.App.UWP.vcxproj | 2 +- project/vs2015.UWP/raylib/raylib.vcxproj | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) (limited to 'project/vs2015.UWP/raylib.App.UWP/App.cpp') diff --git a/project/vs2015.UWP/raylib.App.UWP/App.cpp b/project/vs2015.UWP/raylib.App.UWP/App.cpp index 375b668c..6ce6915c 100644 --- a/project/vs2015.UWP/raylib.App.UWP/App.cpp +++ b/project/vs2015.UWP/raylib.App.UWP/App.cpp @@ -18,16 +18,21 @@ using namespace Platform; using namespace raylibUWP; /* -To-do list +TODO list: - Cache reference to our CoreWindow? - - Implement gestures + - Implement gestures support */ +// Declare uwpWindow as exter to be used by raylib internals +// NOTE: It should be properly assigned before calling InitWindow() +extern "C" { EGLNativeWindowType uwpWindow; }; + /* INPUT CODE */ // Stand-ins for "core.c" variables #define MAX_GAMEPADS 4 // Max number of gamepads supported #define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) #define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) + static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state @@ -36,7 +41,6 @@ static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Curre static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state -//... static char previousMouseState[3] = { 0 }; // Registers previous mouse button state static char currentMouseState[3] = { 0 }; // Registers current mouse button state static int previousMouseWheelY = 0; // Registers previous mouse wheel variation @@ -46,7 +50,7 @@ static bool cursorOnScreen = false; // Tracks if cursor is inside client static bool cursorHidden = false; // Track if cursor is hidden static Vector2 mousePosition; -static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c" +static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c" static bool toggleCursorLock; CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type @@ -122,7 +126,7 @@ void ProcessKeyEvent(Windows::System::VirtualKey key, int action) } } -/* CALLBACKS */ +// Callbacks void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args) { if (args->CurrentPoint->Properties->IsLeftButtonPressed) @@ -206,6 +210,7 @@ void UWPSetMousePosition(Vector2 position) window->PointerPosition = mousePosScreen; mousePosition = position; } + // Enables cursor (unlock cursor) void UWPEnableCursor() { @@ -321,8 +326,7 @@ bool UWPIsKeyPressed(int key) { bool pressed = false; - if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) - pressed = true; + if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true; else pressed = false; return pressed; @@ -422,7 +426,10 @@ void App::SetWindow(CoreWindow^ window) currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); // The CoreWindow has been created, so EGL can be initialized. - InitWindow(800, 450, (EGLNativeWindowType)window); + + uwpWindow = (EGLNativeWindowType)window; + + InitWindow(800, 450, NULL); } // Initializes scene resources @@ -446,7 +453,6 @@ void App::Run() ClearBackground(RAYWHITE); - posX += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_X] * 5; posY += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_Y] * -5; DrawRectangle(posX, posY, 400, 100, RED); @@ -455,38 +461,32 @@ void App::Run() DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE); - if(UWPIsKeyDown(KEY_S)) - { - DrawCircle(100, 100, 100, BLUE); - } + if (UWPIsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); - if(UWPIsKeyPressed(KEY_A)) + if (UWPIsKeyPressed(KEY_A)) { posX -= 50; UWPEnableCursor(); } + if (UWPIsKeyPressed(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 (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); static int pos = 0; pos -= currentMouseWheelY; - DrawRectangle(280, pos + 50, 20, 20, BLACK); + DrawRectangle(280, pos + 50, 20, 20, BLACK); DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); EndDrawing(); + UWP_PollInput(); CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); diff --git a/project/vs2015.UWP/raylib.App.UWP/Package.appxmanifest b/project/vs2015.UWP/raylib.App.UWP/Package.appxmanifest index f0f56862..56020a50 100644 --- a/project/vs2015.UWP/raylib.App.UWP/Package.appxmanifest +++ b/project/vs2015.UWP/raylib.App.UWP/Package.appxmanifest @@ -4,7 +4,7 @@ raylibUWP - Alumno + raysan5 Assets\StoreLogo.png diff --git a/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj index bc7f27d2..6af9db60 100644 --- a/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj +++ b/project/vs2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj @@ -34,7 +34,7 @@ true Windows Store 10.0.14393.0 - 10.0.10586.0 + 10.0.14393.0 10.0 raylib.App.UWP diff --git a/project/vs2015.UWP/raylib/raylib.vcxproj b/project/vs2015.UWP/raylib/raylib.vcxproj index 32e59759..c1fbca50 100644 --- a/project/vs2015.UWP/raylib/raylib.vcxproj +++ b/project/vs2015.UWP/raylib/raylib.vcxproj @@ -28,7 +28,7 @@ StaticLibrary true - v141 + v140 Unicode -- cgit v1.2.3