2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2020-06-12 22:33:55 +08:00
|
|
|
// Copyright (C) 2019-2020 Igara Studio S.A.
|
2018-08-21 03:00:59 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
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
|
|
|
|
2020-06-09 01:44:47 +08:00
|
|
|
#include "app/cmd/background_from_layer.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/modules/gui.h"
|
2018-08-21 03:00:59 +08:00
|
|
|
#include "app/tx.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/sprite.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2015-02-12 23:16:25 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class BackgroundFromLayerCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
BackgroundFromLayerCommand();
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 03:34:43 +08:00
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
BackgroundFromLayerCommand::BackgroundFromLayerCommand()
|
2017-12-02 02:10:21 +08:00
|
|
|
: Command(CommandId::BackgroundFromLayer(), CmdRecordableFlag)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundFromLayerCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
2014-11-17 10:03:30 +08:00
|
|
|
ContextFlags::ActiveLayerIsVisible |
|
|
|
|
ContextFlags::ActiveLayerIsEditable |
|
2015-01-19 09:05:33 +08:00
|
|
|
ContextFlags::ActiveLayerIsImage) &&
|
2012-01-06 06:45:03 +08:00
|
|
|
// Doesn't have a background layer
|
2016-10-18 00:48:52 +08:00
|
|
|
!context->checkFlags(ContextFlags::HasBackgroundLayer) &&
|
|
|
|
// Isn't a reference layer
|
2019-11-07 02:01:22 +08:00
|
|
|
!context->checkFlags(ContextFlags::ActiveLayerIsReference) &&
|
|
|
|
// Isn't a tilemap layer
|
|
|
|
// TODO support background tilemaps
|
|
|
|
!context->checkFlags(ContextFlags::ActiveLayerIsTilemap);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFromLayerCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
2018-07-07 22:54:44 +08:00
|
|
|
Doc* document(writer.document());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
{
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(writer, friendlyName());
|
2020-06-09 01:44:47 +08:00
|
|
|
tx(new cmd::BackgroundFromLayer(static_cast<LayerImage*>(writer.layer())));
|
2018-08-21 03:00:59 +08:00
|
|
|
tx.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2014-05-08 11:30:36 +08:00
|
|
|
|
2024-09-03 10:12:13 +08:00
|
|
|
update_screen_for_document(document);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createBackgroundFromLayerCommand()
|
|
|
|
{
|
|
|
|
return new BackgroundFromLayerCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|