| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | #include "..\..\easy2d.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | TextButton::TextButton() : | 
					
						
							|  |  |  |  | 	m_pNormalText(nullptr), | 
					
						
							|  |  |  |  | 	m_pMouseInText(nullptr), | 
					
						
							|  |  |  |  | 	m_pSelectedText(nullptr), | 
					
						
							|  |  |  |  | 	m_pUnableText(nullptr) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | TextButton::TextButton(TString text) : | 
					
						
							| 
									
										
										
										
											2017-09-18 23:59:08 +08:00
										 |  |  |  | 	TextButton() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	setNormal(new Text(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(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>һ
 | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | 	SafeRelease(m_pNormalText); | 
					
						
							|  |  |  |  | 	SafeRelease(m_pMouseInText); | 
					
						
							|  |  |  |  | 	SafeRelease(m_pSelectedText); | 
					
						
							|  |  |  |  | 	SafeRelease(m_pUnableText); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | void TextButton::_setStatus(Status status) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_eStatus != status) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (status == MOUSEIN) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			if (m_pMouseInText) setRect(m_pMouseInText->getRect()); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else if (status == SELECTED) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			if (m_pSelectedText) setRect(m_pSelectedText->getRect()); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			setRect(m_pNormalText->getRect()); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	MouseNode::_setStatus(status); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 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>һ
 | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | 		SafeRelease(m_pNormalText); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		// <20><EFBFBD><DEB8>ı<EFBFBD>
 | 
					
						
							|  |  |  |  | 		m_pNormalText = text; | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
 | 
					
						
							|  |  |  |  | 		m_pNormalText->retain(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8>ť<EFBFBD><C5A5>С
 | 
					
						
							|  |  |  |  | 		setSize(m_pNormalText->getSize()); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		// <20><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ı<EFBFBD>λ<EFBFBD><CEBB>
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		_resetPosition(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setMouseIn(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | 		SafeRelease(m_pMouseInText); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		m_pMouseInText = text; | 
					
						
							|  |  |  |  | 		m_pMouseInText->retain(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		_resetPosition(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setSelected(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | 		SafeRelease(m_pSelectedText); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		m_pSelectedText = text; | 
					
						
							|  |  |  |  | 		m_pSelectedText->retain(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		_resetPosition(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-12 12:53:34 +08:00
										 |  |  |  | void TextButton::setUnable(Text * text) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (text) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-05 00:53:03 +08:00
										 |  |  |  | 		SafeRelease(m_pUnableText); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		m_pUnableText = text; | 
					
						
							|  |  |  |  | 		m_pUnableText->retain(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		_resetPosition(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | void TextButton::_resetPosition() | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (m_pNormalText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <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>ʾ
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		m_pNormalText->setPos(getX() , getY()); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pMouseInText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pMouseInText->setPos( | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 			getX() + (getWidth() - m_pMouseInText->getWidth()) / 2, | 
					
						
							|  |  |  |  | 			getY() + (getHeight() - m_pMouseInText->getHeight()) / 2); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pSelectedText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pSelectedText->setPos( | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 			getX() + (getWidth() - m_pSelectedText->getWidth()) / 2, | 
					
						
							|  |  |  |  | 			getY() + (getHeight() - m_pSelectedText->getHeight()) / 2); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (m_pUnableText) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pUnableText->setPos( | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 			getX() + (getWidth() - m_pUnableText->getWidth()) / 2, | 
					
						
							|  |  |  |  | 			getY() + (getHeight() - m_pUnableText->getHeight()) / 2); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } |