Update WindowImpl

This commit is contained in:
Nomango 2020-02-09 19:06:25 +08:00
parent d302ec3a20
commit b763064b3d
8 changed files with 18 additions and 49 deletions

View File

@ -5,7 +5,7 @@
#include <kiwano/core/event/KeyEvent.h> #include <kiwano/core/event/KeyEvent.h>
#include <kiwano/core/event/MouseEvent.h> #include <kiwano/core/event/MouseEvent.h>
#include <kiwano/platform/Input.h> #include <kiwano/platform/Input.h>
#include <kiwano/platform/Window.h> #include <kiwano/platform/win32/WindowImpl.h>
#include <kiwano/render/Renderer.h> #include <kiwano/render/Renderer.h>
#include <kiwano-imgui/ImGuiModule.h> #include <kiwano-imgui/ImGuiModule.h>
#include <kiwano-imgui/imgui_impl.h> #include <kiwano-imgui/imgui_impl.h>
@ -15,7 +15,6 @@ namespace kiwano
namespace imgui namespace imgui
{ {
ImGuiModule::ImGuiModule() ImGuiModule::ImGuiModule()
: target_window_(nullptr)
{ {
} }
@ -31,13 +30,11 @@ void ImGuiModule::SetupComponent()
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
// Setup Platform/Renderer bindings // Setup Platform/Renderer bindings
target_window_ = Renderer::GetInstance().GetTargetWindow();
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
io.BackendFlags |= io.BackendFlags |=
ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
io.BackendPlatformName = "imgui_impl_win32"; 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 // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during
// the application lifetime. // the application lifetime.
@ -177,7 +174,7 @@ void ImGuiModule::UpdateMousePos()
if (io.WantSetMousePos) if (io.WantSetMousePos)
{ {
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
::ClientToScreen(target_window_, &pos); ::ClientToScreen(WindowImpl::GetInstance().GetHandle(), &pos);
::SetCursorPos(pos.x, pos.y); ::SetCursorPos(pos.x, pos.y);
} }

View File

@ -26,6 +26,7 @@ namespace kiwano
{ {
namespace imgui namespace imgui
{ {
/** /**
* \~chinese * \~chinese
* @brief ImGuiÄŁżé * @brief ImGuiÄŁżé
@ -57,9 +58,7 @@ private:
void UpdateMousePos(); void UpdateMousePos();
void UpdateMouseCursor(); void UpdateMouseCursor();
private:
WindowHandle target_window_;
}; };
} // namespace imgui } // namespace imgui
} // namespace kiwano } // namespace kiwano

View File

@ -44,16 +44,6 @@ enum class CursorType
}; };
#if defined(KGE_WIN32)
/**
* \~chinese
* @brief ´°¿Ú¾ä±ú
*/
typedef HWND WindowHandle;
#endif
/** /**
* \~chinese * \~chinese
* @brief * @brief
@ -109,12 +99,6 @@ public:
*/ */
uint32_t GetHeight() const; uint32_t GetHeight() const;
/**
* \~chinese
* @brief »ñÈ¡´°¿Ú¾ä±ú
*/
virtual WindowHandle GetHandle() const = 0;
/** /**
* \~chinese * \~chinese
* @brief * @brief

View File

@ -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_; return handle_;
} }

View File

@ -32,11 +32,11 @@ class KGE_API WindowImpl : public Window
public: public:
static WindowImpl& GetInstance(); static WindowImpl& GetInstance();
HWND GetHandle() const;
void Create(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, void Create(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
bool fullscreen) override; bool fullscreen) override;
WindowHandle GetHandle() const override;
void SetTitle(String const& title) override; void SetTitle(String const& title) override;
void SetIcon(uint32_t icon_resource) override; void SetIcon(uint32_t icon_resource) override;
@ -65,11 +65,11 @@ private:
static LRESULT CALLBACK WndProc(HWND, UINT32, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT32, WPARAM, LPARAM);
private: private:
bool resizable_; bool resizable_;
bool is_fullscreen_; bool is_fullscreen_;
wchar_t* device_name_; wchar_t* device_name_;
WindowHandle handle_; HWND handle_;
CursorType mouse_cursor_; CursorType mouse_cursor_;
std::array<KeyCode, 256> key_map_; std::array<KeyCode, 256> key_map_;
}; };

View File

@ -21,6 +21,7 @@
#include <kiwano/core/Logger.h> #include <kiwano/core/Logger.h>
#include <kiwano/core/event/WindowEvent.h> #include <kiwano/core/event/WindowEvent.h>
#include <kiwano/platform/FileSystem.h> #include <kiwano/platform/FileSystem.h>
#include <kiwano/platform/win32/WindowImpl.h>
#include <kiwano/render/ShapeSink.h> #include <kiwano/render/ShapeSink.h>
#include <kiwano/render/DirectX/TextureRenderContextImpl.h> #include <kiwano/render/DirectX/TextureRenderContextImpl.h>
#include <kiwano/render/DirectX/RendererImpl.h> #include <kiwano/render/DirectX/RendererImpl.h>
@ -50,18 +51,18 @@ void RendererImpl::SetupComponent()
win32::ThrowIfFailed(::CoInitialize(nullptr)); win32::ThrowIfFailed(::CoInitialize(nullptr));
target_window_ = Window::GetInstance().GetHandle(); HWND target_window = WindowImpl::GetInstance().GetHandle();
output_size_ = Window::GetInstance().GetSize(); output_size_ = Window::GetInstance().GetSize();
d2d_res_ = nullptr; d2d_res_ = nullptr;
d3d_res_ = nullptr; d3d_res_ = nullptr;
HRESULT hr = target_window_ ? S_OK : E_FAIL; HRESULT hr = target_window ? S_OK : E_FAIL;
// Direct3D device resources // Direct3D device resources
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ID3DDeviceResources::Create(&d3d_res_, target_window_); hr = ID3DDeviceResources::Create(&d3d_res_, target_window);
// Direct2D device resources // Direct2D device resources
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))

View File

@ -24,8 +24,7 @@ namespace kiwano
{ {
Renderer::Renderer() Renderer::Renderer()
: target_window_(nullptr) : vsync_(true)
, vsync_(true)
, clear_color_(Color::Black) , clear_color_(Color::Black)
{ {
} }

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include <kiwano/core/Component.h> #include <kiwano/core/Component.h>
#include <kiwano/platform/Window.h>
#include <kiwano/render/Font.h> #include <kiwano/render/Font.h>
#include <kiwano/render/GifImage.h> #include <kiwano/render/GifImage.h>
#include <kiwano/render/TextStyle.hpp> #include <kiwano/render/TextStyle.hpp>
@ -204,10 +203,6 @@ public:
/// @brief 获取渲染上下文 /// @brief 获取渲染上下文
virtual RenderContext& GetContext() = 0; virtual RenderContext& GetContext() = 0;
/// \~chinese
/// @brief »ñȡĿ±ê´°¿Ú
virtual WindowHandle GetTargetWindow() const;
/// \~chinese /// \~chinese
/// @brief 获取渲染输出大小 /// @brief 获取渲染输出大小
virtual Size GetOutputSize() const; virtual Size GetOutputSize() const;
@ -217,18 +212,12 @@ protected:
protected: protected:
bool vsync_; bool vsync_;
WindowHandle target_window_;
Color clear_color_; Color clear_color_;
Size output_size_; Size output_size_;
}; };
/** @} */ /** @} */
inline WindowHandle Renderer::GetTargetWindow() const
{
return target_window_;
}
inline Size Renderer::GetOutputSize() const inline Size Renderer::GetOutputSize() const
{ {
return output_size_; return output_size_;