[deploy] update window
This commit is contained in:
parent
8cf8972242
commit
10ecc736f8
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue