| 
									
										
										
										
											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-04 22:42:34 +08:00
										 |  |  |  | 	: hWnd_(nullptr) | 
					
						
							|  |  |  |  | 	, width_(640) | 
					
						
							|  |  |  |  | 	, height_(480) | 
					
						
							|  |  |  |  | 	, title_(L"Easy2D Game") | 
					
						
							|  |  |  |  | 	, icon_id_(0) | 
					
						
							|  |  |  |  | 	, dpi_(0.f) | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-02 14:03:04 +08:00
										 |  |  |  | 	::CoInitialize(nullptr); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 	// <20><>ȡϵͳ DPI
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	dpi_ = static_cast<float>(::GetDpiForSystem()); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Window::~Window() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (::GetConsoleWindow()) | 
					
						
							|  |  |  |  | 		::FreeConsole(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	if (hWnd_) | 
					
						
							|  |  |  |  | 		::DestroyWindow(hWnd_); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-02 14:03:04 +08:00
										 |  |  |  | 	::CoUninitialize(); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 17:24:44 +08:00
										 |  |  |  | bool e2d::Window::CheckUnique() | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-05 17:24:44 +08:00
										 |  |  |  | 	HANDLE mutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + title_)); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 17:24:44 +08:00
										 |  |  |  | 	if (mutex == nullptr) | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN("CreateMutex Failed!"); | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	else if (::GetLastError() == ERROR_ALREADY_EXISTS) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-05 17:24:44 +08:00
										 |  |  |  | 		::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-04 22:42:34 +08:00
										 |  |  |  | 	RECT wRECT		= { 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>С
 | 
					
						
							|  |  |  |  | 	::AdjustWindowRectEx(&wRECT, WINDOW_STYLE, FALSE, NULL); | 
					
						
							|  |  |  |  | 	width = static_cast<int>(wRECT.right - wRECT.left); | 
					
						
							|  |  |  |  | 	height = static_cast<int>(wRECT.bottom - wRECT.top); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <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-04 22:42:34 +08:00
										 |  |  |  | 	return e2d::Size(float(width_), float(height_)); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-07-03 18:16:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											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-04 22:42:34 +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-04 22:42:34 +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-04 22:42:34 +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>ť
 | 
					
						
							|  |  |  |  | 			HWND consoleHWnd = ::GetConsoleWindow(); | 
					
						
							|  |  |  |  | 			if (consoleHWnd) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				HMENU hmenu = ::GetSystemMenu(consoleHWnd, FALSE); | 
					
						
							|  |  |  |  | 				::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT); | 
					
						
							|  |  |  |  | 			throw SystemException("Create window failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +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) | 
					
						
							| 
									
										
										
										
											2018-08-23 16:37:51 +08:00
										 |  |  |  | 		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-04 22:42:34 +08:00
										 |  |  |  | 	if (hWnd_) | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		Rect wRect = Locate(width, height); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		::MoveWindow( | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			hWnd_, | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 			int(wRect.origin.x), | 
					
						
							|  |  |  |  | 			int(wRect.origin.y), | 
					
						
							|  |  |  |  | 			int(wRect.size.width), | 
					
						
							|  |  |  |  | 			int(wRect.size.height), | 
					
						
							|  |  |  |  | 			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; | 
					
						
							|  |  |  |  | 	if (hWnd_) | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		::SetWindowText(hWnd_, (LPCWSTR)title); | 
					
						
							| 
									
										
										
										
											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::SetIcon(int icon_id) | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	this->icon_id_ = icon_id; | 
					
						
							|  |  |  |  | 	if (hWnd_) | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		HICON hIcon = (HICON)::LoadImage(HINST_THISCOMPONENT, MAKEINTRESOURCE(icon_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-04 22:42:34 +08:00
										 |  |  |  | 		::SendMessage(hWnd_, WM_SETICON, ICON_BIG, (LPARAM)hIcon); | 
					
						
							|  |  |  |  | 		::SendMessage(hWnd_, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | void e2d::Window::SetCursor(Cursor cursor) | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | 	LPCWSTR pCursorName = nullptr; | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 	switch (cursor) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Normal: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_ARROW; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Hand: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_HAND; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::No: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_NO; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Wait: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_WAIT; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::ArrowWait: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_APPSTARTING; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	default: | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | 	HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName); | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 	::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
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	static HIMC hImc = nullptr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	if (enabled) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hImc != nullptr) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 			::ImmAssociateContext(GetHWnd(), hImc); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			hImc = nullptr; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hImc == nullptr) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +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-05-10 18:18:02 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											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-05-10 18:18:02 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	if (has_cancel) | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		type |= MB_OKCANCEL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 	Game::GetInstance()->Pause(); | 
					
						
							|  |  |  |  | 	int ret = ::MessageBox(hWnd_, (LPCWSTR)text, (LPCWSTR)title, type); | 
					
						
							|  |  |  |  | 	Game::GetInstance()->Resume(); | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	return ret == IDOK; | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +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-05-03 22:21:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		::SetWindowLongPtrW( | 
					
						
							|  |  |  |  | 			hWnd, | 
					
						
							|  |  |  |  | 			GWLP_USERDATA, | 
					
						
							|  |  |  |  | 			PtrToUlong(window) | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-16 22:11:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 1; | 
					
						
							| 
									
										
										
										
											2018-07-16 22:11:27 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		bool hasHandled = false; | 
					
						
							|  |  |  |  | 		Window *window = reinterpret_cast<Window *>( | 
					
						
							|  |  |  |  | 			static_cast<LONG_PTR>( | 
					
						
							|  |  |  |  | 				::GetWindowLongPtrW(hWnd, GWLP_USERDATA) | 
					
						
							|  |  |  |  | 			) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 		switch (msg) | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +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-07-04 00:27:14 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											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-04 22:42:34 +08:00
										 |  |  |  | 			if (game->GetCurrentScene()) | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 				game->GetCurrentScene()->Dispatch(MouseEvent(hWnd, msg, w_param, l_param, window->dpi_), false); | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_KEYDOWN: | 
					
						
							|  |  |  |  | 		case WM_KEYUP: | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											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-04 22:42:34 +08:00
										 |  |  |  | 			if (game->GetCurrentScene()) | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  |  | 				game->GetCurrentScene()->Dispatch(KeyEvent(hWnd, msg, w_param, l_param), false); | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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>Ⱦ
 | 
					
						
							|  |  |  |  | 			// Ŀ<><C4BF><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><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>
 | 
					
						
							|  |  |  |  | 			// <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-07 17:26:21 +08:00
										 |  |  |  | 			::InvalidateRect(hWnd, nullptr, FALSE); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		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-07 17:26:21 +08:00
										 |  |  |  | 			::ValidateRect(hWnd, nullptr); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		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; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		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; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (!hasHandled) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-07 17:26:21 +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; | 
					
						
							|  |  |  |  | } |