| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | #include "Menu.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | namespace easy2d | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 	namespace ui | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		Menu::Menu() | 
					
						
							|  |  |  |  | 			: enabled_(true) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  |  | 		Menu::Menu(const std::vector<spButton>& buttons) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			: enabled_(true) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			for (const auto& button : buttons) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				this->AddButton(button); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		bool Menu::IsEnable() const | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			return enabled_; | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		size_t Menu::GetButtonCount() const | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			return buttons_.size(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		void Menu::SetEnabled(bool enabled) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			if (enabled_ != enabled) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 				enabled_ = enabled; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 				for (const auto& button : buttons_) | 
					
						
							|  |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					button->SetEnabled(enabled); | 
					
						
							|  |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 11:18:11 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  |  | 		void Menu::AddButton(spButton const& button) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			if (button) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				this->AddChild(button); | 
					
						
							|  |  |  |  | 				buttons_.push_back(button); | 
					
						
							|  |  |  |  | 				button->SetEnabled(enabled_); | 
					
						
							|  |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  |  | 		bool Menu::RemoveButton(spButton const& button) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			if (buttons_.empty()) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				return false; | 
					
						
							|  |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			this->RemoveChild(button); | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			if (button) | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 				auto iter = std::find(buttons_.begin(), buttons_.end(), button); | 
					
						
							|  |  |  |  | 				if (iter != buttons_.end()) | 
					
						
							|  |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ťǰ<C5A5><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 					button->SetEnabled(true); | 
					
						
							|  |  |  |  | 					buttons_.erase(iter); | 
					
						
							|  |  |  |  | 					return true; | 
					
						
							|  |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2017-11-07 23:32:44 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-10 14:16:36 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  |  | 		const std::vector<spButton>& Menu::GetAllButtons() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			return buttons_; | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } |