diff options
| author | Reece Mackie <[email protected]> | 2020-04-30 18:48:39 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-04-30 19:48:39 +0200 |
| commit | 4b0386081037172222d91f0ccca93e5810fed84b (patch) | |
| tree | 3a554752c00af2255a4caecb553e19cd4b37cb7f /projects | |
| parent | 2f454aa4b051d000daab0dd71417a716af095e91 (diff) | |
| download | raylib-4b0386081037172222d91f0ccca93e5810fed84b.tar.gz raylib-4b0386081037172222d91f0ccca93e5810fed84b.zip | |
UWP rework (#1231)
* First draft of UWP rework.
* Read desc
- Moved UWP specific functions to uwp_events.h
- Removed BaseApp.
- Implemented example UWP lifecycle.
* Added GIF recording and screenshot support.
* Character inputs and filesystem stuff
* Fix game closing on Xbox when B is pressed.
* Fix the gamepad binding hack
* Add as many keys as I believe are possible.
* Implemented mouse locking of a sort.
* Remove rogue todo, the rest are for a game dev using this example.
* Implemented touch how I "think" it should work. I cant test this.
* Review.
Diffstat (limited to 'projects')
| -rw-r--r-- | projects/VS2017.UWP/raylib.App.UWP/App.cpp | 522 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.App.UWP/App.h | 53 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 570 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj | 9 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj.filters | 7 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.UWP/packages.config | 4 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj | 15 | ||||
| -rw-r--r-- | projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters | 4 |
8 files changed, 584 insertions, 600 deletions
diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index ad3fdb28..84eb99e5 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -1,26 +1,190 @@ #include "pch.h" #include "app.h" -#include "raylib.h" +#include <Windows.h> + +#include <raylib.h> +#include <uwp_events.h> +#include <gestures.h> + +#include <chrono> +#include <thread> + +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; +using namespace Windows::Graphics::Display; +using namespace Microsoft::WRL; +using namespace Platform; using namespace raylibUWP; +// 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) + // The main function creates an IFrameworkViewSource for our app, and runs the app [Platform::MTAThread] int main(Platform::Array<Platform::String^>^) { - auto appSource = ref new ApplicationSource<App>(); + auto appSource = ref new AppSource(); CoreApplication::Run(appSource); - return 0; } +// App implementation App::App() { - // This does not work... need to fix this. + // Currently, UWP ignores flags... You must implement flag functionality yourself SetConfigFlags(0); +} + +void App::Initialize(Windows::ApplicationModel::Core::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<CoreApplicationView^, IActivatedEventArgs^>(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::Suspending += ref new Windows::Foundation::EventHandler<Windows::ApplicationModel::SuspendingEventArgs^>(this, &App::OnSuspending); + CoreApplication::Resuming += ref new EventHandler<Platform::Object^>(this, &App::OnResuming); + + // Store the app data directory + auto dataPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path; + std::wstring dataPathW(dataPath->Begin()); + static std::string dataPathA(dataPathW.begin(), dataPathW.end()); + UWPSetDataPath(dataPathA.c_str()); +} + +void App::SetWindow(Windows::UI::Core::CoreWindow^ window) +{ + // Hook window events + window->SizeChanged += ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged); + window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged); + + // Hook mouse pointer events + window->PointerPressed += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerPressed); + window->PointerReleased += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased); + window->PointerWheelChanged += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerWheelChanged); + window->PointerMoved += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved); + + // Hook keyboard events. + window->KeyDown += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &App::OnKeyDown); + window->KeyUp += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &App::OnKeyUp); + window->CharacterReceived += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::CharacterReceivedEventArgs^>(this, &raylibUWP::App::OnCharacterReceived); + + // The CoreWindow has been created, we can pass this to raylib for EGL context creation when it's time + UWPSetCoreWindowPtr((void*)window); - Setup(640, 480); + // Register backrequested event to stop window from being closed (Most noticable on XBox when B is pressed) + auto navigation = SystemNavigationManager::GetForCurrentView(); + navigation->BackRequested += ref new Windows::Foundation::EventHandler<Windows::UI::Core::BackRequestedEventArgs^>(this, &raylibUWP::App::OnBackRequested); +} + +void App::Load(Platform::String ^entryPoint) {} // Ignored for this example + +static bool mouseLocked = false; +void App::Run() +{ + // Set up our UWP implementation + UWPSetQueryTimeFunc([]() + { + static auto timeStart = std::chrono::high_resolution_clock::now(); + auto delta = std::chrono::high_resolution_clock::now() - timeStart; + return (double)std::chrono::duration_cast<std::chrono::seconds>(delta).count(); + }); + + UWPSetSleepFunc([](double seconds) { std::this_thread::sleep_for(std::chrono::duration<double>(seconds)); }); + + UWPSetDisplaySizeFunc([](int* width, int* height) + { + // Get display dimensions + DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); + *width = dInfo->ScreenWidthInRawPixels; + *height = dInfo->ScreenHeightInRawPixels; + }); + + UWPSetMouseHideFunc([]() + { + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + }); + + UWPSetMouseShowFunc([]() + { + CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); + }); + + UWPSetMouseLockFunc([]() + { + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + mouseLocked = true; + }); + + UWPSetMouseUnlockFunc([]() + { + CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); + mouseLocked = false; + }); + + UWPSetMouseSetPosFunc([](int x, int y) + { + CoreWindow^ window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(x + window->Bounds.X, y + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + }); + + // Set custom output handle + SetTraceLogCallback([](int logType, const char* text, va_list args) + { + std::string format = text; + + switch (logType) + { + case LOG_TRACE: format = std::string("TRACE: ") + format; break; + case LOG_DEBUG: format = std::string("DEBUG: ") + format; break; + case LOG_INFO: format = std::string("INFO: ") + format; break; + case LOG_WARNING: format = std::string("WARNING: ") + format; break; + case LOG_ERROR: format = std::string("ERROR: ") + format; break; + case LOG_FATAL: format = std::string("FATAL: ") + format; break; + default: break; + } + + char buf[1024]; // TODO: Is this large enough? + vsnprintf(buf, sizeof(buf), format.c_str(), args); + std::string output = std::string(buf) + std::string("\n"); + OutputDebugStringA(output.c_str()); + }); + + // Create window + InitWindow(640, 480, "raylib game example"); + + // Run game loop + while (!WindowShouldClose() && !mSuspended) + { + if (mWindowVisible) + { + PreProcessInputs(); + GameLoop(); + PostProcessInputs(); + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + } else CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + + CloseWindow(); +} + +void App::Uninitialize() +{ + // Do any UWP cleanup here. } static int posX = 100; @@ -28,7 +192,7 @@ static int posY = 100; static int gTime = 0; // This method is called every frame -void App::Update() +void App::GameLoop() { // Update //---------------------------------------------------------------------------------- @@ -76,4 +240,348 @@ void App::Update() EndDrawing(); //---------------------------------------------------------------------------------- -}
\ No newline at end of file +} + +struct GamepadBinding +{ + Gamepad^ Gamepad = nullptr; + bool Ready = false; +}; + +static GamepadBinding gGamepadBindings[MAX_GAMEPADS]; + +void App::PreProcessInputs() +{ + // Here, we will see if we have bound gamepads. If we do we check they are still present. If they aren't present we free the binding. + // if anyone does not have a binding but there is a gamepad available, we will bind it to the first player who is missing a controller. + for (auto i = 0; i < MAX_GAMEPADS; i++) + { + // Ensure that the gamepad bindings are still in tact + if (gGamepadBindings[i].Gamepad != nullptr) + { + // Check the gamepad is present + auto found = false; + for (auto j = 0; j < Gamepad::Gamepads->Size; j++) + { + if (gGamepadBindings[i].Gamepad == Gamepad::Gamepads->GetAt(j)) + { + found = true; + break; + } + } + + if (!found) + { + gGamepadBindings[i].Gamepad = nullptr; + gGamepadBindings[i].Ready = false; + } + else gGamepadBindings[i].Ready = true; + } + + // Now we check to find any unbound gamepads we can use + if (gGamepadBindings[i].Gamepad == nullptr) + { + // Loop over all the attached gamepads + Gamepad^ freeGamepad = nullptr; + for (auto j = 0; j < Gamepad::Gamepads->Size; j++) + { + freeGamepad = Gamepad::Gamepads->GetAt(j); + // Loop over existing bindings + for (auto k = 0; k < MAX_GAMEPADS; k++) + { + if (gGamepadBindings[k].Gamepad == freeGamepad) + freeGamepad = nullptr; + } + + // If we passed all 4, this is a free gamepad + if (freeGamepad != nullptr) break; + } + + if (freeGamepad != nullptr) + { + gGamepadBindings[i].Gamepad = freeGamepad; + gGamepadBindings[i].Ready = true; + } + else gGamepadBindings[i].Ready = false; + } + } + + // Send the active gamepads to raylib + for (int i = 0; i < MAX_GAMEPADS; i++) + { + UWPActivateGamepadEvent(i, gGamepadBindings[i].Ready); + } + + // Get current gamepad state + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (gGamepadBindings[i].Ready) + { + // Get current gamepad state + auto gamepad = gGamepadBindings[i].Gamepad; + auto reading = gamepad->GetCurrentReading(); + + // Register all button presses + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_DOWN, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_LEFT, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_UP, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); + + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_TRIGGER_1, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_TRIGGER_1, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); + + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_LEFT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_RIGHT, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller + + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE, false); // Home button not supported by UWP + + // Register buttons for 2nd triggers (because UWP doesn't count these as buttons but rather axis) + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_TRIGGER_2, (bool)(reading.LeftTrigger > 0.1)); + UWPRegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_TRIGGER_2, (bool)(reading.RightTrigger > 0.1)); + + // Get current axis state + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_X, (float)reading.LeftThumbstickX); + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_X, (float)reading.RightThumbstickX); + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_TRIGGER, (float)reading.LeftTrigger); + UWPRegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_TRIGGER, (float)reading.RightTrigger); + } + } +} + +void App::PostProcessInputs() +{ + /* + * So here's the deal. UWP doesn't officially have mouse locking, so we're doing it ourselves here. + * If anyone has any better ideas on how to implement this feel free! + * This is done after the game loop so getting mouse delta etc. still works. + */ + if (mouseLocked) + { + auto w = GetScreenWidth(); + auto h = GetScreenHeight(); + SetMousePosition(w / 2, h / 2); + } +} + +// Events +void App::OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args) +{ + // Run() won't start until the CoreWindow is activated. + CoreWindow::GetForCurrentThread()->Activate(); +} + +void App::OnResuming(Platform::Object^ sender, Platform::Object^ args) +{ + // TODO: In your game, you will need to load your state here + mSuspended = false; +} + +void App::OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args) +{ + // TODO: In your game, you will need to save your state here + mSuspended = true; +} + +void App::OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) +{ + UWPResizeEvent(args->Size.Width, args->Size.Height); + args->Handled = true; +} + +void App::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) +{ + mWindowVisible = args->Visible; + args->Handled = true; +} + +// Input event handlers +void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) +{ + auto props = args->CurrentPoint->Properties; + auto device = args->CurrentPoint->PointerDevice; + + if (device->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Mouse) + { + if (props->IsLeftButtonPressed) UWPMouseButtonEvent(MOUSE_LEFT_BUTTON, true); + if (props->IsMiddleButtonPressed) UWPMouseButtonEvent(MOUSE_MIDDLE_BUTTON, true); + if (props->IsRightButtonPressed) UWPMouseButtonEvent(MOUSE_RIGHT_BUTTON, true); + } + else if (device->PointerDeviceType == PointerDeviceType::Touch) + { + auto pos = args->CurrentPoint->Position; + UWPGestureTouch(args->CurrentPoint->PointerId, pos.X, pos.Y, true); + } + + args->Handled = true; +} + +void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) +{ + auto props = args->CurrentPoint->Properties; + auto device = args->CurrentPoint->PointerDevice; + + if (device->PointerDeviceType == PointerDeviceType::Mouse) + { + if (!props->IsLeftButtonPressed) UWPMouseButtonEvent(MOUSE_LEFT_BUTTON, false); + if (!props->IsMiddleButtonPressed) UWPMouseButtonEvent(MOUSE_MIDDLE_BUTTON, false); + if (!props->IsRightButtonPressed) UWPMouseButtonEvent(MOUSE_RIGHT_BUTTON, false); + } + else if (device->PointerDeviceType == PointerDeviceType::Touch) + { + auto pos = args->CurrentPoint->Position; + UWPGestureTouch(args->CurrentPoint->PointerId, pos.X, pos.Y, false); + } + + args->Handled = true; +} + +void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) +{ + UWPMouseWheelEvent(args->CurrentPoint->Properties->MouseWheelDelta); + args->Handled = true; +} + +void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) +{ + auto pos = args->CurrentPoint->Position; + if (args->CurrentPoint->PointerDevice->PointerDeviceType == PointerDeviceType::Mouse) + { + UWPMousePosEvent((double)pos.X, (double)pos.Y); + args->Handled = true; + } + else if (args->CurrentPoint->PointerDevice->PointerDeviceType == PointerDeviceType::Touch) + { + UWPGestureMove(args->CurrentPoint->PointerId, pos.X, pos.Y); + } +} + +int App::GetRaylibKey(Windows::System::VirtualKey kVey) +{ + using VK = Windows::System::VirtualKey; + int actualKey = -1; + switch (kVey) + { + case VK::Back: actualKey = KEY_BACKSPACE; break; + case VK::Space: actualKey = KEY_SPACE; break; + case VK::Escape: actualKey = KEY_ESCAPE; break; + case VK::Enter: actualKey = KEY_ENTER; break; + case VK::Delete: actualKey = KEY_DELETE; break; + case VK::Right: actualKey = KEY_RIGHT; break; + case VK::Left: actualKey = KEY_LEFT; break; + case VK::Down: actualKey = KEY_DOWN; break; + case VK::Up: actualKey = KEY_UP; break; + case VK::F1: actualKey = KEY_F1; break; + case VK::F2: actualKey = KEY_F2; break; + case VK::F3: actualKey = KEY_F3; break; + case VK::F4: actualKey = KEY_F4; break; + case VK::F5: actualKey = KEY_F5; break; + case VK::F6: actualKey = KEY_F6; break; + case VK::F7: actualKey = KEY_F7; break; + case VK::F8: actualKey = KEY_F8; break; + case VK::F9: actualKey = KEY_F9; break; + case VK::F10: actualKey = KEY_F10; break; + case VK::F11: actualKey = KEY_F11; break; + case VK::F12: actualKey = KEY_F12; break; + case VK::LeftShift: actualKey = KEY_LEFT_SHIFT; break; + case VK::LeftControl: actualKey = KEY_LEFT_CONTROL; break; + case VK::LeftMenu: actualKey = KEY_LEFT_ALT; break; + case VK::RightShift: actualKey = KEY_RIGHT_SHIFT; break; + case VK::RightControl: actualKey = KEY_RIGHT_CONTROL; break; + case VK::RightMenu: actualKey = KEY_RIGHT_ALT; break; + case VK::Number0: actualKey = KEY_ZERO; break; + case VK::Number1: actualKey = KEY_ONE; break; + case VK::Number2: actualKey = KEY_TWO; break; + case VK::Number3: actualKey = KEY_THREE; break; + case VK::Number4: actualKey = KEY_FOUR; break; + case VK::Number5: actualKey = KEY_FIVE; break; + case VK::Number6: actualKey = KEY_SIX; break; + case VK::Number7: actualKey = KEY_SEVEN; break; + case VK::Number8: actualKey = KEY_EIGHT; break; + case VK::Number9: actualKey = KEY_NINE; break; + case VK::NumberPad0: actualKey = KEY_KP_0; break; + case VK::NumberPad1: actualKey = KEY_KP_1; break; + case VK::NumberPad2: actualKey = KEY_KP_2; break; + case VK::NumberPad3: actualKey = KEY_KP_3; break; + case VK::NumberPad4: actualKey = KEY_KP_4; break; + case VK::NumberPad5: actualKey = KEY_KP_5; break; + case VK::NumberPad6: actualKey = KEY_KP_6; break; + case VK::NumberPad7: actualKey = KEY_KP_7; break; + case VK::NumberPad8: actualKey = KEY_KP_8; break; + case VK::NumberPad9: actualKey = KEY_KP_9; break; + case VK::Decimal: actualKey = KEY_KP_DECIMAL; break; + case VK::Divide: actualKey = KEY_KP_DIVIDE; break; + case VK::Multiply: actualKey = KEY_KP_MULTIPLY; break; + case VK::Subtract: actualKey = KEY_KP_SUBTRACT; break; + case VK::Add: actualKey = KEY_KP_ADD; break; + // UWP Doesn't have a specific keypad enter or equal... + case VK::A: actualKey = KEY_A; break; + case VK::B: actualKey = KEY_B; break; + case VK::C: actualKey = KEY_C; break; + case VK::D: actualKey = KEY_D; break; + case VK::E: actualKey = KEY_E; break; + case VK::F: actualKey = KEY_F; break; + case VK::G: actualKey = KEY_G; break; + case VK::H: actualKey = KEY_H; break; + case VK::I: actualKey = KEY_I; break; + case VK::J: actualKey = KEY_J; break; + case VK::K: actualKey = KEY_K; break; + case VK::L: actualKey = KEY_L; break; + case VK::M: actualKey = KEY_M; break; + case VK::N: actualKey = KEY_N; break; + case VK::O: actualKey = KEY_O; break; + case VK::P: actualKey = KEY_P; break; + case VK::Q: actualKey = KEY_Q; break; + case VK::R: actualKey = KEY_R; break; + case VK::S: actualKey = KEY_S; break; + case VK::T: actualKey = KEY_T; break; + case VK::U: actualKey = KEY_U; break; + case VK::V: actualKey = KEY_V; break; + case VK::W: actualKey = KEY_W; break; + case VK::X: actualKey = KEY_X; break; + case VK::Y: actualKey = KEY_Y; break; + case VK::Z: actualKey = KEY_Z; break; + // I don't think we can have any more + } + return actualKey; +} + +void App::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args) +{ + auto k = GetRaylibKey(args->VirtualKey); + auto controlState = (sender->GetKeyState(Windows::System::VirtualKey::Control) & Windows::UI::Core::CoreVirtualKeyStates::Down) == Windows::UI::Core::CoreVirtualKeyStates::Down; + if (k != -1) { + UWPKeyDownEvent(k, true, controlState); + } + args->Handled = true; +} + +void App::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args) +{ + auto k = GetRaylibKey(args->VirtualKey); + if (k != -1) + UWPKeyDownEvent(k, false, false); + args->Handled = true; +} + +void App::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args) +{ + UWPKeyCharEvent(args->KeyCode); +} + +void App::OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args) +{ + // This simply stops the program from closing. + args->Handled = true; +} + +// AppSource implementation +Windows::ApplicationModel::Core::IFrameworkView ^AppSource::CreateView() +{ + return ref new App(); +} diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.h b/projects/VS2017.UWP/raylib.App.UWP/App.h index 7b96d16e..6cbeadac 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.h +++ b/projects/VS2017.UWP/raylib.App.UWP/App.h @@ -4,22 +4,49 @@ #include "pch.h" -// Define what header we use for BaseApp.h -#define PCH "pch.h" - -// Enable hold hack -#define HOLDHACK - -#include "BaseApp.h" - namespace raylibUWP { - ref class App sealed : public BaseApp + ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView { - public: - - App(); + public: + App(); + + // IFrameworkView methods. + void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView) override; + void SetWindow(Windows::UI::Core::CoreWindow^ window) override; + void Load(Platform::String^ entryPoint) override; + void Run() override; + void Uninitialize() override; + private: + bool mWindowVisible = true; + bool mSuspended = false; + + void GameLoop(); + void PreProcessInputs(); + void PostProcessInputs(); + + // Helpers + int GetRaylibKey(Windows::System::VirtualKey kVey); + + // Events + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); + void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args); + void OnResuming(Platform::Object^ sender, Platform::Object^ args); + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ 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); + void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); + void OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args); + }; - void Update() override; + ref class AppSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource + { + public: + Windows::ApplicationModel::Core::IFrameworkView^ CreateView() override; }; } diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h deleted file mode 100644 index 87b952e5..00000000 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ /dev/null @@ -1,570 +0,0 @@ -/********************************************************************************************** -* -* raylib.BaseApp - UWP App generic code for managing interface between C and C++ -* -* LICENSE: zlib/libpng -* -* CONFIGURATION: -* -* #define PCH -* This defines what header is the PCH and needs to be included -* -* #define HOLDHACK -* This enables a hack to fix flickering key presses (Temporary) -* -* Copyright (c) 2013-2020 Ramon Santamaria (@raysan5) -* -* This software is provided "as-is", without any express or implied warranty. In no event -* will the authors be held liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, including commercial -* applications, and to alter it and redistribute it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not claim that you -* wrote the original software. If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but is not required. -* -* 2. Altered source versions must be plainly marked as such, and must not be misrepresented -* as being the original software. -* -* 3. This notice may not be removed or altered from any source distribution. -* -**********************************************************************************************/ - -#pragma once - -#if defined(PCH) -#include PCH -#endif - -#include <chrono> -#include <memory> -#include <wrl.h> - -//EGL -#include <EGL/eglplatform.h> - -#include "raylib.h" -#include "utils.h" - -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; -using namespace Windows::Graphics::Display; -using namespace Microsoft::WRL; -using namespace Platform; - -extern "C" { EGLNativeWindowType handle; }; - -/* -TODO list: - - Cache reference to our CoreWindow? - - Implement gestures support -*/ - -// 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) - -//Mouse cursor locking -bool cursorLocked = false; -Vector2 mouseDelta = {0, 0}; - -//Our mouse cursor -CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type - -//Base app implementation -ref class BaseApp : public Windows::ApplicationModel::Core::IFrameworkView -{ -public: - - // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::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<CoreApplicationView^, IActivatedEventArgs^>(this, &BaseApp::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<Platform::Object^>(this, &BaseApp::OnResuming); - } - - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window) - { - window->SizeChanged += ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &BaseApp::OnWindowSizeChanged); - window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &BaseApp::OnVisibilityChanged); - window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &BaseApp::OnWindowClosed); - - window->PointerPressed += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &BaseApp::PointerPressed); - window->PointerWheelChanged += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &BaseApp::PointerWheelChanged); - window->KeyDown += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &BaseApp::OnKeyDown); - window->KeyUp += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &BaseApp::OnKeyUp); - - Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &BaseApp::MouseMoved); - - DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); - currentDisplayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &BaseApp::OnDpiChanged); - currentDisplayInformation->OrientationChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &BaseApp::OnOrientationChanged); - - // The CoreWindow has been created, so EGL can be initialized. - - handle = (EGLNativeWindowType)window; - - InitWindow(width, height, "raylib game example"); - } - - virtual void Load(Platform::String^ entryPoint) {} - - void Setup(int width, int height) - { - // Set dimensions - this->width = width; - this->height = height; - } - - virtual void Run() - { - // Get display dimensions - DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); - Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels }; - - // Send display dimensions - UWPMessage *msg = CreateUWPMessage(); - msg->type = UWP_MSG_SET_DISPLAY_DIMS; - msg->paramVector0 = screenSize; - UWPSendMessage(msg); - - // Send the time to the core - using clock = std::chrono::high_resolution_clock; - auto timeStart = clock::now(); - - // Set fps if 0 - if (GetFPS() <= 0) SetTargetFPS(60); - - while (!mWindowClosed) - { - if (mWindowVisible) - { - // Send time - auto delta = clock::now() - timeStart; - - UWPMessage *timeMsg = CreateUWPMessage(); - timeMsg->type = UWP_MSG_SET_GAME_TIME; - timeMsg->paramDouble0 = std::chrono::duration_cast<std::chrono::seconds>(delta).count(); - UWPSendMessage(timeMsg); - - // Call update function - Update(); - - PollInput(); - - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - } - else - { - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); - } - } - - CloseWindow(); - } - - //Called every frame (Maybe add draw) - virtual void Update() {} - - virtual void Uninitialize() {} - -protected: - - // Input polling - void PollInput() - { - // Process Messages - { - // Loop over pending messages - while (UWPHasMessages()) - { - // Get the message - auto msg = UWPGetMessage(); - - // Carry out the command - switch(msg->type) - { - case UWP_MSG_SHOW_MOUSE: // Do the same thing because of how UWP works... - case UWP_MSG_UNLOCK_MOUSE: - { - CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - cursorLocked = false; - MoveMouse(GetMousePosition()); - break; - } - case UWP_MSG_HIDE_MOUSE: // Do the same thing because of how UWP works... - case UWP_MSG_LOCK_MOUSE: - { - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - cursorLocked = true; - break; - } - case UWP_MSG_SET_MOUSE_LOCATION: - { - MoveMouse(msg->paramVector0); - break; - } - } - - // Delete the message - DeleteUWPMessage(msg); - } - } - - // Process Keyboard - { - for (int k = 0x08; k < 0xA6; k++) { - auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k); - -#ifdef HOLDHACK - // Super hacky way of waiting three frames to see if we are ready to register the key as deregistered - // This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering - if (KeyboardStateHack[k] == 2) - { - if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) - { - KeyboardStateHack[k] = 3; - } - } - else if (KeyboardStateHack[k] == 3) - { - if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) - { - KeyboardStateHack[k] = 4; - } - } - else if (KeyboardStateHack[k] == 4) - { - if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) - { - //Reset key... - KeyboardStateHack[k] = 0; - - //Tell core - RegisterKey(k, 0); - } - } -#endif - // Left and right alt, KeyUp and KeyDown are not called for it - // No need to hack because this is not a character - - // TODO: Maybe do all other key registrations like this, no more key events? - - if (k == 0xA4 || k == 0xA5) - { - if ((state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) - { - RegisterKey(k, 1); - } - else - { - RegisterKey(k, 0); - } - } - } - } - - // Process Mouse - { - - if (CurrentPointerID > -1) - { - auto point = PointerPoint::GetCurrentPoint(CurrentPointerID); - auto props = point->Properties; - - if (props->IsLeftButtonPressed) - { - RegisterClick(MOUSE_LEFT_BUTTON, 1); - } - else - { - RegisterClick(MOUSE_LEFT_BUTTON, 0); - } - - if (props->IsRightButtonPressed) - { - RegisterClick(MOUSE_RIGHT_BUTTON, 1); - } - else - { - RegisterClick(MOUSE_RIGHT_BUTTON, 0); - } - - if (props->IsMiddleButtonPressed) - { - RegisterClick(MOUSE_MIDDLE_BUTTON, 1); - } - else - { - RegisterClick(MOUSE_MIDDLE_BUTTON, 0); - } - } - - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - - if (cursorLocked) - { - // Track cursor movement delta, recenter it on the client - auto curMousePos = GetMousePosition(); - - auto x = curMousePos.x + mouseDelta.x; - auto y = curMousePos.y + mouseDelta.y; - - UpdateMousePosition({ x, 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 - auto x = window->PointerPosition.X - window->Bounds.X; - auto y = window->PointerPosition.Y - window->Bounds.Y; - - UpdateMousePosition({ x, y }); - } - - mouseDelta = { 0 ,0 }; - } - - // Process Gamepads - { - // 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. - - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_SET_GAMEPAD_ACTIVE; - msg->paramInt0 = i; - msg->paramBool0 = i < Gamepad::Gamepads->Size; - UWPSendMessage(msg); - } - - // Get current gamepad state - for (int i = 0; i < MAX_GAMEPADS; i++) - { - if (IsGamepadAvailable(i)) - { - // 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 - RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_DOWN, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_LEFT, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_UP, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); - - RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_TRIGGER_1, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_TRIGGER_1, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); - - RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_LEFT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller - RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_RIGHT, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller - - RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); - RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE, false); // Home button not supported by UWP - - // Get current axis state - RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_X, (float)reading.LeftThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_X, (float)reading.RightThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_TRIGGER, (float)reading.LeftTrigger); - RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_TRIGGER, (float)reading.RightTrigger); - } - } - } - } - - // Application lifecycle event handlers. - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args) - { - // Run() won't start until the CoreWindow is activated. - CoreWindow::GetForCurrentThread()->Activate(); - } - - void OnResuming(Platform::Object^ sender, Platform::Object^ args) {} - - // Window event handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_HANDLE_RESIZE; - UWPSendMessage(msg); - } - - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) - { - mWindowVisible = args->Visible; - } - - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args) - { - mWindowClosed = true; - } - - // DisplayInformation event handlers. - 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) - { - //Get the current active pointer ID for our loop - CurrentPointerID = args->CurrentPoint->PointerId; - args->Handled = true; - } - - void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_SCROLL_WHEEL_UPDATE; - msg->paramFloat0 = args->CurrentPoint->Properties->MouseWheelDelta; - UWPSendMessage(msg); - } - - void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) - { - mouseDelta.x += args->MouseDelta.X; - mouseDelta.y += args->MouseDelta.Y; - } - - void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) - { -#ifdef HOLDHACK - // Start the hack - KeyboardStateHack[(int)args->VirtualKey] = 1; -#endif - - RegisterKey((int)args->VirtualKey, 1); - } - - void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) - { -#ifdef HOLDHACK - // The same hack - if (KeyboardStateHack[(int)args->VirtualKey] == 1) - { - KeyboardStateHack[(int)args->VirtualKey] = 2; - } - else if (KeyboardStateHack[(int)args->VirtualKey] == 2) - { - KeyboardStateHack[(int)args->VirtualKey] = 3; - } - else if (KeyboardStateHack[(int)args->VirtualKey] == 3) - { - KeyboardStateHack[(int)args->VirtualKey] = 4; - } - else if (KeyboardStateHack[(int)args->VirtualKey] == 4) - { - RegisterKey((int)args->VirtualKey, 0); - KeyboardStateHack[(int)args->VirtualKey] = 0; - } -#else - // No hack, allow flickers - RegisterKey((int)args->VirtualKey, 0); -#endif - } - -private: - - void RegisterKey(int key, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWPMessageType::UWP_MSG_REGISTER_KEY; - msg->paramInt0 = key; - msg->paramChar0 = status; - UWPSendMessage(msg); - } - - void MoveMouse(Vector2 pos) - { - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - Point mousePosScreen = Point(pos.x + window->Bounds.X, pos.y + window->Bounds.Y); - window->PointerPosition = mousePosScreen; - } - - void RegisterGamepadButton(int gamepad, int button, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_SET_GAMEPAD_BUTTON; - msg->paramInt0 = gamepad; - msg->paramInt1 = button; - msg->paramChar0 = status; - UWPSendMessage(msg); - } - - void RegisterGamepadAxis(int gamepad, int axis, float value) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_SET_GAMEPAD_AXIS; - msg->paramInt0 = gamepad; - msg->paramInt1 = axis; - msg->paramFloat0 = value; - UWPSendMessage(msg); - } - - void UpdateMousePosition(Vector2 pos) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWP_MSG_UPDATE_MOUSE_LOCATION; - msg->paramVector0 = pos; - UWPSendMessage(msg); - } - - void RegisterClick(int button, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->type = UWPMessageType::UWP_MSG_REGISTER_CLICK; - msg->paramInt0 = button; - msg->paramChar0 = status; - UWPSendMessage(msg); - } - - bool mWindowClosed = false; - bool mWindowVisible = true; - - int width = 640; - int height = 480; - - int CurrentPointerID = -1; - -#ifdef HOLDHACK - char KeyboardStateHack[0xA6]; // 0xA6 because the highest key we compare against is 0xA5 -#endif -}; - -// Application source for creating the program -template<typename AppType> -ref class ApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource -{ -public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() - { - return ref new AppType(); - } -};
\ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj index f82a352d..cddbe0dc 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj +++ b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Debug|Win32"> @@ -33,7 +33,7 @@ <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> <AppContainerApplication>true</AppContainerApplication> <ApplicationType>Windows Store</ApplicationType> - <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion> <ApplicationTypeRevision>10.0</ApplicationTypeRevision> <ProjectName>raylib.App.UWP</ProjectName> @@ -139,7 +139,6 @@ </ItemGroup> <ItemGroup> <ClInclude Include="App.h" /> - <ClInclude Include="BaseApp.h" /> <ClInclude Include="pch.h" /> </ItemGroup> <ItemGroup> @@ -152,7 +151,6 @@ <AppxManifest Include="Package.appxmanifest"> <SubType>Designer</SubType> </AppxManifest> - <None Include="packages.config" /> <None Include="raylib.App.UWP.TemporaryKey.pfx" /> </ItemGroup> <ItemGroup> @@ -160,6 +158,9 @@ <Project>{ea91e088-7c71-4f32-b761-e054305cd519}</Project> </ProjectReference> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> <Import Project="..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets" Condition="Exists('..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets')" /> diff --git a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj.filters b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj.filters index 1e0fe362..ce747ba6 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj.filters +++ b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj.filters @@ -6,7 +6,6 @@ </ItemGroup> <ItemGroup> <ClInclude Include="App.h" /> - <ClInclude Include="BaseApp.h" /> <ClInclude Include="pch.h" /> </ItemGroup> <ItemGroup> @@ -30,11 +29,11 @@ <AppxManifest Include="Package.appxmanifest" /> </ItemGroup> <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> <Filter Include="Logo"> <UniqueIdentifier>{cdf72d55-f249-4ad6-9a91-f8a084e64933}</UniqueIdentifier> </Filter> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP/packages.config b/projects/VS2017.UWP/raylib.UWP/packages.config new file mode 100644 index 00000000..70c3dea0 --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="ANGLE.WindowsStore" version="2.1.13" targetFramework="native" /> +</packages>
\ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj index e6186bf6..26ae61da 100644 --- a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj @@ -42,6 +42,7 @@ <ClInclude Include="..\..\..\src\raymath.h" /> <ClInclude Include="..\..\..\src\rlgl.h" /> <ClInclude Include="..\..\..\src\utils.h" /> + <ClInclude Include="..\..\..\src\uwp_events.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\src\core.c" /> @@ -52,6 +53,9 @@ <ClCompile Include="..\..\..\src\textures.c" /> <ClCompile Include="..\..\..\src\utils.c" /> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>{ea91e088-7c71-4f32-b761-e054305cd519}</ProjectGuid> <Keyword>StaticLibrary</Keyword> @@ -60,7 +64,7 @@ <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> <AppContainerApplication>true</AppContainerApplication> <ApplicationType>Windows Store</ApplicationType> - <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformMinVersion>10.0.15063.0</WindowsTargetPlatformMinVersion> <ApplicationTypeRevision>10.0</ApplicationTypeRevision> </PropertyGroup> @@ -158,7 +162,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> - <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>SUPPORT_GIF_RECORDING;_CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(SolutionDir)packages\ANGLE.WindowsStore.2.1.13\Include;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> @@ -239,5 +243,12 @@ </ItemDefinitionGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> + <Import Project="..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets" Condition="Exists('..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets')" /> </ImportGroup> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>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}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ANGLE.WindowsStore.2.1.13\build\native\ANGLE.WindowsStore.targets'))" /> + </Target> </Project>
\ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters index cbad7c9b..8050a1ef 100644 --- a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters @@ -16,6 +16,7 @@ <ClInclude Include="..\..\..\src\external\stb_rect_pack.h" /> <ClInclude Include="..\..\..\src\external\stb_truetype.h" /> <ClInclude Include="..\..\..\src\external\stb_vorbis.h" /> + <ClInclude Include="..\..\..\src\uwp_events.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\src\core.c" /> @@ -26,4 +27,7 @@ <ClCompile Include="..\..\..\src\textures.c" /> <ClCompile Include="..\..\..\src\utils.c" /> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> </Project>
\ No newline at end of file |
