From e8abba1b938272e720f67967a1be01817f271ad6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Sep 2015 10:18:47 -0300 Subject: [PATCH] Refactor some UI code - Moved ui::GuiSystem from ui/base.h to ui/system.h as ui::UISystem - Moved some internals to ui::details namespace - Fix crash of UI tests when ~Manager is called - Removed ui::init/exit_system() functions --- src/app/app.cpp | 2 +- src/app/app.h | 4 ++-- src/tests/test.h | 4 ++-- src/ui/CMakeLists.txt | 1 - src/ui/base.h | 6 ------ src/ui/intern.cpp | 7 ++++--- src/ui/intern.h | 15 ++++++++++---- src/ui/manager.cpp | 3 +++ src/ui/overlay_manager.h | 4 ++-- src/ui/system.cpp | 17 ++++++++++++---- src/ui/system.h | 6 ++++++ src/ui/theme.cpp | 4 ++-- src/ui/ui.cpp | 42 ---------------------------------------- src/ui/widget.cpp | 4 ++-- 14 files changed, 48 insertions(+), 71 deletions(-) delete mode 100644 src/ui/ui.cpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 8e70ff776..bb2657029 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -156,7 +156,7 @@ void App::initialize(const AppOptions& options) m_isGui = options.startUI(); m_isShell = options.startShell(); if (m_isGui) - m_guiSystem.reset(new ui::GuiSystem); + m_uiSystem.reset(new ui::UISystem); // Initializes the application loading the modules, setting the // graphics mode, loading the configuration and resources, etc. diff --git a/src/app/app.h b/src/app/app.h index db75015a7..78a5c5705 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -22,7 +22,7 @@ namespace doc { } namespace ui { - class GuiSystem; + class UISystem; } namespace app { @@ -86,7 +86,7 @@ namespace app { static App* m_instance; - base::UniquePtr m_guiSystem; + base::UniquePtr m_uiSystem; CoreModules* m_coreModules; Modules* m_modules; LegacyModules* m_legacy; diff --git a/src/tests/test.h b/src/tests/test.h index c9924d355..b0b5ab53b 100644 --- a/src/tests/test.h +++ b/src/tests/test.h @@ -39,8 +39,8 @@ int main(int argc, char* argv[]) #ifdef TEST_GUI { she::ScopedHandle system(she::create_system()); - ui::GuiSystem guiSystem; - base::UniquePtr manager(new ui::Manager()); + ui::UISystem uiSystem; + ui::Manager uiManager; #endif exitcode = RUN_ALL_TESTS(); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index eaace0763..3c1905734 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -45,7 +45,6 @@ add_library(ui-lib theme.cpp timer.cpp tooltips.cpp - ui.cpp view.cpp viewport.cpp widget.cpp diff --git a/src/ui/base.h b/src/ui/base.h index ce9927d16..5d18d40f6 100644 --- a/src/ui/base.h +++ b/src/ui/base.h @@ -62,12 +62,6 @@ namespace ui { ALIGN_MASK = 0xffff0000, }; - class GuiSystem { - public: - GuiSystem(); - ~GuiSystem(); - }; - } // namespace ui #endif // UI_BASE_H_INCLUDED diff --git a/src/ui/intern.cpp b/src/ui/intern.cpp index 3d2524f67..e9470087d 100644 --- a/src/ui/intern.cpp +++ b/src/ui/intern.cpp @@ -16,16 +16,16 @@ #include namespace ui { +namespace details { static std::list* widgets; -int init_widgets() +void initWidgets() { widgets = new std::list; - return 0; } -void exit_widgets() +void exitWidgets() { delete widgets; } @@ -66,4 +66,5 @@ void reinitThemeForAllWidgets() Manager::getDefault()->invalidate(); } +} // namespace details } // namespace ui diff --git a/src/ui/intern.h b/src/ui/intern.h index a150c0dbd..ecc5e092c 100644 --- a/src/ui/intern.h +++ b/src/ui/intern.h @@ -23,11 +23,18 @@ namespace ui { // intern.cpp - void addWidget(Widget* widget); - void removeWidget(Widget* widget); + namespace details { - void resetFontAllWidgets(); - void reinitThemeForAllWidgets(); + void initWidgets(); + void exitWidgets(); + + void addWidget(Widget* widget); + void removeWidget(Widget* widget); + + void resetFontAllWidgets(); + void reinitThemeForAllWidgets(); + + } // namespace details // theme.cpp diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 3a394760e..cee738410 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -176,6 +176,9 @@ void Manager::run() void Manager::flipDisplay() { + if (!m_display) + return; + OverlayManager* overlays = OverlayManager::instance(); update_cursor_overlay(); diff --git a/src/ui/overlay_manager.h b/src/ui/overlay_manager.h index e10449cf0..fb13436be 100644 --- a/src/ui/overlay_manager.h +++ b/src/ui/overlay_manager.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2013 David Capello +// Copyright (C) 2001-2013, 2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -18,7 +18,7 @@ namespace ui { class Overlay; class OverlayManager { - friend class GuiSystem; // So it can call destroyInstance() from ~GuiSystem + friend class UISystem; // So it can call destroyInstance() from ~UISystem static OverlayManager* m_singleton; OverlayManager(); diff --git a/src/ui/system.cpp b/src/ui/system.cpp index d526828ee..bed68d91a 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -16,6 +16,7 @@ #include "she/surface.h" #include "ui/cursor.h" #include "ui/intern.h" +#include "ui/intern.h" #include "ui/manager.h" #include "ui/overlay.h" #include "ui/overlay_manager.h" @@ -33,7 +34,7 @@ static Overlay* mouse_cursor_overlay = NULL; static bool use_native_mouse_cursor = false; static bool native_cursor_set = false; // If we displayed a native cursor -/* Mouse information (button and position). */ +// Mouse information (button and position). static volatile MouseButtons m_buttons; static gfx::Point m_mouse_pos; @@ -140,14 +141,22 @@ static void update_mouse_cursor() } } -int init_system() +UISystem::UISystem() { mouse_cursor_type = kNoCursor; - return 0; + + details::initWidgets(); } -void exit_system() +UISystem::~UISystem() { + OverlayManager::destroyInstance(); + + // finish theme + CurrentTheme::set(NULL); + + details::exitWidgets(); + _internal_set_mouse_display(NULL); update_mouse_overlay(NULL); } diff --git a/src/ui/system.h b/src/ui/system.h index 89561ee91..30193694b 100644 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -19,6 +19,12 @@ namespace ui { class Widget; + class UISystem { + public: + UISystem(); + ~UISystem(); + }; + int display_w(); int display_h(); diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index dcd994e5a..e8de225f4 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -43,13 +43,13 @@ void Theme::regenerate() onRegenerate(); - resetFontAllWidgets(); + details::resetFontAllWidgets(); // TODO We cannot reinitialize all widgets because this mess all // child spacing, border, etc. But it could be good to change the // uiscale() and get the new look without the need to restart the // whole app. - //reinitThemeForAllWidgets(); + //details::reinitThemeForAllWidgets(); set_mouse_cursor(type); } diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp deleted file mode 100644 index a1f228dcf..000000000 --- a/src/ui/ui.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Aseprite UI Library -// Copyright (C) 2001-2013, 2015 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "ui/base.h" -#include "ui/overlay_manager.h" -#include "ui/theme.h" - -namespace ui { - -int init_widgets(); -void exit_widgets(); - -int init_system(); -void exit_system(); - -GuiSystem::GuiSystem() -{ - // initialize system - init_system(); - init_widgets(); -} - -GuiSystem::~GuiSystem() -{ - OverlayManager::destroyInstance(); - - // finish theme - CurrentTheme::set(NULL); - - // shutdown system - exit_widgets(); - exit_system(); -} - -} // namespace ui diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 52eaf202c..42d78a8fe 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -75,7 +75,7 @@ Widget::Widget(WidgetType type) , m_maxSize(INT_MAX, INT_MAX) , m_childSpacing(0) { - addWidget(this); + details::addWidget(this); } Widget::~Widget() @@ -101,7 +101,7 @@ Widget::~Widget() delete m_preferredSize; // Low level free - removeWidget(this); + details::removeWidget(this); } void Widget::deferDelete()