2023-03-11 22:10:18 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2023-03-12 01:44:55 +08:00
|
|
|
https://axmolengine.github.io/
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
#include "App.h"
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
#include "OpenGLESPage.h"
|
|
|
|
|
|
|
|
using namespace winrt;
|
2023-03-11 22:10:18 +08:00
|
|
|
using namespace Windows::ApplicationModel;
|
|
|
|
using namespace Windows::ApplicationModel::Activation;
|
|
|
|
using namespace Windows::Foundation;
|
|
|
|
using namespace Windows::Foundation::Collections;
|
|
|
|
using namespace Windows::UI::Xaml::Media::Animation;
|
|
|
|
using namespace Windows::UI::Xaml;
|
|
|
|
using namespace Windows::UI::Xaml::Controls;
|
|
|
|
using namespace Windows::UI::Xaml::Controls::Primitives;
|
|
|
|
using namespace Windows::UI::Xaml::Data;
|
|
|
|
using namespace Windows::UI::Xaml::Input;
|
|
|
|
using namespace Windows::UI::Xaml::Interop;
|
|
|
|
using namespace Windows::UI::Xaml::Media;
|
|
|
|
using namespace Windows::UI::Xaml::Navigation;
|
|
|
|
using namespace AxmolAppWinRT;
|
2023-09-26 00:11:33 +08:00
|
|
|
using namespace AxmolAppWinRT::implementation;
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates the singleton application object. This is the first line of authored code
|
|
|
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
|
|
|
/// </summary>
|
2023-03-11 22:10:18 +08:00
|
|
|
App::App()
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
Suspending({ this, &App::OnSuspending });
|
|
|
|
Resuming({this, &App::OnResuming});
|
|
|
|
|
|
|
|
// Resuming({ this, &AppOnResuming });
|
|
|
|
|
|
|
|
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
|
|
|
|
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
|
|
|
|
{
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
{
|
|
|
|
auto errorMessage = e.Message();
|
|
|
|
__debugbreak();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#endif
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-26 00:11:33 +08:00
|
|
|
/// Invoked when the application is launched normally by the end user. Other entry points
|
2023-03-11 22:10:18 +08:00
|
|
|
/// will be used such as when the application is launched to open a specific file.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="e">Details about the launch request and process.</param>
|
2023-09-26 00:11:33 +08:00
|
|
|
void App::OnLaunched(LaunchActivatedEventArgs const& e)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
Frame rootFrame{ nullptr };
|
|
|
|
auto content = Window::Current().Content();
|
|
|
|
if (content)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
rootFrame = content.try_as<Frame>();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do not repeat app initialization when the Window already has content,
|
|
|
|
// just ensure that the window is active
|
|
|
|
if (rootFrame == nullptr)
|
|
|
|
{
|
|
|
|
// Create a Frame to act as the navigation context and associate it with
|
|
|
|
// a SuspensionManager key
|
2023-09-26 00:11:33 +08:00
|
|
|
rootFrame = Frame();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
rootFrame.NavigationFailed({ this, &App::OnNavigationFailed });
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
// Restore the saved session state only when appropriate, scheduling the
|
2023-03-11 22:10:18 +08:00
|
|
|
// final launch steps after the restore is complete
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
if (e.PrelaunchActivated() == false)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
if (rootFrame.Content() == nullptr)
|
|
|
|
{
|
|
|
|
// When the navigation stack isn't restored navigate to the first page,
|
|
|
|
// configuring the new page by passing required information as a navigation
|
|
|
|
// parameter
|
|
|
|
rootFrame.Content(winrt::make<OpenGLESPage>(&mOpenGLES));
|
|
|
|
//rootFrame.Navigate(xaml_typename<AxmolAppWinRT::OpenGLESPage>(), box_value(e.Arguments()));
|
|
|
|
mPage = rootFrame.Content();
|
|
|
|
}
|
|
|
|
// Place the frame in the current Window
|
|
|
|
Window::Current().Content(rootFrame);
|
|
|
|
// Ensure the current window is active
|
|
|
|
Window::Current().Activate();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-26 00:11:33 +08:00
|
|
|
/// Invoked when application execution is being suspended. Application state is saved
|
2023-03-11 22:10:18 +08:00
|
|
|
/// without knowing whether the application will be terminated or resumed with the contents
|
|
|
|
/// of memory still intact.
|
|
|
|
/// </summary>
|
2023-09-26 00:11:33 +08:00
|
|
|
/// <param name="sender">The source of the suspend request.</param>
|
|
|
|
/// <param name="e">Details about the suspend request.</param>
|
|
|
|
void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
// Save application state and stop any background activity
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when application execution is being resumed.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">The source of the resume request.</param>
|
|
|
|
/// <param name="args">Details about the resume request.</param>
|
2023-09-26 00:11:33 +08:00
|
|
|
void App::OnResuming(IInspectable const& sender, IInspectable const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
(void)sender; // Unused parameter
|
|
|
|
(void)args; // Unused parameter
|
|
|
|
|
|
|
|
if (mPage)
|
2023-09-26 00:11:33 +08:00
|
|
|
mPage.as<OpenGLESPage>()->SetVisibility(true);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when Navigation to a certain page fails
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">The Frame which failed navigation</param>
|
|
|
|
/// <param name="e">Details about the navigation failure</param>
|
2023-09-26 00:11:33 +08:00
|
|
|
void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
//throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|