add: Scene::Update
This commit is contained in:
		
							parent
							
								
									422c7cbdc7
								
							
						
					
					
						commit
						318103b148
					
				|  | @ -223,6 +223,10 @@ namespace e2d | ||||||
| 		// 结束
 | 		// 结束
 | ||||||
| 		void Quit(); | 		void Quit(); | ||||||
| 
 | 
 | ||||||
|  | 		// 关闭窗口时触发
 | ||||||
|  | 		// 返回值:返回 false 将阻止窗口关闭
 | ||||||
|  | 		virtual bool OnExit() { return true; } | ||||||
|  | 
 | ||||||
| 		// 修改窗体大小
 | 		// 修改窗体大小
 | ||||||
| 		void SetSize( | 		void SetSize( | ||||||
| 			int width,			/* 窗体宽度 */ | 			int width,			/* 窗体宽度 */ | ||||||
|  |  | ||||||
|  | @ -152,9 +152,8 @@ namespace e2d | ||||||
| 		// 退出场景
 | 		// 退出场景
 | ||||||
| 		virtual void OnExit() {} | 		virtual void OnExit() {} | ||||||
| 
 | 
 | ||||||
| 		// 关闭窗口
 | 		// 更新场景
 | ||||||
| 		// 说明:返回 false 将阻止窗口关闭
 | 		virtual void Update() {} | ||||||
| 		virtual bool OnCloseWindow() { return true; } |  | ||||||
| 
 | 
 | ||||||
| 		// 设置根节点
 | 		// 设置根节点
 | ||||||
| 		void SetRoot( | 		void SetRoot( | ||||||
|  |  | ||||||
|  | @ -32,6 +32,7 @@ float e2d::MouseEvent::GetX() const | ||||||
| { | { | ||||||
| 	HDC hdc = ::GetDC(0); | 	HDC hdc = ::GetDC(0); | ||||||
| 	int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX); | 	int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX); | ||||||
|  | 	::ReleaseDC(0, hdc); | ||||||
| 	return ((float)(short)LOWORD(l_param_)) * 96.f / dpi_x; | 	return ((float)(short)LOWORD(l_param_)) * 96.f / dpi_x; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -39,6 +40,7 @@ float e2d::MouseEvent::GetY() const | ||||||
| { | { | ||||||
| 	HDC hdc = ::GetDC(0); | 	HDC hdc = ::GetDC(0); | ||||||
| 	int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY); | 	int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY); | ||||||
|  | 	::ReleaseDC(0, hdc); | ||||||
| 	return ((float)(short)HIWORD(l_param_)) * 96.f / dpi_y; | 	return ((float)(short)HIWORD(l_param_)) * 96.f / dpi_y; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -47,6 +49,7 @@ e2d::Point e2d::MouseEvent::GetPosition() const | ||||||
| 	HDC hdc = ::GetDC(0); | 	HDC hdc = ::GetDC(0); | ||||||
| 	int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX); | 	int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX); | ||||||
| 	int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY); | 	int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY); | ||||||
|  | 	::ReleaseDC(0, hdc); | ||||||
| 	return Point( | 	return Point( | ||||||
| 		((float)(short)LOWORD(l_param_)) * 96.f / dpi_x, | 		((float)(short)LOWORD(l_param_)) * 96.f / dpi_x, | ||||||
| 		((float)(short)HIWORD(l_param_)) * 96.f / dpi_y | 		((float)(short)HIWORD(l_param_)) * 96.f / dpi_y | ||||||
|  |  | ||||||
|  | @ -209,6 +209,16 @@ void e2d::Game::UpdateScene() | ||||||
| 		curr_scene_ = next_scene_; | 		curr_scene_ = next_scene_; | ||||||
| 		next_scene_ = nullptr; | 		next_scene_ = nullptr; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	if (curr_scene_) | ||||||
|  | 	{ | ||||||
|  | 		curr_scene_->Update(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (next_scene_) | ||||||
|  | 	{ | ||||||
|  | 		next_scene_->Update(); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Game::DrawScene() | void e2d::Game::DrawScene() | ||||||
|  | @ -357,6 +367,7 @@ e2d::Rect e2d::Game::Locate(int width, int height) | ||||||
| 	HDC hdc = ::GetDC(0); | 	HDC hdc = ::GetDC(0); | ||||||
| 	int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | 	int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | ||||||
| 	int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | 	int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | ||||||
|  | 	::ReleaseDC(0, hdc); | ||||||
| 	RECT rect = { 0, 0, LONG(ceil(width * dpi_x / 96.f)), LONG(ceil(height * dpi_y / 96.f)) }; | 	RECT rect = { 0, 0, LONG(ceil(width * dpi_x / 96.f)), LONG(ceil(height * dpi_y / 96.f)) }; | ||||||
| 
 | 
 | ||||||
| 	// 计算合适的窗口大小
 | 	// 计算合适的窗口大小
 | ||||||
|  | @ -543,6 +554,7 @@ LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param) | ||||||
| 				HDC hdc = ::GetDC(0); | 				HDC hdc = ::GetDC(0); | ||||||
| 				int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | 				int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | ||||||
| 				int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | 				int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | ||||||
|  | 				::ReleaseDC(0, hdc); | ||||||
| 				game->width_ = static_cast<int>(width * 96.f / dpi_x); | 				game->width_ = static_cast<int>(width * 96.f / dpi_x); | ||||||
| 				game->height_ = static_cast<int>(height * 96.f / dpi_y); | 				game->height_ = static_cast<int>(height * 96.f / dpi_y); | ||||||
| 			} | 			} | ||||||
|  | @ -588,8 +600,7 @@ LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param) | ||||||
| 		// 窗口关闭消息
 | 		// 窗口关闭消息
 | ||||||
| 		case WM_CLOSE: | 		case WM_CLOSE: | ||||||
| 		{ | 		{ | ||||||
| 			auto currScene = game->GetCurrentScene(); | 			if (game->OnExit()) | ||||||
| 			if (!currScene || currScene->OnCloseWindow()) |  | ||||||
| 			{ | 			{ | ||||||
| 				game->Quit(); | 				game->Quit(); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -150,6 +150,7 @@ e2d::Point e2d::Input::GetMousePos() | ||||||
| 	HDC hdc = ::GetDC(0); | 	HDC hdc = ::GetDC(0); | ||||||
| 	int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | 	int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); | ||||||
| 	int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | 	int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); | ||||||
|  | 	::ReleaseDC(0, hdc); | ||||||
| 
 | 
 | ||||||
| 	POINT mousePos; | 	POINT mousePos; | ||||||
| 	::GetCursorPos(&mousePos); | 	::GetCursorPos(&mousePos); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue