| 
									
										
										
										
											2018-10-03 22:02:46 +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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | #include "Node.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-21 17:18:59 +08:00
										 |  |  | #include "Factory.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | #include "Scene.h"
 | 
					
						
							|  |  |  | #include "Task.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | #include "Action.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | #include "render.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-15 17:59:18 +08:00
										 |  |  | #include "logs.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | namespace easy2d | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  | 	namespace | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		float default_pivot_x = 0.f; | 
					
						
							|  |  |  | 		float default_pivot_y = 0.f; | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		bool border_enabled = false; | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::SetDefaultPivot(float pivot_x, float pivot_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		default_pivot_x = pivot_x; | 
					
						
							|  |  |  | 		default_pivot_y = pivot_y; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void easy2d::Node::EnableBorder() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		border_enabled = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void easy2d::Node::DisableBorder() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		border_enabled = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	Node::Node() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		: inited_(false) | 
					
						
							|  |  |  | 		, visible_(true) | 
					
						
							|  |  |  | 		, dirty_sort_(false) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		, parent_(nullptr) | 
					
						
							|  |  |  | 		, hash_name_(0) | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		, z_order_(0) | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 		, opacity_(1.f) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		, display_opacity_(1.f) | 
					
						
							|  |  |  | 		, children_() | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		, border_color_(Color::Red, 0.6f) | 
					
						
							| 
									
										
										
										
											2018-11-12 02:10:35 +08:00
										 |  |  | 		, initial_matrix_() | 
					
						
							|  |  |  | 		, final_matrix_() | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		, pivot_(default_pivot_x, default_pivot_y) | 
					
						
							|  |  |  | 		, size_() | 
					
						
							| 
									
										
										
										
											2018-09-05 00:08:03 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::Init() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		inited_ = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::OnRender() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// normal node renders nothing
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::Update(Duration const & dt) | 
					
						
							| 
									
										
										
										
											2018-09-07 23:47:21 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		if (!inited_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			Init(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		UpdateActions(this, dt); | 
					
						
							|  |  |  | 		UpdateTasks(dt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!children_.IsEmpty()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			for (auto child = children_.First(); child; child = child->NextItem()) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				child->Update(dt); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-28 18:44:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::Render() | 
					
						
							| 
									
										
										
										
											2018-06-01 17:53:56 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (!visible_) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 		UpdateTransform(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		auto graphics = Graphics::Instance(); | 
					
						
							| 
									
										
										
										
											2018-11-18 23:41:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 		if (children_.IsEmpty()) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  | 			graphics->SetTransform(final_matrix_); | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 			graphics->SetOpacity(display_opacity_); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			OnRender(); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			SortChildren(); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			// render children those are less than 0 in Z-Order
 | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 			spNode child = children_.First(); | 
					
						
							|  |  |  | 			for (spNode next; child; child = next) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 				next = child->NextItem(); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 				if (child->GetZOrder() < 0) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 					child->Render(); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  | 			graphics->SetTransform(final_matrix_); | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 			graphics->SetOpacity(display_opacity_); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			OnRender(); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 			for (spNode next; child; child = next) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 				next = child->NextItem(); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 				child->Render(); | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 	void Node::DispatchEvent(Event * e) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!visible_) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this->HandleEvent(e); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!e->has_target) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			EventDispatcher::DispatchEvent(e); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::HandleEvent(Event * e) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		spNode prev; | 
					
						
							|  |  |  | 		for (auto child = children_.Last(); child; child = prev) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			prev = child->PrevItem(); | 
					
						
							|  |  |  | 			child->HandleEvent(e); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::DrawBorder() | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (visible_) | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			if (border_) | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 				Graphics::Instance()->DrawGeometry(border_, border_color_, 1.5f); | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			for (auto child = children_.First(); child; child = child->NextItem()) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				child->DrawBorder(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::SortChildren() | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		if (dirty_sort_) | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			children_.Sort( | 
					
						
							|  |  |  | 				[](spNode const& n1, spNode const& n2) { return n1->GetZOrder() < n2->GetZOrder(); } | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dirty_sort_ = false; | 
					
						
							| 
									
										
										
										
											2018-10-06 09:45:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 	math::Matrix const & Node::GetTransformMatrix() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		UpdateTransform(); | 
					
						
							|  |  |  | 		return final_matrix_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 	spNode Node::GetParent() const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return parent_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spScene Node::GetScene() const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return scene_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::UpdateTransform() | 
					
						
							| 
									
										
										
										
											2018-07-07 18:04:18 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (!dirty_transform_) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dirty_transform_ = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		Point center{ size_.width * pivot_.x, size_.height * pivot_.y }; | 
					
						
							|  |  |  | 		final_matrix_ = math::Matrix::Scaling(transform_.scale, center) | 
					
						
							|  |  |  | 			* math::Matrix::Skewing(transform_.skew.x, transform_.skew.y, center) | 
					
						
							|  |  |  | 			* math::Matrix::Rotation(transform_.rotation, center) | 
					
						
							|  |  |  | 			* math::Matrix::Translation(transform_.position - center); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 01:02:05 +08:00
										 |  |  | 		initial_matrix_ = final_matrix_ * math::Matrix::Translation( | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 			Point{ size_.width * pivot_.x, size_.height * pivot_.y } | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (parent_) | 
					
						
							| 
									
										
										
										
											2018-09-01 23:00:08 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			initial_matrix_ = initial_matrix_ * parent_->initial_matrix_; | 
					
						
							|  |  |  | 			final_matrix_ = final_matrix_ * parent_->initial_matrix_; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-07 18:04:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		// update children's transform
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 		for (auto child = children_.First(); child; child = child->NextItem()) | 
					
						
							| 
									
										
										
										
											2018-07-28 18:44:37 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			child->dirty_transform_ = true; | 
					
						
							| 
									
										
										
										
											2018-07-28 18:44:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// update border
 | 
					
						
							|  |  |  | 		if (border_enabled) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			UpdateBorder(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-07 18:04:18 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-01 17:53:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 	void Node::UpdateBorder() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		cpRectangleGeometry rect; | 
					
						
							|  |  |  | 		cpTransformedGeometry transformed; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		HRESULT hr = Factory::Instance()->CreateRectangleGeometry( | 
					
						
							|  |  |  | 			rect, | 
					
						
							|  |  |  | 			Rect(Point{}, size_) | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			hr = Factory::Instance()->CreateTransformedGeometry( | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 				transformed, | 
					
						
							|  |  |  | 				final_matrix_, | 
					
						
							|  |  |  | 				rect | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			border_ = transformed; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 	void Node::UpdateOpacity() | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		if (parent_) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			display_opacity_ = opacity_ * parent_->display_opacity_; | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		for (auto child = children_.First(); child; child = child->NextItem()) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			child->UpdateOpacity(); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-09-11 00:37:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 	void Node::SetScene(Scene * scene) | 
					
						
							| 
									
										
										
										
											2018-07-13 00:45:39 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 		scene_ = scene; | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 		for (auto child = children_.First(); child; child = child->NextItem()) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			child->scene_ = scene; | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-13 00:45:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::SetZOrder(int order) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		if (z_order_ == order) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		z_order_ = order; | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (parent_) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			parent_->dirty_sort_ = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetOpacity(float opacity) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 		if (opacity_ == opacity) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 20:26:41 +08:00
										 |  |  | 		display_opacity_ = opacity_ = std::min(std::max(opacity, 0.f), 1.f); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		UpdateOpacity(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetPivotX(float pivot_x) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		this->SetPivot(pivot_x, pivot_.y); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetPivotY(float pivot_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		this->SetPivot(pivot_.x, pivot_y); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetPivot(float pivot_x, float pivot_y) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		if (pivot_.x == pivot_x && pivot_.y == pivot_y) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		pivot_.x = pivot_x; | 
					
						
							|  |  |  | 		pivot_.y = pivot_y; | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		dirty_transform_ = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetWidth(float width) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		this->SetSize(width, size_.height); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetHeight(float height) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		this->SetSize(size_.width, height); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::SetSize(const Size& size) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		this->SetSize(size.width, size.height); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 	void Node::SetSize(float width, float height) | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		if (size_.width == width && size_.height == height) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		size_.width = width; | 
					
						
							|  |  |  | 		size_.height = height; | 
					
						
							|  |  |  | 		dirty_transform_ = true; | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 17:19:03 +08:00
										 |  |  | 	void Node::SetTransform(Transform const& transform) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		transform_ = transform; | 
					
						
							|  |  |  | 		dirty_transform_ = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 	void Node::SetBorderColor(Color const& color) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		border_color_ = color; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-01 19:28:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::SetVisible(bool val) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		visible_ = val; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::SetName(String const& name) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (name_ != name) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			name_ = name; | 
					
						
							|  |  |  | 			hash_name_ = std::hash<String>{}(name); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void Node::AddChild(spNode const& child, int z_order) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-22 23:48:40 +08:00
										 |  |  | 		E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); | 
					
						
							| 
									
										
										
										
											2018-03-01 19:28:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (child) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | #ifdef E2D_DEBUG
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			if (child->parent_) | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 				logs::Errorln("The node to be added already has a parent"); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 			for (Node* parent = parent_; parent; parent = parent->parent_) | 
					
						
							|  |  |  | 				if (parent == child) | 
					
						
							|  |  |  | 					logs::Errorln("A node cannot be its own parent"); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | #endif // E2D_DEBUG
 | 
					
						
							| 
									
										
										
										
											2018-03-01 19:28:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 			children_.PushBack(Node::ItemType(child)); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			child->parent_ = this; | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			child->SetScene(this->scene_); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			child->dirty_transform_ = true; | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			child->SetZOrder(z_order); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 			child->UpdateOpacity(); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			dirty_sort_ = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 18:42:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 	void Node::AddChild(const Nodes& nodes, int z_order) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		for (const auto& node : nodes) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			this->AddChild(node, z_order); | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-28 18:44:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 16:16:16 +08:00
										 |  |  | 	Rect Node::GetBounds() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		return Rect(Point{}, size_); | 
					
						
							| 
									
										
										
										
											2018-11-16 16:16:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 	Node::Nodes Node::GetChildren(String const& name) const | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		Nodes children; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		size_t hash_code = std::hash<String>{}(name); | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 		for (auto child = children_.First(); child != children_.Last(); child = child->NextItem()) | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			if (child->hash_name_ == hash_code && child->name_ == name) | 
					
						
							| 
									
										
										
										
											2018-05-24 00:58:16 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 				children.push_back(child); | 
					
						
							| 
									
										
										
										
											2018-05-24 00:58:16 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		return children; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 	spNode Node::GetChild(String const& name) const | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		size_t hash_code = std::hash<String>{}(name); | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 		for (auto child = children_.First(); child != children_.Last(); child = child->NextItem()) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			if (child->hash_name_ == hash_code && child->name_ == name) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return child; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		return nullptr; | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 	Node::Children const & Node::GetChildren() const | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		return children_; | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::RemoveFromParent() | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (parent_) | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			parent_->RemoveChild(this); | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	bool Node::RemoveChild(spNode const& child) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-22 23:48:40 +08:00
										 |  |  | 		E2D_ASSERT(child && "Node::RemoveChild failed, NULL pointer exception"); | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 		if (children_.IsEmpty()) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		if (child) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			child->parent_ = nullptr; | 
					
						
							|  |  |  | 			if (child->scene_) child->SetScene(nullptr); | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 			children_.Remove(Node::ItemType(child)); | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 16:37:51 +08:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 	void Node::RemoveChildren(String const& child_name) | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 		if (children_.IsEmpty()) | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		size_t hash_code = std::hash<String>{}(child_name); | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 		spNode next; | 
					
						
							| 
									
										
										
										
											2018-11-17 17:15:32 +08:00
										 |  |  | 		for (auto child = children_.First(); child; child = next) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-16 15:53:39 +08:00
										 |  |  | 			next = child->NextItem(); | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (child->hash_name_ == hash_code && child->name_ == child_name) | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				RemoveChild(child); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	void Node::RemoveAllChildren() | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-15 23:40:13 +08:00
										 |  |  | 		children_.Clear(); | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 	bool Node::ContainsPoint(const Point& point) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 01:20:06 +08:00
										 |  |  | 		if (size_.width == 0.f || size_.height == 0.f) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		UpdateTransform(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		cpRectangleGeometry border; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 		ThrowIfFailed( | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 			Factory::Instance()->CreateRectangleGeometry( | 
					
						
							|  |  |  | 				border, | 
					
						
							|  |  |  | 				Rect(Point{}, size_) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | 		BOOL ret = 0; | 
					
						
							|  |  |  | 		// no matter it failed or not
 | 
					
						
							|  |  |  | 		border->FillContainsPoint( | 
					
						
							|  |  |  | 			point, | 
					
						
							|  |  |  | 			ConvertToD2DMatrix(final_matrix_), | 
					
						
							|  |  |  | 			&ret | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return !!ret; | 
					
						
							| 
									
										
										
										
											2017-10-14 11:40:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-21 19:24:18 +08:00
										 |  |  | } |