2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2020-02-06 04:24:21 +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
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/cmd/reselect_mask.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/mask.h"
|
|
|
|
#include "doc/sprite.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class ReselectMaskCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
ReselectMaskCommand();
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2025-07-24 07:00:12 +08:00
|
|
|
ReselectMaskCommand::ReselectMaskCommand() : Command(CommandId::ReselectMask())
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReselectMaskCommand::onEnabled(Context* context)
|
|
|
|
{
|
2020-02-06 04:24:21 +08:00
|
|
|
if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveSprite))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const ContextReader reader(context);
|
|
|
|
const Doc* document(reader.document());
|
2012-01-06 06:45:03 +08:00
|
|
|
return document && // The document does exist
|
|
|
|
!document->isMaskVisible() && // The mask is hidden
|
2014-07-30 12:28:15 +08:00
|
|
|
document->mask() && // The mask does exist
|
|
|
|
!document->mask()->isEmpty(); // But it is not empty
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReselectMaskCommand::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-07-08 12:25:26 +08:00
|
|
|
{
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(writer, "Reselect", DoesntModifyDocument);
|
2018-08-21 03:00:59 +08:00
|
|
|
tx(new cmd::ReselectMask(document));
|
|
|
|
tx.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
update_screen_for_document(document);
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createReselectMaskCommand()
|
|
|
|
{
|
|
|
|
return new ReselectMaskCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|