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
This commit is contained in:
David Capello 2015-09-01 10:18:47 -03:00
parent 20832dee93
commit e8abba1b93
14 changed files with 48 additions and 71 deletions

View File

@ -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.

View File

@ -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<ui::GuiSystem> m_guiSystem;
base::UniquePtr<ui::UISystem> m_uiSystem;
CoreModules* m_coreModules;
Modules* m_modules;
LegacyModules* m_legacy;

View File

@ -39,8 +39,8 @@ int main(int argc, char* argv[])
#ifdef TEST_GUI
{
she::ScopedHandle<she::System> system(she::create_system());
ui::GuiSystem guiSystem;
base::UniquePtr<ui::Manager> manager(new ui::Manager());
ui::UISystem uiSystem;
ui::Manager uiManager;
#endif
exitcode = RUN_ALL_TESTS();

View File

@ -45,7 +45,6 @@ add_library(ui-lib
theme.cpp
timer.cpp
tooltips.cpp
ui.cpp
view.cpp
viewport.cpp
widget.cpp

View File

@ -62,12 +62,6 @@ namespace ui {
ALIGN_MASK = 0xffff0000,
};
class GuiSystem {
public:
GuiSystem();
~GuiSystem();
};
} // namespace ui
#endif // UI_BASE_H_INCLUDED

View File

@ -16,16 +16,16 @@
#include <list>
namespace ui {
namespace details {
static std::list<Widget*>* widgets;
int init_widgets()
void initWidgets()
{
widgets = new std::list<Widget*>;
return 0;
}
void exit_widgets()
void exitWidgets()
{
delete widgets;
}
@ -66,4 +66,5 @@ void reinitThemeForAllWidgets()
Manager::getDefault()->invalidate();
}
} // namespace details
} // namespace ui

View File

@ -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

View File

@ -176,6 +176,9 @@ void Manager::run()
void Manager::flipDisplay()
{
if (!m_display)
return;
OverlayManager* overlays = OverlayManager::instance();
update_cursor_overlay();

View File

@ -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();

View File

@ -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);
}

View File

@ -19,6 +19,12 @@ namespace ui {
class Widget;
class UISystem {
public:
UISystem();
~UISystem();
};
int display_w();
int display_h();

View File

@ -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);
}

View File

@ -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

View File

@ -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()