[deploy] update window

This commit is contained in:
Nomango 2020-02-02 15:47:48 +08:00
parent 8cf8972242
commit 10ecc736f8
4 changed files with 46 additions and 78 deletions

View File

@ -20,6 +20,6 @@
#pragma once #pragma once
#include <kiwano-network/HttpClient.h>
#include <kiwano-network/HttpRequest.h> #include <kiwano-network/HttpRequest.h>
#include <kiwano-network/HttpResponse.hpp> #include <kiwano-network/HttpResponse.hpp>
#include <kiwano-network/HttpClient.h>

View File

@ -23,17 +23,6 @@
namespace kiwano namespace kiwano
{ {
WindowConfig::WindowConfig(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
bool fullscreen)
: title(title)
, width(width)
, height(height)
, icon(icon)
, resizable(resizable)
, fullscreen(fullscreen)
{
}
Window::Window() Window::Window()
: should_close_(false) : should_close_(false)
, width_(0) , width_(0)

View File

@ -26,6 +26,7 @@
namespace kiwano namespace kiwano
{ {
/** /**
* \~chinese * \~chinese
* @brief * @brief
@ -42,35 +43,15 @@ enum class CursorType
SizeNWSE, ///< 指向左上到右下方向的箭头 SizeNWSE, ///< 指向左上到右下方向的箭头
}; };
/**
* \~chinese
* @brief
*/
struct WindowConfig
{
String title; ///< 标题
uint32_t width; ///< 宽度
uint32_t height; ///< 高度
uint32_t icon; ///< 图标资源 ID
bool resizable; ///< 窗口大小可拉伸
bool fullscreen; ///< 全屏模式
/**
* \~chinese
* @brief
* @param title
* @param width
* @param height
* @param icon ID
* @param resizable
* @param fullscreen
*/
WindowConfig(String const& title = L"Kiwano Game", uint32_t width = 640, uint32_t height = 480, uint32_t icon = 0,
bool resizable = false, bool fullscreen = false);
};
#if defined(KGE_WIN32) #if defined(KGE_WIN32)
/**
* \~chinese
* @brief
*/
typedef HWND WindowHandle; typedef HWND WindowHandle;
#endif #endif
/** /**
@ -89,9 +70,16 @@ public:
/** /**
* \~chinese * \~chinese
* @brief * @brief
* @param config * @param title
* @param width
* @param height
* @param icon ID
* @param resizable
* @param fullscreen
* @throw std::runtime_error
*/ */
virtual bool Create(WindowConfig const& config) = 0; virtual void Create(String const& title, uint32_t width, uint32_t height, uint32_t icon = 0, bool resizable = false,
bool fullscreen = false) = 0;
/** /**
* \~chinese * \~chinese
@ -168,11 +156,18 @@ public:
/** /**
* \~chinese * \~chinese
* @brief * @brief
* @return * @return \n
* *
*/ */
EventPtr PollEvent(); EventPtr PollEvent();
/**
* \~chinese
* @brief
* @param evt
*/
void PushEvent(EventPtr evt);
/** /**
* \~chinese * \~chinese
* @brief * @brief
@ -190,15 +185,9 @@ protected:
~Window(); ~Window();
void PushEvent(EventPtr evt);
void SetInternalSize(uint32_t width, uint32_t height);
void SetInternalTitle(String const& title);
virtual void PumpEvents() = 0; virtual void PumpEvents() = 0;
private: protected:
bool should_close_; bool should_close_;
uint32_t width_; uint32_t width_;
uint32_t height_; uint32_t height_;
@ -206,14 +195,4 @@ private:
std::queue<EventPtr> event_queue_; std::queue<EventPtr> event_queue_;
}; };
inline void Window::SetInternalSize(uint32_t width, uint32_t height)
{
width_ = width;
height_ = height;
}
inline void Window::SetInternalTitle(String const& title)
{
title_ = title;
}
} // namespace kiwano } // namespace kiwano

View File

@ -103,7 +103,8 @@ public:
~WindowImpl(); ~WindowImpl();
bool Create(WindowConfig const& config) override; void Create(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
bool fullscreen) override;
WindowHandle GetHandle() const override; WindowHandle GetHandle() const override;
@ -192,7 +193,8 @@ WindowImpl::WindowImpl()
WindowImpl::~WindowImpl() {} WindowImpl::~WindowImpl() {}
bool WindowImpl::Create(WindowConfig const& config) void WindowImpl::Create(String const& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable,
bool fullscreen)
{ {
HINSTANCE hinst = GetModuleHandleW(nullptr); HINSTANCE hinst = GetModuleHandleW(nullptr);
WNDCLASSEX wcex = { 0 }; WNDCLASSEX wcex = { 0 };
@ -208,9 +210,9 @@ bool WindowImpl::Create(WindowConfig const& config)
wcex.lpszMenuName = nullptr; wcex.lpszMenuName = nullptr;
wcex.hCursor = ::LoadCursorW(hinst, IDC_ARROW); wcex.hCursor = ::LoadCursorW(hinst, IDC_ARROW);
if (config.icon) if (icon)
{ {
wcex.hIcon = (HICON)::LoadImageW(hinst, MAKEINTRESOURCE(config.icon), IMAGE_ICON, 0, 0, wcex.hIcon = (HICON)::LoadImageW(hinst, MAKEINTRESOURCE(icon), IMAGE_ICON, 0, 0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
} }
@ -231,13 +233,10 @@ bool WindowImpl::Create(WindowConfig const& config)
device_name_ = new wchar_t[len + 1]; device_name_ = new wchar_t[len + 1];
lstrcpyW(device_name_, monitor_info_ex.szDevice); lstrcpyW(device_name_, monitor_info_ex.szDevice);
uint32_t width = config.width; int left = -1, top = -1;
uint32_t height = config.height;
int left = -1;
int top = -1;
resizable_ = config.resizable; resizable_ = resizable;
is_fullscreen_ = config.fullscreen; is_fullscreen_ = fullscreen;
if (is_fullscreen_) if (is_fullscreen_)
{ {
@ -264,17 +263,19 @@ bool WindowImpl::Create(WindowConfig const& config)
height = win_height; height = win_height;
} }
handle_ = ::CreateWindowExW(is_fullscreen_ ? WS_EX_TOPMOST : 0, KGE_WND_CLASS_NAME, config.title.c_str(), handle_ = ::CreateWindowExW(is_fullscreen_ ? WS_EX_TOPMOST : 0, KGE_WND_CLASS_NAME, title.c_str(), GetStyle(), left,
GetStyle(), left, top, width, height, nullptr, nullptr, hinst, nullptr); top, width, height, nullptr, nullptr, hinst, nullptr);
if (handle_ == nullptr) if (handle_ == nullptr)
{ {
::UnregisterClass(KGE_WND_CLASS_NAME, hinst); ::UnregisterClass(KGE_WND_CLASS_NAME, hinst);
KGE_ERROR(L"Failed with HRESULT of %08X", HRESULT_FROM_WIN32(GetLastError())); KGE_ERROR(L"Failed with HRESULT of %08X", HRESULT_FROM_WIN32(GetLastError()));
return false; throw std::runtime_error("Create window failed");
} }
SetInternalSize(width, height); width_ = width;
height_ = height;
// disable imm // disable imm
::ImmAssociateContext(handle_, nullptr); ::ImmAssociateContext(handle_, nullptr);
@ -289,7 +290,6 @@ bool WindowImpl::Create(WindowConfig const& config)
{ {
ChangeFullScreenResolution(width, height, device_name_); ChangeFullScreenResolution(width, height, device_name_);
} }
return true;
} }
WindowHandle WindowImpl::GetHandle() const WindowHandle WindowImpl::GetHandle() const
@ -591,7 +591,8 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA
{ {
// KGE_SYS_LOG(L"Window resized"); // KGE_SYS_LOG(L"Window resized");
window->SetInternalSize(((uint32_t)(short)LOWORD(lparam)), ((uint32_t)(short)HIWORD(lparam))); window->width_ = ((uint32_t)(short)LOWORD(lparam));
window->height_ = ((uint32_t)(short)HIWORD(lparam));
WindowResizedEventPtr evt = new WindowResizedEvent; WindowResizedEventPtr evt = new WindowResizedEvent;
evt->width = window->GetWidth(); evt->width = window->GetWidth();
@ -626,11 +627,10 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA
{ {
KGE_SYS_LOG(L"Window title changed"); KGE_SYS_LOG(L"Window title changed");
String title = String::cstr(reinterpret_cast<LPCWSTR>(lparam)); window->title_ = String::cstr(reinterpret_cast<LPCWSTR>(lparam));
window->SetInternalTitle(title);
WindowTitleChangedEventPtr evt = new WindowTitleChangedEvent; WindowTitleChangedEventPtr evt = new WindowTitleChangedEvent;
evt->title = title; evt->title = window->title_;
window->PushEvent(evt); window->PushEvent(evt);
} }
break; break;