| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | // 
 | 
					
						
							|  |  |  | // 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-08-08 14:15:06 +08:00
										 |  |  | #include "ShapeNode.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | #include "../base/logs.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | namespace kiwano | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	ShapeNode::ShapeNode() | 
					
						
							|  |  |  | 		: fill_color_(Color::White) | 
					
						
							|  |  |  | 		, stroke_color_(Color(Color::Black, 0)) | 
					
						
							|  |  |  | 		, stroke_width_(1.f) | 
					
						
							|  |  |  | 		, outline_join_(StrokeStyle::Miter) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	ShapeNode::ShapeNode(ComPtr<ID2D1Geometry> geometry) | 
					
						
							|  |  |  | 		: ShapeNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 		SetGeometry(geometry); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	ShapeNode::~ShapeNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	Rect ShapeNode::GetBoundingBox() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (!geo_) | 
					
						
							|  |  |  | 			return Rect{}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		D2D1_RECT_F rect; | 
					
						
							|  |  |  | 		// no matter it failed or not
 | 
					
						
							|  |  |  | 		geo_->GetBounds(D2D1::Matrix3x2F::Identity(), &rect); | 
					
						
							|  |  |  | 		return Rect{ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top }; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	float ShapeNode::GetLength() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		float length = 0.f; | 
					
						
							|  |  |  | 		if (geo_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			// no matter it failed or not
 | 
					
						
							|  |  |  | 			geo_->ComputeLength(D2D1::Matrix3x2F::Identity(), &length); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return length; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	bool ShapeNode::ComputePointAtLength(float length, Point& point, Vec2& tangent) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (geo_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (SUCCEEDED(geo_->ComputePointAtLength( | 
					
						
							|  |  |  | 				length, | 
					
						
							|  |  |  | 				D2D1::Matrix3x2F::Identity(), | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 				DX::ConvertToPoint2F(&point), | 
					
						
							|  |  |  | 				DX::ConvertToPoint2F(&tangent)))) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	float ShapeNode::ComputeArea() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (!geo_) | 
					
						
							|  |  |  | 			return 0.f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float area = 0.f; | 
					
						
							|  |  |  | 		// no matter it failed or not
 | 
					
						
							|  |  |  | 		geo_->ComputeArea(D2D1::Matrix3x2F::Identity(), &area); | 
					
						
							|  |  |  | 		return area; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	bool ShapeNode::ContainsPoint(Point const& point) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (!geo_) | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BOOL ret = 0; | 
					
						
							|  |  |  | 		// no matter it failed or not
 | 
					
						
							|  |  |  | 		geo_->FillContainsPoint( | 
					
						
							|  |  |  | 			DX::ConvertToPoint2F(point), | 
					
						
							|  |  |  | 			D2D1::Matrix3x2F::Identity(), | 
					
						
							|  |  |  | 			&ret | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return !!ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void ShapeNode::SetFillColor(const Color & color) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		fill_color_ = color; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void ShapeNode::SetStrokeColor(const Color & color) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		stroke_color_ = color; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void ShapeNode::SetStrokeWidth(float width) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		stroke_width_ = std::max(width, 0.f); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void ShapeNode::SetOutlineJoinStyle(StrokeStyle outline_join) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		outline_join_ = outline_join; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void ShapeNode::OnRender() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (geo_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			Renderer::Instance()->FillGeometry( | 
					
						
							|  |  |  | 				geo_, | 
					
						
							|  |  |  | 				fill_color_ | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Renderer::Instance()->DrawGeometry( | 
					
						
							|  |  |  | 				geo_, | 
					
						
							|  |  |  | 				stroke_color_, | 
					
						
							|  |  |  | 				stroke_width_, | 
					
						
							|  |  |  | 				outline_join_ | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	// LineNode
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	LineNode::LineNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	LineNode::LineNode(Point const& begin, Point const& end) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetLine(begin, end); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	LineNode::~LineNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void LineNode::SetLine(Point const& begin, Point const& end) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ComPtr<ID2D1PathGeometry> path_geo; | 
					
						
							|  |  |  | 		ComPtr<ID2D1GeometrySink> path_sink; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 15:27:01 +08:00
										 |  |  | 		HRESULT hr = Renderer::Instance()->GetD2DDeviceResources()->GetFactory()->CreatePathGeometry(&path_geo); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hr = path_geo->Open(&path_sink); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			path_sink->BeginFigure(DX::ConvertToPoint2F(begin), D2D1_FIGURE_BEGIN_FILLED); | 
					
						
							|  |  |  | 			path_sink->AddLine(DX::ConvertToPoint2F(end)); | 
					
						
							|  |  |  | 			path_sink->EndFigure(D2D1_FIGURE_END_OPEN); | 
					
						
							|  |  |  | 			hr = path_sink->Close(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			geo_ = path_geo; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void LineNode::SetBegin(Point const& begin) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetLine(begin, end_); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void LineNode::SetEnd(Point const& end) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetLine(begin_, end); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	// RectNode
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	RectNode::RectNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	RectNode::RectNode(Rect const& rect) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetRect(rect); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	RectNode::RectNode(Point const& left_top, Size const& size) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetRect(Rect{ left_top, size }); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	RectNode::~RectNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void RectNode::SetRect(Rect const& rect) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ComPtr<ID2D1RectangleGeometry> geo; | 
					
						
							| 
									
										
										
										
											2019-07-30 15:27:01 +08:00
										 |  |  | 		auto factory = Renderer::Instance()->GetD2DDeviceResources()->GetFactory(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(factory->CreateRectangleGeometry(DX::ConvertToRectF(rect), &geo))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			geo_ = geo; | 
					
						
							|  |  |  | 			rect_ = rect; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	// RoundedRectNode
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RoundedRectNode::RoundedRectNode() | 
					
						
							|  |  |  | 		: radius_x_(0.f) | 
					
						
							|  |  |  | 		, radius_y_(0.f) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RoundedRectNode::RoundedRectNode(Rect const& rect, float radius_x, float radius_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SetRoundedRect(rect, radius_x, radius_y); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RoundedRectNode::~RoundedRectNode() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void RoundedRectNode::SetRadius(float radius_x, float radius_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SetRoundedRect(rect_, radius_x, radius_y); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void RoundedRectNode::SetRect(Rect const& rect) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SetRoundedRect(rect, radius_x_, radius_y_); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void RoundedRectNode::SetRoundedRect(Rect const& rect, float radius_x, float radius_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ComPtr<ID2D1RoundedRectangleGeometry> geo; | 
					
						
							|  |  |  | 		auto factory = Renderer::Instance()->GetD2DDeviceResources()->GetFactory(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(factory->CreateRoundedRectangleGeometry( | 
					
						
							|  |  |  | 			D2D1::RoundedRect( | 
					
						
							|  |  |  | 				DX::ConvertToRectF(rect), | 
					
						
							|  |  |  | 				radius_x, | 
					
						
							|  |  |  | 				radius_y | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			&geo))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			geo_ = geo; | 
					
						
							|  |  |  | 			rect_ = rect; | 
					
						
							|  |  |  | 			radius_x_ = radius_x; | 
					
						
							|  |  |  | 			radius_y_ = radius_y; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// CircleNode
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	CircleNode::CircleNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 		: radius_(0.f) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	CircleNode::CircleNode(Point const& center, float radius) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetCircle(center, radius); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	CircleNode::~CircleNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void CircleNode::SetRadius(float radius) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetCircle(center_, radius); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void CircleNode::SetCenter(Point const& center) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetCircle(center, radius_); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void CircleNode::SetCircle(Point const& center, float radius) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ComPtr<ID2D1EllipseGeometry> geo; | 
					
						
							| 
									
										
										
										
											2019-07-30 15:27:01 +08:00
										 |  |  | 		auto factory = Renderer::Instance()->GetD2DDeviceResources()->GetFactory(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(factory->CreateEllipseGeometry( | 
					
						
							|  |  |  | 			D2D1::Ellipse( | 
					
						
							|  |  |  | 				DX::ConvertToPoint2F(center), | 
					
						
							|  |  |  | 				radius, | 
					
						
							|  |  |  | 				radius), | 
					
						
							|  |  |  | 			&geo))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			geo_ = geo; | 
					
						
							|  |  |  | 			center_ = center; | 
					
						
							|  |  |  | 			radius_ = radius; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	// EllipseNode
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	EllipseNode::EllipseNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 		: radius_x_(0.f) | 
					
						
							|  |  |  | 		, radius_y_(0.f) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	EllipseNode::EllipseNode(Point const& center, float radius_x, float radius_y) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetEllipse(center, radius_x, radius_y); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	EllipseNode::~EllipseNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void EllipseNode::SetRadius(float radius_x, float radius_y) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetEllipse(center_, radius_x, radius_y); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void EllipseNode::SetCenter(Point const& center) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		SetEllipse(center, radius_x_, radius_y_); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void EllipseNode::SetEllipse(Point const& center, float radius_x, float radius_y) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ComPtr<ID2D1EllipseGeometry> geo; | 
					
						
							| 
									
										
										
										
											2019-07-30 15:27:01 +08:00
										 |  |  | 		auto factory = Renderer::Instance()->GetD2DDeviceResources()->GetFactory(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (SUCCEEDED(factory->CreateEllipseGeometry( | 
					
						
							|  |  |  | 			D2D1::Ellipse( | 
					
						
							|  |  |  | 				DX::ConvertToPoint2F(center), | 
					
						
							|  |  |  | 				radius_x, | 
					
						
							|  |  |  | 				radius_y), | 
					
						
							|  |  |  | 			&geo))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			geo_ = geo; | 
					
						
							|  |  |  | 			radius_x_ = radius_x; | 
					
						
							|  |  |  | 			radius_y_ = radius_y; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	// PathNode
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	PathNode::PathNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	PathNode::~PathNode() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::BeginPath(Point const& begin_pos) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		current_geometry_ = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 15:27:01 +08:00
										 |  |  | 		auto factory = Renderer::Instance()->GetD2DDeviceResources()->GetFactory(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		ThrowIfFailed( | 
					
						
							|  |  |  | 			factory->CreatePathGeometry(¤t_geometry_) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ThrowIfFailed( | 
					
						
							|  |  |  | 			current_geometry_->Open(¤t_sink_) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		current_sink_->BeginFigure(DX::ConvertToPoint2F(begin_pos), D2D1_FIGURE_BEGIN_FILLED); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::EndPath(bool closed) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (current_sink_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			current_sink_->EndFigure(closed ? D2D1_FIGURE_END_CLOSED : D2D1_FIGURE_END_OPEN); | 
					
						
							|  |  |  | 			ThrowIfFailed( | 
					
						
							|  |  |  | 				current_sink_->Close() | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			geo_ = current_geometry_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			current_sink_ = nullptr; | 
					
						
							|  |  |  | 			current_geometry_ = nullptr; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::AddLine(Point const& point) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (current_sink_) | 
					
						
							|  |  |  | 			current_sink_->AddLine(DX::ConvertToPoint2F(point)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::AddLines(Array<Point> const& points) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (current_sink_ && !points.empty()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			current_sink_->AddLines( | 
					
						
							|  |  |  | 				reinterpret_cast<const D2D_POINT_2F*>(&points[0]), | 
					
						
							|  |  |  | 				static_cast<UINT32>(points.size()) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::AddBezier(Point const& point1, Point const& point2, Point const& point3) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (current_sink_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			current_sink_->AddBezier( | 
					
						
							|  |  |  | 				D2D1::BezierSegment( | 
					
						
							|  |  |  | 					DX::ConvertToPoint2F(point1), | 
					
						
							|  |  |  | 					DX::ConvertToPoint2F(point2), | 
					
						
							|  |  |  | 					DX::ConvertToPoint2F(point3) | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if (current_sink_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			current_sink_->AddArc( | 
					
						
							|  |  |  | 				D2D1::ArcSegment( | 
					
						
							|  |  |  | 					DX::ConvertToPoint2F(point), | 
					
						
							|  |  |  | 					DX::ConvertToSizeF(radius), | 
					
						
							|  |  |  | 					rotation, | 
					
						
							|  |  |  | 					clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE, | 
					
						
							|  |  |  | 					is_small ? D2D1_ARC_SIZE_SMALL : D2D1_ARC_SIZE_LARGE | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | 	void PathNode::ClearPath() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		geo_ = nullptr; | 
					
						
							|  |  |  | 		current_sink_ = nullptr; | 
					
						
							|  |  |  | 		current_geometry_ = nullptr; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 14:15:06 +08:00
										 |  |  | } |