Fix game closing on Xbox when B is pressed.

This commit is contained in:
Reece Mackie 2020-04-30 15:02:01 +01:00
parent 3767a324a7
commit 95c03b2fee
2 changed files with 11 additions and 0 deletions

View File

@ -83,6 +83,10 @@ void App::SetWindow(Windows::UI::Core::CoreWindow^ window)
// The CoreWindow has been created, we can pass this to raylib for EGL context creation when it's time // The CoreWindow has been created, we can pass this to raylib for EGL context creation when it's time
UWPSetCoreWindowPtr((void*)window); UWPSetCoreWindowPtr((void*)window);
// 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 void App::Load(Platform::String ^entryPoint) {} // Ignored for this example
@ -454,6 +458,12 @@ void App::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI
UWPKeyCharEvent(args->KeyCode); 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 // AppSource implementation
Windows::ApplicationModel::Core::IFrameworkView ^AppSource::CreateView() Windows::ApplicationModel::Core::IFrameworkView ^AppSource::CreateView()
{ {

View File

@ -40,6 +40,7 @@ namespace raylibUWP
void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ 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 OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
void OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args);
}; };
ref class AppSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource ref class AppSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource