2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 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
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/undo_transaction.h"
|
|
|
|
#include "app/undoers/set_mask.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "raster/mask.h"
|
|
|
|
#include "raster/sprite.h"
|
|
|
|
|
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();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new ReselectMaskCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
ReselectMaskCommand::ReselectMaskCommand()
|
|
|
|
: Command("ReselectMask",
|
|
|
|
"Reselect Mask",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReselectMaskCommand::onEnabled(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
|
|
|
Document* document(writer.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);
|
|
|
|
Document* document(writer.document());
|
2012-07-08 12:25:26 +08:00
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
UndoTransaction undo(writer.context(), "Mask Reselection", undo::DoesntModifyDocument);
|
2012-07-08 12:25:26 +08:00
|
|
|
if (undo.isEnabled())
|
|
|
|
undo.pushUndoer(new undoers::SetMask(undo.getObjects(), document));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-07-08 12:25:26 +08:00
|
|
|
// Make the mask visible again.
|
|
|
|
document->setMaskVisible(true);
|
|
|
|
|
|
|
|
undo.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
document->generateMaskBoundaries();
|
|
|
|
update_screen_for_document(document);
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createReselectMaskCommand()
|
|
|
|
{
|
|
|
|
return new ReselectMaskCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|