-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectXPage.xaml.cpp
118 lines (93 loc) · 3.15 KB
/
DirectXPage.xaml.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
//
// DirectXPage.xaml.cpp
// Implementation of the DirectXPage.xaml class.
//
#include "pch.h"
#include "DirectXPage.xaml.h"
using namespace Puck;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::Input;
using namespace Windows::UI::Core;
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::Media;
using namespace Windows::UI::Xaml::Navigation;
DirectXPage::DirectXPage()
{
InitializeComponent();
m_renderer = ref new SimpleTextRenderer();
m_renderer->Initialize(
Window::Current->CoreWindow,
SwapChainPanel,
DisplayProperties::LogicalDpi
);
Window::Current->CoreWindow->SizeChanged +=
ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &DirectXPage::OnWindowSizeChanged);
DisplayProperties::LogicalDpiChanged +=
ref new DisplayPropertiesEventHandler(this, &DirectXPage::OnLogicalDpiChanged);
DisplayProperties::OrientationChanged +=
ref new DisplayPropertiesEventHandler(this, &DirectXPage::OnOrientationChanged);
DisplayProperties::DisplayContentsInvalidated +=
ref new DisplayPropertiesEventHandler(this, &DirectXPage::OnDisplayContentsInvalidated);
m_eventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(this, &DirectXPage::OnRendering));
m_timer = ref new BasicTimer();
}
void DirectXPage::OnPointerMoved(Object^ sender, PointerRoutedEventArgs^ args)
{
PointerPoint ^p = args->GetCurrentPoint(nullptr);
m_renderer->OnMouseMove(p->Position);
}
void DirectXPage::OnPointerPressed(Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
{
PointerPoint ^p = args->GetCurrentPoint(nullptr);
bool left = p->Properties->IsLeftButtonPressed;
bool right = p->Properties->IsRightButtonPressed;
m_renderer->OnMouseDown(p->Position, left, right);
}
void DirectXPage::OnPointerReleased(Object^ sender, PointerRoutedEventArgs^ args)
{
// TODO -- what should happen on release?
}
void DirectXPage::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
{
m_renderer->UpdateForWindowSizeChange();
}
void DirectXPage::OnLogicalDpiChanged(Object^ sender)
{
m_renderer->SetDpi(DisplayProperties::LogicalDpi);
}
void DirectXPage::OnOrientationChanged(Object^ sender)
{
m_renderer->UpdateForWindowSizeChange();
}
void DirectXPage::OnDisplayContentsInvalidated(Object^ sender)
{
m_renderer->ValidateDevice();
}
void DirectXPage::OnRendering(Object^ sender, Object^ args)
{
m_timer->Update();
m_renderer->Update(m_timer->Total, m_timer->Delta);
m_renderer->Render();
m_renderer->Present();
}
void DirectXPage::OnPreviousColorPressed(Object^ sender, RoutedEventArgs^ args)
{
}
void DirectXPage::OnNextColorPressed(Object^ sender, RoutedEventArgs^ args)
{
}
void DirectXPage::SaveInternalState(IPropertySet^ state)
{
m_renderer->SaveInternalState(state);
}
void DirectXPage::LoadInternalState(IPropertySet^ state)
{
m_renderer->LoadInternalState(state);
}