Main window, empty GPU files.
This commit is contained in:
@@ -23,6 +23,7 @@ class Loop {
|
||||
virtual void Post(std::function<void()> fn) = 0;
|
||||
|
||||
virtual void Quit() = 0;
|
||||
virtual void AwaitQuit() = 0;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <poly/ui/win32/win32_loop.h>
|
||||
|
||||
#include <poly/assert.h>
|
||||
|
||||
namespace poly {
|
||||
namespace ui {
|
||||
namespace win32 {
|
||||
@@ -26,10 +28,18 @@ class PostedFn {
|
||||
};
|
||||
|
||||
Win32Loop::Win32Loop() : thread_id_(0) {
|
||||
thread_ = std::thread([this]() {
|
||||
poly::threading::Fence init_fence;
|
||||
thread_ = std::thread([&]() {
|
||||
poly::threading::set_name("Win32 Loop");
|
||||
thread_id_ = GetCurrentThreadId();
|
||||
|
||||
init_fence.Signal();
|
||||
|
||||
ThreadMain();
|
||||
|
||||
quit_fence_.Signal();
|
||||
});
|
||||
init_fence.Wait();
|
||||
}
|
||||
|
||||
Win32Loop::~Win32Loop() = default;
|
||||
@@ -57,16 +67,22 @@ void Win32Loop::ThreadMain() {
|
||||
}
|
||||
|
||||
void Win32Loop::Post(std::function<void()> fn) {
|
||||
assert_true(thread_id_ != 0);
|
||||
PostThreadMessage(thread_id_, kWmWin32LoopPost,
|
||||
reinterpret_cast<WPARAM>(this),
|
||||
reinterpret_cast<LPARAM>(new PostedFn(std::move(fn))));
|
||||
}
|
||||
|
||||
void Win32Loop::Quit() {
|
||||
assert_true(thread_id_ != 0);
|
||||
PostThreadMessage(thread_id_, kWmWin32LoopQuit,
|
||||
reinterpret_cast<WPARAM>(this), 0);
|
||||
}
|
||||
|
||||
void Win32Loop::AwaitQuit() {
|
||||
quit_fence_.Wait();
|
||||
}
|
||||
|
||||
} // namespace win32
|
||||
} // namespace ui
|
||||
} // namespace poly
|
||||
|
||||
@@ -13,8 +13,12 @@
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <poly/threading.h>
|
||||
#include <poly/ui/loop.h>
|
||||
|
||||
namespace poly {
|
||||
@@ -24,17 +28,19 @@ namespace win32 {
|
||||
class Win32Loop : public Loop {
|
||||
public:
|
||||
Win32Loop();
|
||||
~Win32Loop();
|
||||
~Win32Loop() override;
|
||||
|
||||
void Post(std::function<void()> fn) override;
|
||||
|
||||
void Quit() override;
|
||||
void AwaitQuit() override;
|
||||
|
||||
private:
|
||||
void ThreadMain();
|
||||
|
||||
std::thread thread_;
|
||||
DWORD thread_id_;
|
||||
poly::threading::Fence quit_fence_;
|
||||
};
|
||||
|
||||
} // namespace win32
|
||||
|
||||
@@ -24,6 +24,11 @@ Win32Window::Win32Window(const std::wstring& title)
|
||||
|
||||
Win32Window::~Win32Window() {}
|
||||
|
||||
bool Win32Window::Initialize() {
|
||||
CreateHWND();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Win32Window::CreateHWND() {
|
||||
HINSTANCE hInstance = GetModuleHandle(nullptr);
|
||||
|
||||
@@ -62,6 +67,7 @@ bool Win32Window::CreateHWND() {
|
||||
}
|
||||
|
||||
main_menu_ = CreateMenu();
|
||||
AppendMenu(main_menu_, MF_STRING, 0, L"TODO");
|
||||
SetMenu(hwnd_, main_menu_);
|
||||
|
||||
// Disable flicks.
|
||||
@@ -130,13 +136,25 @@ bool Win32Window::set_title(const std::wstring& title) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// bool Win32Window::SetSize(uint32_t width, uint32_t height) {
|
||||
// RECT rc = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
|
||||
// AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
// // TODO(benvanik): center?
|
||||
// MoveWindow(handle_, 0, 0, rc.right - rc.left, rc.bottom - rc.top, TRUE);
|
||||
// return true;
|
||||
// }
|
||||
void Win32Window::Resize(int32_t width, int32_t height) {
|
||||
RECT rc = {0, 0, width, height};
|
||||
bool has_menu = main_menu_ ? true : false;
|
||||
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, has_menu);
|
||||
Window::Resize(rc.right - rc.left, rc.bottom - rc.top);
|
||||
}
|
||||
|
||||
void Win32Window::Resize(int32_t left, int32_t top, int32_t right,
|
||||
int32_t bottom) {
|
||||
RECT rc = {left, top, right, bottom};
|
||||
bool has_menu = main_menu_ ? true : false;
|
||||
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, has_menu);
|
||||
Window::Resize(rc.left, rc.top, rc.right, rc.bottom);
|
||||
}
|
||||
|
||||
void Win32Window::ResizeToFill(int32_t pad_left, int32_t pad_top,
|
||||
int32_t pad_right, int32_t pad_bottom) {
|
||||
// TODO(benvanik): fullscreen.
|
||||
}
|
||||
|
||||
void Win32Window::OnClose() {
|
||||
if (!closing_ && hwnd_) {
|
||||
|
||||
@@ -24,8 +24,16 @@ class Win32Window : public Window<Win32Control> {
|
||||
Win32Window(const std::wstring& title);
|
||||
~Win32Window() override;
|
||||
|
||||
bool Initialize() override;
|
||||
|
||||
bool set_title(const std::wstring& title) override;
|
||||
|
||||
void Resize(int32_t width, int32_t height) override;
|
||||
void Resize(int32_t left, int32_t top, int32_t right,
|
||||
int32_t bottom) override;
|
||||
void ResizeToFill(int32_t pad_left, int32_t pad_top, int32_t pad_right,
|
||||
int32_t pad_bottom) override;
|
||||
|
||||
protected:
|
||||
bool CreateHWND() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user