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
|
|
|
|
|
|
|
|
#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/ui/editor/editor.h"
|
|
|
|
#include "app/ui/status_bar.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 {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-03-17 08:56:18 +08:00
|
|
|
class GotoCommand : public Command {
|
|
|
|
public:
|
|
|
|
GotoCommand(const char* short_name, const char* friendly_name, CommandFlags flags)
|
|
|
|
: Command(short_name, friendly_name, flags) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void updateStatusBar(DocumentLocation& location) {
|
|
|
|
if (location.layer() != NULL)
|
|
|
|
StatusBar::instance()
|
|
|
|
->setStatusText(1000, "Layer `%s' selected",
|
2014-07-30 12:28:15 +08:00
|
|
|
location.layer()->name().c_str());
|
2014-03-17 08:56:18 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GotoPreviousLayerCommand : public GotoCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
GotoPreviousLayerCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoPreviousLayerCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
GotoPreviousLayerCommand::GotoPreviousLayerCommand()
|
2014-03-17 08:56:18 +08:00
|
|
|
: GotoCommand("GotoPreviousLayer",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Previous Layer",
|
2014-03-17 08:56:18 +08:00
|
|
|
CmdUIOnlyFlag)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GotoPreviousLayerCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GotoPreviousLayerCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite = reader.sprite();
|
|
|
|
DocumentLocation location = *reader.location();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
if (location.layerIndex() > 0)
|
|
|
|
location.layerIndex(location.layerIndex().previous());
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2013-03-12 07:29:45 +08:00
|
|
|
location.layerIndex(LayerIndex(sprite->countLayers()-1));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Flash the current layer
|
|
|
|
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
|
2013-03-12 07:29:45 +08:00
|
|
|
current_editor->setLayer(location.layer());
|
2012-01-06 06:45:03 +08:00
|
|
|
current_editor->flashCurrentLayer();
|
|
|
|
|
2014-03-17 08:56:18 +08:00
|
|
|
updateStatusBar(location);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2014-03-17 08:56:18 +08:00
|
|
|
class GotoNextLayerCommand : public GotoCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
GotoNextLayerCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoNextLayerCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
GotoNextLayerCommand::GotoNextLayerCommand()
|
2014-03-17 08:56:18 +08:00
|
|
|
: GotoCommand("GotoNextLayer",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Next Layer",
|
2014-03-17 08:56:18 +08:00
|
|
|
CmdUIOnlyFlag)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GotoNextLayerCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GotoNextLayerCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite = reader.sprite();
|
|
|
|
DocumentLocation location = *reader.location();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
if (location.layerIndex() < sprite->countLayers()-1)
|
|
|
|
location.layerIndex(location.layerIndex().next());
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2013-03-12 07:29:45 +08:00
|
|
|
location.layerIndex(LayerIndex(0));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Flash the current layer
|
|
|
|
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
|
2013-03-12 07:29:45 +08:00
|
|
|
current_editor->setLayer(location.layer());
|
2012-01-06 06:45:03 +08:00
|
|
|
current_editor->flashCurrentLayer();
|
|
|
|
|
2014-03-17 08:56:18 +08:00
|
|
|
updateStatusBar(location);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoPreviousLayerCommand()
|
|
|
|
{
|
|
|
|
return new GotoPreviousLayerCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoNextLayerCommand()
|
|
|
|
{
|
|
|
|
return new GotoNextLayerCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|