| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | #include "..\..\Easy2d.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | TextButton::TextButton() : | 
					
						
							|  |  |  |  | 	m_pNormalText(nullptr), | 
					
						
							|  |  |  |  | 	m_pMouseInText(nullptr), | 
					
						
							|  |  |  |  | 	m_pSelectedText(nullptr), | 
					
						
							|  |  |  |  | 	m_pUnableText(nullptr) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	m_nWidth = 0; | 
					
						
							|  |  |  |  | 	m_nHeight = 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | TextButton::TextButton(Text * text) : | 
					
						
							|  |  |  |  | 	TextButton() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | 	setNormal(text);	// <20><><EFBFBD>ð<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ʱ<CCAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | TextButton::~TextButton() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
 | 
					
						
							|  |  |  |  | 	SAFE_RELEASE(m_pNormalText); | 
					
						
							|  |  |  |  | 	SAFE_RELEASE(m_pMouseInText); | 
					
						
							|  |  |  |  | 	SAFE_RELEASE(m_pSelectedText); | 
					
						
							|  |  |  |  | 	SAFE_RELEASE(m_pUnableText); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::_onNormal() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pNormalText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pNormalText->_onDraw(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::_onMouseIn() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pMouseInText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pMouseInText->_onDraw(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_onNormal(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::_onSelected() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pSelectedText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pSelectedText->_onDraw(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_onNormal(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::_onDisable() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pUnableText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pUnableText->_onDraw(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_onNormal(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setNormal(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// ԭ<>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
 | 
					
						
							|  |  |  |  | 		SAFE_RELEASE(m_pNormalText); | 
					
						
							|  |  |  |  | 		// <20><EFBFBD><DEB8>ı<EFBFBD>
 | 
					
						
							|  |  |  |  | 		m_pNormalText = text; | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
 | 
					
						
							|  |  |  |  | 		m_pNormalText->retain(); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ı<EFBFBD>λ<EFBFBD><CEBB>
 | 
					
						
							|  |  |  |  | 		resetTextPosition(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setMouseIn(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SAFE_RELEASE(m_pMouseInText); | 
					
						
							|  |  |  |  | 		m_pMouseInText = text; | 
					
						
							|  |  |  |  | 		m_pMouseInText->retain(); | 
					
						
							|  |  |  |  | 		resetTextPosition(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setSelected(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SAFE_RELEASE(m_pSelectedText); | 
					
						
							|  |  |  |  | 		m_pSelectedText = text; | 
					
						
							|  |  |  |  | 		m_pSelectedText->retain(); | 
					
						
							|  |  |  |  | 		resetTextPosition(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setUnable(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SAFE_RELEASE(m_pUnableText); | 
					
						
							|  |  |  |  | 		m_pUnableText = text; | 
					
						
							|  |  |  |  | 		m_pUnableText->retain(); | 
					
						
							|  |  |  |  | 		resetTextPosition(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::setX(int x) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Node::setX(x); | 
					
						
							|  |  |  |  | 	resetTextPosition(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::setY(int y) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Node::setY(y); | 
					
						
							|  |  |  |  | 	resetTextPosition(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::setPos(int x, int y) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Node::setPos(x, y); | 
					
						
							|  |  |  |  | 	resetTextPosition(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void TextButton::resetTextPosition() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pNormalText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8>ť<EFBFBD><C5A5>С
 | 
					
						
							|  |  |  |  | 		m_nWidth = m_pNormalText->getWidth(); | 
					
						
							|  |  |  |  | 		m_nHeight = m_pNormalText->getHeight(); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ݰ<EFBFBD>ťλ<C5A5>ú<EFBFBD><C3BA><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>þ<EFBFBD><C3BE><EFBFBD><EFBFBD><EFBFBD>ʾ
 | 
					
						
							|  |  |  |  | 		m_pNormalText->setPos(m_nX , m_nY); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pMouseInText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pMouseInText->setPos( | 
					
						
							|  |  |  |  | 			m_nX + (m_nWidth - m_pMouseInText->getWidth()) / 2,  | 
					
						
							|  |  |  |  | 			m_nY + (m_nHeight - m_pMouseInText->getHeight()) / 2); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pSelectedText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pSelectedText->setPos( | 
					
						
							|  |  |  |  | 			m_nX + (m_nWidth - m_pSelectedText->getWidth()) / 2,  | 
					
						
							|  |  |  |  | 			m_nY + (m_nHeight - m_pSelectedText->getHeight()) / 2); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pUnableText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pUnableText->setPos( | 
					
						
							|  |  |  |  | 			m_nX + (m_nWidth - m_pUnableText->getWidth()) / 2,  | 
					
						
							|  |  |  |  | 			m_nY + (m_nHeight - m_pUnableText->getHeight()) / 2); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } |