mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-27 06:35:16 +00:00
Add command to change the palette size manually with a number
This commit is contained in:
parent
3accd85662
commit
a12816c04e
@ -725,6 +725,7 @@
|
||||
<item command="PaletteEditor" text="&Palette Editor">
|
||||
<param name="switch" value="true" />
|
||||
</item>
|
||||
<item command="PaletteSize" text="Palette Si&ze" />
|
||||
<separator />
|
||||
<item command="SetPaletteEntrySize" text="&Small Size">
|
||||
<param name="size" value="7" />
|
||||
|
18
data/widgets/palette_size.xml
Normal file
18
data/widgets/palette_size.xml
Normal 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="&OK" closewindow="true" id="ok" magnet="true" minwidth="60" />
|
||||
<button text="&Cancel" closewindow="true" />
|
||||
</box>
|
||||
</grid>
|
||||
</window>
|
||||
</gui>
|
@ -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
|
||||
|
79
src/app/commands/cmd_palette_size.cpp
Normal file
79
src/app/commands/cmd_palette_size.cpp
Normal 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
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user