refactor functions
This commit is contained in:
		
							parent
							
								
									fff3e8c370
								
							
						
					
					
						commit
						15e039f278
					
				|  | @ -6,10 +6,10 @@ static std::map<size_t, ID2D1Bitmap*> s_mBitmapsFromFile; | ||||||
| 
 | 
 | ||||||
| e2d::Image::Image() | e2d::Image::Image() | ||||||
| 	: m_pBitmap(nullptr) | 	: m_pBitmap(nullptr) | ||||||
| 	, m_fSourceClipX(0) | 	, m_fSourceCropX(0) | ||||||
| 	, m_fSourceClipY(0) | 	, m_fSourceCropY(0) | ||||||
| 	, m_fSourceClipWidth(0) | 	, m_fSourceCropWidth(0) | ||||||
| 	, m_fSourceClipHeight(0) | 	, m_fSourceCropHeight(0) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -18,10 +18,10 @@ e2d::Image::Image(String strFileName) | ||||||
| 	this->open(strFileName); | 	this->open(strFileName); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::Image::Image(String strFileName, double nClipX, double nClipY, double nClipWidth, double nClipHeight) | e2d::Image::Image(String strFileName, double nCropX, double nCropY, double nCropWidth, double nCropHeight) | ||||||
| { | { | ||||||
| 	this->open(strFileName); | 	this->open(strFileName); | ||||||
| 	this->clip(nClipX, nClipY, nClipWidth, nClipHeight); | 	this->crop(nCropX, nCropY, nCropWidth, nCropHeight); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::Image::~Image() | e2d::Image::~Image() | ||||||
|  | @ -42,35 +42,35 @@ void e2d::Image::open(String strFilePath) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	m_pBitmap = s_mBitmapsFromFile.at(strFilePath.getHashCode()); | 	m_pBitmap = s_mBitmapsFromFile.at(strFilePath.getHashCode()); | ||||||
| 	m_fSourceClipX = m_fSourceClipY = 0; | 	m_fSourceCropX = m_fSourceCropY = 0; | ||||||
| 	m_fSourceClipWidth = m_pBitmap->GetSize().width; | 	m_fSourceCropWidth = m_pBitmap->GetSize().width; | ||||||
| 	m_fSourceClipHeight = m_pBitmap->GetSize().height; | 	m_fSourceCropHeight = m_pBitmap->GetSize().height; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Image::clip(double x, double y, double width, double height) | void e2d::Image::crop(double x, double y, double width, double height) | ||||||
| { | { | ||||||
| 	if (m_pBitmap) | 	if (m_pBitmap) | ||||||
| 	{ | 	{ | ||||||
| 		m_fSourceClipX = min(max(x, 0), this->getSourceWidth()); | 		m_fSourceCropX = min(max(x, 0), this->getSourceWidth()); | ||||||
| 		m_fSourceClipY = min(max(y, 0), this->getSourceHeight()); | 		m_fSourceCropY = min(max(y, 0), this->getSourceHeight()); | ||||||
| 		m_fSourceClipWidth = min(max(width, 0), this->getSourceWidth() - m_fSourceClipX); | 		m_fSourceCropWidth = min(max(width, 0), this->getSourceWidth() - m_fSourceCropX); | ||||||
| 		m_fSourceClipHeight = min(max(height, 0), this->getSourceHeight() - m_fSourceClipY); | 		m_fSourceCropHeight = min(max(height, 0), this->getSourceHeight() - m_fSourceCropY); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| double e2d::Image::getWidth() const | double e2d::Image::getWidth() const | ||||||
| { | { | ||||||
| 	return m_fSourceClipWidth; | 	return m_fSourceCropWidth; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| double e2d::Image::getHeight() const | double e2d::Image::getHeight() const | ||||||
| { | { | ||||||
| 	return m_fSourceClipHeight; | 	return m_fSourceCropHeight; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::Size e2d::Image::getSize() const | e2d::Size e2d::Image::getSize() const | ||||||
| { | { | ||||||
| 	return Size(m_fSourceClipWidth, m_fSourceClipHeight); | 	return Size(m_fSourceCropWidth, m_fSourceCropHeight); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| double e2d::Image::getSourceWidth() const | double e2d::Image::getSourceWidth() const | ||||||
|  | @ -109,19 +109,19 @@ e2d::Size e2d::Image::getSourceSize() const | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| double e2d::Image::getClipX() const | double e2d::Image::getCropX() const | ||||||
| { | { | ||||||
| 	return m_fSourceClipX; | 	return m_fSourceCropX; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| double e2d::Image::getClipY() const | double e2d::Image::getCropY() const | ||||||
| { | { | ||||||
| 	return m_fSourceClipY; | 	return m_fSourceCropY; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::Point e2d::Image::getClipPos() const | e2d::Point e2d::Image::getCropPos() const | ||||||
| { | { | ||||||
| 	return Point(m_fSourceClipX, m_fSourceClipY); | 	return Point(m_fSourceCropX, m_fSourceCropY); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool e2d::Image::preload(String fileName) | bool e2d::Image::preload(String fileName) | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ e2d::Sprite::Sprite(String imageFileName, double x, double y, double width, doub | ||||||
| 	: m_pImage(nullptr) | 	: m_pImage(nullptr) | ||||||
| { | { | ||||||
| 	open(imageFileName); | 	open(imageFileName); | ||||||
| 	clip(x, y, width, height); | 	crop(x, y, width, height); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::Sprite::~Sprite() | e2d::Sprite::~Sprite() | ||||||
|  | @ -47,12 +47,12 @@ void e2d::Sprite::open(String imageFileName) | ||||||
| 	open(new Image(imageFileName)); | 	open(new Image(imageFileName)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Sprite::clip(double x, double y, double width, double height) | void e2d::Sprite::crop(double x, double y, double width, double height) | ||||||
| { | { | ||||||
| 	m_pImage->clip(x, y, width, height); | 	m_pImage->crop(x, y, width, height); | ||||||
| 	Node::setSize( | 	Node::setSize( | ||||||
| 		min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()), | 		min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getCropX()), | ||||||
| 		min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY()) | 		min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getCropY()) | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -66,8 +66,8 @@ void e2d::Sprite::onRender() | ||||||
| 	if (m_pImage && m_pImage->getBitmap()) | 	if (m_pImage && m_pImage->getBitmap()) | ||||||
| 	{ | 	{ | ||||||
| 		// »ñȡͼƬ²Ã¼ôλÖÃ
 | 		// »ñȡͼƬ²Ã¼ôλÖÃ
 | ||||||
| 		float fClipX = static_cast<float>(m_pImage->getClipX()); | 		float fCropX = static_cast<float>(m_pImage->getCropX()); | ||||||
| 		float fClipY = static_cast<float>(m_pImage->getClipY()); | 		float fCropY = static_cast<float>(m_pImage->getCropY()); | ||||||
| 		// äÖȾͼƬ
 | 		// äÖȾͼƬ
 | ||||||
| 		Renderer::getRenderTarget()->DrawBitmap( | 		Renderer::getRenderTarget()->DrawBitmap( | ||||||
| 			m_pImage->getBitmap(), | 			m_pImage->getBitmap(), | ||||||
|  | @ -75,10 +75,10 @@ void e2d::Sprite::onRender() | ||||||
| 			m_fDisplayOpacity, | 			m_fDisplayOpacity, | ||||||
| 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | ||||||
| 			D2D1::RectF( | 			D2D1::RectF( | ||||||
| 				fClipX, | 				fCropX, | ||||||
| 				fClipY, | 				fCropY, | ||||||
| 				fClipX + m_fWidth, | 				fCropX + m_fWidth, | ||||||
| 				fClipY + m_fHeight | 				fCropY + m_fHeight | ||||||
| 			) | 			) | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -490,11 +490,11 @@ public: | ||||||
| 
 | 
 | ||||||
| 	// 从本地文件中读取资源
 | 	// 从本地文件中读取资源
 | ||||||
| 	Image( | 	Image( | ||||||
| 		String strFilePath,/* 图片文件路径 */ | 		String strFilePath,	/* 图片文件路径 */ | ||||||
| 		double nClipX,		/* 裁剪位置 X 坐标 */ | 		double nCropX,		/* 裁剪位置 X 坐标 */ | ||||||
| 		double nClipY,		/* 裁剪位置 Y 坐标 */ | 		double nCropY,		/* 裁剪位置 Y 坐标 */ | ||||||
| 		double nClipWidth,	/* 裁剪宽度 */ | 		double nCropWidth,	/* 裁剪宽度 */ | ||||||
| 		double nClipHeight	/* 裁剪高度 */ | 		double nCropHeight	/* 裁剪高度 */ | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	virtual ~Image(); | 	virtual ~Image(); | ||||||
|  | @ -504,12 +504,12 @@ public: | ||||||
| 		String strFilePath | 		String strFilePath | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 裁剪图片
 | 	// 将图片裁剪为矩形
 | ||||||
| 	void clip( | 	void crop( | ||||||
| 		double nClipX,		/* 裁剪位置 X 坐标 */ | 		double nCropX,		/* 裁剪位置 X 坐标 */ | ||||||
| 		double nClipY,		/* 裁剪位置 Y 坐标 */ | 		double nCropY,		/* 裁剪位置 Y 坐标 */ | ||||||
| 		double nClipWidth,	/* 裁剪宽度 */ | 		double nCropWidth,	/* 裁剪宽度 */ | ||||||
| 		double nClipHeight	/* 裁剪高度 */ | 		double nCropHeight	/* 裁剪高度 */ | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 获取宽度
 | 	// 获取宽度
 | ||||||
|  | @ -531,13 +531,13 @@ public: | ||||||
| 	virtual Size getSourceSize() const; | 	virtual Size getSourceSize() const; | ||||||
| 	 | 	 | ||||||
| 	// 获取裁剪位置 X 坐标
 | 	// 获取裁剪位置 X 坐标
 | ||||||
| 	virtual double getClipX() const; | 	virtual double getCropX() const; | ||||||
| 
 | 
 | ||||||
| 	// 获取裁剪位置 Y 坐标
 | 	// 获取裁剪位置 Y 坐标
 | ||||||
| 	virtual double getClipY() const; | 	virtual double getCropY() const; | ||||||
| 
 | 
 | ||||||
| 	// 获取裁剪位置
 | 	// 获取裁剪位置
 | ||||||
| 	virtual Point getClipPos() const; | 	virtual Point getCropPos() const; | ||||||
| 
 | 
 | ||||||
| 	// 获取 ID2D1Bitmap 对象
 | 	// 获取 ID2D1Bitmap 对象
 | ||||||
| 	ID2D1Bitmap * getBitmap(); | 	ID2D1Bitmap * getBitmap(); | ||||||
|  | @ -551,10 +551,10 @@ public: | ||||||
| 	static void clearCache(); | 	static void clearCache(); | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
| 	double	m_fSourceClipX; | 	double	m_fSourceCropX; | ||||||
| 	double	m_fSourceClipY; | 	double	m_fSourceCropY; | ||||||
| 	double	m_fSourceClipWidth; | 	double	m_fSourceCropWidth; | ||||||
| 	double	m_fSourceClipHeight; | 	double	m_fSourceCropHeight; | ||||||
| 	ID2D1Bitmap * m_pBitmap; | 	ID2D1Bitmap * m_pBitmap; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -487,7 +487,7 @@ public: | ||||||
| 		String imageFileName | 		String imageFileName | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 从文件图片创建精灵并裁剪
 | 	// 创建精灵并裁剪图片
 | ||||||
| 	Sprite( | 	Sprite( | ||||||
| 		String imageFileName, | 		String imageFileName, | ||||||
| 		double x, | 		double x, | ||||||
|  | @ -508,8 +508,8 @@ public: | ||||||
| 		Image * image | 		Image * image | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// 裁剪图片
 | 	// 将图片裁剪为矩形
 | ||||||
| 	virtual void clip( | 	virtual void crop( | ||||||
| 		double x, | 		double x, | ||||||
| 		double y, | 		double y, | ||||||
| 		double width, | 		double width, | ||||||
|  |  | ||||||
							
								
								
									
										18
									
								
								core/etool.h
								
								
								
								
							
							
						
						
									
										18
									
								
								core/etool.h
								
								
								
								
							|  | @ -105,15 +105,15 @@ public: | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
| 	String			m_sName; | 	String		m_sName; | ||||||
| 	bool			m_bRunning; | 	bool		m_bRunning; | ||||||
| 	bool			m_bAtOnce; | 	bool		m_bAtOnce; | ||||||
| 	bool			m_bAutoRelease; | 	bool		m_bAutoRelease; | ||||||
| 	bool			m_bClear; | 	bool		m_bClear; | ||||||
| 	int				m_nRunTimes; | 	int			m_nRunTimes; | ||||||
| 	int				m_nUpdateTimes; | 	int			m_nUpdateTimes; | ||||||
| 	double			m_fInterval; | 	double		m_fInterval; | ||||||
| 	double			m_fLast; | 	double		m_fLast; | ||||||
| 	Function	m_Callback; | 	Function	m_Callback; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue