Add Ctrl+T to transform the cel content (close #560)

This commit is contained in:
David Capello 2014-12-13 19:32:58 -03:00
parent 702d99af2d
commit 5c9240d4d1
4 changed files with 113 additions and 0 deletions

View File

@ -80,6 +80,7 @@
<key command="PlayAnimation" shortcut="Enter" />
<!-- Select -->
<key command="MaskAll" shortcut="Ctrl+A" mac="Cmd+A" />
<key command="MaskContent" shortcut="Ctrl+T" mac="Cmd+T" />
<key command="DeselectMask" shortcut="Ctrl+D" mac="Cmd+D" />
<key command="ReselectMask" shortcut="Ctrl+Shift+D" mac="Cmd+Shift+D" />
<key command="InvertMask" shortcut="Ctrl+Shift+I" mac="Cmd+Shift+I" />
@ -431,6 +432,7 @@
<param name="target" value="mask" />
<param name="orientation" value="vertical" />
</item>
<item command="MaskContent" text="Transfor&amp;m" />
<separator />
<item command="ReplaceColor" text="R&amp;eplace Color..." />
<item command="InvertColor" text="&amp;Invert" />

View File

@ -77,6 +77,7 @@ add_library(app-lib
commands/cmd_load_palette.cpp
commands/cmd_mask_all.cpp
commands/cmd_mask_by_color.cpp
commands/cmd_mask_content.cpp
commands/cmd_merge_down_layer.cpp
commands/cmd_move_cel.cpp
commands/cmd_move_mask.cpp

View File

@ -0,0 +1,109 @@
/* 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/app.h"
#include "app/commands/command.h"
#include "app/context_access.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/tools/tool_box.h"
#include "app/ui/editor/editor.h"
#include "app/ui/toolbar.h"
#include "app/undo_transaction.h"
#include "app/undoers/set_mask.h"
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
#include "doc/image.h"
#include "doc/mask.h"
#include "doc/sprite.h"
namespace app {
class MaskContentCommand : public Command {
public:
MaskContentCommand();
Command* clone() const override { return new MaskContentCommand(*this); }
protected:
bool onEnabled(Context* context);
void onExecute(Context* context);
};
MaskContentCommand::MaskContentCommand()
: Command("MaskContent",
"Mask Content",
CmdRecordableFlag)
{
}
bool MaskContentCommand::onEnabled(Context* context)
{
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::ActiveLayerIsImage);
}
void MaskContentCommand::onExecute(Context* context)
{
ContextWriter writer(context);
Document* document(writer.document());
Sprite* sprite(writer.sprite());
Layer* layer = writer.layer();
Cel* cel = writer.cel(); // Get current cel (can be NULL)
if (!cel)
return;
UndoTransaction undo(writer.context(), "Select Content", undo::DoesntModifyDocument);
if (undo.isEnabled())
undo.pushUndoer(new undoers::SetMask(undo.getObjects(), document));
gfx::Rect imgBounds = cel->image()->bounds();
if (algorithm::shrink_bounds(cel->image(), imgBounds,
cel->image()->maskColor())) {
document->mask()->replace(
imgBounds.offset(cel->bounds().getOrigin()));
document->setMaskVisible(true);
document->resetTransformation();
}
else {
document->mask()->clear();
document->setMaskVisible(false);
}
undo.commit();
document->generateMaskBoundaries();
// Select marquee tool
if (tools::Tool* tool = App::instance()->getToolBox()
->getToolById(tools::WellKnownTools::RectangularMarquee)) {
ToolBar::instance()->selectTool(tool);
current_editor->startSelectionTransformation(gfx::Point(0, 0));
}
update_screen_for_document(document);
}
Command* CommandFactory::createMaskContentCommand()
{
return new MaskContentCommand;
}
} // namespace app

View File

@ -70,6 +70,7 @@ FOR_EACH_COMMAND(LoadPalette)
FOR_EACH_COMMAND(MakeUniqueEditor)
FOR_EACH_COMMAND(MaskAll)
FOR_EACH_COMMAND(MaskByColor)
FOR_EACH_COMMAND(MaskContent)
FOR_EACH_COMMAND(MergeDownLayer)
FOR_EACH_COMMAND(MoveCel)
FOR_EACH_COMMAND(MoveMask)