2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2015-01-19 09:05:33 +08:00
|
|
|
* Copyright (C) 2001-2015 David Capello
|
2012-01-06 06:45:03 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/cmd/set_mask.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/context_access.h"
|
2012-06-16 10:37:59 +08:00
|
|
|
#include "app/file_selector.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/util/msk_file.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/mask.h"
|
|
|
|
#include "doc/sprite.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/alert.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
class LoadMaskCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
std::string m_filename;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LoadMaskCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new LoadMaskCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onLoadParams(Params* params);
|
|
|
|
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
LoadMaskCommand::LoadMaskCommand()
|
|
|
|
: Command("LoadMask",
|
|
|
|
"LoadMask",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
m_filename = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadMaskCommand::onLoadParams(Params* params)
|
|
|
|
{
|
|
|
|
m_filename = params->get("filename");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadMaskCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadMaskCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string filename = m_filename;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (context->isUiAvailable()) {
|
2012-06-16 10:37:59 +08:00
|
|
|
filename = app::show_file_selector("Load .msk File", filename, "msk");
|
2012-01-06 06:45:03 +08:00
|
|
|
if (filename.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_filename = filename;
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Mask> mask(load_msk_file(m_filename.c_str()));
|
2012-01-06 06:45:03 +08:00
|
|
|
if (!mask)
|
|
|
|
throw base::Exception("Error loading .msk file: %s",
|
|
|
|
static_cast<const char*>(m_filename.c_str()));
|
|
|
|
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(reader);
|
|
|
|
Document* document = writer.document();
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Mask Load", DoesntModifyDocument);
|
|
|
|
transaction.execute(new cmd::SetMask(document, mask));
|
|
|
|
transaction.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
document->generateMaskBoundaries();
|
|
|
|
update_screen_for_document(document);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createLoadMaskCommand()
|
|
|
|
{
|
|
|
|
return new LoadMaskCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|