| 
									
										
										
										
											2017-11-07 23:04:33 +08:00
										 |  |  | #include "..\ecommon.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::ESpriteFrame() | 
					
						
							|  |  |  | 	: m_fSourceClipX(0) | 
					
						
							|  |  |  | 	, m_fSourceClipY(0) | 
					
						
							|  |  |  | 	, m_fSourceClipWidth(0) | 
					
						
							|  |  |  | 	, m_fSourceClipHeight(0) | 
					
						
							|  |  |  | 	, m_pTexture(nullptr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::ESpriteFrame(ETexture * texture) | 
					
						
							|  |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(texture); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName) | 
					
						
							|  |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(new ETexture(imageFileName)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 12:51:01 +08:00
										 |  |  | e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(new ETexture(resourceName, resourceType)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::ESpriteFrame(ETexture * texture, float x, float y, float width, float height) | 
					
						
							|  |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(texture); | 
					
						
							|  |  |  | 	_clipTexture(x, y, width, height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName, float x, float y, float width, float height) | 
					
						
							|  |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(new ETexture(imageFileName)); | 
					
						
							|  |  |  | 	_clipTexture(x, y, width, height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 12:51:01 +08:00
										 |  |  | e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | 	: ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_setTexture(new ETexture(resourceName, resourceType)); | 
					
						
							|  |  |  | 	_clipTexture(x, y, width, height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESpriteFrame::~ESpriteFrame() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 	SafeRelease(&m_pTexture); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float e2d::ESpriteFrame::getWidth() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_fSourceClipWidth; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float e2d::ESpriteFrame::getHeight() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_fSourceClipHeight; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ETexture * e2d::ESpriteFrame::getTexture() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_pTexture; | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ESpriteFrame::_setTexture(ETexture * texture) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (texture) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  | 		SafeRelease(&m_pTexture); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | 		m_pTexture = texture; | 
					
						
							|  |  |  | 		m_pTexture->retain(); | 
					
						
							|  |  |  | 		m_fSourceClipX = 0; | 
					
						
							|  |  |  | 		m_fSourceClipY = 0; | 
					
						
							|  |  |  | 		m_fSourceClipWidth = texture->getSourceWidth(); | 
					
						
							|  |  |  | 		m_fSourceClipHeight = texture->getSourceHeight(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ESpriteFrame::_clipTexture(float x, float y, float width, float height) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_pTexture) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_fSourceClipX = min(max(x, 0), m_pTexture->getSourceWidth()); | 
					
						
							|  |  |  | 		m_fSourceClipY = min(max(y, 0), m_pTexture->getSourceHeight()); | 
					
						
							|  |  |  | 		m_fSourceClipWidth = min(max(width, 0), m_pTexture->getSourceWidth() - m_fSourceClipX); | 
					
						
							|  |  |  | 		m_fSourceClipHeight = min(max(height, 0), m_pTexture->getSourceHeight() - m_fSourceClipY); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |