bgfx/examples/common/entry/entry_winrt.cpp

193 lines
4.0 KiB
C++
Raw Normal View History

2014-11-14 16:23:31 +03:00
/*
2015-01-02 02:04:46 +03:00
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
2014-11-14 16:23:31 +03:00
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "entry_p.h"
#if BX_PLATFORM_WINRT
#include <bgfxplatform.h>
#include <bx/thread.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;
using namespace Windows::Graphics::Display;
using namespace Platform;
static char* g_emptyArgs[] = { "" };
static entry::WindowHandle g_defaultWindow = { 0 };
static entry::EventQueue g_eventQueue;
ref class App sealed : public IFrameworkView
{
2014-11-16 02:48:24 +03:00
public:
App()
: m_windowVisible(true)
, m_windowClosed(false)
{
}
2014-11-14 16:23:31 +03:00
2014-11-16 02:48:24 +03:00
// IFrameworkView Methods.
2014-11-14 16:23:31 +03:00
virtual void Initialize(CoreApplicationView^ applicationView)
2014-11-16 02:48:24 +03:00
{
applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
}
2014-11-14 16:23:31 +03:00
virtual void SetWindow(CoreWindow^ window)
2014-11-16 02:48:24 +03:00
{
window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
2014-11-14 16:23:31 +03:00
2014-11-16 02:48:24 +03:00
bgfx::winrtSetWindow(reinterpret_cast<IUnknown*>(window));
}
2014-11-14 16:23:31 +03:00
virtual void Load(String^ entryPoint)
2014-11-16 02:48:24 +03:00
{
}
2014-11-14 16:23:31 +03:00
virtual void Run()
2014-11-16 02:48:24 +03:00
{
2014-11-14 16:23:31 +03:00
bx::Thread thread;
thread.init(MainThreadFunc, nullptr);
2014-11-16 02:48:24 +03:00
CoreWindow^ window = CoreWindow::GetForCurrentThread();
if (window == nullptr) {
int i = 4;
i++;
}
//auto bounds = window->Bounds;
//g_eventQueue.postSizeEvent(g_defaultWindow, bounds.Width, bounds.Height);
while (!m_windowClosed)
{
if (m_windowVisible)
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
}
else
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
}
}
g_eventQueue.postExitEvent();
thread.shutdown();
}
2014-11-14 16:23:31 +03:00
virtual void Uninitialize()
2014-11-16 02:48:24 +03:00
{
}
2014-11-14 16:23:31 +03:00
private:
2014-11-16 02:48:24 +03:00
bool m_windowVisible;
bool m_windowClosed;
2014-11-14 16:23:31 +03:00
2014-11-16 02:48:24 +03:00
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow^ window = CoreWindow::GetForCurrentThread();
if (window == nullptr) {
int i = 4;
i++;
}
2014-11-14 16:23:31 +03:00
2014-11-16 02:48:24 +03:00
CoreWindow::GetForCurrentThread()->Activate();
}
2014-11-14 16:23:31 +03:00
2014-11-16 02:48:24 +03:00
void OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
{
m_windowVisible = args->Visible;
}
2014-11-14 16:23:31 +03:00
void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
2014-11-16 02:48:24 +03:00
{
m_windowClosed = true;
}
static int32_t MainThreadFunc(void*)
{
return entry::main(0, g_emptyArgs);
}
2014-11-14 16:23:31 +03:00
};
ref class AppSource sealed : IFrameworkViewSource
{
public:
virtual IFrameworkView^ CreateView()
2014-11-16 02:48:24 +03:00
{
return ref new App();
}
2014-11-14 16:23:31 +03:00
};
namespace entry
{
2014-11-16 02:48:24 +03:00
const Event* poll()
2014-11-14 16:23:31 +03:00
{
return g_eventQueue.poll();
}
const Event* poll(WindowHandle _handle)
{
return g_eventQueue.poll(_handle);
}
void release(const Event* _event)
{
g_eventQueue.release(_event);
}
2014-11-16 02:48:24 +03:00
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
2014-11-14 16:23:31 +03:00
{
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 setMouseLock(WindowHandle _handle, bool _lock)
{
BX_UNUSED(_handle, _lock);
}
}
[MTAThread]
int main(Array<String^>^)
{
2014-11-16 02:48:24 +03:00
auto appSource = ref new AppSource();
CoreApplication::Run(appSource);
return 0;
2014-11-14 16:23:31 +03:00
}
2014-11-16 02:48:24 +03:00
#endif // BX_PLATFORM_WINRT