2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
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
|
|
|
|
|
|
|
|
#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:
|
2015-04-21 03:27:09 +08:00
|
|
|
void updateStatusBar(Site& site) {
|
|
|
|
if (site.layer() != NULL)
|
2014-03-17 08:56:18 +08:00
|
|
|
StatusBar::instance()
|
|
|
|
->setStatusText(1000, "Layer `%s' selected",
|
2015-04-21 03:27:09 +08:00
|
|
|
site.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:
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-08-21 21:03:04 +08:00
|
|
|
return (current_editor != nullptr &&
|
|
|
|
current_editor->document());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GotoPreviousLayerCommand::onExecute(Context* context)
|
|
|
|
{
|
2015-08-21 21:03:04 +08:00
|
|
|
Site site = current_editor->getSite();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-04-21 03:27:09 +08:00
|
|
|
if (site.layerIndex() > 0)
|
|
|
|
site.layerIndex(site.layerIndex().previous());
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2015-08-21 21:03:04 +08:00
|
|
|
site.layerIndex(LayerIndex(site.sprite()->countLayers()-1));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Flash the current layer
|
2015-04-21 03:27:09 +08:00
|
|
|
current_editor->setLayer(site.layer());
|
2012-01-06 06:45:03 +08:00
|
|
|
current_editor->flashCurrentLayer();
|
|
|
|
|
2015-04-21 03:27:09 +08:00
|
|
|
updateStatusBar(site);
|
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:
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-08-21 21:03:04 +08:00
|
|
|
return (current_editor != nullptr &&
|
|
|
|
current_editor->document());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GotoNextLayerCommand::onExecute(Context* context)
|
|
|
|
{
|
2015-08-21 21:03:04 +08:00
|
|
|
Site site = current_editor->getSite();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 21:03:04 +08:00
|
|
|
if (site.layerIndex() < site.sprite()->countLayers()-1)
|
2015-04-21 03:27:09 +08:00
|
|
|
site.layerIndex(site.layerIndex().next());
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2015-04-21 03:27:09 +08:00
|
|
|
site.layerIndex(LayerIndex(0));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Flash the current layer
|
2015-04-21 03:27:09 +08:00
|
|
|
current_editor->setLayer(site.layer());
|
2012-01-06 06:45:03 +08:00
|
|
|
current_editor->flashCurrentLayer();
|
|
|
|
|
2015-04-21 03:27:09 +08:00
|
|
|
updateStatusBar(site);
|
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
|