| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dbase.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer*		e2d::Renderer::_instance = nullptr; | 
					
						
							|  |  |  |  | ID2D1Factory*		e2d::Renderer::_d2dFactory = nullptr; | 
					
						
							|  |  |  |  | IWICImagingFactory*	e2d::Renderer::_imagingFactory = nullptr; | 
					
						
							|  |  |  |  | IDWriteFactory*		e2d::Renderer::_writeFactory = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_miterStrokeStyle = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_bevelStrokeStyle = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_roundStrokeStyle = nullptr; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer * e2d::Renderer::getInstance() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (!_instance) | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		_instance = new (std::nothrow) Renderer; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _instance; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | void e2d::Renderer::destroyInstance() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (_instance) | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		delete _instance; | 
					
						
							|  |  |  |  | 		_instance = nullptr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		SafeRelease(_miterStrokeStyle); | 
					
						
							|  |  |  |  | 		SafeRelease(_bevelStrokeStyle); | 
					
						
							|  |  |  |  | 		SafeRelease(_roundStrokeStyle); | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		SafeRelease(_d2dFactory); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		SafeRelease(_imagingFactory); | 
					
						
							|  |  |  |  | 		SafeRelease(_writeFactory); | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer::Renderer() | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 	: _lastRenderTime(0) | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 	, _fpsFormat(nullptr) | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	, _renderTarget(nullptr) | 
					
						
							|  |  |  |  | 	, _solidBrush(nullptr) | 
					
						
							|  |  |  |  | 	, _textRenderer(nullptr) | 
					
						
							|  |  |  |  | 	, _clearColor(D2D1::ColorF(D2D1::ColorF::Black)) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 15:33:09 +08:00
										 |  |  |  | 	CoInitialize(nullptr); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer::~Renderer() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 	SafeRelease(_fpsFormat); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	SafeRelease(_textRenderer); | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 	SafeRelease(_solidBrush); | 
					
						
							|  |  |  |  | 	SafeRelease(_renderTarget); | 
					
						
							| 
									
										
										
										
											2018-07-04 15:33:09 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	CoUninitialize(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | void e2d::Renderer::discardDeviceResources() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	SafeRelease(_renderTarget); | 
					
						
							|  |  |  |  | 	SafeRelease(_solidBrush); | 
					
						
							|  |  |  |  | 	SafeRelease(_textRenderer); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 22:05:23 +08:00
										 |  |  |  | void e2d::Renderer::render() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	HRESULT hr = S_OK; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
 | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	auto renderTarget = this->getRenderTarget(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>ʼ<EFBFBD><CABC>Ⱦ
 | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	renderTarget->BeginDraw(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	// ʹ<>ñ<EFBFBD><C3B1><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
 | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	renderTarget->Clear(_clearColor); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-07-05 22:05:23 +08:00
										 |  |  |  | 	SceneManager::getInstance()->render(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	// <20><>Ⱦ FPS
 | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 	if (Game::getInstance()->getConfig().isFpsShow()) | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 		_renderFps(); | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	// <20><>ֹ<EFBFBD><D6B9>Ⱦ
 | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	hr = renderTarget->EndDraw(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (hr == D2DERR_RECREATE_TARGET) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> Direct3D <20>豸<EFBFBD><E8B1B8>ִ<EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ʱ<EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>Դ
 | 
					
						
							|  |  |  |  | 		hr = S_OK; | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 		this->discardDeviceResources(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (FAILED(hr)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 		throw SystemException(L"Device loss recovery failed"); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | void e2d::Renderer::_renderFps() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  |  | 	double duration = Game::getInstance()->getTotalDuration().seconds(); | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 	if (duration == _lastRenderTime) | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	String fpsText = String::format(L"FPS: %.1lf", (1.0 / (duration - _lastRenderTime))); | 
					
						
							|  |  |  |  | 	_lastRenderTime = duration; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	auto writeFactory = Renderer::getWriteFactory(); | 
					
						
							|  |  |  |  | 	if (!_fpsFormat) | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 		HRESULT hr = writeFactory->CreateTextFormat( | 
					
						
							|  |  |  |  | 			L"", | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_WEIGHT_NORMAL, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_STYLE_NORMAL, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_STRETCH_NORMAL, | 
					
						
							|  |  |  |  | 			20, | 
					
						
							|  |  |  |  | 			L"", | 
					
						
							|  |  |  |  | 			&_fpsFormat | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 			_fpsFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 	IDWriteTextLayout * fpsLayout = nullptr; | 
					
						
							|  |  |  |  | 	HRESULT hr = writeFactory->CreateTextLayout( | 
					
						
							|  |  |  |  | 		(const WCHAR *)fpsText, | 
					
						
							|  |  |  |  | 		(UINT32)fpsText.getLength(), | 
					
						
							|  |  |  |  | 		_fpsFormat, | 
					
						
							|  |  |  |  | 		0, | 
					
						
							|  |  |  |  | 		0, | 
					
						
							|  |  |  |  | 		&fpsLayout | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  |  | 		_solidBrush->SetOpacity(1.0f); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		auto textRenderer = this->getTextRenderer(); | 
					
						
							|  |  |  |  | 		textRenderer->SetTextStyle( | 
					
						
							|  |  |  |  | 			D2D1::ColorF(D2D1::ColorF::White), | 
					
						
							|  |  |  |  | 			TRUE, | 
					
						
							|  |  |  |  | 			D2D1::ColorF(D2D1::ColorF::Black, 0.4f), | 
					
						
							|  |  |  |  | 			1.5f, | 
					
						
							|  |  |  |  | 			D2D1_LINE_JOIN_ROUND | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 		fpsLayout->Draw(nullptr, textRenderer, 10, 0); | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-24 12:49:32 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	SafeRelease(fpsLayout); | 
					
						
							| 
									
										
										
										
											2018-07-17 12:32:20 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | e2d::Color e2d::Renderer::getBackgroundColor() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return Color(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Renderer::setBackgroundColor(Color color) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_clearColor = color.toD2DColorF(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1HwndRenderTarget * e2d::Renderer::getRenderTarget() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	if (!_renderTarget) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HWND hWnd = Window::getInstance()->getHWnd(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9>ԴӦ<D4B4><D3A6> Direct3D <20>豸<EFBFBD><E8B1B8>ʧʱ<CAA7>ؽ<EFBFBD>
 | 
					
						
							|  |  |  |  | 		RECT rc; | 
					
						
							|  |  |  |  | 		GetClientRect(hWnd, &rc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		D2D1_SIZE_U size = D2D1::SizeU( | 
					
						
							|  |  |  |  | 			rc.right - rc.left, | 
					
						
							|  |  |  |  | 			rc.bottom - rc.top | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		bool VSyncEnabled = Game::getInstance()->getConfig().isVSyncEnabled(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> Direct2D <20><>ȾĿ<C8BE><C4BF>
 | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateHwndRenderTarget( | 
					
						
							|  |  |  |  | 			D2D1::RenderTargetProperties(), | 
					
						
							|  |  |  |  | 			D2D1::HwndRenderTargetProperties( | 
					
						
							|  |  |  |  | 				hWnd, | 
					
						
							|  |  |  |  | 				size, | 
					
						
							|  |  |  |  | 				VSyncEnabled ? D2D1_PRESENT_OPTIONS_NONE : D2D1_PRESENT_OPTIONS_IMMEDIATELY), | 
					
						
							|  |  |  |  | 			&_renderTarget | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1HwndRenderTarget failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _renderTarget; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1SolidColorBrush * e2d::Renderer::getSolidColorBrush() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-24 20:21:25 +08:00
										 |  |  |  | 	if (!_solidBrush) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
 | 
					
						
							|  |  |  |  | 		HRESULT hr = this->getRenderTarget()->CreateSolidColorBrush( | 
					
						
							|  |  |  |  | 			D2D1::ColorF(D2D1::ColorF::White), | 
					
						
							|  |  |  |  | 			&_solidBrush | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1SolidColorBrush failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _solidBrush; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::TextRenderer * e2d::Renderer::getTextRenderer() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_textRenderer) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
 | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 		HRESULT hr = TextRenderer::Create( | 
					
						
							|  |  |  |  | 			&_textRenderer, | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			Renderer::getFactory(), | 
					
						
							|  |  |  |  | 			this->getRenderTarget(), | 
					
						
							|  |  |  |  | 			this->getSolidColorBrush() | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create TextRenderer failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _textRenderer; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1Factory * e2d::Renderer::getFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_d2dFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = D2D1CreateFactory( | 
					
						
							|  |  |  |  | 			D2D1_FACTORY_TYPE_SINGLE_THREADED, | 
					
						
							|  |  |  |  | 			&_d2dFactory | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1Factory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _d2dFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | IWICImagingFactory * e2d::Renderer::getImagingFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_imagingFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> WIC <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʽ<EFBFBD><CABD>ͼƬ
 | 
					
						
							|  |  |  |  | 		HRESULT hr = CoCreateInstance( | 
					
						
							|  |  |  |  | 			CLSID_WICImagingFactory, | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			CLSCTX_INPROC_SERVER, | 
					
						
							|  |  |  |  | 			IID_IWICImagingFactory, | 
					
						
							|  |  |  |  | 			reinterpret_cast<void**>(&_imagingFactory) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create IWICImagingFactory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _imagingFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | IDWriteFactory * e2d::Renderer::getWriteFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_writeFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> DirectWrite <20><><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		HRESULT hr = DWriteCreateFactory( | 
					
						
							|  |  |  |  | 			DWRITE_FACTORY_TYPE_SHARED, | 
					
						
							|  |  |  |  | 			__uuidof(IDWriteFactory), | 
					
						
							|  |  |  |  | 			reinterpret_cast<IUnknown**>(&_writeFactory) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create IDWriteFactory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _writeFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_miterStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_MITER, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_miterStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _miterStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_bevelStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_BEVEL, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_bevelStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _bevelStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_roundStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_ROUND, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_roundStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _roundStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } |