From 34834792e3aeb02845466e48f0decf2706495a68 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 4 Jan 2019 16:30:28 -0300 Subject: [PATCH] Add support to call PaletteSize without UI --- src/app/CMakeLists.txt | 2 +- src/app/commands/cmd_palette_size.cpp | 41 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 8d88b8ac5..c02686d06 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -254,7 +254,6 @@ if(ENABLE_UI) commands/cmd_open_with_app.cpp commands/cmd_options.cpp commands/cmd_palette_editor.cpp - commands/cmd_palette_size.cpp commands/cmd_paste.cpp commands/cmd_paste_text.cpp commands/cmd_pixel_perfect_mode.cpp @@ -516,6 +515,7 @@ add_library(app-lib commands/cmd_new_frame.cpp commands/cmd_new_layer.cpp commands/cmd_open_file.cpp + commands/cmd_palette_size.cpp commands/cmd_remove_layer.cpp commands/cmd_save_file.cpp commands/cmd_sprite_size.cpp diff --git a/src/app/commands/cmd_palette_size.cpp b/src/app/commands/cmd_palette_size.cpp index 098808537..7d39b375b 100644 --- a/src/app/commands/cmd_palette_size.cpp +++ b/src/app/commands/cmd_palette_size.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -53,25 +54,35 @@ void PaletteSizeCommand::onExecute(Context* context) ContextReader reader(context); frame_t frame = reader.frame(); Palette palette(*reader.sprite()->palette(frame)); + int ncolors = (m_size != 0 ? m_size: palette.size()); - app::gen::PaletteSize window; - window.colors()->setTextf("%d", palette.size()); - window.openWindowInForeground(); - if (window.closer() == window.ok()) { - int ncolors = window.colors()->textInt(); - if (ncolors == palette.size()) +#ifdef ENABLE_UI + if (m_size == 0 && context->isUIAvailable()) { + app::gen::PaletteSize window; + window.colors()->setTextf("%d", ncolors); + window.openWindowInForeground(); + if (window.closer() != window.ok()) return; - palette.resize(MID(1, ncolors, std::numeric_limits::max())); - - ContextWriter writer(reader); - Tx tx(context, "Palette Size", ModifyDocument); - tx(new cmd::SetPalette(writer.sprite(), frame, &palette)); - tx.commit(); - - set_current_palette(&palette, false); - ui::Manager::getDefault()->invalidate(); + ncolors = window.colors()->textInt(); } +#endif + + if (ncolors == palette.size()) + return; + + palette.resize(MID(1, ncolors, std::numeric_limits::max())); + + ContextWriter writer(reader); + Tx tx(context, "Palette Size", ModifyDocument); + tx(new cmd::SetPalette(writer.sprite(), frame, &palette)); + tx.commit(); + + set_current_palette(&palette, false); +#ifdef ENABLE_UI + if (context->isUIAvailable()) + ui::Manager::getDefault()->invalidate(); +#endif } Command* CommandFactory::createPaletteSizeCommand()