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/MouseEvent.h>
#include <kiwano/platform/Input.h>
#include <kiwano/platform/Window.h>
#include <kiwano/platform/win32/WindowImpl.h>
#include <kiwano/render/Renderer.h>
#include <kiwano-imgui/ImGuiModule.h>
#include <kiwano-imgui/imgui_impl.h>
@ -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);
}

View File

@ -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

View File

@ -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

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_;
}

View File

@ -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<KeyCode, 256> key_map_;
};

View File

@ -21,6 +21,7 @@
#include <kiwano/core/Logger.h>
#include <kiwano/core/event/WindowEvent.h>
#include <kiwano/platform/FileSystem.h>
#include <kiwano/platform/win32/WindowImpl.h>
#include <kiwano/render/ShapeSink.h>
#include <kiwano/render/DirectX/TextureRenderContextImpl.h>
#include <kiwano/render/DirectX/RendererImpl.h>
@ -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))

View File

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

View File

@ -20,7 +20,6 @@
#pragma once
#include <kiwano/core/Component.h>
#include <kiwano/platform/Window.h>
#include <kiwano/render/Font.h>
#include <kiwano/render/GifImage.h>
#include <kiwano/render/TextStyle.hpp>
@ -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_;