summaryrefslogtreecommitdiffhomepage
path: root/project
diff options
context:
space:
mode:
authorSam C <[email protected]>2017-12-28 13:00:03 -0800
committerSam C <[email protected]>2017-12-28 13:00:03 -0800
commit9941a6f4aa32727ea9980ef37139cde26a956804 (patch)
tree9f7681c1f1e14438598c794256966549513dc956 /project
parentc801830bcc55380a23a32d9d11be106f4c2e50b6 (diff)
downloadraylib-9941a6f4aa32727ea9980ef37139cde26a956804.tar.gz
raylib-9941a6f4aa32727ea9980ef37139cde26a956804.zip
Replace keyboard callbacks with polling
Diffstat (limited to 'project')
-rw-r--r--project/vs2015.UWP/raylib.App.UWP/App.cpp266
-rw-r--r--project/vs2015.UWP/raylib.App.UWP/App.h4
2 files changed, 131 insertions, 139 deletions
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<DisplayInformation^, Object^>(this, &App::OnDpiChanged);
currentDisplayInformation->OrientationChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &App::OnOrientationChanged);
- window->KeyDown += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyDown);
- window->KeyUp += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(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;