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
|
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "entry_p.h"
#if BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE
#include <bgfx/platform.h>
#include <bx/thread.h>
#include <bx/fpumath.h>
#include <Unknwn.h>
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::System;
using namespace Windows::Foundation;
#if BX_PLATFORM_WINRT
using namespace Windows::Graphics::Display;
#endif // BX_PLATFORM_WINRT
using namespace Platform;
static char* g_emptyArgs[] = { "" };
static entry::WindowHandle g_defaultWindow = { 0 };
static entry::EventQueue g_eventQueue;
///
inline void winrtSetWindow(::IUnknown* _window)
{
bgfx::PlatformData pd;
pd.ndt = NULL;
pd.nwh = _window;
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
ref class App sealed : public IFrameworkView
{
public:
App()
: m_windowVisible(true)
, m_windowClosed(false)
{
}
// IFrameworkView Methods.
virtual void Initialize(CoreApplicationView^ applicationView)
{
applicationView->Activated += ref new
TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
CoreApplication::Suspending += ref new
EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
CoreApplication::Resuming += ref new
EventHandler<Platform::Object^>(this, &App::OnResuming);
}
virtual void SetWindow(CoreWindow^ window)
{
window->VisibilityChanged += ref new
TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
window->Closed += ref new
TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
winrtSetWindow(reinterpret_cast<IUnknown*>(window) );
}
virtual void Load(String^ entryPoint)
{
}
virtual void Run()
{
bx::Thread thread;
thread.init(MainThreadFunc, nullptr);
CoreWindow^ window = CoreWindow::GetForCurrentThread();
auto bounds = window->Bounds;
#if BX_PLATFORM_WINRT
auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi;
static const float dipsPerInch = 96.0f;
g_eventQueue.postSizeEvent(g_defaultWindow
, lround(bx::ffloor(bounds.Width * dpi / dipsPerInch + 0.5f) )
, lround(bx::ffloor(bounds.Height * dpi / dipsPerInch + 0.5f) )
);
#endif // BX_PLATFORM_WINRT
while (!m_windowClosed)
{
if (m_windowVisible)
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
}
else
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
}
}
g_eventQueue.postExitEvent();
thread.shutdown();
}
virtual void Uninitialize()
{
}
private:
bool m_windowVisible;
bool m_windowClosed;
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow::GetForCurrentThread()->Activate();
}
void OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
{
m_windowVisible = args->Visible;
}
void OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
{
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
BX_UNUSED(deferral);
}
void OnResuming(Platform::Object^ sender, Platform::Object^ args)
{
}
void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
{
m_windowClosed = true;
}
static int32_t MainThreadFunc(void*)
{
return entry::main(0, g_emptyArgs);
}
};
ref class AppSource sealed : IFrameworkViewSource
{
public:
virtual IFrameworkView^ CreateView()
{
return ref new App();
}
};
namespace entry
{
const Event* poll()
{
return g_eventQueue.poll();
}
const Event* poll(WindowHandle _handle)
{
return g_eventQueue.poll(_handle);
}
void release(const Event* _event)
{
g_eventQueue.release(_event);
}
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
{
BX_UNUSED(_x, _y, _width, _height, _flags, _title);
WindowHandle handle = { UINT16_MAX };
return handle;
}
void destroyWindow(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
{
BX_UNUSED(_handle, _x, _y);
}
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
{
BX_UNUSED(_handle, _width, _height);
}
void setWindowTitle(WindowHandle _handle, const char* _title)
{
BX_UNUSED(_handle, _title);
}
void toggleWindowFrame(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void toggleFullscreen(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setMouseLock(WindowHandle _handle, bool _lock)
{
BX_UNUSED(_handle, _lock);
}
}
[MTAThread]
int main(Array<String^>^)
{
auto appSource = ref new AppSource();
CoreApplication::Run(appSource);
return 0;
}
#endif // BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE
|