| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | #include "Application.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  | #include "logs.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | #include "modules.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | #include "render.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | #include "window.h"
 | 
					
						
							|  |  |  | #include "input.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | #include "Event.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | #include "Scene.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | #include "DebugNode.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | #include "Transition.h"
 | 
					
						
							|  |  |  | #include <windowsx.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | #include <imm.h>
 | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:36 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | #pragma comment (lib ,"imm32.lib")
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace easy2d | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 	namespace | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		LRESULT(*pre_proc)(HWND, UINT, WPARAM, LPARAM) = nullptr;	// Custom message proc for user
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	Application::Application(String const& app_name) | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 		: end_(true) | 
					
						
							|  |  |  | 		, inited_(false) | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		, curr_scene_(nullptr) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		, next_scene_(nullptr) | 
					
						
							|  |  |  | 		, transition_(nullptr) | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		, time_scale_(1.f) | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		, app_name_(app_name) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		::CoInitialize(nullptr); | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Use(&Renderer::Instance()); | 
					
						
							|  |  |  | 		Use(&Input::Instance()); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	Application::~Application() | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 		Destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		::CoUninitialize(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::Init(const Options& options) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		ThrowIfFailed( | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 			Window::Instance().Create( | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 				options.title, | 
					
						
							|  |  |  | 				options.width, | 
					
						
							|  |  |  | 				options.height, | 
					
						
							|  |  |  | 				options.icon, | 
					
						
							| 
									
										
										
										
											2019-01-25 01:45:03 +08:00
										 |  |  | 				options.fullscreen, | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 				Application::WndProc | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 		HWND hwnd = Window::Instance().GetHandle(); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 		Renderer::Instance().SetTargetWindow(hwnd); | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 		Renderer::Instance().SetClearColor(options.clear_color); | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		Renderer::Instance().SetVSyncEnabled(options.vsync); | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 		// Setup all components
 | 
					
						
							|  |  |  | 		for (Component* c : components_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			c->Setup(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 09:07:51 +08:00
										 |  |  | 		OnStart(); | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		// disable imm
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		::ImmAssociateContext(hwnd, nullptr); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		// use Application instance in message loop
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:16:53 +08:00
										 |  |  | 		::SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(this)); | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		inited_ = true; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::Run() | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 		HWND hwnd = Window::Instance().GetHandle(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		if (hwnd) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 			end_ = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 			Window::Instance().Prepare(); | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			MSG msg = {}; | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 			while (::GetMessageW(&msg, nullptr, 0, 0) && !end_) | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				::TranslateMessage(&msg); | 
					
						
							|  |  |  | 				::DispatchMessageW(&msg); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::Quit() | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 		end_ = true; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 21:45:56 +08:00
										 |  |  | 	void Application::Destroy() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 		if (inited_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			inited_ = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 			if (curr_scene_) | 
					
						
							|  |  |  | 				curr_scene_->OnExit(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 			transition_.Reset(); | 
					
						
							|  |  |  | 			next_scene_.Reset(); | 
					
						
							|  |  |  | 			curr_scene_.Reset(); | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 			debug_node_.Reset(); | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 			for (auto iter = components_.rbegin(); iter != components_.rend(); ++iter) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				(*iter)->Destroy(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 			Window::Instance().Destroy(); | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-02-03 21:45:56 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 	void Application::Use(Component* component) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (component) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(E2D_DEBUG)
 | 
					
						
							|  |  |  | 			if (components_.contains(component)) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				E2D_ASSERT(false && "Component already exists!"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			components_.push_back(component); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Application::Remove(Component* component) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (component) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			for (auto iter = components_.begin(); iter != components_.end(); iter++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if ((*iter) == component) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					(*iter)->Destroy(); | 
					
						
							|  |  |  | 					components_.erase(iter); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::EnterScene(ScenePtr const & scene) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		E2D_ASSERT(scene && "Application::EnterScene failed, NULL pointer exception"); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		if (curr_scene_ == scene || next_scene_ == scene) | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		next_scene_ = scene; | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::EnterScene(ScenePtr const& scene, TransitionPtr const& transition) | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		EnterScene(scene); | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		if (transition && next_scene_) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			if (transition_) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				transition_->Stop(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			transition_ = transition; | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			transition_->Init(curr_scene_, next_scene_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	ScenePtr const& Application::GetCurrentScene() | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return curr_scene_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 	void Application::SetTimeScale(float scale_factor) | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 		time_scale_ = scale_factor; | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 	void Application::SetPreMessageProc(LRESULT(*proc)(HWND, UINT, WPARAM, LPARAM)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		pre_proc = proc; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Application::ShowDebugInfo(bool show) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (show) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			debug_node_ = new DebugNode; | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 			Renderer::Instance().StartCollectData(); | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			debug_node_.Reset(); | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 			Renderer::Instance().StopCollectData(); | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	void Application::Update() | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		static auto last = time::Now(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const auto now = time::Now(); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		const auto dt = (now - last) * time_scale_; | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		last = now; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		if (transition_) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 			transition_->Update(dt); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (transition_->IsDone()) | 
					
						
							|  |  |  | 				transition_ = nullptr; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 19:30:02 +08:00
										 |  |  | 		if (next_scene_ && !transition_) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			if (curr_scene_) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				curr_scene_->OnExit(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			next_scene_->OnEnter(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			curr_scene_ = next_scene_; | 
					
						
							|  |  |  | 			next_scene_ = nullptr; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-01-08 19:30:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 21:45:56 +08:00
										 |  |  | 		OnUpdate(dt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 19:30:02 +08:00
										 |  |  | 		if (curr_scene_) | 
					
						
							|  |  |  | 			curr_scene_->Update(dt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (next_scene_) | 
					
						
							|  |  |  | 			next_scene_->Update(dt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		if (debug_node_) | 
					
						
							|  |  |  | 			debug_node_->Update(dt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Input::Instance().Update(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 	void Application::Render() | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		ThrowIfFailed( | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 			Renderer::Instance().BeginDraw() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (transition_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			transition_->Render(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (curr_scene_) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			curr_scene_->Render(); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		if (debug_node_) | 
					
						
							|  |  |  | 			debug_node_->Render(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OnRender(); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		ThrowIfFailed( | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 			Renderer::Instance().EndDraw() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 	void Application::AllocConsole() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!::GetConsoleWindow()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (!::AllocConsole()) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				E2D_WARNING_LOG(L"AllocConsole failed"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				HWND console = ::GetConsoleWindow(); | 
					
						
							|  |  |  | 				FILE * dummy; | 
					
						
							|  |  |  | 				freopen_s(&dummy, "CONOUT$", "w+t", stdout); | 
					
						
							|  |  |  | 				freopen_s(&dummy, "CONIN$", "r+t", stdin); | 
					
						
							|  |  |  | 				freopen_s(&dummy, "CONOUT$", "w+t", stderr); | 
					
						
							|  |  |  | 				(void)dummy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				std::cout.clear(); | 
					
						
							|  |  |  | 				std::wcout.clear(); | 
					
						
							|  |  |  | 				std::cin.clear(); | 
					
						
							|  |  |  | 				std::wcin.clear(); | 
					
						
							|  |  |  | 				std::cerr.clear(); | 
					
						
							|  |  |  | 				std::wcerr.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// disable the close button of console
 | 
					
						
							|  |  |  | 				if (console) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					HMENU hmenu = ::GetSystemMenu(console, FALSE); | 
					
						
							|  |  |  | 					::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 	LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) | 
					
						
							| 
									
										
										
										
											2019-01-21 21:24:45 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 		if (pre_proc && pre_proc(hwnd, msg, wparam, lparam)) | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 00:16:53 +08:00
										 |  |  | 		Application * app = reinterpret_cast<Application*>( | 
					
						
							|  |  |  | 			static_cast<LONG_PTR>(::GetWindowLongPtrW(hwnd, GWLP_USERDATA)) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-01-21 21:24:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		if (!app) | 
					
						
							| 
									
										
										
										
											2019-01-21 21:24:45 +08:00
										 |  |  | 			return ::DefWindowProcW(hwnd, msg, wparam, lparam); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		switch (msg) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		case WM_PAINT: | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 			app->Update(); | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 			app->Render(); | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-11 11:11:39 +08:00
										 |  |  | 			::InvalidateRect(hwnd, NULL, FALSE); | 
					
						
							| 
									
										
										
										
											2019-01-21 21:24:45 +08:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		case WM_KEYDOWN: | 
					
						
							|  |  |  | 		case WM_KEYUP: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 			Input::Instance().UpdateKey((int)wparam, (msg == WM_KEYDOWN) ? true : false); | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 			if (!app->transition_ && app->curr_scene_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Event evt((msg == WM_KEYDOWN) ? Event::KeyDown : Event::KeyUp); | 
					
						
							| 
									
										
										
										
											2019-02-03 21:45:56 +08:00
										 |  |  | 				evt.key.code = static_cast<int>(wparam); | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 				evt.key.count = static_cast<int>(lparam & 0xFF); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		case WM_LBUTTONUP: | 
					
						
							|  |  |  | 		case WM_LBUTTONDOWN: | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		//case WM_LBUTTONDBLCLK:
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 		case WM_MBUTTONUP: | 
					
						
							|  |  |  | 		case WM_MBUTTONDOWN: | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		//case WM_MBUTTONDBLCLK:
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		case WM_RBUTTONUP: | 
					
						
							|  |  |  | 		case WM_RBUTTONDOWN: | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		//case WM_RBUTTONDBLCLK:
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		case WM_MOUSEMOVE: | 
					
						
							|  |  |  | 		case WM_MOUSEWHEEL: | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 			if		(msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) { Input::Instance().UpdateKey(VK_LBUTTON, (msg == WM_LBUTTONDOWN) ? true : false); } | 
					
						
							|  |  |  | 			else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { Input::Instance().UpdateKey(VK_RBUTTON, (msg == WM_RBUTTONDOWN) ? true : false); } | 
					
						
							|  |  |  | 			else if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONUP) { Input::Instance().UpdateKey(VK_MBUTTON, (msg == WM_MBUTTONDOWN) ? true : false); } | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 			if (!app->transition_ && app->curr_scene_) | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 				Event evt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 15:33:02 +08:00
										 |  |  | 				evt.mouse.x = static_cast<float>(GET_X_LPARAM(lparam)); | 
					
						
							|  |  |  | 				evt.mouse.y = static_cast<float>(GET_Y_LPARAM(lparam)); | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 				evt.mouse.left_btn_down = !!(wparam & MK_LBUTTON); | 
					
						
							|  |  |  | 				evt.mouse.left_btn_down = !!(wparam & MK_RBUTTON); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				if		(msg == WM_MOUSEMOVE) { evt.type = Event::MouseMove; } | 
					
						
							|  |  |  | 				else if (msg == WM_LBUTTONDOWN || msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN) { evt.type = Event::MouseBtnDown; } | 
					
						
							|  |  |  | 				else if (msg == WM_LBUTTONUP   || msg == WM_RBUTTONUP   || msg == WM_MBUTTONUP) { evt.type = Event::MouseBtnUp; } | 
					
						
							|  |  |  | 				else if (msg == WM_MOUSEWHEEL) { evt.type = Event::MouseWheel; evt.mouse.wheel = GET_WHEEL_DELTA_WPARAM(wparam) / (float)WHEEL_DELTA; } | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if		(msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) { evt.mouse.button = MouseButton::Left; } | 
					
						
							|  |  |  | 				else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { evt.mouse.button = MouseButton::Right; } | 
					
						
							|  |  |  | 				else if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONUP) { evt.mouse.button = MouseButton::Middle; } | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-03-11 17:24:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (msg == WM_MOUSEMOVE) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				Input::Instance().UpdateMousePos( | 
					
						
							|  |  |  | 					static_cast<float>(GET_X_LPARAM(lparam)), | 
					
						
							|  |  |  | 					static_cast<float>(GET_Y_LPARAM(lparam)) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		case WM_SIZE: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 			UINT width = LOWORD(lparam); | 
					
						
							|  |  |  | 			UINT height = HIWORD(lparam); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 13:44:02 +08:00
										 |  |  | 			Renderer::Instance().GetDeviceResources()->SetLogicalSize(Size{ (float)width, (float)height }); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			if (SIZE_MAXHIDE == wparam || SIZE_MINIMIZED == wparam) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 				E2D_LOG(L"Window minimized"); | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 				E2D_LOG(L"Window resized"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (app->curr_scene_) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 					Event evt(Event::WindowResized); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 					evt.win.width = static_cast<int>(width); | 
					
						
							|  |  |  | 					evt.win.height = static_cast<int>(height); | 
					
						
							|  |  |  | 					app->curr_scene_->Dispatch(evt); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Window::Instance().UpdateWindowRect(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 		case WM_MOVE: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (app->curr_scene_) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x = (int)(short)LOWORD(lparam); | 
					
						
							|  |  |  | 				int y = (int)(short)HIWORD(lparam); | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Event evt(Event::WindowMoved); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 				evt.win.x = x; | 
					
						
							|  |  |  | 				evt.win.y = y; | 
					
						
							|  |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		case WM_ACTIVATE: | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-21 21:24:45 +08:00
										 |  |  | 			bool active = (LOWORD(wparam) != WA_INACTIVE); | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			E2D_LOG(active ? L"Window activated" : L"Window deactivated"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 			Window::Instance().SetActive(active); | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 			if (app->curr_scene_) | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Event evt(Event::WindowFocusChanged); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 				evt.win.focus = active; | 
					
						
							|  |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		case WM_SETTEXT: | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 			E2D_LOG(L"Window title changed"); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (app->curr_scene_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Event evt(Event::WindowTitleChanged); | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  | 				evt.win.title = reinterpret_cast<const wchar_t*>(lparam); | 
					
						
							|  |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		case WM_SETICON: | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 			E2D_LOG(L"Window icon changed"); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case WM_DISPLAYCHANGE: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			E2D_LOG(L"The display resolution has changed"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			::InvalidateRect(hwnd, nullptr, FALSE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case WM_CLOSE: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-27 09:07:51 +08:00
										 |  |  | 			E2D_LOG(L"Window is closing"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (app->OnClosing()) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Window::Instance().Destroy(); | 
					
						
							| 
									
										
										
										
											2019-01-27 09:07:51 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case WM_DESTROY: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			E2D_LOG(L"Window was destroyed"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 			if (app->curr_scene_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  | 				Event evt(Event::WindowClosed); | 
					
						
							| 
									
										
										
										
											2019-01-25 14:48:37 +08:00
										 |  |  | 				app->curr_scene_->Dispatch(evt); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 09:07:51 +08:00
										 |  |  | 			app->OnDestroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  | 			::PostQuitMessage(0); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 23:48:40 +08:00
										 |  |  | 		return ::DefWindowProcW(hwnd, msg, wparam, lparam); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | } |