Magic_Game/core/modules/Window.cpp

542 lines
10 KiB
C++
Raw Normal View History

2018-09-05 13:17:07 +08:00
#include "..\e2dmodule.h"
2018-04-21 21:24:46 +08:00
#include "..\e2dmanager.h"
2018-09-06 23:26:32 +08:00
#include "..\e2dobject.h"
2018-01-30 16:45:38 +08:00
#include <imm.h>
#pragma comment (lib ,"imm32.lib")
2018-08-02 00:27:45 +08:00
#define WINDOW_STYLE WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME
#define REGISTER_CLASS L"Easy2DApp"
2018-01-30 16:45:38 +08:00
2018-09-04 22:42:34 +08:00
e2d::Window * e2d::Window::instance_ = nullptr;
2018-08-28 00:06:10 +08:00
2018-09-04 22:42:34 +08:00
e2d::Window * e2d::Window::GetInstance()
2018-08-28 00:06:10 +08:00
{
2018-09-04 22:42:34 +08:00
if (!instance_)
instance_ = new (std::nothrow) Window;
return instance_;
2018-08-28 00:06:10 +08:00
}
2018-09-04 22:42:34 +08:00
void e2d::Window::DestroyInstance()
2018-08-28 00:06:10 +08:00
{
2018-09-04 22:42:34 +08:00
if (instance_)
2018-08-28 00:06:10 +08:00
{
2018-09-04 22:42:34 +08:00
delete instance_;
instance_ = nullptr;
2018-08-28 00:06:10 +08:00
}
}
2018-09-07 17:26:21 +08:00
e2d::Size e2d::Window::GetScreenSize()
{
int screen_width = ::GetSystemMetrics(SM_CXSCREEN);
int screen_height = ::GetSystemMetrics(SM_CYSCREEN);
Size screen_size(
static_cast<float>(screen_width),
static_cast<float>(screen_height)
);
return std::move(screen_size);
}
2018-08-28 00:06:10 +08:00
e2d::Window::Window()
2018-09-11 15:47:51 +08:00
: hwnd_(nullptr)
2018-09-04 22:42:34 +08:00
, width_(640)
, height_(480)
, title_(L"Easy2D Game")
, icon_id_(0)
, dpi_(0.f)
{
::CoInitialize(nullptr);
2018-08-19 15:11:20 +08:00
// <20><>ȡϵͳ DPI
2018-09-11 17:54:21 +08:00
Renderer::GetFactory()->GetDesktopDpi(&dpi_, &dpi_);
2018-08-15 00:06:03 +08:00
}
e2d::Window::~Window()
{
if (::GetConsoleWindow())
::FreeConsole();
2018-09-11 15:47:51 +08:00
if (hwnd_)
::DestroyWindow(hwnd_);
2018-08-15 00:06:03 +08:00
::CoUninitialize();
2018-08-15 00:06:03 +08:00
}
bool e2d::Window::CheckUnique()
2018-08-15 00:06:03 +08:00
{
HANDLE mutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + title_));
2018-08-15 00:06:03 +08:00
if (mutex == nullptr)
2018-08-15 00:06:03 +08:00
{
WARN("CreateMutex Failed!");
return false;
}
2018-08-15 00:06:03 +08:00
else if (::GetLastError() == ERROR_ALREADY_EXISTS)
{
::CloseHandle(mutex);
2018-08-15 00:06:03 +08:00
return false;
}
return true;
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
e2d::Rect e2d::Window::Locate(int width, int height)
2018-08-02 00:27:45 +08:00
{
Rect result;
2018-09-11 15:47:51 +08:00
RECT rect = { 0, 0, LONG(ceil(width * dpi_ / 96.f)), LONG(ceil(height * dpi_ / 96.f)) };
2018-09-07 17:26:21 +08:00
int max_width = ::GetSystemMetrics(SM_CXSCREEN);
int max_height = ::GetSystemMetrics(SM_CYSCREEN);
2018-08-02 00:27:45 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵĴ<CAB5><C4B4>ڴ<EFBFBD>С
2018-09-11 15:47:51 +08:00
::AdjustWindowRectEx(&rect, WINDOW_STYLE, FALSE, NULL);
width = static_cast<int>(rect.right - rect.left);
height = static_cast<int>(rect.bottom - rect.top);
2018-08-02 00:27:45 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>ڴ<EFBFBD>С<EFBFBD>ȷֱ<C8B7><D6B1>ʴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-07 17:26:21 +08:00
WARN_IF(max_width < width || max_height < height, "The window Is larger than screen!");
width = std::min(width, max_width);
height = std::min(height, max_height);
2018-08-02 00:27:45 +08:00
2018-09-07 17:26:21 +08:00
float x = float((max_width - width) / 2), y = float((max_height - height) / 2);
2018-08-02 00:27:45 +08:00
return std::move(Rect(x, y, float(width), float(height)));
}
2018-09-04 22:42:34 +08:00
void e2d::Window::Poll()
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
while (::PeekMessage(&msg_, nullptr, 0, 0, PM_REMOVE))
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
::TranslateMessage(&msg_);
::DispatchMessage(&msg_);
2018-01-30 16:45:38 +08:00
}
}
2018-09-04 22:42:34 +08:00
int e2d::Window::GetWidth() const
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
return width_;
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
int e2d::Window::GetHeight() const
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
return height_;
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
e2d::Size e2d::Window::GetSize() const
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
e2d::Size size(
static_cast<float>(width_),
static_cast<float>(height_)
);
return std::move(size);
}
2018-09-04 22:42:34 +08:00
float e2d::Window::GetDpi() const
2018-07-28 22:22:58 +08:00
{
2018-09-04 22:42:34 +08:00
return dpi_;
2018-07-28 22:22:58 +08:00
}
2018-09-04 22:42:34 +08:00
const e2d::String& e2d::Window::GetTitle() const
{
2018-09-04 22:42:34 +08:00
return title_;
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
HWND e2d::Window::GetHWnd()
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
if (!hwnd_)
2018-08-28 00:06:10 +08:00
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpszClassName = REGISTER_CLASS;
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = Window::WndProc;
wcex.hIcon = nullptr;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(LONG_PTR);
wcex.hInstance = HINST_THISCOMPONENT;
wcex.hbrBackground = nullptr;
wcex.lpszMenuName = nullptr;
wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
2018-09-04 22:42:34 +08:00
if (icon_id_ != 0)
2018-08-28 00:06:10 +08:00
{
wcex.hIcon = (HICON)::LoadImage(
HINST_THISCOMPONENT,
2018-09-04 22:42:34 +08:00
MAKEINTRESOURCE(icon_id_),
2018-08-28 00:06:10 +08:00
IMAGE_ICON,
0,
0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE
);
}
// ע<><EFBFBD><E1B4B0><EFBFBD><EFBFBD>
RegisterClassEx(&wcex);
// <20><><EFBFBD><EFBFBD>ڴ<EFBFBD>С
2018-09-04 22:42:34 +08:00
Rect clientRect = Locate(width_, height_);
2018-08-28 00:06:10 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-11 15:47:51 +08:00
hwnd_ = ::CreateWindowEx(
2018-08-28 00:06:10 +08:00
NULL,
REGISTER_CLASS,
2018-09-04 22:42:34 +08:00
(LPCTSTR)title_,
2018-08-28 00:06:10 +08:00
WINDOW_STYLE,
int(clientRect.origin.x),
int(clientRect.origin.y),
int(clientRect.size.width),
int(clientRect.size.height),
nullptr,
nullptr,
HINST_THISCOMPONENT,
this
);
2018-09-11 15:47:51 +08:00
if (hwnd_)
2018-08-28 00:06:10 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-04 22:42:34 +08:00
SetTypewritingEnabled(false);
2018-08-28 00:06:10 +08:00
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̨<EFBFBD>رհ<D8B1>ť
2018-09-11 15:47:51 +08:00
HWND console_hwnd = ::GetConsoleWindow();
if (console_hwnd)
2018-08-28 00:06:10 +08:00
{
2018-09-11 15:47:51 +08:00
HMENU hmenu = ::GetSystemMenu(console_hwnd, FALSE);
2018-08-28 00:06:10 +08:00
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
}
}
else
{
::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT);
2018-09-10 20:55:20 +08:00
throw RuntimeException("Create window failed");
2018-08-28 00:06:10 +08:00
}
}
2018-09-11 15:47:51 +08:00
return hwnd_;
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
void e2d::Window::SetSize(int width, int height)
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
if (width_ == width && height_ == height)
return;
2018-08-15 00:06:03 +08:00
2018-09-04 22:42:34 +08:00
width_ = width;
height_ = height;
2018-08-15 00:06:03 +08:00
2018-09-11 15:47:51 +08:00
if (hwnd_)
2018-07-03 23:39:00 +08:00
{
2018-09-11 15:47:51 +08:00
Rect rect = Locate(width, height);
2018-08-02 00:27:45 +08:00
::MoveWindow(
2018-09-11 15:47:51 +08:00
hwnd_,
int(rect.origin.x),
int(rect.origin.y),
int(rect.size.width),
int(rect.size.height),
2018-08-02 00:27:45 +08:00
TRUE
);
2018-07-03 23:39:00 +08:00
}
2018-01-30 16:45:38 +08:00
}
2018-09-04 22:42:34 +08:00
void e2d::Window::SetTitle(const String& title)
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
title_ = title;
2018-09-11 15:47:51 +08:00
if (hwnd_)
2018-07-03 23:39:00 +08:00
{
2018-09-11 15:47:51 +08:00
::SetWindowText(hwnd_, (LPCWSTR)title);
2018-07-03 23:39:00 +08:00
}
2018-01-30 16:45:38 +08:00
}
2018-09-07 18:00:56 +08:00
void e2d::Window::SetIcon(int resource_id)
{
2018-09-07 18:00:56 +08:00
this->icon_id_ = resource_id;
2018-09-11 15:47:51 +08:00
if (hwnd_)
2018-07-03 23:39:00 +08:00
{
2018-09-07 18:00:56 +08:00
HICON icon = (HICON)::LoadImage(
HINST_THISCOMPONENT,
MAKEINTRESOURCE(resource_id),
IMAGE_ICON,
0,
0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE
);
2018-07-03 23:39:00 +08:00
// <20><><EFBFBD>ô<EFBFBD><C3B4>ڵ<EFBFBD>ͼ<EFBFBD><CDBC>
2018-09-11 15:47:51 +08:00
::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon);
::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon);
2018-07-03 23:39:00 +08:00
}
}
2018-09-04 22:42:34 +08:00
void e2d::Window::SetCursor(Cursor cursor)
{
2018-09-11 15:47:51 +08:00
LPCWSTR cursor_name = nullptr;
switch (cursor)
{
2018-05-24 20:37:34 +08:00
case Cursor::Normal:
2018-09-11 15:47:51 +08:00
cursor_name = IDC_ARROW;
break;
2018-05-24 20:37:34 +08:00
case Cursor::Hand:
2018-09-11 15:47:51 +08:00
cursor_name = IDC_HAND;
break;
2018-05-24 20:37:34 +08:00
case Cursor::No:
2018-09-11 15:47:51 +08:00
cursor_name = IDC_NO;
break;
2018-05-24 20:37:34 +08:00
case Cursor::Wait:
2018-09-11 15:47:51 +08:00
cursor_name = IDC_WAIT;
break;
2018-05-24 20:37:34 +08:00
case Cursor::ArrowWait:
2018-09-11 15:47:51 +08:00
cursor_name = IDC_APPSTARTING;
break;
default:
break;
}
2018-09-11 15:47:51 +08:00
HCURSOR hcursor = ::LoadCursor(nullptr, cursor_name);
if (hcursor)
{
::SetCursor(hcursor);
}
}
2018-09-04 22:42:34 +08:00
void e2d::Window::SetConsoleEnabled(bool enabled)
2018-01-30 16:45:38 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڵĿ<DAB5><C4BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
HWND hwnd = ::GetConsoleWindow();
// <20>رտ<D8B1><D5BF><EFBFBD>̨
2018-07-13 01:33:53 +08:00
if (enabled)
2018-01-30 16:45:38 +08:00
{
if (hwnd)
{
::ShowWindow(hwnd, SW_SHOWNORMAL);
}
else
{
// <20><>ʾһ<CABE><D2BB><EFBFBD>¿<EFBFBD><C2BF><EFBFBD>̨
if (::AllocConsole())
{
hwnd = ::GetConsoleWindow();
// <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FILE * stdoutStream, * stdinStream, * stderrStream;
2018-08-19 15:11:20 +08:00
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
freopen_s(&stdinStream, "conin$", "r+t", stdin);
freopen_s(&stderrStream, "conout$", "w+t", stderr);
2018-01-30 16:45:38 +08:00
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̨<EFBFBD>رհ<D8B1>ť
HMENU hmenu = ::GetSystemMenu(hwnd, FALSE);
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
}
}
}
else
{
if (hwnd)
{
::ShowWindow(hwnd, SW_HIDE);
}
}
}
2018-09-04 22:42:34 +08:00
void e2d::Window::SetTypewritingEnabled(bool enabled)
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
static HIMC himc = nullptr;
2018-01-30 16:45:38 +08:00
2018-07-04 17:00:21 +08:00
if (enabled)
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
if (himc != nullptr)
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
::ImmAssociateContext(GetHWnd(), himc);
himc = nullptr;
2018-01-30 16:45:38 +08:00
}
}
else
{
2018-09-11 15:47:51 +08:00
if (himc == nullptr)
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
himc = ::ImmAssociateContext(GetHWnd(), nullptr);
2018-01-30 16:45:38 +08:00
}
}
}
2018-09-04 22:42:34 +08:00
bool e2d::Window::Popup(const String & text, const String & title, PopupStyle style, bool has_cancel)
{
2018-07-17 00:35:27 +08:00
UINT type = 0;
switch (style)
{
2018-09-04 22:42:34 +08:00
case PopupStyle::Info:
2018-07-17 00:35:27 +08:00
type = MB_ICONINFORMATION;
break;
2018-09-04 22:42:34 +08:00
case PopupStyle::Warning:
2018-07-17 00:35:27 +08:00
type = MB_ICONWARNING;
break;
2018-09-04 22:42:34 +08:00
case PopupStyle::Error:
2018-07-17 00:35:27 +08:00
type = MB_ICONERROR;
break;
default:
break;
}
2018-09-04 22:42:34 +08:00
if (has_cancel)
2018-07-17 00:35:27 +08:00
{
type |= MB_OKCANCEL;
}
2018-09-04 22:42:34 +08:00
Game::GetInstance()->Pause();
2018-09-11 15:47:51 +08:00
int ret = ::MessageBox(hwnd_, (LPCWSTR)text, (LPCWSTR)title, type);
2018-09-04 22:42:34 +08:00
Game::GetInstance()->Resume();
2018-07-17 00:35:27 +08:00
return ret == IDOK;
}
2018-01-30 16:45:38 +08:00
2018-09-11 15:47:51 +08:00
LRESULT e2d::Window::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
2018-01-30 16:45:38 +08:00
{
LRESULT result = 0;
2018-09-04 22:42:34 +08:00
if (msg == WM_CREATE)
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
LPCREATESTRUCT pcs = (LPCREATESTRUCT)l_param;
2018-08-15 00:06:03 +08:00
Window *window = (Window *)pcs->lpCreateParams;
2018-08-15 00:06:03 +08:00
::SetWindowLongPtrW(
2018-09-11 15:47:51 +08:00
hwnd,
2018-08-15 00:06:03 +08:00
GWLP_USERDATA,
PtrToUlong(window)
);
2018-08-15 00:06:03 +08:00
result = 1;
}
2018-08-15 00:06:03 +08:00
else
2018-01-30 16:45:38 +08:00
{
2018-09-11 15:47:51 +08:00
bool has_handled = false;
2018-08-15 00:06:03 +08:00
Window *window = reinterpret_cast<Window *>(
static_cast<LONG_PTR>(
2018-09-11 15:47:51 +08:00
::GetWindowLongPtrW(hwnd, GWLP_USERDATA)
2018-08-15 00:06:03 +08:00
)
);
2018-09-04 22:42:34 +08:00
switch (msg)
2018-08-15 00:06:03 +08:00
{
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_MBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONDBLCLK:
case WM_RBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
{
2018-09-04 22:42:34 +08:00
auto game = Game::GetInstance();
if (game->IsTransitioning())
2018-08-15 23:30:23 +08:00
break;
2018-09-11 15:31:50 +08:00
auto curr_scene = game->GetCurrentScene();
if (curr_scene)
2018-08-15 23:30:23 +08:00
{
2018-09-11 15:31:50 +08:00
curr_scene->Dispatch(MouseEvent(msg, w_param, l_param));
2018-08-15 23:30:23 +08:00
}
}
2018-08-15 00:06:03 +08:00
result = 0;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case WM_KEYDOWN:
case WM_KEYUP:
{
2018-09-04 22:42:34 +08:00
auto game = Game::GetInstance();
if (game->IsTransitioning())
2018-08-15 23:30:23 +08:00
break;
2018-09-11 15:31:50 +08:00
auto curr_scene = game->GetCurrentScene();
if (curr_scene)
2018-08-15 23:30:23 +08:00
{
2018-09-11 15:31:50 +08:00
curr_scene->Dispatch(KeyEvent(msg, w_param, l_param));
2018-08-15 23:30:23 +08:00
}
}
2018-08-15 00:06:03 +08:00
result = 0;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С<EFBFBD><EFBFBD><E4BBAF>Ϣ
case WM_SIZE:
{
2018-09-04 22:42:34 +08:00
UINT width = LOWORD(l_param);
UINT height = HIWORD(l_param);
2018-01-30 16:45:38 +08:00
2018-09-04 22:42:34 +08:00
if (w_param == SIZE_RESTORED)
2018-08-15 00:06:03 +08:00
{
2018-09-04 22:42:34 +08:00
window->width_ = static_cast<int>(width * 96.f / window->dpi_);
window->height_ = static_cast<int>(height * 96.f / window->dpi_);
2018-08-15 00:06:03 +08:00
}
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB> WM_SIZE <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
2018-09-11 15:47:51 +08:00
// Ŀ<><C4BF><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ܵ<EFBFBD>
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> EndDraw ʱ<><CAB1><EFBFBD><EFBFBD>
2018-09-07 17:26:21 +08:00
auto render_target = Renderer::GetInstance()->GetRenderTarget();
if (render_target)
2018-08-15 00:06:03 +08:00
{
2018-09-07 17:26:21 +08:00
render_target->Resize(D2D1::SizeU(width, height));
2018-08-15 00:06:03 +08:00
}
}
break;
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><E4BBAF>Ϣ
case WM_SETTEXT:
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
window->title_ = (const wchar_t*)l_param;
2018-01-30 16:45:38 +08:00
}
2018-08-15 00:06:03 +08:00
break;
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʱ仯<CAB1><E4BBAF>Ϣ
case WM_DISPLAYCHANGE:
{
// <20>ػ<EFBFBD><D8BB>ͻ<EFBFBD><CDBB><EFBFBD>
2018-09-11 15:47:51 +08:00
::InvalidateRect(hwnd, nullptr, FALSE);
2018-08-15 00:06:03 +08:00
}
result = 0;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
// <20>ػ洰<D8BB><E6B4B0>
case WM_PAINT:
{
2018-09-04 22:42:34 +08:00
Game::GetInstance()->DrawScene();
2018-09-11 15:47:51 +08:00
::ValidateRect(hwnd, nullptr);
2018-08-15 00:06:03 +08:00
}
result = 0;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
// <20><><EFBFBD>ڹر<DAB9><D8B1><EFBFBD>Ϣ
case WM_CLOSE:
{
2018-09-04 22:42:34 +08:00
auto game = Game::GetInstance();
auto currScene = game->GetCurrentScene();
if (!currScene || currScene->OnCloseWindow())
2018-08-15 00:06:03 +08:00
{
2018-09-04 22:42:34 +08:00
game->Quit();
2018-08-15 00:06:03 +08:00
}
}
result = 0;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case WM_DESTROY:
{
2018-09-07 17:26:21 +08:00
::PostQuitMessage(0);
2018-08-15 00:06:03 +08:00
}
result = 1;
2018-09-11 15:47:51 +08:00
has_handled = true;
2018-08-15 00:06:03 +08:00
break;
2018-01-30 16:45:38 +08:00
2018-08-15 00:06:03 +08:00
}
2018-09-11 15:47:51 +08:00
if (!has_handled)
2018-08-15 00:06:03 +08:00
{
2018-09-11 15:47:51 +08:00
result = ::DefWindowProc(hwnd, msg, w_param, l_param);
2018-08-15 00:06:03 +08:00
}
}
2018-01-30 16:45:38 +08:00
return result;
}