| 
									
										
										
										
											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.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "window.h"
 | 
					
						
							|  |  |  |  | #include "render.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  |  | #include "logs.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | #include "../math/scalar.hpp"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #define WINDOW_STYLE	WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME
 | 
					
						
							|  |  |  |  | #define REGISTER_CLASS	L"Easy2DApp"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace easy2d | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	namespace | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		void GetContentScale(float* scale_x, float* scale_y); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		Rect LocateWindow(int width, int height, float scale_x, float scale_y); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	WindowImpl::WindowImpl() | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		: handle(nullptr) | 
					
						
							|  |  |  |  | 		, scale_x(1.f) | 
					
						
							|  |  |  |  | 		, scale_y(1.f) | 
					
						
							| 
									
										
										
										
											2018-11-21 16:26:52 +08:00
										 |  |  |  | 		, initialized_(false) | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	WindowImpl::~WindowImpl() | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  |  | 		E2D_LOG("Destroying window"); | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  |  | 	void WindowImpl::Init(String title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug) | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 16:26:52 +08:00
										 |  |  |  | 		if (initialized_) | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 			return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 16:26:52 +08:00
										 |  |  |  | 		E2D_LOG("Creating window"); | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		HINSTANCE hinstance	= GetModuleHandle(nullptr); | 
					
						
							|  |  |  |  | 		WNDCLASSEX wcex		= { 0 }; | 
					
						
							|  |  |  |  | 		wcex.cbSize			= sizeof(WNDCLASSEX); | 
					
						
							|  |  |  |  | 		wcex.lpszClassName	= REGISTER_CLASS; | 
					
						
							|  |  |  |  | 		wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | 
					
						
							| 
									
										
										
										
											2018-11-19 17:56:17 +08:00
										 |  |  |  | 		wcex.lpfnWndProc	= proc; | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		wcex.hIcon			= nullptr; | 
					
						
							|  |  |  |  | 		wcex.cbClsExtra		= 0; | 
					
						
							|  |  |  |  | 		wcex.cbWndExtra		= sizeof(LONG_PTR); | 
					
						
							|  |  |  |  | 		wcex.hInstance		= hinstance; | 
					
						
							|  |  |  |  | 		wcex.hbrBackground	= nullptr; | 
					
						
							|  |  |  |  | 		wcex.lpszMenuName	= nullptr; | 
					
						
							|  |  |  |  | 		wcex.hCursor		= ::LoadCursor(nullptr, IDC_ARROW); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (icon) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			wcex.hIcon = (HICON)::LoadImage( | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 				hinstance, | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 				icon, | 
					
						
							|  |  |  |  | 				IMAGE_ICON, | 
					
						
							|  |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		::RegisterClassEx(&wcex); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		GetContentScale(&scale_x, &scale_y); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>㴰<EFBFBD>ڴ<EFBFBD>С
 | 
					
						
							|  |  |  |  | 		Rect client_rect = LocateWindow(width, height, scale_x, scale_y); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		handle = ::CreateWindowEx( | 
					
						
							|  |  |  |  | 			NULL, | 
					
						
							|  |  |  |  | 			REGISTER_CLASS, | 
					
						
							|  |  |  |  | 			title.c_str(), | 
					
						
							|  |  |  |  | 			WINDOW_STYLE, | 
					
						
							|  |  |  |  | 			static_cast<int>(client_rect.origin.x), | 
					
						
							|  |  |  |  | 			static_cast<int>(client_rect.origin.y), | 
					
						
							|  |  |  |  | 			static_cast<int>(client_rect.size.width), | 
					
						
							|  |  |  |  | 			static_cast<int>(client_rect.size.height), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			hinstance, | 
					
						
							|  |  |  |  | 			this | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (handle == nullptr) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			::UnregisterClass(REGISTER_CLASS, hinstance); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 			const char* err = "Create window failed!"; | 
					
						
							| 
									
										
										
										
											2018-11-16 17:19:03 +08:00
										 |  |  |  | 			logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), err); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  |  | 			throw std::runtime_error(err); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 16:26:52 +08:00
										 |  |  |  | 		initialized_ = true; | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	String WindowImpl::GetTitle() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (handle) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			wchar_t title[256]; | 
					
						
							|  |  |  |  | 			GetWindowTextW(handle, title, 256); | 
					
						
							|  |  |  |  | 			return title; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		return String(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  |  | 	void WindowImpl::SetTitle(String const& title) | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (handle) | 
					
						
							|  |  |  |  | 			::SetWindowText(handle, title.c_str()); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	Size WindowImpl::GetSize() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (handle) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			RECT rect; | 
					
						
							|  |  |  |  | 			GetClientRect(handle, &rect); | 
					
						
							|  |  |  |  | 			return Size( | 
					
						
							|  |  |  |  | 				static_cast<float>(rect.right - rect.left), | 
					
						
							|  |  |  |  | 				static_cast<float>(rect.bottom - rect.top) | 
					
						
							|  |  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		return Size(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	float WindowImpl::GetWidth() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return GetSize().width; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	float WindowImpl::GetHeight() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return GetSize().height; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	void WindowImpl::SetSize(int width, int height) | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (handle) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			Rect rect = LocateWindow(width, height, scale_x, scale_y); | 
					
						
							|  |  |  |  | 			::MoveWindow( | 
					
						
							|  |  |  |  | 				handle, | 
					
						
							|  |  |  |  | 				static_cast<int>(rect.origin.x), | 
					
						
							|  |  |  |  | 				static_cast<int>(rect.origin.y), | 
					
						
							|  |  |  |  | 				static_cast<int>(rect.size.width), | 
					
						
							|  |  |  |  | 				static_cast<int>(rect.size.height), | 
					
						
							|  |  |  |  | 				TRUE | 
					
						
							|  |  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	void WindowImpl::SetIcon(LPCWSTR icon_resource) | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (handle) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			HINSTANCE hinstance = GetModuleHandle(nullptr); | 
					
						
							|  |  |  |  | 			HICON icon = (HICON)::LoadImage( | 
					
						
							|  |  |  |  | 				hinstance, | 
					
						
							|  |  |  |  | 				icon_resource, | 
					
						
							|  |  |  |  | 				IMAGE_ICON, | 
					
						
							|  |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | 
					
						
							|  |  |  |  | 			); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			::SendMessage(handle, WM_SETICON, ICON_BIG, (LPARAM)icon); | 
					
						
							|  |  |  |  | 			::SendMessage(handle, WM_SETICON, ICON_SMALL, (LPARAM)icon); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	HWND WindowImpl::GetHandle() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return handle; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	float WindowImpl::GetContentScaleX() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return scale_x; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:36:50 +08:00
										 |  |  |  | 	float WindowImpl::GetContentScaleY() const | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return scale_y; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	namespace | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		void GetContentScale(float* scale_x, float* scale_y) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			const float DEFAULT_SCREEN_DPI = 96.f; | 
					
						
							|  |  |  |  | 			const HDC dc = GetDC(NULL); | 
					
						
							|  |  |  |  | 			float xdpi = static_cast<float>(GetDeviceCaps(dc, LOGPIXELSX)); | 
					
						
							|  |  |  |  | 			float ydpi = static_cast<float>(GetDeviceCaps(dc, LOGPIXELSY)); | 
					
						
							|  |  |  |  | 			ReleaseDC(NULL, dc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			if (scale_x) | 
					
						
							|  |  |  |  | 				*scale_x = xdpi / DEFAULT_SCREEN_DPI; | 
					
						
							|  |  |  |  | 			if (scale_y) | 
					
						
							|  |  |  |  | 				*scale_y = ydpi / DEFAULT_SCREEN_DPI; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		Rect LocateWindow(int width, int height, float scale_x, float scale_y) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			int max_width = ::GetSystemMetrics(SM_CXSCREEN); | 
					
						
							|  |  |  |  | 			int max_height = ::GetSystemMetrics(SM_CYSCREEN); | 
					
						
							|  |  |  |  | 			RECT rect = | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				0, | 
					
						
							|  |  |  |  | 				static_cast<LONG>(math::Ceil(width * scale_x)), | 
					
						
							|  |  |  |  | 				static_cast<LONG>(math::Ceil(height * scale_y)) | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			::AdjustWindowRectEx(&rect, WINDOW_STYLE, FALSE, NULL); | 
					
						
							|  |  |  |  | 			width = static_cast<int>(rect.right - rect.left); | 
					
						
							|  |  |  |  | 			height = static_cast<int>(rect.bottom - rect.top); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  |  | 			if (max_width < width || max_height < height) | 
					
						
							|  |  |  |  | 				logs::Warningln("The window is larger than screen!"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 			width = std::min(width, max_width); | 
					
						
							|  |  |  |  | 			height = std::min(height, max_height); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			return Rect( | 
					
						
							|  |  |  |  | 				static_cast<float>((max_width - width) / 2), | 
					
						
							|  |  |  |  | 				static_cast<float>((max_height - height) / 2), | 
					
						
							|  |  |  |  | 				static_cast<float>(width), | 
					
						
							|  |  |  |  | 				static_cast<float>(height) | 
					
						
							|  |  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | } |