2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
2022-10-20 15:31:22 +00:00
|
|
|
// Copyright (C) 2019-2022 Igara Studio S.A.
|
2018-08-20 19:00:59 +00:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 15:16:25 +00:00
|
|
|
//
|
2016-08-26 20:02:58 +00:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2014-08-08 04:00:02 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-02-15 12:48:38 +00:00
|
|
|
#include "app/app.h"
|
2015-07-06 21:48:55 +00:00
|
|
|
#include "app/cmd/shift_masked_cel.h"
|
2014-08-08 04:00:02 +00:00
|
|
|
#include "app/commands/cmd_move_mask.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/context_access.h"
|
2018-07-07 06:07:16 +00:00
|
|
|
#include "app/doc_api.h"
|
2017-12-01 02:41:45 +00:00
|
|
|
#include "app/i18n/strings.h"
|
2014-08-08 04:00:02 +00:00
|
|
|
#include "app/modules/gui.h"
|
2015-02-15 12:48:38 +00:00
|
|
|
#include "app/pref/preferences.h"
|
2018-08-20 19:00:59 +00:00
|
|
|
#include "app/tx.h"
|
2018-07-15 02:24:49 +00:00
|
|
|
#include "app/ui/doc_view.h"
|
2015-02-15 12:48:38 +00:00
|
|
|
#include "app/ui/editor/editor.h"
|
2016-05-18 15:03:28 +00:00
|
|
|
#include "app/ui_context.h"
|
2014-10-29 14:58:03 +00:00
|
|
|
#include "base/convert_to.h"
|
2014-10-21 01:21:31 +00:00
|
|
|
#include "doc/mask.h"
|
|
|
|
#include "doc/sprite.h"
|
2017-12-01 02:41:45 +00:00
|
|
|
#include "fmt/format.h"
|
2014-08-08 04:00:02 +00:00
|
|
|
#include "ui/view.h"
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
|
|
|
MoveMaskCommand::MoveMaskCommand()
|
2017-12-01 18:10:21 +00:00
|
|
|
: Command(CommandId::MoveMask(), CmdRecordableFlag)
|
2014-08-08 04:00:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-11 18:40:22 +00:00
|
|
|
void MoveMaskCommand::onLoadParams(const Params& params)
|
2014-08-08 04:00:02 +00:00
|
|
|
{
|
2015-03-11 18:40:22 +00:00
|
|
|
std::string target = params.get("target");
|
2014-08-25 02:33:13 +00:00
|
|
|
if (target == "boundaries") m_target = Boundaries;
|
2014-08-08 04:00:02 +00:00
|
|
|
else if (target == "content") m_target = Content;
|
|
|
|
|
2015-07-06 21:48:55 +00:00
|
|
|
if (params.has_param("wrap"))
|
|
|
|
m_wrap = params.get_as<bool>("wrap");
|
|
|
|
else
|
|
|
|
m_wrap = false;
|
2017-12-01 02:41:45 +00:00
|
|
|
|
|
|
|
m_moveThing.onLoadParams(params);
|
2014-08-08 04:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MoveMaskCommand::onEnabled(Context* context)
|
|
|
|
{
|
2015-07-06 21:48:55 +00:00
|
|
|
switch (m_target) {
|
|
|
|
|
|
|
|
case Boundaries:
|
|
|
|
return context->checkFlags(ContextFlags::HasActiveDocument |
|
|
|
|
ContextFlags::HasVisibleMask);
|
|
|
|
|
|
|
|
case Content:
|
|
|
|
if (m_wrap)
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasVisibleMask |
|
2017-12-01 20:18:23 +00:00
|
|
|
ContextFlags::HasActiveImage |
|
|
|
|
ContextFlags::ActiveLayerIsEditable);
|
2022-10-20 15:31:22 +00:00
|
|
|
else {
|
|
|
|
auto editor = Editor::activeEditor();
|
|
|
|
return (editor != nullptr) &&
|
2022-07-07 19:33:39 +00:00
|
|
|
context->checkFlags(ContextFlags::HasActiveDocument |
|
|
|
|
ContextFlags::HasVisibleMask |
|
|
|
|
ContextFlags::HasActiveImage);
|
2022-10-20 15:31:22 +00:00
|
|
|
}
|
2015-07-06 21:48:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-08-08 04:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveMaskCommand::onExecute(Context* context)
|
|
|
|
{
|
2017-12-01 02:41:45 +00:00
|
|
|
gfx::Point delta = m_moveThing.getDelta(context);
|
2016-05-18 15:03:28 +00:00
|
|
|
|
|
|
|
switch (m_target) {
|
|
|
|
|
|
|
|
case Boundaries: {
|
|
|
|
ContextWriter writer(context);
|
2018-07-07 14:54:44 +00:00
|
|
|
Doc* document(writer.document());
|
2016-05-18 15:03:28 +00:00
|
|
|
{
|
2023-12-13 00:34:30 +00:00
|
|
|
Tx tx(writer, "Move Selection", DoesntModifyDocument);
|
2016-05-18 15:03:28 +00:00
|
|
|
gfx::Point pt = document->mask()->bounds().origin();
|
2018-08-20 19:00:59 +00:00
|
|
|
document->getApi(tx).setMaskPosition(pt.x+delta.x, pt.y+delta.y);
|
|
|
|
tx.commit();
|
2016-05-18 15:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_screen_for_document(document);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Content:
|
|
|
|
if (m_wrap) {
|
|
|
|
ContextWriter writer(context);
|
|
|
|
if (writer.cel()) {
|
|
|
|
// Rotate content
|
2023-12-13 00:34:30 +00:00
|
|
|
Tx tx(writer, "Shift Pixels");
|
2018-08-20 19:00:59 +00:00
|
|
|
tx(new cmd::ShiftMaskedCel(writer.cel(), delta.x, delta.y));
|
|
|
|
tx.commit();
|
2016-05-18 15:03:28 +00:00
|
|
|
}
|
|
|
|
update_screen_for_document(writer.document());
|
|
|
|
}
|
|
|
|
else {
|
2022-10-20 15:31:22 +00:00
|
|
|
auto editor = Editor::activeEditor();
|
|
|
|
editor->startSelectionTransformation(delta, 0.0);
|
2016-05-18 15:03:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 14:58:03 +00:00
|
|
|
std::string MoveMaskCommand::onGetFriendlyName() const
|
|
|
|
{
|
2017-12-01 02:41:45 +00:00
|
|
|
std::string content;
|
2014-10-29 14:58:03 +00:00
|
|
|
switch (m_target) {
|
2017-12-01 02:41:45 +00:00
|
|
|
case Boundaries: content = Strings::commands_MoveMask_Boundaries(); break;
|
|
|
|
case Content: content = Strings::commands_MoveMask_Content(); break;
|
2014-10-29 14:58:03 +00:00
|
|
|
}
|
2017-12-01 02:41:45 +00:00
|
|
|
return fmt::format(getBaseFriendlyName(),
|
|
|
|
content, m_moveThing.getFriendlyString());
|
2014-10-29 14:58:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 04:00:02 +00:00
|
|
|
Command* CommandFactory::createMoveMaskCommand()
|
|
|
|
{
|
|
|
|
return new MoveMaskCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace app
|