| 
									
										
										
										
											2013-08-09 08:01:20 +08:00
										 |  |  | // Aseprite UI Library
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  | // Copyright (C) 2020-2022  Igara Studio S.A.
 | 
					
						
							| 
									
										
										
										
											2017-08-15 21:39:06 +08:00
										 |  |  | // Copyright (C) 2001-2017  David Capello
 | 
					
						
							| 
									
										
										
										
											2010-09-28 06:18:17 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-03-30 07:08:05 +08:00
										 |  |  | // This file is released under the terms of the MIT license.
 | 
					
						
							|  |  |  | // Read LICENSE.txt for more information.
 | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							| 
									
										
										
										
											2009-07-13 04:29:16 +08:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-07-13 04:29:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:49:58 +08:00
										 |  |  | #include "ui/manager.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  | #include "ui/system.h"
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:49:58 +08:00
										 |  |  | #include "ui/theme.h"
 | 
					
						
							|  |  |  | #include "ui/widget.h"
 | 
					
						
							| 
									
										
										
										
											2012-07-09 10:24:42 +08:00
										 |  |  | #include "ui/window.h"
 | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  | #include <memory>
 | 
					
						
							|  |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | namespace ui { | 
					
						
							| 
									
										
										
										
											2015-09-01 21:18:47 +08:00
										 |  |  | namespace details { | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  | static std::unique_ptr<std::set<Widget*>> widgets; | 
					
						
							| 
									
										
										
										
											2009-08-05 09:53:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 21:18:47 +08:00
										 |  |  | void initWidgets() | 
					
						
							| 
									
										
										
										
											2009-08-05 09:53:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  |   assert_ui_thread(); | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  |   widgets = std::make_unique<std::set<Widget*>>(); | 
					
						
							| 
									
										
										
										
											2009-08-05 09:53:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 21:18:47 +08:00
										 |  |  | void exitWidgets() | 
					
						
							| 
									
										
										
										
											2009-08-05 09:53:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  |   assert_ui_thread(); | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  |   widgets.reset(); | 
					
						
							| 
									
										
										
										
											2009-08-05 09:53:02 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-31 00:38:24 +08:00
										 |  |  | void addWidget(Widget* widget) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  |   assert_ui_thread(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  |   widgets->insert(widget); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-31 00:38:24 +08:00
										 |  |  | void removeWidget(Widget* widget) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  |   assert_ui_thread(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-05 05:10:02 +08:00
										 |  |  |   ASSERT(!Manager::widgetAssociatedToManager(widget)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  |   widgets->erase(widget); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  | // TODO we should be able to re-initialize all widgets without using
 | 
					
						
							|  |  |  | //      this global "widgets" set, so we don't have to keep track of
 | 
					
						
							|  |  |  | //      all widgets globally
 | 
					
						
							| 
									
										
										
										
											2013-03-31 00:38:24 +08:00
										 |  |  | void reinitThemeForAllWidgets() | 
					
						
							| 
									
										
										
										
											2010-03-09 10:43:28 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-20 20:50:27 +08:00
										 |  |  |   assert_ui_thread(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 01:18:14 +08:00
										 |  |  |   // Reinitialize the theme in this order:
 | 
					
						
							|  |  |  |   // 1. From the manager to children (windows and children widgets in
 | 
					
						
							|  |  |  |   //    the window etc.)
 | 
					
						
							| 
									
										
										
										
											2017-08-15 21:39:06 +08:00
										 |  |  |   auto theme = get_theme(); | 
					
						
							| 
									
										
										
										
											2021-05-23 01:18:14 +08:00
										 |  |  |   if (auto man = Manager::getDefault()) { | 
					
						
							|  |  |  |     man->setTheme(theme); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // 2. If some other widget wasn't updated (e.g. is outside the
 | 
					
						
							|  |  |  |   // hierarchy of widgets), we update the theme for that one too.
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // TODO Is this really needed?
 | 
					
						
							|  |  |  |   for (auto widget : *widgets) { | 
					
						
							|  |  |  |     if (theme != widget->theme()) | 
					
						
							|  |  |  |       widget->setTheme(theme); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 21:18:47 +08:00
										 |  |  | } // namespace details
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | } // namespace ui
 |