change: Node::SetAnchor -> Node::SetPivot
This commit is contained in:
		
							parent
							
								
									4d9649eedf
								
							
						
					
					
						commit
						190a04a24f
					
				|  | @ -10,7 +10,7 @@ | ||||||
| 		if (Old) this->RemoveChild(Old);						\ | 		if (Old) this->RemoveChild(Old);						\ | ||||||
| 		if (New)												\ | 		if (New)												\ | ||||||
| 		{														\ | 		{														\ | ||||||
| 			New->SetAnchor(anchor_.x, anchor_.y);				\ | 			New->SetPivot(GetPivotX(), GetPivotY());			\ | ||||||
| 			this->AddChild(New);								\ | 			this->AddChild(New);								\ | ||||||
| 		}														\ | 		}														\ | ||||||
| 		Old = New;												\ | 		Old = New;												\ | ||||||
|  | @ -135,13 +135,13 @@ void e2d::Button::SetCallbackOnClick(const Function& func) | ||||||
| 	callback_ = func; | 	callback_ = func; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Button::SetAnchor(float anchor_x, float anchor_y) | void e2d::Button::SetPivot(float pivot_x, float pivot_y) | ||||||
| { | { | ||||||
| 	Node::SetAnchor(anchor_x, anchor_y); | 	Node::SetPivot(pivot_x, pivot_y); | ||||||
| 	SAFE_SET(normal_, SetAnchor, anchor_x, anchor_y); | 	SAFE_SET(normal_, SetPivot, pivot_x, pivot_y); | ||||||
| 	SAFE_SET(mouseover_, SetAnchor, anchor_x, anchor_y); | 	SAFE_SET(mouseover_, SetPivot, pivot_x, pivot_y); | ||||||
| 	SAFE_SET(selected_, SetAnchor, anchor_x, anchor_y); | 	SAFE_SET(selected_, SetPivot, pivot_x, pivot_y); | ||||||
| 	SAFE_SET(disabled_, SetAnchor, anchor_x, anchor_y); | 	SAFE_SET(disabled_, SetPivot, pivot_x, pivot_y); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool e2d::Button::Dispatch(const MouseEvent & e, bool handled) | bool e2d::Button::Dispatch(const MouseEvent & e, bool handled) | ||||||
|  |  | ||||||
|  | @ -72,9 +72,9 @@ namespace e2d | ||||||
| 
 | 
 | ||||||
| 		// 设置支点位置
 | 		// 设置支点位置
 | ||||||
| 		// 默认为 (0, 0), 范围 [0, 1]
 | 		// 默认为 (0, 0), 范围 [0, 1]
 | ||||||
| 		virtual void SetAnchor( | 		virtual void SetPivot( | ||||||
| 			float anchor_x, | 			float pivot_x, | ||||||
| 			float anchor_y | 			float pivot_y | ||||||
| 		) override; | 		) override; | ||||||
| 
 | 
 | ||||||
| 	protected: | 	protected: | ||||||
|  |  | ||||||
|  | @ -468,10 +468,10 @@ namespace e2d | ||||||
| 		const Size& GetRealSize() const; | 		const Size& GetRealSize() const; | ||||||
| 
 | 
 | ||||||
| 		// 获取节点的支点
 | 		// 获取节点的支点
 | ||||||
| 		float GetAnchorX() const; | 		float GetPivotX() const; | ||||||
| 
 | 
 | ||||||
| 		// 获取节点的支点
 | 		// 获取节点的支点
 | ||||||
| 		float GetAnchorY() const; | 		float GetPivotY() const; | ||||||
| 
 | 
 | ||||||
| 		// 获取节点大小
 | 		// 获取节点大小
 | ||||||
| 		Size GetSize() const; | 		Size GetSize() const; | ||||||
|  | @ -612,21 +612,21 @@ namespace e2d | ||||||
| 
 | 
 | ||||||
| 		// 设置支点的横向位置
 | 		// 设置支点的横向位置
 | ||||||
| 		// 默认为 0, 范围 [0, 1]
 | 		// 默认为 0, 范围 [0, 1]
 | ||||||
| 		virtual void SetAnchorX( | 		virtual void SetPivotX( | ||||||
| 			float anchor_x | 			float pivot_x | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 		// 设置支点的纵向位置
 | 		// 设置支点的纵向位置
 | ||||||
| 		// 默认为 0, 范围 [0, 1]
 | 		// 默认为 0, 范围 [0, 1]
 | ||||||
| 		virtual void SetAnchorY( | 		virtual void SetPivotY( | ||||||
| 			float anchor_y | 			float pivot_y | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 		// 设置支点位置
 | 		// 设置支点位置
 | ||||||
| 		// 默认为 (0, 0), 范围 [0, 1]
 | 		// 默认为 (0, 0), 范围 [0, 1]
 | ||||||
| 		virtual void SetAnchor( | 		virtual void SetPivot( | ||||||
| 			float anchor_x, | 			float pivot_x, | ||||||
| 			float anchor_y | 			float pivot_y | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
| 		// 修改节点宽度
 | 		// 修改节点宽度
 | ||||||
|  |  | ||||||
|  | @ -285,6 +285,10 @@ bool e2d::Image::Preload(const Resource& res) | ||||||
| 
 | 
 | ||||||
| bool e2d::Image::Preload(const String & file_name) | bool e2d::Image::Preload(const String & file_name) | ||||||
| { | { | ||||||
|  | 	size_t hash = file_name.GetHash(); | ||||||
|  | 	if (bitmap_cache_.find(hash) != bitmap_cache_.end()) | ||||||
|  | 		return true; | ||||||
|  | 
 | ||||||
| 	File image_file; | 	File image_file; | ||||||
| 	if (!image_file.Open(file_name)) | 	if (!image_file.Open(file_name)) | ||||||
| 		return false; | 		return false; | ||||||
|  | @ -292,9 +296,6 @@ bool e2d::Image::Preload(const String & file_name) | ||||||
| 	// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
 | 	// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
 | ||||||
| 	// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
 | 	// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
 | ||||||
| 	String image_file_path = image_file.GetPath(); | 	String image_file_path = image_file.GetPath(); | ||||||
| 	size_t hash = image_file_path.GetHash(); |  | ||||||
| 	if (bitmap_cache_.find(hash) != bitmap_cache_.end()) |  | ||||||
| 		return true; |  | ||||||
| 
 | 
 | ||||||
| 	IWICImagingFactory *imaging_factory = Renderer::GetImagingFactory(); | 	IWICImagingFactory *imaging_factory = Renderer::GetImagingFactory(); | ||||||
| 	ID2D1HwndRenderTarget* render_target = Renderer::GetInstance()->GetRenderTarget(); | 	ID2D1HwndRenderTarget* render_target = Renderer::GetInstance()->GetRenderTarget(); | ||||||
|  |  | ||||||
|  | @ -365,12 +365,12 @@ const e2d::Size& e2d::Node::GetRealSize() const | ||||||
| 	return transform_.size; | 	return transform_.size; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float e2d::Node::GetAnchorX() const | float e2d::Node::GetPivotX() const | ||||||
| { | { | ||||||
| 	return transform_.pivot_x; | 	return transform_.pivot_x; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float e2d::Node::GetAnchorY() const | float e2d::Node::GetPivotY() const | ||||||
| { | { | ||||||
| 	return transform_.pivot_y; | 	return transform_.pivot_y; | ||||||
| } | } | ||||||
|  | @ -536,23 +536,23 @@ void e2d::Node::SetOpacity(float opacity) | ||||||
| 	UpdateOpacity(); | 	UpdateOpacity(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Node::SetAnchorX(float anchor_x) | void e2d::Node::SetPivotX(float pivot_x) | ||||||
| { | { | ||||||
| 	this->SetAnchor(anchor_x, transform_.pivot_y); | 	this->SetPivot(pivot_x, transform_.pivot_y); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Node::SetAnchorY(float anchor_y) | void e2d::Node::SetPivotY(float pivot_y) | ||||||
| { | { | ||||||
| 	this->SetAnchor(transform_.pivot_x, anchor_y); | 	this->SetPivot(transform_.pivot_x, pivot_y); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Node::SetAnchor(float anchor_x, float anchor_y) | void e2d::Node::SetPivot(float pivot_x, float pivot_y) | ||||||
| { | { | ||||||
| 	if (transform_.pivot_x == anchor_x && transform_.pivot_y == anchor_y) | 	if (transform_.pivot_x == pivot_x && transform_.pivot_y == pivot_y) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	transform_.pivot_x = anchor_x; | 	transform_.pivot_x = pivot_x; | ||||||
| 	transform_.pivot_y = anchor_y; | 	transform_.pivot_y = pivot_y; | ||||||
| 	dirty_transform_ = true; | 	dirty_transform_ = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -93,15 +93,6 @@ bool e2d::Sprite::Open(const String & file_name) | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Sprite::Crop(const Rect& crop_rect) |  | ||||||
| { |  | ||||||
| 	image_->Crop(crop_rect); |  | ||||||
| 	Node::SetSize( |  | ||||||
| 		std::min(std::max(crop_rect.size.width, 0.f), image_->GetSourceWidth() - image_->GetCropX()), |  | ||||||
| 		std::min(std::max(crop_rect.size.height, 0.f), image_->GetSourceHeight() - image_->GetCropY()) |  | ||||||
| 	); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| e2d::Image * e2d::Sprite::GetImage() const | e2d::Image * e2d::Sprite::GetImage() const | ||||||
| { | { | ||||||
| 	return image_; | 	return image_; | ||||||
|  | @ -112,19 +103,18 @@ void e2d::Sprite::Draw() const | ||||||
| 	if (image_ && image_->GetBitmap()) | 	if (image_ && image_->GetBitmap()) | ||||||
| 	{ | 	{ | ||||||
| 		// »ñȡͼƬ²Ã¼ôλÖÃ
 | 		// »ñȡͼƬ²Ã¼ôλÖÃ
 | ||||||
| 		float fCropX = image_->GetCropX(); | 		auto crop_pos = image_->GetCropPos(); | ||||||
| 		float fCropY = image_->GetCropY(); |  | ||||||
| 		// äÖȾͼƬ
 | 		// äÖȾͼƬ
 | ||||||
| 		Renderer::GetInstance()->GetRenderTarget()->DrawBitmap( | 		Renderer::GetInstance()->GetRenderTarget()->DrawBitmap( | ||||||
| 			image_->GetBitmap(), | 			image_->GetBitmap(), | ||||||
| 			D2D1::RectF(0, 0, size_.width, size_.height), | 			D2D1::RectF(0, 0, transform_.size.width, transform_.size.height), | ||||||
| 			display_opacity_, | 			display_opacity_, | ||||||
| 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | ||||||
| 			D2D1::RectF( | 			D2D1::RectF( | ||||||
| 				fCropX, | 				crop_pos.x, | ||||||
| 				fCropY, | 				crop_pos.y, | ||||||
| 				fCropX + size_.width, | 				crop_pos.y + transform_.size.width, | ||||||
| 				fCropY + size_.height | 				crop_pos.y + transform_.size.height | ||||||
| 			) | 			) | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -294,7 +294,7 @@ void e2d::Text::Draw() const | ||||||
| 	{ | 	{ | ||||||
| 		auto renderer = Renderer::GetInstance(); | 		auto renderer = Renderer::GetInstance(); | ||||||
| 		// 创建文本区域
 | 		// 创建文本区域
 | ||||||
| 		D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, size_.width, size_.height); | 		D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, transform_.size.width, transform_.size.height); | ||||||
| 		// 设置画刷颜色和透明度
 | 		// 设置画刷颜色和透明度
 | ||||||
| 		renderer->GetSolidBrush()->SetOpacity(display_opacity_); | 		renderer->GetSolidBrush()->SetOpacity(display_opacity_); | ||||||
| 		// 获取文本渲染器
 | 		// 获取文本渲染器
 | ||||||
|  | @ -429,7 +429,7 @@ void e2d::Text::CreateLayout() | ||||||
| 				(const wchar_t *)text_, | 				(const wchar_t *)text_, | ||||||
| 				length, | 				length, | ||||||
| 				text_format_, | 				text_format_, | ||||||
| 				size_.width, | 				transform_.size.width, | ||||||
| 				0, | 				0, | ||||||
| 				&text_layout_ | 				&text_layout_ | ||||||
| 			) | 			) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue