diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index aed13b23b..e27909e25 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -6,11 +6,11 @@ * * 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) +* #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-2019 Ramon Santamaria (@raysan5) * @@ -63,8 +63,8 @@ extern "C" { EGLNativeWindowType uwpWindow; }; /* TODO list: - - Cache reference to our CoreWindow? - - Implement gestures support + - Cache reference to our CoreWindow? + - Implement gestures support */ // Stand-ins for "core.c" variables @@ -84,474 +84,474 @@ 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(this, &BaseApp::OnActivated); + // 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(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 + // 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, &BaseApp::OnResuming); - } + CoreApplication::Resuming += ref new EventHandler(this, &BaseApp::OnResuming); + } - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window) - { - window->SizeChanged += ref new TypedEventHandler(this, &BaseApp::OnWindowSizeChanged); - window->VisibilityChanged += ref new TypedEventHandler(this, &BaseApp::OnVisibilityChanged); - window->Closed += ref new TypedEventHandler(this, &BaseApp::OnWindowClosed); + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window) + { + window->SizeChanged += ref new TypedEventHandler(this, &BaseApp::OnWindowSizeChanged); + window->VisibilityChanged += ref new TypedEventHandler(this, &BaseApp::OnVisibilityChanged); + window->Closed += ref new TypedEventHandler(this, &BaseApp::OnWindowClosed); - window->PointerPressed += ref new TypedEventHandler(this, &BaseApp::PointerPressed); - window->PointerWheelChanged += ref new TypedEventHandler(this, &BaseApp::PointerWheelChanged); - window->KeyDown += ref new TypedEventHandler(this, &BaseApp::OnKeyDown); - window->KeyUp += ref new TypedEventHandler(this, &BaseApp::OnKeyUp); + window->PointerPressed += ref new TypedEventHandler(this, &BaseApp::PointerPressed); + window->PointerWheelChanged += ref new TypedEventHandler(this, &BaseApp::PointerWheelChanged); + window->KeyDown += ref new TypedEventHandler(this, &BaseApp::OnKeyDown); + window->KeyUp += ref new TypedEventHandler(this, &BaseApp::OnKeyUp); - Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &BaseApp::MouseMoved); + Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &BaseApp::MouseMoved); - DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); - currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &BaseApp::OnDpiChanged); - currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &BaseApp::OnOrientationChanged); + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &BaseApp::OnDpiChanged); + currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &BaseApp::OnOrientationChanged); - // The CoreWindow has been created, so EGL can be initialized. + // The CoreWindow has been created, so EGL can be initialized. - uwpWindow = (EGLNativeWindowType)window; + uwpWindow = (EGLNativeWindowType)window; - InitWindow(width, height, NULL); - } + InitWindow(width, height, NULL); + } - virtual void Load(Platform::String^ entryPoint) {} + virtual void Load(Platform::String^ entryPoint) {} - void Setup(int width, int height) - { - //Set dimensions - this->width = width; - this->height = height; - } + 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 }; + virtual void Run() + { + //Get display dimensions + DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); + Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels }; - //Send display dimensions - UWPMessage* msg = CreateUWPMessage(); - msg->Type = SetDisplayDims; - msg->Vector0 = screenSize; - UWPSendMessage(msg); + //Send display dimensions + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetDisplayDims; + msg->Vector0 = screenSize; + UWPSendMessage(msg); - //Send the time to the core - using clock = std::chrono::high_resolution_clock; - auto timeStart = clock::now(); + //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); + if (GetFPS() <= 0) + SetTargetFPS(60); - while (!mWindowClosed) - { - if (mWindowVisible) - { + while (!mWindowClosed) + { + if (mWindowVisible) + { //Send time - auto delta = clock::now() - timeStart; + auto delta = clock::now() - timeStart; - UWPMessage* timeMsg = CreateUWPMessage(); - timeMsg->Type = SetGameTime; - timeMsg->Double0 = std::chrono::duration_cast(delta).count(); - UWPSendMessage(timeMsg); + UWPMessage* timeMsg = CreateUWPMessage(); + timeMsg->Type = SetGameTime; + timeMsg->Double0 = std::chrono::duration_cast(delta).count(); + UWPSendMessage(timeMsg); - //Call update function - Update(); + //Call update function + Update(); - PollInput(); + PollInput(); - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - } - else - { - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); - } - } + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + } + else + { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + } - CloseWindow(); - } + CloseWindow(); + } - //Called every frame (Maybe add draw) - virtual void Update() {} + //Called every frame (Maybe add draw) + virtual void Update() {} - virtual void Uninitialize() {} + virtual void Uninitialize() {} protected: - // Input polling - void PollInput() - { - // Process Messages - { - //Loop over pending messages - while (UWPHasMessages()) - { - //Get the message - auto msg = UWPGetMessage(); + // 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 ShowMouse: //Do the same thing because of how UWP works... - case UnlockMouse: - { - CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - cursorLocked = false; - MoveMouse(GetMousePosition()); - break; - } - case HideMouse: //Do the same thing because of how UWP works... - case LockMouse: - { - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - cursorLocked = true; - break; - } - case SetMouseLocation: - { - MoveMouse(msg->Vector0); - break; - } - } + //Carry out the command + switch(msg->Type) + { + case ShowMouse: //Do the same thing because of how UWP works... + case UnlockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + cursorLocked = false; + MoveMouse(GetMousePosition()); + break; + } + case HideMouse: //Do the same thing because of how UWP works... + case LockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorLocked = true; + break; + } + case SetMouseLocation: + { + MoveMouse(msg->Vector0); + break; + } + } - //Delete the message - DeleteUWPMessage(msg); - } - } + //Delete the message + DeleteUWPMessage(msg); + } + } - // Process Keyboard - { - for (int k = 0x08; k < 0xA6; k++) { - auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k); + // 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; + //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); - } - } + //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 + //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? + //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); - } - } - } - } + 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; + // 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->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->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); - } - } + if (props->IsMiddleButtonPressed) + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 0); + } + } - CoreWindow ^window = CoreWindow::GetForCurrentThread(); + CoreWindow ^window = CoreWindow::GetForCurrentThread(); - if (cursorLocked) - { - // Track cursor movement delta, recenter it on the client - auto curMousePos = GetMousePosition(); + 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; + auto x = curMousePos.x + mouseDelta.x; + auto y = curMousePos.y + mouseDelta.y; - UpdateMousePosition({ x, 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; + // 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 }); - } + UpdateMousePosition({ x, y }); + } - mouseDelta = { 0 ,0 }; - } + 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. + // 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 = MarkGamepadActive; - msg->Int0 = i; - msg->Bool0 = i < Gamepad::Gamepads->Size; - UWPSendMessage(msg); - } + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadActive; + msg->Int0 = i; + msg->Bool0 = 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(); + // 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_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP + // 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_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP - // Get current axis state - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger); - } - } - } - } + // Get current axis state + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger); + } + } + } + } - // 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(); - } + // 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) {} + 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 = HandleResize; - UWPSendMessage(msg); - } + // Window event handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HandleResize; + UWPSendMessage(msg); + } - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) - { - mWindowVisible = args->Visible; - } + 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; - } + 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) {} + // 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; - } + // 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 = ScrollWheelUpdate; - msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta; - UWPSendMessage(msg); - } + void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ScrollWheelUpdate; + msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta; + UWPSendMessage(msg); + } - void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) - { - mouseDelta.x += args->MouseDelta.X; - mouseDelta.y += args->MouseDelta.Y; - } + 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) - { + void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) + { #ifdef HOLDHACK - //Start the hack - KeyboardStateHack[(int)args->VirtualKey] = 1; + //Start the hack + KeyboardStateHack[(int)args->VirtualKey] = 1; #endif - RegisterKey((int)args->VirtualKey, 1); - } + RegisterKey((int)args->VirtualKey, 1); + } - void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) - { + 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; - } + //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); + //No hack, allow flickers + RegisterKey((int)args->VirtualKey, 0); #endif - } + } private: - void RegisterKey(int key, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->Type = UWPMessageType::RegisterKey; - msg->Int0 = key; - msg->Char0 = status; - UWPSendMessage(msg); - } + void RegisterKey(int key, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterKey; + msg->Int0 = key; + msg->Char0 = 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 MoveMouse(Vector2 pos) + { + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(pos.x + window->Bounds.X, pos.y + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + } - void RegisterGamepadButton(int gamepad, int button, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->Type = MarkGamepadButton; - msg->Int0 = gamepad; - msg->Int1 = button; - msg->Char0 = status; - UWPSendMessage(msg); - } + void RegisterGamepadButton(int gamepad, int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadButton; + msg->Int0 = gamepad; + msg->Int1 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } - void RegisterGamepadAxis(int gamepad, int axis, float value) - { - UWPMessage* msg = CreateUWPMessage(); - msg->Type = MarkGamepadAxis; - msg->Int0 = gamepad; - msg->Int1 = axis; - msg->Float0 = value; - UWPSendMessage(msg); - } + void RegisterGamepadAxis(int gamepad, int axis, float value) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadAxis; + msg->Int0 = gamepad; + msg->Int1 = axis; + msg->Float0 = value; + UWPSendMessage(msg); + } - void UpdateMousePosition(Vector2 pos) - { - UWPMessage* msg = CreateUWPMessage(); - msg->Type = UpdateMouseLocation; - msg->Vector0 = pos; - UWPSendMessage(msg); - } + void UpdateMousePosition(Vector2 pos) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UpdateMouseLocation; + msg->Vector0 = pos; + UWPSendMessage(msg); + } - void RegisterClick(int button, char status) - { - UWPMessage* msg = CreateUWPMessage(); - msg->Type = UWPMessageType::RegisterClick; - msg->Int0 = button; - msg->Char0 = status; - UWPSendMessage(msg); - } + void RegisterClick(int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterClick; + msg->Int0 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } - bool mWindowClosed = false; - bool mWindowVisible = true; + bool mWindowClosed = false; + bool mWindowVisible = true; - int width = 640; - int height = 480; + int width = 640; + int height = 480; - int CurrentPointerID = -1; + int CurrentPointerID = -1; #ifdef HOLDHACK - char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5 + char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5 #endif }; @@ -560,8 +560,8 @@ template ref class ApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource { public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() - { - return ref new AppType(); - } + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() + { + return ref new AppType(); + } }; \ No newline at end of file