8 #include "MainPage.xaml.h"
10 using namespace ShootingGame;
12 using namespace Platform;
13 using namespace Windows::ApplicationModel;
14 using namespace Windows::ApplicationModel::Activation;
15 using namespace Windows::ApplicationModel::Core;
16 using namespace Windows::UI::Core;
17 using namespace Windows::UI::Input;
18 using namespace Windows::UI::ViewManagement;
19 using namespace Windows::Foundation;
20 using namespace Windows::Foundation::Collections;
21 using namespace Windows::UI::Xaml;
22 using namespace Windows::UI::Xaml::Controls;
23 using namespace Windows::UI::Xaml::Controls::Primitives;
24 using namespace Windows::UI::Xaml::Data;
25 using namespace Windows::UI::Xaml::Input;
26 using namespace Windows::UI::Xaml::Interop;
27 using namespace Windows::UI::Xaml::Media;
28 using namespace Windows::UI::Xaml::Navigation;
29 using namespace Windows::UI::Xaml::Media::Animation;
30 using namespace Windows::Graphics::Display;
33 // The Split Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234228
36 /// Initializes the singleton application object. This is the first line of authored code
37 /// executed, and as such is the logical equivalent of main() or WinMain().
41 InitializeComponent();
42 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
46 /// Invoked when the application is launched normally by the end user. Other entry points
47 /// will be used when the application is launched to open a specific file, to display
48 /// search results, and so forth.
50 /// <param name="args">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
53 if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
55 //TODO: Load state from previously suspended application
58 auto mainPage = ref new MainPage();
60 // Place the frame in the current Window and ensure that it is active
61 Window::Current->Content = mainPage;
62 Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
63 Window::Current->Activate();
65 simpleSprites_ = ref new SimpleSprites();
66 simpleSprites_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
69 CompositionTarget::Rendering::add
70 (ref new EventHandler<Object^>(this, &App::OnRendering));
71 ApplicationView::GetForCurrentView()->ViewStateChanged +=
72 ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
74 &App::OnViewStateChanged
77 CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
78 CoreApplication::Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
81 DisplayProperties::LogicalDpiChanged +=
82 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
84 CoreWindow^ window = Window::Current->CoreWindow;
85 window->SizeChanged +=
86 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
88 window->PointerPressed +=
89 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
91 window->PointerReleased +=
92 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
94 window->PointerMoved +=
95 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
98 timer_ = ref new BasicTimer();
103 /// Invoked when application execution is being suspended. Application state is saved
104 /// without knowing whether the application will be terminated or resumed with the contents
105 /// of memory still intact.
107 /// <param name="sender">The source of the suspend request.</param>
108 /// <param name="e">Details about the suspend request.</param>
109 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
111 //TODO: Save application state and stop any background activity
114 //----------------------------------------------------------------------
115 void App::OnRendering(
121 simpleSprites_->Update(timer_->Total,timer_->Delta);
122 simpleSprites_->Render();
123 simpleSprites_->Present();
126 //--------------------------------------------------------------------------------------
127 void App::OnWindowSizeChanged(
128 _In_ CoreWindow^ sender,
129 _In_ WindowSizeChangedEventArgs^ args
132 simpleSprites_->UpdateForWindowSizeChange();
135 //--------------------------------------------------------------------------------------
136 void App::OnLogicalDpiChanged(
140 simpleSprites_->SetDpi(DisplayProperties::LogicalDpi);
142 //--------------------------------------------------------------------------------------
143 void App::OnWindowActivationChanged(
144 _In_ Platform::Object^ sender,
145 _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
149 //--------------------------------------------------------------------------------------
150 void App::OnResuming(
151 _In_ Platform::Object^ sender,
152 _In_ Platform::Object^ args
156 //--------------------------------------------------------------------------------------
157 void App::OnViewStateChanged(
158 _In_ ApplicationView^ view,
159 _In_ ApplicationViewStateChangedEventArgs^ args
164 void App::OnPointerPressed(
165 _In_ Windows::UI::Core::CoreWindow^ sender,
166 _In_ Windows::UI::Core::PointerEventArgs^ args
171 void App::OnPointerReleased(
172 _In_ Windows::UI::Core::CoreWindow^ sender,
173 _In_ Windows::UI::Core::PointerEventArgs^ args
178 void App::OnPointerMoved(
179 _In_ Windows::UI::Core::CoreWindow^ sender,
180 _In_ Windows::UI::Core::PointerEventArgs^ args