mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 04:59:24 +00:00
Add the Palette menu with Load/Save commands
This commit is contained in:
parent
f59f6f7d5e
commit
ddf4a13490
11
data/gui.xml
11
data/gui.xml
@ -344,6 +344,14 @@
|
||||
<param name="frame" value="all" />
|
||||
</item>
|
||||
</menu>
|
||||
<menu text="&Palette">
|
||||
<item command="PaletteEditor" text="&Palette Editor">
|
||||
<param name="switch" value="true" />
|
||||
</item>
|
||||
<separator />
|
||||
<item command="LoadPalette" text="&Load Palette" />
|
||||
<item command="SavePalette" text="&Save Palette" />
|
||||
</menu>
|
||||
<menu text="Selec&t">
|
||||
<item command="MaskAll" text="&All" />
|
||||
<item command="DeselectMask" text="&Deselect" />
|
||||
@ -367,9 +375,6 @@
|
||||
<item command="Timeline" text="&Timeline">
|
||||
<param name="switch" value="true" />
|
||||
</item>
|
||||
<item command="PaletteEditor" text="&Palette Editor">
|
||||
<param name="switch" value="true" />
|
||||
</item>
|
||||
<item command="Preview" text="Previe&w" />
|
||||
<separator />
|
||||
<item command="Refresh" text="&Refresh && Reload Skin" />
|
||||
|
@ -46,6 +46,7 @@ add_library(app-library
|
||||
commands/cmd_layer_from_background.cpp
|
||||
commands/cmd_layer_properties.cpp
|
||||
commands/cmd_load_mask.cpp
|
||||
commands/cmd_load_palette.cpp
|
||||
commands/cmd_mask_all.cpp
|
||||
commands/cmd_mask_by_color.cpp
|
||||
commands/cmd_merge_down_layer.cpp
|
||||
@ -70,6 +71,7 @@ add_library(app-library
|
||||
commands/cmd_rotate_canvas.cpp
|
||||
commands/cmd_save_file.cpp
|
||||
commands/cmd_save_mask.cpp
|
||||
commands/cmd_save_palette.cpp
|
||||
commands/cmd_scroll.cpp
|
||||
commands/cmd_sprite_editor.cpp
|
||||
commands/cmd_sprite_properties.cpp
|
||||
|
88
src/app/commands/cmd_load_palette.cpp
Normal file
88
src/app/commands/cmd_load_palette.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/file_selector.h"
|
||||
#include "app/modules/palettes.h"
|
||||
#include "app/undo_transaction.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/palette.h"
|
||||
#include "ui/alert.h"
|
||||
#include "ui/manager.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
class LoadPaletteCommand : public Command {
|
||||
public:
|
||||
LoadPaletteCommand();
|
||||
Command* clone() { return new LoadPaletteCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context) OVERRIDE;
|
||||
};
|
||||
|
||||
LoadPaletteCommand::LoadPaletteCommand()
|
||||
: Command("LoadPalette",
|
||||
"Load Palette",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
void LoadPaletteCommand::onExecute(Context* context)
|
||||
{
|
||||
ContextWriter writer(context);
|
||||
|
||||
base::string filename = app::show_file_selector("Load Palette", "", "png,pcx,bmp,tga,lbm,col,gpl");
|
||||
if (!filename.empty()) {
|
||||
base::UniquePtr<raster::Palette> palette(raster::Palette::load(filename.c_str()));
|
||||
if (!palette) {
|
||||
Alert::show("Error<<Loading palette file||&Close");
|
||||
}
|
||||
else if (writer.document()) {
|
||||
UndoTransaction undoTransaction(writer.context(), "Load Palette");
|
||||
writer.document()->getApi()
|
||||
.setPalette(writer.sprite(), writer.frame(), palette);
|
||||
undoTransaction.commit();
|
||||
}
|
||||
else {
|
||||
set_default_palette(palette);
|
||||
}
|
||||
|
||||
// Set the palette calling the hooks
|
||||
set_current_palette(palette, false);
|
||||
|
||||
// Redraw the entire screen
|
||||
ui::Manager::getDefault()->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
Command* CommandFactory::createLoadPaletteCommand()
|
||||
{
|
||||
return new LoadPaletteCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -89,8 +89,6 @@ protected:
|
||||
void onMoreOptionsClick(Event& ev);
|
||||
void onCopyColorsClick(Event& ev);
|
||||
void onPasteColorsClick(Event& ev);
|
||||
void onLoadPaletteClick(Event& ev);
|
||||
void onSavePaletteClick(Event& ev);
|
||||
void onRampClick(Event& ev);
|
||||
void onQuantizeClick(Event& ev);
|
||||
|
||||
@ -115,8 +113,6 @@ private:
|
||||
HsvSliders m_hsvSliders;
|
||||
Button m_copyButton;
|
||||
Button m_pasteButton;
|
||||
Button m_loadButton;
|
||||
Button m_saveButton;
|
||||
Button m_rampButton;
|
||||
Button m_quantizeButton;
|
||||
|
||||
@ -257,8 +253,6 @@ PaletteEntryEditor::PaletteEntryEditor()
|
||||
, m_moreOptions("+")
|
||||
, m_copyButton("Copy")
|
||||
, m_pasteButton("Paste")
|
||||
, m_loadButton("Load")
|
||||
, m_saveButton("Save")
|
||||
, m_rampButton("Ramp")
|
||||
, m_quantizeButton("Quantize")
|
||||
, m_disableHexUpdate(false)
|
||||
@ -276,8 +270,6 @@ PaletteEntryEditor::PaletteEntryEditor()
|
||||
setup_mini_look(&m_moreOptions);
|
||||
setup_mini_look(&m_copyButton);
|
||||
setup_mini_look(&m_pasteButton);
|
||||
setup_mini_look(&m_loadButton);
|
||||
setup_mini_look(&m_saveButton);
|
||||
setup_mini_look(&m_rampButton);
|
||||
setup_mini_look(&m_quantizeButton);
|
||||
|
||||
@ -297,13 +289,6 @@ PaletteEntryEditor::PaletteEntryEditor()
|
||||
box->addChild(&m_pasteButton);
|
||||
m_bottomBox.addChild(box);
|
||||
}
|
||||
{
|
||||
Box* box = new Box(JI_HORIZONTAL);
|
||||
box->child_spacing = 0;
|
||||
box->addChild(&m_loadButton);
|
||||
box->addChild(&m_saveButton);
|
||||
m_bottomBox.addChild(box);
|
||||
}
|
||||
m_bottomBox.addChild(&m_rampButton);
|
||||
m_bottomBox.addChild(&m_quantizeButton);
|
||||
|
||||
@ -322,8 +307,6 @@ PaletteEntryEditor::PaletteEntryEditor()
|
||||
m_moreOptions.Click.connect(&PaletteEntryEditor::onMoreOptionsClick, this);
|
||||
m_copyButton.Click.connect(&PaletteEntryEditor::onCopyColorsClick, this);
|
||||
m_pasteButton.Click.connect(&PaletteEntryEditor::onPasteColorsClick, this);
|
||||
m_loadButton.Click.connect(&PaletteEntryEditor::onLoadPaletteClick, this);
|
||||
m_saveButton.Click.connect(&PaletteEntryEditor::onSavePaletteClick, this);
|
||||
m_rampButton.Click.connect(&PaletteEntryEditor::onRampClick, this);
|
||||
m_quantizeButton.Click.connect(&PaletteEntryEditor::onQuantizeClick, this);
|
||||
|
||||
@ -574,47 +557,6 @@ void PaletteEntryEditor::onPasteColorsClick(Event& ev)
|
||||
onPalChange();
|
||||
}
|
||||
|
||||
void PaletteEntryEditor::onLoadPaletteClick(Event& ev)
|
||||
{
|
||||
Palette *palette;
|
||||
base::string filename = app::show_file_selector("Load Palette", "", "png,pcx,bmp,tga,lbm,col,gpl");
|
||||
if (!filename.empty()) {
|
||||
palette = Palette::load(filename.c_str());
|
||||
if (!palette) {
|
||||
Alert::show("Error<<Loading palette file||&Close");
|
||||
}
|
||||
else {
|
||||
setNewPalette(palette, "Load Palette");
|
||||
delete palette;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEntryEditor::onSavePaletteClick(Event& ev)
|
||||
{
|
||||
base::string filename;
|
||||
int ret;
|
||||
|
||||
again:
|
||||
filename = app::show_file_selector("Save Palette", "", "png,pcx,bmp,tga,col,gpl");
|
||||
if (!filename.empty()) {
|
||||
if (base::file_exists(filename)) {
|
||||
ret = Alert::show("Warning<<File exists, overwrite it?<<%s||&Yes||&No||&Cancel",
|
||||
base::get_file_name(filename).c_str());
|
||||
|
||||
if (ret == 2)
|
||||
goto again;
|
||||
else if (ret != 1)
|
||||
return;
|
||||
}
|
||||
|
||||
Palette* palette = get_current_palette();
|
||||
if (!palette->save(filename.c_str())) {
|
||||
Alert::show("Error<<Saving palette file||&Close");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteEntryEditor::onRampClick(Event& ev)
|
||||
{
|
||||
PaletteView* palette_editor = ColorBar::instance()->getPaletteView();
|
||||
|
82
src/app/commands/cmd_save_palette.cpp
Normal file
82
src/app/commands/cmd_save_palette.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2013 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/commands/command.h"
|
||||
#include "app/file_selector.h"
|
||||
#include "app/modules/palettes.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/path.h"
|
||||
#include "raster/palette.h"
|
||||
#include "ui/alert.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
class SavePaletteCommand : public Command {
|
||||
public:
|
||||
SavePaletteCommand();
|
||||
Command* clone() { return new SavePaletteCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context) OVERRIDE;
|
||||
};
|
||||
|
||||
SavePaletteCommand::SavePaletteCommand()
|
||||
: Command("SavePalette",
|
||||
"Save Palette",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
void SavePaletteCommand::onExecute(Context* context)
|
||||
{
|
||||
base::string filename;
|
||||
int ret;
|
||||
|
||||
again:
|
||||
filename = app::show_file_selector("Save Palette", "", "png,pcx,bmp,tga,col,gpl");
|
||||
if (!filename.empty()) {
|
||||
if (base::file_exists(filename)) {
|
||||
ret = Alert::show("Warning<<File exists, overwrite it?<<%s||&Yes||&No||&Cancel",
|
||||
base::get_file_name(filename).c_str());
|
||||
|
||||
if (ret == 2)
|
||||
goto again;
|
||||
else if (ret != 1)
|
||||
return;
|
||||
}
|
||||
|
||||
raster::Palette* palette = get_current_palette();
|
||||
if (!palette->save(filename.c_str())) {
|
||||
Alert::show("Error<<Saving palette file||&Close");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Command* CommandFactory::createSavePaletteCommand()
|
||||
{
|
||||
return new SavePaletteCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -64,6 +64,7 @@ FOR_EACH_COMMAND(Launch)
|
||||
FOR_EACH_COMMAND(LayerFromBackground)
|
||||
FOR_EACH_COMMAND(LayerProperties)
|
||||
FOR_EACH_COMMAND(LoadMask)
|
||||
FOR_EACH_COMMAND(LoadPalette)
|
||||
FOR_EACH_COMMAND(MakeUniqueEditor)
|
||||
FOR_EACH_COMMAND(MaskAll)
|
||||
FOR_EACH_COMMAND(MaskByColor)
|
||||
@ -93,6 +94,7 @@ FOR_EACH_COMMAND(SaveFile)
|
||||
FOR_EACH_COMMAND(SaveFileAs)
|
||||
FOR_EACH_COMMAND(SaveFileCopyAs)
|
||||
FOR_EACH_COMMAND(SaveMask)
|
||||
FOR_EACH_COMMAND(SavePalette)
|
||||
FOR_EACH_COMMAND(Scroll)
|
||||
FOR_EACH_COMMAND(ShowGrid)
|
||||
FOR_EACH_COMMAND(SnapToGrid)
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "app/undoers/set_layer_name.h"
|
||||
#include "app/undoers/set_mask.h"
|
||||
#include "app/undoers/set_mask_position.h"
|
||||
#include "app/undoers/set_palette_colors.h"
|
||||
#include "app/undoers/set_sprite_pixel_format.h"
|
||||
#include "app/undoers/set_sprite_size.h"
|
||||
#include "app/undoers/set_stock_pixel_format.h"
|
||||
@ -71,6 +72,7 @@
|
||||
#include "raster/stock.h"
|
||||
|
||||
|
||||
|
||||
namespace app {
|
||||
|
||||
DocumentApi::DocumentApi(Document* document, undo::UndoersCollector* undoers)
|
||||
@ -1089,4 +1091,29 @@ void DocumentApi::deselectMask()
|
||||
m_document->setMaskVisible(false);
|
||||
}
|
||||
|
||||
void DocumentApi::setPalette(Sprite* sprite, FrameNumber frame, Palette* newPalette)
|
||||
{
|
||||
Palette* currentSpritePalette = sprite->getPalette(frame); // Sprite current pal
|
||||
int from, to;
|
||||
|
||||
// Check differences between current sprite palette and current system palette
|
||||
from = to = -1;
|
||||
currentSpritePalette->countDiff(newPalette, &from, &to);
|
||||
|
||||
if (from >= 0 && to >= from) {
|
||||
DocumentUndo* undo = m_document->getUndo();
|
||||
|
||||
// Add undo information to save the range of pal entries that will be modified.
|
||||
if (undo->isEnabled()) {
|
||||
m_undoers->pushUndoer
|
||||
(new undoers::SetPaletteColors(getObjects(),
|
||||
sprite, currentSpritePalette,
|
||||
frame, from, to));
|
||||
}
|
||||
|
||||
// Change the sprite palette
|
||||
sprite->setPalette(newPalette, false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -32,6 +32,7 @@ namespace raster {
|
||||
class LayerFolder;
|
||||
class LayerImage;
|
||||
class Mask;
|
||||
class Palette;
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
@ -107,6 +108,9 @@ namespace app {
|
||||
void setMaskPosition(int x, int y);
|
||||
void deselectMask();
|
||||
|
||||
// Palette API
|
||||
void setPalette(Sprite* sprite, FrameNumber frame, Palette* newPalette);
|
||||
|
||||
private:
|
||||
undo::ObjectsContainer* getObjects() const;
|
||||
void addFrameForLayer(Layer* layer, FrameNumber frame);
|
||||
|
Loading…
Reference in New Issue
Block a user