| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Menu::Menu() | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _bEnable(true) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 20:22:41 +08:00
										 |  |  |  | #ifdef HIGHER_THAN_VS2012
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _bEnable(true) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-24 20:22:41 +08:00
										 |  |  |  | 	for (auto button : vButtons) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->addButton(button); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #else
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Menu::Menu(int number, Button * button1, ...) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _bEnable(true) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	Button ** ppButton = &button1; | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	while (number > 0) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->addButton(*ppButton); | 
					
						
							|  |  |  |  | 		ppButton++; | 
					
						
							|  |  |  |  | 		number--; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | bool e2d::Menu::isEnable() const | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	return _bEnable; | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | size_t e2d::Menu::getButtonCount() const | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	return _vButtons.size(); | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Menu::setEnable(bool enable) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_bEnable != enable) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		_bEnable = enable; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		for (auto button : _vButtons) | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 			button->setEnable(enable); | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Menu::addButton(Button * button) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 	if (button) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->addChild(button); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		_vButtons.push_back(button); | 
					
						
							|  |  |  |  | 		button->setEnable(_bEnable); | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | bool e2d::Menu::removeButton(Button * button) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_vButtons.empty()) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	this->removeChild(button); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (button) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		size_t size = _vButtons.size(); | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 		for (size_t i = 0; i < size; i++) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 			if (_vButtons[i] == button) | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 				// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ťǰ<C5A5><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 				button->setEnable(true); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 				_vButtons.erase(_vButtons.begin() + i); | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 				return true; | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return false; | 
					
						
							|  |  |  |  | } |