Add support to call PaletteSize without UI

This commit is contained in:
David Capello 2019-01-04 16:30:28 -03:00
parent b7c68579ca
commit 34834792e3
2 changed files with 27 additions and 16 deletions

View File

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

View File

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