2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2021-03-10 02:24:41 +08:00
|
|
|
// Copyright (C) 2018-2021 Igara Studio S.A.
|
2018-03-15 01:14:47 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2011-03-23 08:11:25 +08:00
|
|
|
|
2019-01-03 20:07:56 +08:00
|
|
|
#include "app/app_mod.h"
|
2011-07-27 10:25:02 +08:00
|
|
|
#include "app/check_update.h"
|
2016-05-31 06:03:28 +08:00
|
|
|
#include "app/cli/app_options.h"
|
|
|
|
|
#include "app/cli/cli_processor.h"
|
|
|
|
|
#include "app/cli/default_cli_delegate.h"
|
|
|
|
|
#include "app/cli/preview_cli_delegate.h"
|
2019-04-02 02:44:49 +08:00
|
|
|
#include "app/color_spaces.h"
|
2010-08-25 11:26:37 +08:00
|
|
|
#include "app/color_utils.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/commands.h"
|
|
|
|
|
#include "app/console.h"
|
2015-04-06 05:51:43 +08:00
|
|
|
#include "app/crash/data_recovery.h"
|
2017-06-11 02:02:39 +08:00
|
|
|
#include "app/extensions.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/file/file.h"
|
|
|
|
|
#include "app/file/file_formats_manager.h"
|
|
|
|
|
#include "app/file_system.h"
|
|
|
|
|
#include "app/gui_xml.h"
|
2018-03-20 06:37:39 +08:00
|
|
|
#include "app/i18n/strings.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ini_file.h"
|
|
|
|
|
#include "app/log.h"
|
|
|
|
|
#include "app/modules.h"
|
|
|
|
|
#include "app/modules/gfx.h"
|
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
|
#include "app/modules/palettes.h"
|
2014-12-15 07:19:31 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/recent_files.h"
|
2014-04-20 07:52:56 +08:00
|
|
|
#include "app/resource_finder.h"
|
2014-08-20 11:11:19 +08:00
|
|
|
#include "app/send_crash.h"
|
2018-07-07 13:47:42 +08:00
|
|
|
#include "app/site.h"
|
2016-04-26 02:20:53 +08:00
|
|
|
#include "app/tools/active_tool.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/tool_box.h"
|
2016-11-08 03:32:54 +08:00
|
|
|
#include "app/ui/backup_indicator.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/color_bar.h"
|
2018-07-15 10:24:49 +08:00
|
|
|
#include "app/ui/doc_view.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
|
#include "app/ui/editor/editor_view.h"
|
2015-05-10 06:55:33 +08:00
|
|
|
#include "app/ui/input_chain.h"
|
2014-10-29 22:58:03 +08:00
|
|
|
#include "app/ui/keyboard_shortcuts.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/main_window.h"
|
|
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
|
#include "app/ui/toolbar.h"
|
2015-05-05 02:52:00 +08:00
|
|
|
#include "app/ui/workspace.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui_context.h"
|
2016-01-30 20:13:46 +08:00
|
|
|
#include "app/util/clipboard.h"
|
2011-01-21 10:33:57 +08:00
|
|
|
#include "base/exception.h"
|
2014-08-24 11:09:01 +08:00
|
|
|
#include "base/fs.h"
|
2016-11-08 03:32:54 +08:00
|
|
|
#include "base/scoped_lock.h"
|
2015-04-02 01:59:49 +08:00
|
|
|
#include "base/split_string.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2017-12-07 05:50:23 +08:00
|
|
|
#include "fmt/format.h"
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/display.h"
|
|
|
|
|
#include "os/error.h"
|
|
|
|
|
#include "os/surface.h"
|
|
|
|
|
#include "os/system.h"
|
2019-04-02 02:44:49 +08:00
|
|
|
#include "render/render.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/intern.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2020-03-16 21:29:58 +08:00
|
|
|
#include "ver/info.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2020-06-10 21:57:49 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#include "os/osx/system.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-09-09 07:10:48 +08:00
|
|
|
#include <iostream>
|
2018-08-09 04:27:26 +08:00
|
|
|
#include <memory>
|
2011-03-23 08:11:25 +08:00
|
|
|
|
2016-11-21 21:25:27 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2018-08-20 22:25:08 +08:00
|
|
|
#include "app/script/engine.h"
|
2016-11-21 21:25:27 +08:00
|
|
|
#include "app/shell.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-25 00:21:37 +08:00
|
|
|
#ifdef ENABLE_STEAM
|
|
|
|
|
#include "steam/steam.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
|
2018-11-21 06:42:53 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class ConsoleEngineDelegate : public script::EngineDelegate {
|
|
|
|
|
public:
|
|
|
|
|
void onConsolePrint(const char* text) override {
|
|
|
|
|
m_console.printf("%s\n", text);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
Console m_console;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
#endif // ENABLER_SCRIPTING
|
|
|
|
|
|
2014-12-15 07:19:31 +08:00
|
|
|
class App::CoreModules {
|
2009-10-14 22:09:59 +08:00
|
|
|
public:
|
2019-12-11 23:27:56 +08:00
|
|
|
#ifdef ENABLE_UI
|
|
|
|
|
typedef app::UIContext ContextT;
|
|
|
|
|
#else
|
|
|
|
|
typedef app::Context ContextT;
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-09-03 04:42:32 +08:00
|
|
|
ConfigModule m_configModule;
|
2019-12-11 23:27:56 +08:00
|
|
|
ContextT m_context;
|
2014-12-15 07:19:31 +08:00
|
|
|
};
|
|
|
|
|
|
2018-03-28 22:48:59 +08:00
|
|
|
class App::LoadLanguage {
|
|
|
|
|
public:
|
|
|
|
|
LoadLanguage(Preferences& pref,
|
|
|
|
|
Extensions& exts) {
|
|
|
|
|
Strings::createInstance(pref, exts);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-15 07:19:31 +08:00
|
|
|
class App::Modules {
|
|
|
|
|
public:
|
2012-09-03 04:42:32 +08:00
|
|
|
LoggerModule m_loggerModule;
|
2010-01-29 11:15:33 +08:00
|
|
|
FileSystemModule m_file_system_module;
|
2018-03-28 22:48:59 +08:00
|
|
|
Extensions m_extensions;
|
|
|
|
|
// Load main language (after loading the extensions)
|
|
|
|
|
LoadLanguage m_loadLanguage;
|
2011-04-02 21:47:03 +08:00
|
|
|
tools::ToolBox m_toolbox;
|
2016-04-26 02:20:53 +08:00
|
|
|
tools::ActiveToolManager m_activeToolManager;
|
2017-11-30 22:57:18 +08:00
|
|
|
Commands m_commands;
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2010-09-18 11:28:24 +08:00
|
|
|
RecentFiles m_recent_files;
|
2015-05-10 06:55:33 +08:00
|
|
|
InputChain m_inputChain;
|
2016-01-30 20:13:46 +08:00
|
|
|
clipboard::ClipboardManager m_clipboardManager;
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2019-05-27 22:10:52 +08:00
|
|
|
// This is a raw pointer because we want to delete it explicitly.
|
|
|
|
|
// (e.g. if an exception occurs, the ~Modules() doesn't have to
|
|
|
|
|
// delete m_recovery)
|
2015-04-09 07:28:30 +08:00
|
|
|
app::crash::DataRecovery* m_recovery;
|
2012-08-23 08:05:02 +08:00
|
|
|
|
2018-03-28 22:48:59 +08:00
|
|
|
Modules(const bool createLogInDesktop,
|
|
|
|
|
Preferences& pref)
|
2016-02-27 04:08:42 +08:00
|
|
|
: m_loggerModule(createLogInDesktop)
|
2018-03-28 22:48:59 +08:00
|
|
|
, m_loadLanguage(pref, m_extensions)
|
2016-04-26 02:20:53 +08:00
|
|
|
, m_activeToolManager(&m_toolbox)
|
2019-03-19 00:30:17 +08:00
|
|
|
#ifdef ENABLE_UI
|
2018-03-15 01:14:47 +08:00
|
|
|
, m_recent_files(pref.general.recentItems())
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2016-02-27 04:08:42 +08:00
|
|
|
, m_recovery(nullptr) {
|
|
|
|
|
}
|
2015-04-09 07:28:30 +08:00
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
~Modules() {
|
|
|
|
|
ASSERT(m_recovery == nullptr);
|
2015-04-09 07:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
app::crash::DataRecovery* recovery() {
|
|
|
|
|
return m_recovery;
|
2015-04-09 07:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:27:56 +08:00
|
|
|
void createDataRecovery(Context* ctx) {
|
2015-05-10 07:18:10 +08:00
|
|
|
#ifdef ENABLE_DATA_RECOVERY
|
2019-12-11 23:27:56 +08:00
|
|
|
m_recovery = new app::crash::DataRecovery(ctx);
|
2019-05-27 22:10:52 +08:00
|
|
|
m_recovery->SessionsListIsReady.connect(
|
|
|
|
|
[] {
|
|
|
|
|
ui::assert_ui_thread();
|
|
|
|
|
auto app = App::instance();
|
|
|
|
|
if (app && app->mainWindow()) {
|
|
|
|
|
// Notify that the list of sessions is ready.
|
|
|
|
|
app->mainWindow()->dataRecoverySessionsAreReady();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void searchDataRecoverySessions() {
|
|
|
|
|
#ifdef ENABLE_DATA_RECOVERY
|
|
|
|
|
ASSERT(m_recovery);
|
|
|
|
|
if (m_recovery)
|
|
|
|
|
m_recovery->launchSearch();
|
2015-05-10 07:18:10 +08:00
|
|
|
#endif
|
2015-04-09 07:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteDataRecovery() {
|
2015-05-10 07:18:10 +08:00
|
|
|
#ifdef ENABLE_DATA_RECOVERY
|
2019-06-08 00:18:23 +08:00
|
|
|
if (m_recovery) {
|
|
|
|
|
delete m_recovery;
|
|
|
|
|
m_recovery = nullptr;
|
|
|
|
|
}
|
2015-05-10 07:18:10 +08:00
|
|
|
#endif
|
2015-04-09 07:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
2009-10-14 22:09:59 +08:00
|
|
|
};
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2019-01-03 20:07:56 +08:00
|
|
|
App* App::m_instance = nullptr;
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2019-01-03 20:07:56 +08:00
|
|
|
App::App(AppMod* mod)
|
|
|
|
|
: m_mod(mod)
|
|
|
|
|
, m_coreModules(nullptr)
|
|
|
|
|
, m_modules(nullptr)
|
|
|
|
|
, m_legacy(nullptr)
|
2010-09-19 04:36:21 +08:00
|
|
|
, m_isGui(false)
|
2012-09-09 07:10:48 +08:00
|
|
|
, m_isShell(false)
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2016-11-08 03:32:54 +08:00
|
|
|
, m_backupIndicator(nullptr)
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2018-09-01 01:30:32 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
|
|
|
|
, m_engine(new script::Engine)
|
|
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(m_instance == NULL);
|
2009-10-09 09:34:06 +08:00
|
|
|
m_instance = this;
|
2014-11-06 20:42:09 +08:00
|
|
|
}
|
2009-10-09 09:34:06 +08:00
|
|
|
|
2019-11-02 02:04:22 +08:00
|
|
|
int App::initialize(const AppOptions& options)
|
2014-11-06 20:42:09 +08:00
|
|
|
{
|
2020-04-16 22:19:39 +08:00
|
|
|
os::System* system = os::instance();
|
|
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2016-05-31 06:03:28 +08:00
|
|
|
m_isGui = options.startUI() && !options.previewCLI();
|
2018-05-07 11:11:50 +08:00
|
|
|
#else
|
|
|
|
|
m_isGui = false;
|
|
|
|
|
#endif
|
2015-04-23 06:28:24 +08:00
|
|
|
m_isShell = options.startShell();
|
2014-12-15 07:19:31 +08:00
|
|
|
m_coreModules = new CoreModules;
|
2018-06-20 01:10:19 +08:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (options.disableWintab() ||
|
2020-05-31 03:54:35 +08:00
|
|
|
!preferences().experimental.loadWintabDriver() ||
|
|
|
|
|
preferences().tablet.api() == "pointer") {
|
|
|
|
|
system->setTabletAPI(os::TabletAPI::WindowsPointerInput);
|
2018-06-20 01:10:19 +08:00
|
|
|
}
|
2020-05-31 03:54:35 +08:00
|
|
|
else if (preferences().tablet.api() == "wintab_packets")
|
|
|
|
|
system->setTabletAPI(os::TabletAPI::WintabPackets);
|
|
|
|
|
else // preferences().tablet.api() == "wintab"
|
|
|
|
|
system->setTabletAPI(os::TabletAPI::Wintab);
|
2018-06-20 01:10:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
2020-06-10 21:57:49 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
if (!preferences().general.osxAsyncView())
|
|
|
|
|
os::osx_set_async_view(false);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-16 22:19:39 +08:00
|
|
|
system->setAppName(get_app_name());
|
|
|
|
|
system->setAppMode(m_isGui ? os::AppMode::GUI:
|
|
|
|
|
os::AppMode::CLI);
|
2019-10-25 01:59:22 +08:00
|
|
|
|
2017-04-15 19:13:20 +08:00
|
|
|
if (m_isGui)
|
2017-08-15 21:39:06 +08:00
|
|
|
m_uiSystem.reset(new ui::UISystem);
|
2016-02-27 03:13:54 +08:00
|
|
|
|
2016-02-27 04:08:42 +08:00
|
|
|
bool createLogInDesktop = false;
|
2016-02-27 03:13:54 +08:00
|
|
|
switch (options.verboseLevel()) {
|
|
|
|
|
case AppOptions::kNoVerbose:
|
|
|
|
|
base::set_log_level(ERROR);
|
|
|
|
|
break;
|
|
|
|
|
case AppOptions::kVerbose:
|
|
|
|
|
base::set_log_level(INFO);
|
|
|
|
|
break;
|
|
|
|
|
case AppOptions::kHighlyVerbose:
|
|
|
|
|
base::set_log_level(VERBOSE);
|
2016-02-27 04:08:42 +08:00
|
|
|
createLogInDesktop = true;
|
2016-02-27 03:13:54 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:27:56 +08:00
|
|
|
initialize_color_spaces(preferences());
|
2019-04-02 06:57:53 +08:00
|
|
|
|
2018-03-28 22:48:59 +08:00
|
|
|
// Load modules
|
2018-03-15 01:14:47 +08:00
|
|
|
m_modules = new Modules(createLogInDesktop, preferences());
|
2010-09-19 04:36:21 +08:00
|
|
|
m_legacy = new LegacyModules(isGui() ? REQUIRE_INTERFACE: 0);
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2015-12-23 07:04:44 +08:00
|
|
|
m_brushes.reset(new AppBrushes);
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2011-08-07 01:36:40 +08:00
|
|
|
|
2015-04-23 06:28:24 +08:00
|
|
|
// Data recovery is enabled only in GUI mode
|
|
|
|
|
if (isGui() && preferences().general.dataRecovery())
|
2019-12-11 23:27:56 +08:00
|
|
|
m_modules->createDataRecovery(context());
|
2015-04-09 07:28:30 +08:00
|
|
|
|
2014-08-20 20:16:59 +08:00
|
|
|
if (isPortable())
|
2016-10-27 23:25:33 +08:00
|
|
|
LOG("APP: Running in portable mode\n");
|
2010-04-26 08:29:50 +08:00
|
|
|
|
2015-07-06 21:59:44 +08:00
|
|
|
// Load or create the default palette, or migrate the default
|
|
|
|
|
// palette from an old format palette to the new one, etc.
|
2016-09-05 22:59:25 +08:00
|
|
|
load_default_palette();
|
2014-09-03 11:39:15 +08:00
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2010-09-19 04:36:21 +08:00
|
|
|
// Initialize GUI interface
|
|
|
|
|
if (isGui()) {
|
2016-10-27 23:25:33 +08:00
|
|
|
LOG("APP: GUI mode\n");
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2018-05-24 23:56:07 +08:00
|
|
|
// Set the ClipboardDelegate impl to copy/paste text in the native
|
|
|
|
|
// clipboard from the ui::Entry control.
|
|
|
|
|
m_uiSystem->setClipboardDelegate(&m_modules->m_clipboardManager);
|
|
|
|
|
|
2018-03-20 06:37:39 +08:00
|
|
|
// Setup the GUI cursor and redraw screen
|
2016-08-31 04:27:19 +08:00
|
|
|
ui::set_use_native_cursors(preferences().cursor.useNativeCursor());
|
|
|
|
|
ui::set_mouse_cursor_scale(preferences().cursor.cursorScale());
|
2014-11-26 08:30:56 +08:00
|
|
|
ui::set_mouse_cursor(kArrowCursor);
|
2014-08-11 06:51:14 +08:00
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
ui::Manager::getDefault()->invalidate();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2019-01-03 20:07:56 +08:00
|
|
|
// Create the main window.
|
2012-07-10 00:20:58 +08:00
|
|
|
m_mainWindow.reset(new MainWindow);
|
2019-01-03 20:07:56 +08:00
|
|
|
if (m_mod)
|
|
|
|
|
m_mod->modMainWindow(m_mainWindow.get());
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
// Data recovery is enabled only in GUI mode
|
|
|
|
|
if (preferences().general.dataRecovery())
|
|
|
|
|
m_modules->searchDataRecoverySessions();
|
|
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
// Default status of the main window.
|
2013-01-21 05:40:37 +08:00
|
|
|
app_rebuild_documents_tabs();
|
2019-06-05 21:16:34 +08:00
|
|
|
m_mainWindow->statusBar()->showDefaultText();
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2019-06-05 21:16:34 +08:00
|
|
|
// Show the main window (this is not modal, the code continues)
|
2012-07-10 00:20:58 +08:00
|
|
|
m_mainWindow->openWindow();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-04-16 02:21:24 +08:00
|
|
|
// Redraw the whole screen.
|
2012-06-18 09:02:54 +08:00
|
|
|
ui::Manager::getDefault()->invalidate();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif // ENABLE_UI
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2020-04-03 02:47:12 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
|
|
|
|
// Call the init() function from all plugins
|
|
|
|
|
LOG("APP: Initializing scripts...\n");
|
|
|
|
|
extensions().executeInitActions();
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
// Process options
|
2016-10-27 23:25:33 +08:00
|
|
|
LOG("APP: Processing options...\n");
|
2021-03-10 02:24:41 +08:00
|
|
|
int code;
|
2016-05-31 06:03:28 +08:00
|
|
|
{
|
2018-08-09 04:27:26 +08:00
|
|
|
std::unique_ptr<CliDelegate> delegate;
|
2016-05-31 06:03:28 +08:00
|
|
|
if (options.previewCLI())
|
|
|
|
|
delegate.reset(new PreviewCliDelegate);
|
|
|
|
|
else
|
|
|
|
|
delegate.reset(new DefaultCliDelegate);
|
|
|
|
|
|
|
|
|
|
CliProcessor cli(delegate.get(), options);
|
2021-03-10 02:24:41 +08:00
|
|
|
code = cli.process(context());
|
2013-12-09 07:19:32 +08:00
|
|
|
}
|
2016-04-12 06:15:42 +08:00
|
|
|
|
2020-07-31 01:29:35 +08:00
|
|
|
LOG("APP: Finish launching...\n");
|
2020-04-16 22:19:39 +08:00
|
|
|
system->finishLaunching();
|
2021-03-10 02:24:41 +08:00
|
|
|
return code;
|
2017-12-12 00:40:26 +08:00
|
|
|
}
|
2017-12-07 05:50:23 +08:00
|
|
|
|
2017-12-12 00:40:26 +08:00
|
|
|
void App::run()
|
|
|
|
|
{
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2017-12-12 00:40:26 +08:00
|
|
|
// Run the GUI
|
|
|
|
|
if (isGui()) {
|
2018-06-19 21:59:12 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
// How to interpret one finger on Windows tablets.
|
|
|
|
|
ui::Manager::getDefault()->getDisplay()
|
|
|
|
|
->setInterpretOneFingerGestureAsMouseMovement(
|
2019-12-11 23:27:56 +08:00
|
|
|
preferences().experimental.oneFingerAsMouseMovement());
|
2018-06-19 21:59:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
2017-12-07 05:50:23 +08:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__)
|
2017-12-12 00:40:26 +08:00
|
|
|
// Setup app icon for Linux window managers
|
|
|
|
|
try {
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Display* display = os::instance()->defaultDisplay();
|
|
|
|
|
os::SurfaceList icons;
|
2017-12-12 00:40:26 +08:00
|
|
|
|
|
|
|
|
for (const int size : { 32, 64, 128 }) {
|
|
|
|
|
ResourceFinder rf;
|
|
|
|
|
rf.includeDataDir(fmt::format("icons/ase{0}.png", size).c_str());
|
|
|
|
|
if (rf.findFirst()) {
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Surface* surf = os::instance()->loadRgbaSurface(rf.filename().c_str());
|
2017-12-12 00:40:26 +08:00
|
|
|
if (surf)
|
|
|
|
|
icons.push_back(surf);
|
|
|
|
|
}
|
2017-12-07 05:50:23 +08:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 00:40:26 +08:00
|
|
|
display->setIcons(icons);
|
2017-12-07 05:50:23 +08:00
|
|
|
|
2017-12-12 00:40:26 +08:00
|
|
|
for (auto surf : icons)
|
|
|
|
|
surf->dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception&) {
|
|
|
|
|
// Just ignore the exception, we couldn't change the app icon, no
|
|
|
|
|
// big deal.
|
|
|
|
|
}
|
2017-12-07 05:50:23 +08:00
|
|
|
#endif
|
2013-12-09 07:19:32 +08:00
|
|
|
|
2016-02-29 19:32:10 +08:00
|
|
|
// Initialize Steam API
|
2016-02-25 00:21:37 +08:00
|
|
|
#ifdef ENABLE_STEAM
|
|
|
|
|
steam::SteamAPI steam;
|
2016-06-08 01:47:59 +08:00
|
|
|
if (steam.initialized())
|
2018-08-09 23:58:43 +08:00
|
|
|
os::instance()->activateApp();
|
2016-02-25 00:21:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
2019-08-01 02:25:02 +08:00
|
|
|
#if defined(_DEBUG) || defined(ENABLE_DEVMODE)
|
2017-08-16 02:47:06 +08:00
|
|
|
// On OS X, when we compile Aseprite on devmode, we're using it
|
2016-07-01 22:21:40 +08:00
|
|
|
// outside an app bundle, so we must active the app explicitly.
|
2019-10-25 00:43:47 +08:00
|
|
|
if (isGui())
|
|
|
|
|
os::instance()->activateApp();
|
2016-07-01 22:21:40 +08:00
|
|
|
#endif
|
|
|
|
|
|
2011-07-28 08:26:22 +08:00
|
|
|
#ifdef ENABLE_UPDATER
|
2011-07-27 10:25:02 +08:00
|
|
|
// Launch the thread to check for updates.
|
2015-02-26 23:28:26 +08:00
|
|
|
app::CheckUpdateThreadLauncher checkUpdate(
|
|
|
|
|
m_mainWindow->getCheckUpdateDelegate());
|
2011-07-27 10:25:02 +08:00
|
|
|
checkUpdate.launch();
|
2011-07-28 08:26:22 +08:00
|
|
|
#endif
|
2011-07-27 10:25:02 +08:00
|
|
|
|
2014-08-20 11:11:19 +08:00
|
|
|
app::SendCrash sendCrash;
|
|
|
|
|
sendCrash.search();
|
|
|
|
|
|
2018-11-21 06:42:53 +08:00
|
|
|
// Keep the console alive the whole program execute (just in case
|
|
|
|
|
// we've to print errors).
|
|
|
|
|
Console console;
|
|
|
|
|
#ifdef ENABLE_SCRIPTING
|
2020-04-03 02:47:12 +08:00
|
|
|
// Use the app::Console() for script errors
|
2018-11-21 06:42:53 +08:00
|
|
|
ConsoleEngineDelegate delegate;
|
|
|
|
|
script::ScopedEngineDelegate setEngineDelegate(m_engine.get(), &delegate);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-07-27 10:25:02 +08:00
|
|
|
// Run the GUI main message loop
|
2015-07-30 05:12:35 +08:00
|
|
|
ui::Manager::getDefault()->run();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif // ENABLE_UI
|
2014-11-07 08:04:32 +08:00
|
|
|
|
2016-11-21 21:25:27 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2012-09-09 07:10:48 +08:00
|
|
|
// Start shell to execute scripts.
|
2014-11-07 08:04:32 +08:00
|
|
|
if (m_isShell) {
|
2018-09-01 01:30:32 +08:00
|
|
|
m_engine->printLastResult(); // TODO is this needed?
|
2015-06-20 07:01:30 +08:00
|
|
|
Shell shell;
|
2018-09-01 01:30:32 +08:00
|
|
|
shell.run(*m_engine);
|
2012-09-09 07:10:48 +08:00
|
|
|
}
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif // ENABLE_SCRIPTING
|
2010-01-29 11:15:33 +08:00
|
|
|
|
2020-04-03 02:47:12 +08:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_SCRIPTING
|
|
|
|
|
// Call the exit() function from all plugins
|
|
|
|
|
extensions().executeExitActions();
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-06-04 22:36:19 +08:00
|
|
|
#ifdef ENABLE_UI
|
|
|
|
|
if (isGui()) {
|
2019-06-05 03:45:59 +08:00
|
|
|
// Select no document
|
2019-12-11 23:27:56 +08:00
|
|
|
static_cast<UIContext*>(context())->setActiveView(nullptr);
|
2019-06-05 03:45:59 +08:00
|
|
|
|
2019-06-04 22:36:19 +08:00
|
|
|
// Delete backups (this is a normal shutdown, we are not handling
|
|
|
|
|
// exceptions, and we are not in a destructor).
|
|
|
|
|
m_modules->deleteDataRecovery();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Destroy all documents from the UIContext.
|
|
|
|
|
std::vector<Doc*> docs;
|
2019-06-07 01:58:45 +08:00
|
|
|
#ifdef ENABLE_UI
|
2019-12-11 23:27:56 +08:00
|
|
|
for (Doc* doc : static_cast<UIContext*>(context())->getAndRemoveAllClosedDocs())
|
2019-06-04 22:36:19 +08:00
|
|
|
docs.push_back(doc);
|
2019-06-07 01:58:45 +08:00
|
|
|
#endif
|
2019-12-11 23:27:56 +08:00
|
|
|
for (Doc* doc : context()->documents())
|
2019-06-04 22:36:19 +08:00
|
|
|
docs.push_back(doc);
|
|
|
|
|
for (Doc* doc : docs) {
|
2014-11-07 08:04:32 +08:00
|
|
|
// First we close the document. In this way we receive recent
|
2018-07-07 22:54:44 +08:00
|
|
|
// notifications related to the document as a app::Doc. If
|
|
|
|
|
// we delete the document directly, we destroy the app::Doc
|
2014-11-07 08:04:32 +08:00
|
|
|
// too early, and then doc::~Document() call
|
2018-07-07 19:38:04 +08:00
|
|
|
// DocsObserver::onRemoveDocument(). In this way, observers
|
2018-07-07 22:54:44 +08:00
|
|
|
// could think that they have a fully created app::Doc when
|
2014-11-07 08:04:32 +08:00
|
|
|
// in reality it's a doc::Document (in the middle of a
|
|
|
|
|
// destruction process).
|
|
|
|
|
//
|
|
|
|
|
// TODO: This problem is because we're extending doc::Document,
|
2018-07-07 22:54:44 +08:00
|
|
|
// in the future, we should remove app::Doc.
|
2014-11-07 08:04:32 +08:00
|
|
|
doc->close();
|
|
|
|
|
delete doc;
|
|
|
|
|
}
|
2019-06-05 21:21:18 +08:00
|
|
|
|
|
|
|
|
#ifdef ENABLE_UI
|
|
|
|
|
if (isGui()) {
|
|
|
|
|
// Destroy the window.
|
|
|
|
|
m_mainWindow.reset(nullptr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2013-08-09 08:01:20 +08:00
|
|
|
// Finishes the Aseprite application.
|
2009-10-09 09:34:06 +08:00
|
|
|
App::~App()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-10-14 22:09:59 +08:00
|
|
|
try {
|
2016-10-27 23:25:33 +08:00
|
|
|
LOG("APP: Exit\n");
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(m_instance == this);
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2018-10-11 23:01:21 +08:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
|
|
|
|
// Destroy scripting engine
|
|
|
|
|
m_engine.reset(nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-03 10:04:04 +08:00
|
|
|
// Delete file formats.
|
|
|
|
|
FileFormatsManager::destroyInstance();
|
|
|
|
|
|
2012-08-23 08:05:02 +08:00
|
|
|
// Fire App Exit signal.
|
2010-03-01 10:36:05 +08:00
|
|
|
App::instance()->Exit();
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2012-08-23 08:05:02 +08:00
|
|
|
// Finalize modules, configuration and core.
|
2015-05-21 03:23:53 +08:00
|
|
|
Editor::destroyEditorSharedInternals();
|
2009-10-14 22:09:59 +08:00
|
|
|
|
2016-11-08 03:32:54 +08:00
|
|
|
if (m_backupIndicator) {
|
|
|
|
|
delete m_backupIndicator;
|
|
|
|
|
m_backupIndicator = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
// Save brushes
|
|
|
|
|
m_brushes.reset(nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-01-29 11:15:33 +08:00
|
|
|
delete m_legacy;
|
|
|
|
|
delete m_modules;
|
2019-04-25 05:31:43 +08:00
|
|
|
|
|
|
|
|
// Save preferences only if we are running in GUI mode. when we
|
|
|
|
|
// run in batch mode we might want to reset some preferences so
|
|
|
|
|
// the scripts have a reproducible behavior. Those reset
|
|
|
|
|
// preferences must not be saved.
|
|
|
|
|
if (isGui())
|
2019-12-11 23:27:56 +08:00
|
|
|
preferences().save();
|
2019-04-25 05:31:43 +08:00
|
|
|
|
2014-12-15 07:19:31 +08:00
|
|
|
delete m_coreModules;
|
2011-01-23 07:30:44 +08:00
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2014-10-29 22:58:03 +08:00
|
|
|
// Destroy the loaded gui.xml data.
|
|
|
|
|
delete KeyboardShortcuts::instance();
|
2011-01-23 07:30:44 +08:00
|
|
|
delete GuiXml::instance();
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2009-10-14 22:09:59 +08:00
|
|
|
m_instance = NULL;
|
|
|
|
|
}
|
2014-12-28 22:06:11 +08:00
|
|
|
catch (const std::exception& e) {
|
2020-06-18 04:05:43 +08:00
|
|
|
LOG(ERROR, "APP: Error: %s\n", e.what());
|
2018-08-09 23:58:43 +08:00
|
|
|
os::error_message(e.what());
|
2014-12-28 22:06:11 +08:00
|
|
|
|
|
|
|
|
// no re-throw
|
|
|
|
|
}
|
2009-10-14 22:09:59 +08:00
|
|
|
catch (...) {
|
2020-03-16 21:29:58 +08:00
|
|
|
os::error_message("Error closing the program.\n(uncaught exception)");
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2010-03-01 10:36:05 +08:00
|
|
|
// no re-throw
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
Context* App::context()
|
|
|
|
|
{
|
2019-12-11 23:27:56 +08:00
|
|
|
return &m_coreModules->m_context;
|
2018-05-07 11:11:50 +08:00
|
|
|
}
|
|
|
|
|
|
2014-08-20 20:16:59 +08:00
|
|
|
bool App::isPortable()
|
|
|
|
|
{
|
2014-08-24 11:09:01 +08:00
|
|
|
static bool* is_portable = NULL;
|
|
|
|
|
if (!is_portable) {
|
|
|
|
|
is_portable =
|
|
|
|
|
new bool(
|
|
|
|
|
base::is_file(base::join_path(
|
|
|
|
|
base::get_file_path(base::get_app_path()),
|
|
|
|
|
"aseprite.ini")));
|
|
|
|
|
}
|
|
|
|
|
return *is_portable;
|
2014-08-20 20:16:59 +08:00
|
|
|
}
|
|
|
|
|
|
2016-04-23 00:19:06 +08:00
|
|
|
tools::ToolBox* App::toolBox() const
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
{
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(m_modules != NULL);
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
return &m_modules->m_toolbox;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
tools::Tool* App::activeTool() const
|
|
|
|
|
{
|
2016-04-26 02:20:53 +08:00
|
|
|
return m_modules->m_activeToolManager.activeTool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tools::ActiveToolManager* App::activeToolManager() const
|
|
|
|
|
{
|
|
|
|
|
return &m_modules->m_activeToolManager;
|
2015-05-19 03:53:25 +08:00
|
|
|
}
|
|
|
|
|
|
2016-04-23 00:19:06 +08:00
|
|
|
RecentFiles* App::recentFiles() const
|
2010-09-18 11:28:24 +08:00
|
|
|
{
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2010-09-18 11:28:24 +08:00
|
|
|
ASSERT(m_modules != NULL);
|
|
|
|
|
return &m_modules->m_recent_files;
|
2018-05-07 11:11:50 +08:00
|
|
|
#else
|
|
|
|
|
return nullptr;
|
|
|
|
|
#endif
|
2010-09-18 11:28:24 +08:00
|
|
|
}
|
|
|
|
|
|
2016-04-23 00:19:06 +08:00
|
|
|
Workspace* App::workspace() const
|
|
|
|
|
{
|
|
|
|
|
if (m_mainWindow)
|
|
|
|
|
return m_mainWindow->getWorkspace();
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContextBar* App::contextBar() const
|
|
|
|
|
{
|
|
|
|
|
if (m_mainWindow)
|
|
|
|
|
return m_mainWindow->getContextBar();
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timeline* App::timeline() const
|
|
|
|
|
{
|
|
|
|
|
if (m_mainWindow)
|
|
|
|
|
return m_mainWindow->getTimeline();
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-15 07:19:31 +08:00
|
|
|
Preferences& App::preferences() const
|
|
|
|
|
{
|
2019-12-11 23:27:56 +08:00
|
|
|
return m_coreModules->m_context.preferences();
|
2014-12-15 07:19:31 +08:00
|
|
|
}
|
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
Extensions& App::extensions() const
|
|
|
|
|
{
|
|
|
|
|
return m_modules->m_extensions;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 04:47:53 +08:00
|
|
|
crash::DataRecovery* App::dataRecovery() const
|
|
|
|
|
{
|
|
|
|
|
return m_modules->recovery();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2014-08-20 11:11:19 +08:00
|
|
|
void App::showNotification(INotificationDelegate* del)
|
2014-05-25 22:21:10 +08:00
|
|
|
{
|
2020-03-07 01:45:13 +08:00
|
|
|
if (m_mainWindow)
|
|
|
|
|
m_mainWindow->showNotification(del);
|
2014-05-25 22:21:10 +08:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 03:32:54 +08:00
|
|
|
void App::showBackupNotification(bool state)
|
|
|
|
|
{
|
2018-12-21 20:37:47 +08:00
|
|
|
assert_ui_thread();
|
2016-11-08 03:32:54 +08:00
|
|
|
if (state) {
|
|
|
|
|
if (!m_backupIndicator)
|
|
|
|
|
m_backupIndicator = new BackupIndicator;
|
|
|
|
|
m_backupIndicator->start();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (m_backupIndicator)
|
|
|
|
|
m_backupIndicator->stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 11:39:15 +08:00
|
|
|
void App::updateDisplayTitleBar()
|
|
|
|
|
{
|
2020-03-16 21:29:58 +08:00
|
|
|
std::string defaultTitle = fmt::format("{} v{}", get_app_name(), get_app_version());
|
2014-09-03 11:39:15 +08:00
|
|
|
std::string title;
|
|
|
|
|
|
2018-07-15 10:24:49 +08:00
|
|
|
DocView* docView = UIContext::instance()->activeView();
|
2014-09-03 11:39:15 +08:00
|
|
|
if (docView) {
|
|
|
|
|
// Prepend the document's filename.
|
2016-02-13 12:33:43 +08:00
|
|
|
title += docView->document()->name();
|
2014-09-03 11:39:15 +08:00
|
|
|
title += " - ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
title += defaultTitle;
|
2020-03-02 10:42:08 +08:00
|
|
|
os::instance()->defaultDisplay()->setTitle(title);
|
2014-09-03 11:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
InputChain& App::inputChain()
|
|
|
|
|
{
|
|
|
|
|
return m_modules->m_inputChain;
|
|
|
|
|
}
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2015-05-10 06:55:33 +08:00
|
|
|
|
2019-10-01 20:24:03 +08:00
|
|
|
// Updates palette and redraw the screen.
|
|
|
|
|
void app_refresh_screen()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2019-10-01 20:24:03 +08:00
|
|
|
Context* ctx = UIContext::instance();
|
|
|
|
|
ASSERT(ctx != NULL);
|
2013-03-12 07:29:45 +08:00
|
|
|
|
2019-10-01 20:24:03 +08:00
|
|
|
Site site = ctx->activeSite();
|
2015-04-21 03:27:09 +08:00
|
|
|
if (Palette* pal = site.palette())
|
2013-03-12 07:29:45 +08:00
|
|
|
set_current_palette(pal, false);
|
2009-06-11 23:11:11 +08:00
|
|
|
else
|
2018-10-26 04:29:32 +08:00
|
|
|
set_current_palette(nullptr, false);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-04-16 02:21:24 +08:00
|
|
|
// Invalidate the whole screen.
|
2012-06-18 09:02:54 +08:00
|
|
|
ui::Manager::getDefault()->invalidate();
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif // ENABLE_UI
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2015-05-05 02:52:00 +08:00
|
|
|
// TODO remove app_rebuild_documents_tabs() and replace it by
|
|
|
|
|
// observable events in the document (so a tab can observe if the
|
|
|
|
|
// document is modified).
|
2011-03-23 08:11:25 +08:00
|
|
|
void app_rebuild_documents_tabs()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2015-09-11 03:44:33 +08:00
|
|
|
if (App::instance()->isGui()) {
|
2016-04-23 00:19:06 +08:00
|
|
|
App::instance()->workspace()->updateTabs();
|
2015-09-11 03:44:33 +08:00
|
|
|
App::instance()->updateDisplayTitleBar();
|
|
|
|
|
}
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif // ENABLE_UI
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
PixelFormat app_get_current_pixel_format()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2019-04-25 05:31:43 +08:00
|
|
|
Context* ctx = App::instance()->context();
|
|
|
|
|
ASSERT(ctx);
|
2009-06-11 23:11:11 +08:00
|
|
|
|
2019-04-25 05:31:43 +08:00
|
|
|
Doc* doc = ctx->activeDocument();
|
|
|
|
|
if (doc)
|
|
|
|
|
return doc->sprite()->pixelFormat();
|
2008-03-23 02:43:56 +08:00
|
|
|
else
|
|
|
|
|
return IMAGE_RGB;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2010-08-25 11:26:37 +08:00
|
|
|
int app_get_color_to_clear_layer(Layer* layer)
|
2008-03-27 22:29:33 +08:00
|
|
|
{
|
2014-05-08 11:30:36 +08:00
|
|
|
ASSERT(layer != NULL);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-05-08 11:30:36 +08:00
|
|
|
app::Color color;
|
|
|
|
|
|
|
|
|
|
// The `Background' is erased with the `Background Color'
|
2014-08-08 07:19:31 +08:00
|
|
|
if (layer->isBackground()) {
|
2018-05-07 11:11:50 +08:00
|
|
|
#ifdef ENABLE_UI
|
2014-08-08 07:19:31 +08:00
|
|
|
if (ColorBar::instance())
|
|
|
|
|
color = ColorBar::instance()->getBgColor();
|
|
|
|
|
else
|
2018-05-07 11:11:50 +08:00
|
|
|
#endif
|
2014-08-08 07:19:31 +08:00
|
|
|
color = app::Color::fromRgb(0, 0, 0); // TODO get background color color from doc::Settings
|
|
|
|
|
}
|
2014-05-08 11:30:36 +08:00
|
|
|
else // All transparent layers are cleared with the mask color
|
|
|
|
|
color = app::Color::fromMask();
|
2008-03-27 22:29:33 +08:00
|
|
|
|
2010-08-25 11:26:37 +08:00
|
|
|
return color_utils::color_for_layer(color, layer);
|
2008-03-27 22:29:33 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
} // namespace app
|