forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
630 lines (500 loc) · 22.9 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//--------------------------------------------------------------------------------------
// Main.cpp
//
// Entry point for Universal Windows Platform (UWP) app.
//
// Initialize the mouse cursor object and implements the event handling for
// necessary mouse cursor events to implement clip cursor or relative mouse mode.
// Keyboard handling is also implemented here.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "MouseCursor.h"
#include <ppltasks.h>
#include "Telemetry.h"
using namespace concurrency;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::UI::ViewManagement;
using namespace Windows::System;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace DirectX;
using namespace DirectX::SimpleMath;
ref class ViewProvider sealed : public IFrameworkView
{
public:
ViewProvider() :
m_exit( false ),
m_visible( true ),
m_in_sizemove(false),
m_DPI( 96.f ),
m_logicalWidth( 800.f ),
m_logicalHeight( 600.f ),
m_nativeOrientation( DisplayOrientations::None ),
m_currentOrientation( DisplayOrientations::None )
{
m_outputWidthPixels = m_logicalWidthPixels = ConvertDipsToPixels(m_logicalWidth);
m_outputHeightPixels = m_logicalHeightPixels = ConvertDipsToPixels(m_logicalHeight);
}
// IFrameworkView methods
virtual void Initialize( CoreApplicationView^ applicationView )
{
applicationView->Activated +=
ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>( this, &ViewProvider::OnActivated );
CoreApplication::Suspending +=
ref new EventHandler<SuspendingEventArgs^>( this, &ViewProvider::OnSuspending );
CoreApplication::Resuming +=
ref new EventHandler<Platform::Object^>( this, &ViewProvider::OnResuming );
m_sample = std::make_unique<Sample>();
// Sample Usage Telemetry
//
// Disable or remove this code block to opt-out of sample usage telemetry
//
if (ATG::EventRegisterATGSampleTelemetry() == ERROR_SUCCESS)
{
wchar_t exeName[MAX_PATH + 1] = {};
if (!GetModuleFileNameW(nullptr, exeName, MAX_PATH))
{
wcscpy_s(exeName, L"Unknown");
}
wchar_t fname[_MAX_FNAME] = {};
wchar_t ext[_MAX_EXT] = {};
(void)_wsplitpath_s(exeName, nullptr, 0, nullptr, 0, fname, _MAX_FNAME, ext, _MAX_EXT);
(void)_wmakepath_s(exeName, nullptr, nullptr, fname, ext); // keep only the filename + extension
ATG::EventWriteSampleLoaded(exeName);
}
}
virtual void Uninitialize()
{
m_sample.reset();
}
virtual void SetWindow( CoreWindow^ window )
{
window->SizeChanged +=
ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>( this, &ViewProvider::OnWindowSizeChanged );
#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)
try
{
window->ResizeStarted +=
ref new TypedEventHandler<CoreWindow^, Object^>(this, &ViewProvider::OnResizeStarted);
window->ResizeCompleted +=
ref new TypedEventHandler<CoreWindow^, Object^>(this, &ViewProvider::OnResizeCompleted);
}
catch (...)
{
// Requires Windows 10 Creators Update (10.0.15063) or later
}
#endif
window->VisibilityChanged +=
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>( this, &ViewProvider::OnVisibilityChanged );
window->Closed +=
ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>( this, &ViewProvider::OnWindowClosed );
auto dispatcher = CoreWindow::GetForCurrentThread()->Dispatcher;
dispatcher->AcceleratorKeyActivated +=
ref new TypedEventHandler<CoreDispatcher^, AcceleratorKeyEventArgs^>(this, &ViewProvider::OnAcceleratorKeyActivated);
auto navigation = Windows::UI::Core::SystemNavigationManager::GetForCurrentView();
navigation->BackRequested +=
ref new EventHandler<BackRequestedEventArgs^>(this, &ViewProvider::OnBackRequested);
auto currentDisplayInformation = DisplayInformation::GetForCurrentView();
currentDisplayInformation->DpiChanged +=
ref new TypedEventHandler<DisplayInformation^, Object^>( this, &ViewProvider::OnDpiChanged );
currentDisplayInformation->OrientationChanged +=
ref new TypedEventHandler<DisplayInformation^, Object^>( this, &ViewProvider::OnOrientationChanged );
DisplayInformation::DisplayContentsInvalidated +=
ref new TypedEventHandler<DisplayInformation^, Object^>( this, &ViewProvider::OnDisplayContentsInvalidated );
// Mouse press and move handlers for the uncaptured mouse
window->PointerPressed +=
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow ^, Windows::UI::Core::PointerEventArgs ^>( this, &ViewProvider::OnPointerPressed );
window->PointerMoved +=
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow ^, Windows::UI::Core::PointerEventArgs ^>( this, &ViewProvider::OnPointerMoved );
// Handler for mouse movement when the mouse is captured
Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
ref new Windows::Foundation::TypedEventHandler<Windows::Devices::Input::MouseDevice ^, Windows::Devices::Input::MouseEventArgs ^>( this, &ViewProvider::OnMouseMoved );
// Handler for dealing with losing the capture mode
window->PointerCaptureLost +=
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow ^, Windows::UI::Core::PointerEventArgs ^>( this, &ViewProvider::OnPointerCaptureLost );
window->KeyDown +=
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow ^, Windows::UI::Core::KeyEventArgs ^>( this, &ViewProvider::OnKeyDown );
m_DPI = currentDisplayInformation->LogicalDpi;
m_logicalWidth = window->Bounds.Width;
m_logicalHeight = window->Bounds.Height;
m_nativeOrientation = currentDisplayInformation->NativeOrientation;
m_currentOrientation = currentDisplayInformation->CurrentOrientation;
m_outputWidthPixels = m_logicalWidthPixels = ConvertDipsToPixels( m_logicalWidth );
m_outputHeightPixels = m_logicalHeightPixels = ConvertDipsToPixels( m_logicalHeight );
DXGI_MODE_ROTATION rotation = ComputeDisplayRotation();
if ( rotation == DXGI_MODE_ROTATION_ROTATE90 || rotation == DXGI_MODE_ROTATION_ROTATE270 )
{
std::swap(m_outputWidthPixels, m_outputHeightPixels);
}
m_sample->Initialize( reinterpret_cast<IUnknown*>( window ),
m_outputWidthPixels, m_outputHeightPixels, rotation );
}
virtual void Load( Platform::String^ entryPoint )
{
}
virtual void Run()
{
while ( !m_exit )
{
if ( m_visible )
{
m_sample->Tick();
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents( CoreProcessEventsOption::ProcessAllIfPresent );
}
else
{
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents( CoreProcessEventsOption::ProcessOneAndAllPending );
}
}
}
protected:
// Event handlers
void OnActivated( CoreApplicationView^ applicationView, IActivatedEventArgs^ args )
{
if (args->Kind == ActivationKind::Launch)
{
auto launchArgs = static_cast<LaunchActivatedEventArgs^>(args);
if (launchArgs->PrelaunchActivated)
{
// Opt-out of Prelaunch
CoreApplication::Exit();
return;
}
}
int w, h;
m_sample->GetDefaultSize( w, h );
m_DPI = DisplayInformation::GetForCurrentView()->LogicalDpi;
ApplicationView::PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize;
// Change to ApplicationViewWindowingMode::FullScreen to default to full screen
auto desiredSize = Size( ConvertPixelsToDips( w ),
ConvertPixelsToDips( h ) );
ApplicationView::PreferredLaunchViewSize = desiredSize;
auto view = ApplicationView::GetForCurrentView();
auto minSize = Size( ConvertPixelsToDips( 320 ),
ConvertPixelsToDips( 200 ) );
view->SetPreferredMinSize( minSize );
CoreWindow::GetForCurrentThread()->Activate();
view->FullScreenSystemOverlayMode = FullScreenSystemOverlayMode::Standard;
CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
view->TryResizeView(desiredSize);
}
void OnSuspending( Platform::Object^ sender, SuspendingEventArgs^ args )
{
auto deferral = args->SuspendingOperation->GetDeferral();
create_task( [ this, deferral ] ()
{
m_sample->OnSuspending();
deferral->Complete();
} );
}
void OnResuming( Platform::Object^ sender, Platform::Object^ args )
{
m_sample->OnResuming();
}
void OnWindowSizeChanged( CoreWindow^ sender, WindowSizeChangedEventArgs^ args )
{
float prevWidth = (float) m_logicalWidthPixels;
float prevHeight = (float) m_logicalHeightPixels;
m_logicalWidth = sender->Bounds.Width;
m_logicalHeight = sender->Bounds.Height;
m_logicalWidthPixels = ConvertDipsToPixels(m_logicalWidth);
m_logicalHeightPixels = ConvertDipsToPixels(m_logicalHeight);
if (m_in_sizemove)
return;
// Adjust drawn cursor location based on size change
if (m_relative)
{
m_virtualCursorOnscreenPosition.X = m_logicalWidthPixels / 2.0f;
m_virtualCursorOnscreenPosition.Y = m_logicalHeightPixels / 2.0f;
}
else if (m_clipCursor)
{
m_virtualCursorOnscreenPosition.X = m_virtualCursorOnscreenPosition.X * (m_logicalWidthPixels / prevWidth);
m_virtualCursorOnscreenPosition.Y = m_virtualCursorOnscreenPosition.Y * (m_logicalHeightPixels / prevHeight);
m_sample->UpdatePointer(m_virtualCursorOnscreenPosition);
}
HandleWindowSizeChanged();
}
#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)
void OnResizeStarted(CoreWindow^ sender, Platform::Object^ args)
{
m_in_sizemove = true;
}
void OnResizeCompleted(CoreWindow^ sender, Platform::Object^ args)
{
m_in_sizemove = false;
HandleWindowSizeChanged();
}
#endif
void OnVisibilityChanged( CoreWindow^ sender, VisibilityChangedEventArgs^ args )
{
m_visible = args->Visible;
if ( m_visible )
m_sample->OnActivated();
else
m_sample->OnDeactivated();
}
void OnWindowClosed( CoreWindow^ sender, CoreWindowEventArgs^ args )
{
m_exit = true;
}
void OnAcceleratorKeyActivated(CoreDispatcher^, AcceleratorKeyEventArgs^ args)
{
if (args->EventType == CoreAcceleratorKeyEventType::SystemKeyDown
&& args->VirtualKey == VirtualKey::Enter
&& args->KeyStatus.IsMenuKeyDown
&& !args->KeyStatus.WasKeyDown)
{
// Implements the classic ALT+ENTER fullscreen toggle
auto view = ApplicationView::GetForCurrentView();
if (view->IsFullScreenMode)
view->ExitFullScreenMode();
else
view->TryEnterFullScreenMode();
args->Handled = true;
}
}
void OnBackRequested(Platform::Object^, Windows::UI::Core::BackRequestedEventArgs^ args)
{
// UWP on Xbox One triggers a back request whenever the B button is pressed
// which can result in the app being suspended if unhandled
args->Handled = true;
}
void OnDpiChanged( DisplayInformation^ sender, Object^ args )
{
m_DPI = sender->LogicalDpi;
HandleWindowSizeChanged();
}
void OnOrientationChanged( DisplayInformation^ sender, Object^ args )
{
auto resizeManager = CoreWindowResizeManager::GetForCurrentView();
resizeManager->ShouldWaitForLayoutCompletion = true;
m_nativeOrientation = sender->NativeOrientation;
m_currentOrientation = sender->CurrentOrientation;
HandleWindowSizeChanged();
resizeManager->NotifyLayoutCompleted();
}
void OnDisplayContentsInvalidated( DisplayInformation^ sender, Object^ args )
{
m_sample->ValidateDevice();
}
// This handler is for the uncaptured windows mouse. When the mouse is still uncaptured ( in absolute mode )
// pointer pressed events are handled to check if the user selected either UI option.
// If a UI tile is selected, the mouse is captured and either relative or clip cursor mode is entered.
//
void OnPointerPressed( Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs ^args )
{
if ( m_absolute )
{
// Check which mode the user selected
float newX = (float) ConvertDipsToPixels( args->CurrentPoint->Position.X );
float newY = (float) ConvertDipsToPixels( args->CurrentPoint->Position.Y );
Sample::MouseMode mode = m_sample->SetMode( Windows::Foundation::Point( newX, newY ) );
// if the user selected relative mode, capture the mouse
if ( mode == Sample::RELATIVE_MOUSE )
{
m_absolute = false;
m_relative = true;
// Set the pointer cursor to null. This causes the windows mouse to disappear so the
// app or game's mouse can then be drawn.
sender->SetPointerCapture();
sender->PointerCursor = nullptr;
// Save the pointers position
m_virtualCursorOnscreenPosition.X = newX;
m_virtualCursorOnscreenPosition.Y = newY;
m_virtualCursorOnscreenPosition.X = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.X, (float) m_logicalWidthPixels ) );
m_virtualCursorOnscreenPosition.Y = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.Y, (float) m_logicalHeightPixels ) );
}
// If the user selected clip cursor mode, capture the mouse
else if ( mode == Sample::CLIPCURSOR_MOUSE )
{
m_absolute = false;
m_clipCursor = true;
// Set the pointer cursor to null. This causes the windows mouse to disappear so the
// app or game's mouse can then be drawn.
sender->SetPointerCapture();
sender->PointerCursor = nullptr;
// Save the pointers position
m_virtualCursorOnscreenPosition.X = newX;
m_virtualCursorOnscreenPosition.Y = newY;
m_virtualCursorOnscreenPosition.X = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.X, (float)m_logicalWidth) );
m_virtualCursorOnscreenPosition.Y = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.Y, (float) m_logicalHeight ) );
}
}
}
// When ESC is pressed, exit clip cursor or relative mode and return to absolute mode
void OnKeyDown( Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::KeyEventArgs ^args )
{
if ( args->VirtualKey == Windows::System::VirtualKey::Escape && !m_absolute )
{
sender->ReleasePointerCapture();
sender->PointerCursor = ref new CoreCursor( CoreCursorType::Arrow, 0 );
// Use the window location and the virtual cursors location to reposition the windows mouse
Windows::Foundation::Point newPoint;
newPoint.X = sender->Bounds.X + ConvertPixelsToDips(int(m_virtualCursorOnscreenPosition.X));
newPoint.Y = sender->Bounds.Y + ConvertPixelsToDips(int(m_virtualCursorOnscreenPosition.Y));
sender->PointerPosition = newPoint;
m_clipCursor = false;
m_relative = false;
m_absolute = true;
Windows::Foundation::Point pt( 0,0 );
m_sample->SetMode( pt );
}
}
// When the pointer capture is lost exit clip cursor or relative mode and return to absolute mode
void OnPointerCaptureLost( Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs ^args )
{
sender->ReleasePointerCapture();
sender->PointerCursor = ref new CoreCursor( CoreCursorType::Arrow, 0 );
// Use the window location and the virtual cursors location to reposition the windows mouse
Windows::Foundation::Point newPoint;
newPoint.X = sender->Bounds.X + ConvertPixelsToDips(int(m_virtualCursorOnscreenPosition.X));
newPoint.Y = sender->Bounds.Y + ConvertPixelsToDips(int(m_virtualCursorOnscreenPosition.Y));
sender->PointerPosition = newPoint;
m_clipCursor = false;
m_relative = false;
m_absolute = true;
Windows::Foundation::Point pt( 0, 0 );
m_sample->SetMode( pt );
}
// When the mouse moves in absolute mode check to see if it is hovering over a selection box
void OnPointerMoved( Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs ^args )
{
if ( m_absolute )
{
float newX = (float) ConvertDipsToPixels( args->CurrentPoint->Position.X );
float newY = (float) ConvertDipsToPixels( args->CurrentPoint->Position.Y );
m_sample->CheckLocation( Windows::Foundation::Point( newX, newY ) );
}
}
// When the mouse moves in captured mode update the on screen position for clip cursor or update the camera/target for relative mode
void OnMouseMoved( Windows::Devices::Input::MouseDevice ^sender, Windows::Devices::Input::MouseEventArgs ^args )
{
float newX = (float)ConvertDipsToPixels((float)args->MouseDelta.X);
float newY = (float)ConvertDipsToPixels((float)args->MouseDelta.Y);
if ( m_clipCursor )
{
m_virtualCursorOnscreenPosition.X = m_virtualCursorOnscreenPosition.X + newX;
m_virtualCursorOnscreenPosition.Y = m_virtualCursorOnscreenPosition.Y + newY;
m_virtualCursorOnscreenPosition.X = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.X, (float) m_logicalWidthPixels ) );
m_virtualCursorOnscreenPosition.Y = fmaxf( 0.f, fminf( m_virtualCursorOnscreenPosition.Y, (float) m_logicalHeightPixels ) );
m_sample->UpdatePointer( m_virtualCursorOnscreenPosition );
}
else if ( m_relative )
{
m_sample->UpdateCamera( Vector3( newX, newY, 0.f ) );
}
}
private:
bool m_exit;
bool m_visible;
bool m_in_sizemove;
float m_DPI;
float m_logicalWidth;
float m_logicalHeight;
int m_logicalWidthPixels;
int m_logicalHeightPixels;
int m_outputHeightPixels;
int m_outputWidthPixels;
std::unique_ptr<Sample> m_sample;
// Mode
bool m_clipCursor = false;
bool m_relative = false;
bool m_absolute = true;
Windows::Foundation::Point m_virtualCursorOnscreenPosition;
Windows::Graphics::Display::DisplayOrientations m_nativeOrientation;
Windows::Graphics::Display::DisplayOrientations m_currentOrientation;
inline int ConvertDipsToPixels( float dips ) const
{
return int( dips * m_DPI / 96.f + 0.5f );
}
inline float ConvertPixelsToDips(int pixels) const
{
return (float(pixels) * 96.f / m_DPI);
}
DXGI_MODE_ROTATION ComputeDisplayRotation() const
{
DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
switch ( m_nativeOrientation )
{
case DisplayOrientations::Landscape:
switch ( m_currentOrientation )
{
case DisplayOrientations::Landscape:
rotation = DXGI_MODE_ROTATION_IDENTITY;
break;
case DisplayOrientations::Portrait:
rotation = DXGI_MODE_ROTATION_ROTATE270;
break;
case DisplayOrientations::LandscapeFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE180;
break;
case DisplayOrientations::PortraitFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE90;
break;
}
break;
case DisplayOrientations::Portrait:
switch ( m_currentOrientation )
{
case DisplayOrientations::Landscape:
rotation = DXGI_MODE_ROTATION_ROTATE90;
break;
case DisplayOrientations::Portrait:
rotation = DXGI_MODE_ROTATION_IDENTITY;
break;
case DisplayOrientations::LandscapeFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE270;
break;
case DisplayOrientations::PortraitFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE180;
break;
}
break;
}
return rotation;
}
void HandleWindowSizeChanged()
{
m_outputWidthPixels = m_logicalWidthPixels = ConvertDipsToPixels(m_logicalWidth);
m_outputHeightPixels = m_logicalHeightPixels = ConvertDipsToPixels(m_logicalHeight);
DXGI_MODE_ROTATION rotation = ComputeDisplayRotation();
if ( rotation == DXGI_MODE_ROTATION_ROTATE90 || rotation == DXGI_MODE_ROTATION_ROTATE270 )
{
std::swap(m_outputWidthPixels, m_outputHeightPixels);
}
m_sample->OnWindowSizeChanged(m_outputWidthPixels, m_outputHeightPixels, rotation );
}
};
ref class ViewProviderFactory : IFrameworkViewSource
{
public:
virtual IFrameworkView^ CreateView()
{
return ref new ViewProvider();
}
};
// Entry point
[ Platform::MTAThread ]
int __cdecl main(Platform::Array<Platform::String^>^ /*argv*/)
{
if (!XMVerifyCPUSupport())
{
throw std::exception("XMVerifyCPUSupport");
}
auto viewProviderFactory = ref new ViewProviderFactory();
CoreApplication::Run( viewProviderFactory );
return 0;
}
// Exit helper
void ExitSample()
{
Windows::ApplicationModel::Core::CoreApplication::Exit();
}