diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp index a3129855..f65a4a5b 100644 --- a/src/kiwano-imgui/ImGuiModule.cpp +++ b/src/kiwano-imgui/ImGuiModule.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -15,7 +15,6 @@ namespace kiwano namespace imgui { ImGuiModule::ImGuiModule() - : target_window_(nullptr) { } @@ -31,13 +30,11 @@ void ImGuiModule::SetupComponent() ImGui::StyleColorsDark(); // Setup Platform/Renderer bindings - target_window_ = Renderer::GetInstance().GetTargetWindow(); - io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) io.BackendPlatformName = "imgui_impl_win32"; - io.ImeWindowHandle = target_window_; + io.ImeWindowHandle = WindowImpl::GetInstance().GetHandle(); // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during // the application lifetime. @@ -177,7 +174,7 @@ void ImGuiModule::UpdateMousePos() if (io.WantSetMousePos) { POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; - ::ClientToScreen(target_window_, &pos); + ::ClientToScreen(WindowImpl::GetInstance().GetHandle(), &pos); ::SetCursorPos(pos.x, pos.y); } diff --git a/src/kiwano-imgui/ImGuiModule.h b/src/kiwano-imgui/ImGuiModule.h index 6f726d2c..60a005ca 100644 --- a/src/kiwano-imgui/ImGuiModule.h +++ b/src/kiwano-imgui/ImGuiModule.h @@ -26,6 +26,7 @@ namespace kiwano { namespace imgui { + /** * \~chinese * @brief ImGui模块 @@ -57,9 +58,7 @@ private: void UpdateMousePos(); void UpdateMouseCursor(); - -private: - WindowHandle target_window_; }; + } // namespace imgui } // namespace kiwano diff --git a/src/kiwano/platform/Window.h b/src/kiwano/platform/Window.h index 0fe19d75..0ef4c2b6 100644 --- a/src/kiwano/platform/Window.h +++ b/src/kiwano/platform/Window.h @@ -44,16 +44,6 @@ enum class CursorType }; -#if defined(KGE_WIN32) - -/** - * \~chinese - * @brief 窗口句柄 - */ -typedef HWND WindowHandle; - -#endif - /** * \~chinese * @brief 窗口类,控制窗口标题、大小、图标等 @@ -109,12 +99,6 @@ public: */ uint32_t GetHeight() const; - /** - * \~chinese - * @brief 获取窗口句柄 - */ - virtual WindowHandle GetHandle() const = 0; - /** * \~chinese * @brief 设置标题 diff --git a/src/kiwano/platform/win32/WindowImpl.cpp b/src/kiwano/platform/win32/WindowImpl.cpp index 104bfe9c..bedf93b9 100644 --- a/src/kiwano/platform/win32/WindowImpl.cpp +++ b/src/kiwano/platform/win32/WindowImpl.cpp @@ -258,7 +258,7 @@ void WindowImpl::Create(String const& title, uint32_t width, uint32_t height, ui } } -WindowHandle WindowImpl::GetHandle() const +HWND WindowImpl::GetHandle() const { return handle_; } diff --git a/src/kiwano/platform/win32/WindowImpl.h b/src/kiwano/platform/win32/WindowImpl.h index fc46a1dd..c67f87a4 100644 --- a/src/kiwano/platform/win32/WindowImpl.h +++ b/src/kiwano/platform/win32/WindowImpl.h @@ -32,11 +32,11 @@ class KGE_API WindowImpl : public Window public: static WindowImpl& GetInstance(); + HWND GetHandle() const; + void Create(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, bool fullscreen) override; - WindowHandle GetHandle() const override; - void SetTitle(String const& title) override; void SetIcon(uint32_t icon_resource) override; @@ -65,11 +65,11 @@ private: static LRESULT CALLBACK WndProc(HWND, UINT32, WPARAM, LPARAM); private: - bool resizable_; - bool is_fullscreen_; - wchar_t* device_name_; - WindowHandle handle_; - CursorType mouse_cursor_; + bool resizable_; + bool is_fullscreen_; + wchar_t* device_name_; + HWND handle_; + CursorType mouse_cursor_; std::array key_map_; }; diff --git a/src/kiwano/render/DirectX/RendererImpl.cpp b/src/kiwano/render/DirectX/RendererImpl.cpp index 0f9ff4d2..3109e9e3 100644 --- a/src/kiwano/render/DirectX/RendererImpl.cpp +++ b/src/kiwano/render/DirectX/RendererImpl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -50,18 +51,18 @@ void RendererImpl::SetupComponent() win32::ThrowIfFailed(::CoInitialize(nullptr)); - target_window_ = Window::GetInstance().GetHandle(); + HWND target_window = WindowImpl::GetInstance().GetHandle(); output_size_ = Window::GetInstance().GetSize(); d2d_res_ = nullptr; d3d_res_ = nullptr; - HRESULT hr = target_window_ ? S_OK : E_FAIL; + HRESULT hr = target_window ? S_OK : E_FAIL; // Direct3D device resources if (SUCCEEDED(hr)) { - hr = ID3DDeviceResources::Create(&d3d_res_, target_window_); + hr = ID3DDeviceResources::Create(&d3d_res_, target_window); // Direct2D device resources if (SUCCEEDED(hr)) diff --git a/src/kiwano/render/Renderer.cpp b/src/kiwano/render/Renderer.cpp index 36956eac..53904c2c 100644 --- a/src/kiwano/render/Renderer.cpp +++ b/src/kiwano/render/Renderer.cpp @@ -24,8 +24,7 @@ namespace kiwano { Renderer::Renderer() - : target_window_(nullptr) - , vsync_(true) + : vsync_(true) , clear_color_(Color::Black) { } diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h index c820aa7d..ba115797 100644 --- a/src/kiwano/render/Renderer.h +++ b/src/kiwano/render/Renderer.h @@ -20,7 +20,6 @@ #pragma once #include -#include #include #include #include @@ -204,10 +203,6 @@ public: /// @brief 获取渲染上下文 virtual RenderContext& GetContext() = 0; - /// \~chinese - /// @brief 获取目标窗口 - virtual WindowHandle GetTargetWindow() const; - /// \~chinese /// @brief 获取渲染输出大小 virtual Size GetOutputSize() const; @@ -217,18 +212,12 @@ protected: protected: bool vsync_; - WindowHandle target_window_; Color clear_color_; Size output_size_; }; /** @} */ -inline WindowHandle Renderer::GetTargetWindow() const -{ - return target_window_; -} - inline Size Renderer::GetOutputSize() const { return output_size_;