Add command to change the palette size manually with a number

This commit is contained in:
David Capello 2015-06-30 12:21:41 -03:00
parent 3accd85662
commit a12816c04e
5 changed files with 100 additions and 0 deletions

View File

@ -725,6 +725,7 @@
<item command="PaletteEditor" text="&amp;Palette Editor">
<param name="switch" value="true" />
</item>
<item command="PaletteSize" text="Palette Si&amp;ze" />
<separator />
<item command="SetPaletteEntrySize" text="&amp;Small Size">
<param name="size" value="7" />

View File

@ -0,0 +1,18 @@
<!-- ASEPRITE -->
<!-- Copyright (C) 2015 by David Capello -->
<gui>
<window text="Palette Size" id="palette_size">
<grid columns="3">
<label text="Number of colors:" />
<entry expansive="true" maxsize="4" id="colors" magnet="true" />
<box cell_align="horizontal" />
<separator horizontal="true" cell_hspan="3" />
<box horizontal="true" homogeneous="true" cell_hspan="3" cell_align="right">
<button text="&amp;OK" closewindow="true" id="ok" magnet="true" minwidth="60" />
<button text="&amp;Cancel" closewindow="true" />
</box>
</grid>
</window>
</gui>

View File

@ -201,6 +201,7 @@ add_library(app-lib
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_play_animation.cpp
commands/cmd_refresh.cpp

View File

@ -0,0 +1,79 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/cmd/set_palette.h"
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/context_access.h"
#include "app/modules/palettes.h"
#include "app/transaction.h"
#include "doc/palette.h"
#include "doc/sprite.h"
#include "generated_palette_size.h"
namespace app {
class PaletteSizeCommand : public Command {
public:
PaletteSizeCommand();
Command* clone() const override { return new PaletteSizeCommand(*this); }
protected:
void onLoadParams(const Params& params) override;
void onExecute(Context* context) override;
private:
int m_size;
};
PaletteSizeCommand::PaletteSizeCommand()
: Command("PaletteSize",
"Palette Size",
CmdRecordableFlag)
{
m_size = 0;
}
void PaletteSizeCommand::onLoadParams(const Params& params)
{
m_size = params.get_as<int>("size");
}
void PaletteSizeCommand::onExecute(Context* context)
{
ContextWriter writer(context);
Sprite* sprite = writer.sprite();
frame_t frame = writer.frame();
Palette palette(*sprite->palette(frame));
app::gen::PaletteSize window;
window.colors()->setTextf("%d", palette.size());
window.openWindowInForeground();
if (window.getKiller() == window.ok()) {
int ncolors = window.colors()->getTextInt();
palette.resize(MID(1, ncolors, INT_MAX));
Transaction transaction(context, "Palette Size", ModifyDocument);
transaction.execute(new cmd::SetPalette(sprite, frame, &palette));
transaction.commit();
set_current_palette(&palette, false);
ui::Manager::getDefault()->invalidate();
}
}
Command* CommandFactory::createPaletteSizeCommand()
{
return new PaletteSizeCommand;
}
} // namespace app

View File

@ -80,6 +80,7 @@ FOR_EACH_COMMAND(OpenInFolder)
FOR_EACH_COMMAND(OpenWithApp)
FOR_EACH_COMMAND(Options)
FOR_EACH_COMMAND(PaletteEditor)
FOR_EACH_COMMAND(PaletteSize)
FOR_EACH_COMMAND(Paste)
FOR_EACH_COMMAND(PlayAnimation)
FOR_EACH_COMMAND(Redo)