diff --git a/src/app/commands/cmd_change_pixel_format.cpp b/src/app/commands/cmd_change_pixel_format.cpp index 6f6f4fc1b..3a30d653a 100644 --- a/src/app/commands/cmd_change_pixel_format.cpp +++ b/src/app/commands/cmd_change_pixel_format.cpp @@ -484,7 +484,8 @@ protected: std::string onGetFriendlyName() const override; private: - bool m_useUI; + bool m_showDlg; + bool m_showProgress; doc::PixelFormat m_format; render::Dithering m_dithering; doc::RgbMapAlgorithm m_rgbmap; @@ -494,7 +495,8 @@ private: ChangePixelFormatCommand::ChangePixelFormatCommand() : Command(CommandId::ChangePixelFormat(), CmdUIOnlyFlag) { - m_useUI = true; + m_showDlg = true; + m_showProgress = true; m_format = IMAGE_RGB; m_dithering = render::Dithering(); m_rgbmap = doc::RgbMapAlgorithm::DEFAULT; @@ -503,15 +505,20 @@ ChangePixelFormatCommand::ChangePixelFormatCommand() void ChangePixelFormatCommand::onLoadParams(const Params& params) { - m_useUI = false; + m_showDlg = false; + m_showProgress = true; std::string format = params.get("format"); if (format == "rgb") m_format = IMAGE_RGB; else if (format == "grayscale" || format == "gray") m_format = IMAGE_GRAYSCALE; else if (format == "indexed") m_format = IMAGE_INDEXED; - else - m_useUI = true; + else { + m_showDlg = true; + } + + if (params.has_param("ui")) + m_showDlg = m_showProgress = params.get_as("ui"); std::string dithering = params.get("dithering"); if (dithering == "ordered") @@ -587,7 +594,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context) if (!sprite) return false; - if (m_useUI) + if (m_showDlg) return true; if (sprite->pixelFormat() == IMAGE_INDEXED && @@ -600,7 +607,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context) bool ChangePixelFormatCommand::onChecked(Context* context) { - if (m_useUI) + if (m_showDlg) return false; const ContextReader reader(context); @@ -622,7 +629,7 @@ void ChangePixelFormatCommand::onExecute(Context* context) bool flatten = false; #ifdef ENABLE_UI - if (m_useUI) { + if (context->isUIAvailable() && m_showDlg) { ColorModeWindow window(Editor::activeEditor()); window.remapWindow(); @@ -651,7 +658,7 @@ void ChangePixelFormatCommand::onExecute(Context* context) return; { - SpriteJob job(context, doc, Strings::color_mode_title()); + SpriteJob job(context, doc, Strings::color_mode_title(), m_showProgress); Sprite* sprite(job.sprite()); // TODO this was moved in the main UI thread because @@ -691,7 +698,7 @@ std::string ChangePixelFormatCommand::onGetFriendlyName() const { std::string conversion; - if (!m_useUI) { + if (!m_showDlg) { switch (m_format) { case IMAGE_RGB: conversion = Strings::commands_ChangePixelFormat_RGB(); diff --git a/src/app/commands/cmd_color_quantization.cpp b/src/app/commands/cmd_color_quantization.cpp index dcf339412..986f8b2a3 100644 --- a/src/app/commands/cmd_color_quantization.cpp +++ b/src/app/commands/cmd_color_quantization.cpp @@ -93,10 +93,7 @@ bool ColorQuantizationCommand::onEnabled(Context* ctx) void ColorQuantizationCommand::onExecute(Context* ctx) { -#ifdef ENABLE_UI const bool ui = (params().ui() && ctx->isUIAvailable()); -#endif - auto& pref = Preferences::instance(); bool withAlpha = params().withAlpha(); int maxColors = params().maxColors(); @@ -183,7 +180,7 @@ void ColorQuantizationCommand::onExecute(Context* ctx) const Palette* curPalette = site.sprite()->palette(frame); Palette tmpPalette(frame, entries.picks()); - SpriteJob job(ctx, doc, "Color Quantization"); + SpriteJob job(ctx, doc, "Color Quantization", ui); const bool newBlend = pref.experimental.newBlend(); job.startJobWithCallback( [sprite, withAlpha, curPalette, &tmpPalette, &job, &entries, diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp index 552c8e6a0..addbcb322 100644 --- a/src/app/commands/cmd_export_sprite_sheet.cpp +++ b/src/app/commands/cmd_export_sprite_sheet.cpp @@ -1193,8 +1193,9 @@ public: ExportSpriteSheetJob( DocExporter& exporter, const Site& site, - const ExportSpriteSheetParams& params) - : Job(Strings::export_sprite_sheet_generating().c_str()) + const ExportSpriteSheetParams& params, + const bool showProgress) + : Job(Strings::export_sprite_sheet_generating(), showProgress) , m_exporter(exporter) , m_site(site) , m_params(params) { } @@ -1373,7 +1374,9 @@ void ExportSpriteSheetCommand::onExecute(Context* context) std::unique_ptr newDocument; #ifdef ENABLE_UI if (context->isUIAvailable()) { - ExportSpriteSheetJob job(exporter, site, params); + ExportSpriteSheetJob job(exporter, site, params, + // Progress bar can be disabled with ui=false + params.ui()); job.startJob(); job.waitJob(); diff --git a/src/app/commands/cmd_open_file.cpp b/src/app/commands/cmd_open_file.cpp index ca74ebce0..158352717 100644 --- a/src/app/commands/cmd_open_file.cpp +++ b/src/app/commands/cmd_open_file.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -36,8 +36,8 @@ namespace app { class OpenFileJob : public Job, public IFileOpProgress { public: - OpenFileJob(FileOp* fop) - : Job(Strings::open_file_loading().c_str()) + OpenFileJob(FileOp* fop, const bool showProgress) + : Job(Strings::open_file_loading(), showProgress) , m_fop(fop) { } @@ -76,6 +76,7 @@ private: OpenFileCommand::OpenFileCommand() : Command(CommandId::OpenFile(), CmdRecordableFlag) + , m_ui(true) , m_repeatCheckbox(false) , m_oneFrame(false) , m_seqDecision(gen::SequenceDecision::ASK) @@ -86,6 +87,12 @@ void OpenFileCommand::onLoadParams(const Params& params) { m_filename = params.get("filename"); m_folder = params.get("folder"); // Initial folder + + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; + m_repeatCheckbox = params.get_as("repeat_checkbox"); m_oneFrame = params.get_as("oneframe"); @@ -220,7 +227,7 @@ void OpenFileCommand::onExecute(Context* context) m_usedFiles.push_back(fn); } - OpenFileJob task(fop.get()); + OpenFileJob task(fop.get(), m_ui); task.showProgressWindow(); // Post-load processing, it is called from the GUI because may require user intervention. diff --git a/src/app/commands/cmd_open_file.h b/src/app/commands/cmd_open_file.h index 5437611f4..056c04c09 100644 --- a/src/app/commands/cmd_open_file.h +++ b/src/app/commands/cmd_open_file.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020-2021 Igara Studio S.A. +// Copyright (C) 2020-2024 Igara Studio S.A. // Copyright (C) 2016-2018 David Capello // // This program is distributed under the terms of @@ -36,6 +36,7 @@ namespace app { private: std::string m_filename; std::string m_folder; + bool m_ui; bool m_repeatCheckbox; bool m_oneFrame; base::paths m_usedFiles; diff --git a/src/app/commands/cmd_rotate.cpp b/src/app/commands/cmd_rotate.cpp index 49ef0826f..25da56f9b 100644 --- a/src/app/commands/cmd_rotate.cpp +++ b/src/app/commands/cmd_rotate.cpp @@ -46,8 +46,10 @@ public: RotateJob(Context* ctx, Doc* doc, const std::string& jobName, - int angle, const CelList& cels, bool rotateSprite) - : SpriteJob(ctx, doc, jobName) + int angle, const CelList& cels, + const bool rotateSprite, + const bool showProgress) + : SpriteJob(ctx, doc, jobName, showProgress) , m_cels(cels) , m_rotateSprite(rotateSprite) { m_angle = angle; @@ -167,12 +169,18 @@ protected: RotateCommand::RotateCommand() : Command(CommandId::Rotate(), CmdRecordableFlag) { + m_ui = true; m_flipMask = false; m_angle = 0; } void RotateCommand::onLoadParams(const Params& params) { + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; + std::string target = params.get("target"); m_flipMask = (target == "mask"); @@ -238,7 +246,7 @@ void RotateCommand::onExecute(Context* context) } { - RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite); + RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite, m_ui); job.startJob(); job.waitJob(); } diff --git a/src/app/commands/cmd_rotate.h b/src/app/commands/cmd_rotate.h index 49fe91f51..21f3aabf6 100644 --- a/src/app/commands/cmd_rotate.h +++ b/src/app/commands/cmd_rotate.h @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2024 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -27,6 +28,7 @@ namespace app { std::string onGetFriendlyName() const override; private: + bool m_ui; bool m_flipMask; int m_angle; }; diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index c5e17f2ea..ffebb69c7 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2023 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -49,8 +49,8 @@ namespace app { class SaveFileJob : public Job, public IFileOpProgress { public: - SaveFileJob(FileOp* fop) - : Job(Strings::save_file_saving().c_str()) + SaveFileJob(FileOp* fop, const bool showProgressBar) + : Job(Strings::save_file_saving(), showProgressBar) , m_fop(fop) { } @@ -239,7 +239,7 @@ void SaveFileBaseCommand::saveDocumentInBackground( if (resizeOnTheFly == ResizeOnTheFly::On) fop->setOnTheFlyScale(scale); - SaveFileJob job(fop.get()); + SaveFileJob job(fop.get(), params().ui()); job.showProgressWindow(); if (fop->hasError()) { diff --git a/src/app/commands/cmd_sprite_size.cpp b/src/app/commands/cmd_sprite_size.cpp index 98383def9..3f82d6359 100644 --- a/src/app/commands/cmd_sprite_size.cpp +++ b/src/app/commands/cmd_sprite_size.cpp @@ -83,8 +83,9 @@ public: SpriteSizeJob(Context* ctx, Doc* doc, const int new_width, const int new_height, - const ResizeMethod resize_method) - : SpriteJob(ctx, doc, Strings::sprite_size_title()) { + const ResizeMethod resize_method, + const bool showProgress) + : SpriteJob(ctx, doc, Strings::sprite_size_title(), showProgress) { m_new_width = new_width; m_new_height = new_height; m_resize_method = resize_method; @@ -373,9 +374,7 @@ bool SpriteSizeCommand::onEnabled(Context* context) void SpriteSizeCommand::onExecute(Context* context) { -#ifdef ENABLE_UI const bool ui = (params().ui() && context->isUIAvailable()); -#endif const Site site = context->activeSite(); Doc* doc = site.document(); Sprite* sprite = site.sprite(); @@ -465,7 +464,7 @@ void SpriteSizeCommand::onExecute(Context* context) new_height = std::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT); { - SpriteSizeJob job(context, doc, new_width, new_height, resize_method); + SpriteSizeJob job(context, doc, new_width, new_height, resize_method, ui); job.startJob(); job.waitJob(); } diff --git a/src/app/job.cpp b/src/app/job.cpp index 592bbd7ea..f6221ad01 100644 --- a/src/app/job.cpp +++ b/src/app/job.cpp @@ -33,18 +33,19 @@ int Job::runningJobs() return g_runningJobs; } -Job::Job(const std::string& jobName) +Job::Job(const std::string& jobName, + const bool showProgress) { m_last_progress = 0.0; m_done_flag = false; m_canceled_flag = false; - if (App::instance()->isGui()) { + if (showProgress && App::instance()->isGui()) { m_alert_window = ui::Alert::create( fmt::format(Strings::alerts_job_working(), jobName)); m_alert_window->addProgress(); - m_timer.reset(new ui::Timer(kMonitoringPeriod, m_alert_window.get())); + m_timer = std::make_unique(kMonitoringPeriod, m_alert_window.get()); m_timer->Tick.connect(&Job::onMonitoringTick, this); m_timer->start(); } @@ -53,7 +54,7 @@ Job::Job(const std::string& jobName) Job::~Job() { if (App::instance()->isGui()) { - ASSERT(!m_timer->isRunning()); + ASSERT(!m_timer || !m_timer->isRunning()); if (m_alert_window) m_alert_window->closeWindow(NULL); diff --git a/src/app/job.h b/src/app/job.h index 6c21bdd22..d302c2c4d 100644 --- a/src/app/job.h +++ b/src/app/job.h @@ -24,7 +24,10 @@ namespace app { public: static int runningJobs(); - Job(const std::string& jobName); + Job(const std::string& jobName, bool showProgress); + Job() = delete; + Job(const Job&) = delete; + Job& operator==(const Job&) = delete; virtual ~Job(); // Starts the job calling onJob() event in another thread and @@ -68,12 +71,6 @@ namespace app { bool m_done_flag; bool m_canceled_flag; std::exception_ptr m_error; - - // these methods are privated and not defined - Job(); - Job(const Job&); - Job& operator==(const Job&); - }; } // namespace app diff --git a/src/app/sprite_job.cpp b/src/app/sprite_job.cpp index dbbac0615..55d89ab69 100644 --- a/src/app/sprite_job.cpp +++ b/src/app/sprite_job.cpp @@ -16,8 +16,9 @@ namespace app { SpriteJob::SpriteJob(Context* ctx, Doc* doc, - const std::string& jobName) - : Job(jobName) + const std::string& jobName, + const bool showProgress) + : Job(jobName, showProgress) , m_doc(doc) , m_sprite(doc->sprite()) , m_tx(Tx::DontLockDoc, ctx, doc, jobName, ModifyDocument) diff --git a/src/app/sprite_job.h b/src/app/sprite_job.h index d0fe180df..e837127ec 100644 --- a/src/app/sprite_job.h +++ b/src/app/sprite_job.h @@ -37,7 +37,8 @@ class SpriteJob : public Job, public render::TaskDelegate { public: SpriteJob(Context* ctx, Doc* doc, - const std::string& jobName); + const std::string& jobName, + const bool showProgress); ~SpriteJob(); Doc* document() const { return m_doc; }