29 #include YFM_Helper_Host
30 #include YFM_Helper_ShellHelper // for YSL_DEBUG_DECL_TIMER;
35 using namespace Drawing;
42 std::chrono::nanoseconds host_sleep(
u64(1000000000 / g_max_free_fps));
57 WndProc(::HWND h_wnd, ::UINT msg, ::WPARAM w_param, ::LPARAM l_param)
59 const auto p(reinterpret_cast<Window*>(::GetWindowLongPtrW(h_wnd,
68 ::UINT size(
sizeof(::RAWINPUT));
69 byte lpb[
sizeof(::RAWINPUT)]{};
71 if(
YB_LIKELY(::GetRawInputData(::HRAWINPUT(l_param), RID_INPUT, lpb,
72 &size,
sizeof(::RAWINPUTHEADER)) != ::UINT(-1)))
74 const auto p_raw(reinterpret_cast<::RAWINPUT*>(lpb));
76 if(
YB_LIKELY(p_raw->header.dwType == RIM_TYPEMOUSE))
78 if(p_raw->data.mouse.usButtonFlags == RI_MOUSE_WHEEL)
79 p->GetHost().RawMouseButton
80 = p_raw->data.mouse.usButtonData;
85 auto& m(p->MessageMap);
86 const auto i(m.find(msg));
90 i->second(w_param, l_param);
94 return ::DefWindowProcW(h_wnd, msg, w_param, l_param);
101 Environment::Environment()
102 : wnd_map(), wmap_mtx()
110 Environment::~Environment()
125 Environment::GetForegroundWindow() const
ynothrow
128 return FindWindow(::GetForegroundWindow());
137 std::unique_lock<std::mutex> lck(wmap_mtx);
140 wnd_map.insert(make_pair(h, p));
146 std::unique_lock<std::mutex> lck(wmap_mtx);
147 const auto i(wnd_map.find(h));
149 return i == wnd_map.end() ?
nullptr : i->second;
153 Environment::HostLoop()
159 ::MSG msg{
nullptr, 0, 0, 0, 0, {0, 0}};
161 if(::PeekMessageW(&msg,
nullptr, 0, 0, PM_REMOVE) != 0)
163 if(msg.message == WM_QUIT)
167 ::TranslateMessage(&msg);
168 ::DispatchMessageW(&msg);
183 # if YF_Multithread == 1
185 Environment::LeaveWindowThread()
187 if(--wnd_thrd_count == 0 && ExitOnAllWindowThreadCompleted)
195 std::unique_lock<std::mutex> lck(wmap_mtx);
196 const auto i(wnd_map.find(h));
198 if(i != wnd_map.end())
203 Environment::UpdateRenderWindows()
205 std::unique_lock<std::mutex> lck(wmap_mtx);
207 for(
const auto& pr : wnd_map)
209 pr.second->Refresh();
yconstexpr wchar_t WindowClassName[]
YF_API void PostQuitMessage(int nExitCode, Messaging::Priority p=0xF0)
以优先级 p 发起 Shell 终止请求,返回 nExitCode。
#define YCL_Trace(_lv,...)
YCLib 默认调试跟踪。
const second_tag get_value
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
if(YB_LIKELY(!error)) if(YB_LIKELY(!(error
#define YF_Multithread
多线程环境。
::ANativeWindow * NativeWindowHandle
std::string to_string(unsigned char val)
转换为字符串。
#define YTraceDe(...)
YCLib 默认调试跟踪。
#define yconstexpr
指定编译时常量表达式。
#define YSL_DEBUG_DECL_TIMER(_name,...)