OSDN Git Service

バックバッファを作ってみた。
[shooting3/shootinggame.git] / ShootingGame / App.xaml.cpp
1 //
2 // App.xaml.cpp
3 // App.xaml クラスの実装。
4 //
5
6 #include "pch.h"
7 #include "App.xaml.h"
8 #include "MainPage.xaml.h"
9
10 using namespace ShootingGame;
11
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;
31
32
33 // The Split Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234228
34
35 /// <summary>
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().
38 /// </summary>
39 App::App()
40 {
41         InitializeComponent();
42         Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
43 }
44
45 /// <summary>
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.
49 /// </summary>
50 /// <param name="args">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
52 {
53         if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
54         {
55                 //TODO: Load state from previously suspended application
56         }
57
58         auto mainPage = ref new MainPage();
59
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();
64
65         simpleSprites_ = ref new SimpleSprites();
66         simpleSprites_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
67
68         eventToken_ = 
69                 CompositionTarget::Rendering::add
70                 (ref new EventHandler<Object^>(this, &App::OnRendering));
71         ApplicationView::GetForCurrentView()->ViewStateChanged +=
72                 ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
73                 this,
74                 &App::OnViewStateChanged
75                 );
76
77         CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
78         CoreApplication::Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
79
80
81         DisplayProperties::LogicalDpiChanged +=
82                 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
83
84         CoreWindow^ window = Window::Current->CoreWindow;
85         window->SizeChanged += 
86                 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
87
88         window->PointerPressed +=
89                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
90
91         window->PointerReleased +=
92                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
93
94         window->PointerMoved +=
95                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
96
97
98         timer_ = ref new BasicTimer();
99
100 }
101
102 /// <summary>
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.
106 /// </summary>
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)
110 {
111         //TODO: Save application state and stop any background activity
112 }
113
114 //----------------------------------------------------------------------
115 void App::OnRendering(
116         _In_ Object^ sender, 
117         _In_ Object^ args
118         )
119 {
120         timer_->Update();
121         simpleSprites_->Update(timer_->Total,timer_->Delta);
122         simpleSprites_->Render();
123         simpleSprites_->Present();
124
125 }
126 //--------------------------------------------------------------------------------------
127 void App::OnWindowSizeChanged(
128         _In_ CoreWindow^ sender,
129         _In_ WindowSizeChangedEventArgs^ args
130         )
131 {
132         simpleSprites_->UpdateForWindowSizeChange();
133
134 }
135 //--------------------------------------------------------------------------------------
136 void App::OnLogicalDpiChanged(
137         _In_ Object^ sender
138         )
139 {
140         simpleSprites_->SetDpi(DisplayProperties::LogicalDpi);
141 }
142 //--------------------------------------------------------------------------------------
143 void App::OnWindowActivationChanged(
144         _In_ Platform::Object^ sender,
145         _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
146         )
147 {
148 }
149 //--------------------------------------------------------------------------------------
150 void App::OnResuming(
151         _In_ Platform::Object^ sender,
152         _In_ Platform::Object^ args
153         )
154 {
155 }
156 //--------------------------------------------------------------------------------------
157 void App::OnViewStateChanged(
158         _In_ ApplicationView^ view, 
159         _In_ ApplicationViewStateChangedEventArgs^ args
160         )
161 {
162 }
163
164 void App::OnPointerPressed(
165         _In_ Windows::UI::Core::CoreWindow^ sender,
166         _In_ Windows::UI::Core::PointerEventArgs^ args
167         )
168 {
169 }
170
171 void App::OnPointerReleased(
172         _In_ Windows::UI::Core::CoreWindow^ sender,
173         _In_ Windows::UI::Core::PointerEventArgs^ args
174         )
175 {
176 }
177
178 void App::OnPointerMoved(
179         _In_ Windows::UI::Core::CoreWindow^ sender,
180         _In_ Windows::UI::Core::PointerEventArgs^ args
181         )
182 {
183 }
184