| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | #include "..\enodes.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | #include "..\Win\winbase.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::ESprite::ESprite() | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	: m_fSourcePosX(0) | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | 	, m_fSourcePosY(0) | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	, m_pTexture(nullptr) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | e2d::ESprite::ESprite(const EString & imageFileName) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 	: ESprite() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	setTexture(new ETexture(imageFileName)); | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | e2d::ESprite::ESprite(const EString & imageFileName, float x, float y, float width, float height) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	setTexture(new ETexture(imageFileName)); | 
					
						
							|  |  |  | 	clipTexture(x, y, width, height); | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  | e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 	: ESprite() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	setTexture(new ETexture(resourceName, resourceType)); | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType, float x, float y, float width, float height) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	setTexture(new ETexture(resourceName, resourceType)); | 
					
						
							|  |  |  | 	clipTexture(x, y, width, height); | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | e2d::ESprite::~ESprite() | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	SafeRelease(&m_pTexture); | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | void e2d::ESprite::setTexture(ETexture * texture) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	SafeRelease(&m_pTexture); | 
					
						
							|  |  |  | 	m_pTexture = texture; | 
					
						
							|  |  |  | 	m_pTexture->retain(); | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | 	m_fSourcePosX = m_fSourcePosY = 0; | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	ENode::_setWidth(m_pTexture->getSourceWidth()); | 
					
						
							|  |  |  | 	ENode::_setHeight(m_pTexture->getSourceHeight()); | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | void e2d::ESprite::setTexture(ETexture * texture, float x, float y, float width, float height) | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	setTexture(texture); | 
					
						
							|  |  |  | 	clipTexture(x, y, width, height); | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | void e2d::ESprite::clipTexture(float x, float y, float width, float height) | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_fSourcePosX = max(x, 0); | 
					
						
							|  |  |  | 	m_fSourcePosY = max(y, 0); | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	ENode::_setWidth(min(max(width, 0), m_pTexture->getSourceWidth() - m_fSourcePosX)); | 
					
						
							|  |  |  | 	ENode::_setHeight(min(max(height, 0), m_pTexture->getSourceHeight() - m_fSourcePosX)); | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::ESprite::_onRender() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	if (m_pTexture && m_pTexture->_getBitmap()) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// Draw bitmap
 | 
					
						
							|  |  |  | 		GetRenderTarget()->DrawBitmap( | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 			m_pTexture->_getBitmap(), | 
					
						
							|  |  |  | 			D2D1::RectF(0, 0, getRealWidth(), getRealHeight()), | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  | 			m_fDisplayOpacity, | 
					
						
							|  |  |  | 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 			D2D1::RectF(m_fSourcePosX, m_fSourcePosY, getRealWidth(), getRealHeight()) | 
					
						
							| 
									
										
										
										
											2017-10-15 23:58:39 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |