mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-24 12:41:08 +00:00
Add SetPaletteCommand
This commit is contained in:
parent
2b7bd3e831
commit
283d883d37
@ -75,6 +75,7 @@ add_library(app-lib
|
||||
commands/cmd_save_mask.cpp
|
||||
commands/cmd_save_palette.cpp
|
||||
commands/cmd_scroll.cpp
|
||||
commands/cmd_set_palette.cpp
|
||||
commands/cmd_sprite_editor.cpp
|
||||
commands/cmd_sprite_properties.cpp
|
||||
commands/cmd_sprite_size.cpp
|
||||
|
@ -20,18 +20,15 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/commands/cmd_set_palette.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/context.h"
|
||||
#include "app/file_selector.h"
|
||||
#include "app/ini_file.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 {
|
||||
|
||||
@ -55,30 +52,18 @@ LoadPaletteCommand::LoadPaletteCommand()
|
||||
|
||||
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_config_string("GfxMode", "Palette", filename.c_str());
|
||||
SetPaletteCommand* cmd = static_cast<SetPaletteCommand*>(
|
||||
CommandsModule::instance()->getCommandByName(CommandId::SetPalette));
|
||||
cmd->setPalette(palette);
|
||||
context->executeCommand(cmd);
|
||||
}
|
||||
|
||||
// Set the palette calling the hooks
|
||||
set_current_palette(palette, false);
|
||||
|
||||
// Redraw the entire screen
|
||||
ui::Manager::getDefault()->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
80
src/app/commands/cmd_set_palette.cpp
Normal file
80
src/app/commands/cmd_set_palette.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2014 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/cmd_set_palette.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/file_selector.h"
|
||||
#include "app/ini_file.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;
|
||||
|
||||
SetPaletteCommand::SetPaletteCommand()
|
||||
: Command("SetPalette",
|
||||
"Set Palette",
|
||||
CmdRecordableFlag)
|
||||
, m_palette(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void SetPaletteCommand::onExecute(Context* context)
|
||||
{
|
||||
ASSERT(m_palette);
|
||||
if (!m_palette)
|
||||
return;
|
||||
|
||||
ContextWriter writer(context);
|
||||
|
||||
if (writer.document()) {
|
||||
UndoTransaction undoTransaction(writer.context(), "Set Palette");
|
||||
writer.document()->getApi()
|
||||
.setPalette(writer.sprite(), writer.frame(), m_palette);
|
||||
undoTransaction.commit();
|
||||
}
|
||||
// Set default palette
|
||||
else {
|
||||
set_default_palette(m_palette);
|
||||
set_config_string("GfxMode", "Palette", m_palette->getFilename().c_str());
|
||||
}
|
||||
|
||||
// Set the palette calling the hooks
|
||||
set_current_palette(m_palette, false);
|
||||
|
||||
// Redraw the entire screen
|
||||
ui::Manager::getDefault()->invalidate();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createSetPaletteCommand()
|
||||
{
|
||||
return new SetPaletteCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
48
src/app/commands/cmd_set_palette.h
Normal file
48
src/app/commands/cmd_set_palette.h
Normal file
@ -0,0 +1,48 @@
|
||||
/* Aseprite
|
||||
* Copyright (C) 2001-2014 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
|
||||
*/
|
||||
|
||||
#ifndef APP_COMMANDS_CMD_SET_PALETTE_H_INCLUDED
|
||||
#define APP_COMMANDS_CMD_SET_PALETTE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/commands/command.h"
|
||||
#include "base/compiler_specific.h"
|
||||
|
||||
namespace raster {
|
||||
class Palette;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
|
||||
class SetPaletteCommand : public Command {
|
||||
public:
|
||||
SetPaletteCommand();
|
||||
Command* clone() const OVERRIDE { return new SetPaletteCommand(*this); }
|
||||
|
||||
void setPalette(raster::Palette* palette) { m_palette = palette; }
|
||||
|
||||
protected:
|
||||
virtual void onExecute(Context* context) OVERRIDE;
|
||||
|
||||
private:
|
||||
raster::Palette* m_palette;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -97,6 +97,7 @@ FOR_EACH_COMMAND(SaveFileCopyAs)
|
||||
FOR_EACH_COMMAND(SaveMask)
|
||||
FOR_EACH_COMMAND(SavePalette)
|
||||
FOR_EACH_COMMAND(Scroll)
|
||||
FOR_EACH_COMMAND(SetPalette)
|
||||
FOR_EACH_COMMAND(ShowGrid)
|
||||
FOR_EACH_COMMAND(SnapToGrid)
|
||||
FOR_EACH_COMMAND(SplitEditorHorizontally)
|
||||
|
Loading…
x
Reference in New Issue
Block a user