2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2016-06-11 02:23:45 +08:00
|
|
|
// Copyright (C) 2001-2016 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
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"
|
2016-06-11 02:23:45 +08:00
|
|
|
#include "app/ui/timeline.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
|
|
|
|
2016-06-11 02:23:45 +08:00
|
|
|
class GotoLayerCommand : public Command {
|
2014-03-17 08:56:18 +08:00
|
|
|
public:
|
2016-06-11 02:23:45 +08:00
|
|
|
GotoLayerCommand(int offset,
|
|
|
|
const char* shortName,
|
|
|
|
const char* friendlyName,
|
|
|
|
CommandFlags flags)
|
|
|
|
: Command(shortName, friendlyName, flags),
|
|
|
|
m_offset(offset) {
|
2014-03-17 08:56:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-06-11 02:23:45 +08:00
|
|
|
|
|
|
|
bool onEnabled(Context* context) override {
|
|
|
|
return (current_editor &&
|
|
|
|
current_editor->document());
|
|
|
|
}
|
|
|
|
|
|
|
|
void onExecute(Context* context) override {
|
|
|
|
Site site = current_editor->getSite();
|
|
|
|
|
|
|
|
Layer* layer = site.layer();
|
|
|
|
if (!layer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_offset > 0) {
|
|
|
|
int i = m_offset;
|
|
|
|
while (i-- > 0) {
|
2016-12-08 20:11:54 +08:00
|
|
|
layer = layer->getNextBrowsable();
|
2016-06-21 11:02:13 +08:00
|
|
|
if (!layer)
|
|
|
|
layer = site.sprite()->firstBrowsableLayer();
|
2016-06-11 02:23:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_offset < 0) {
|
|
|
|
int i = m_offset;
|
|
|
|
while (i++ < 0) {
|
2016-12-08 20:11:54 +08:00
|
|
|
layer = layer->getPreviousBrowsable();
|
2016-06-15 02:00:11 +08:00
|
|
|
if (!layer)
|
2016-06-21 08:15:35 +08:00
|
|
|
layer = site.sprite()->root()->lastLayer();
|
2016-06-11 02:23:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 02:00:11 +08:00
|
|
|
site.layer(layer);
|
2016-06-11 02:23:45 +08:00
|
|
|
|
|
|
|
// Flash the current layer
|
|
|
|
current_editor->setLayer(site.layer());
|
|
|
|
current_editor->flashCurrentLayer();
|
|
|
|
|
|
|
|
updateStatusBar(site);
|
|
|
|
}
|
|
|
|
|
2015-04-21 03:27:09 +08:00
|
|
|
void updateStatusBar(Site& site) {
|
|
|
|
if (site.layer() != NULL)
|
2016-06-11 02:23:45 +08:00
|
|
|
StatusBar::instance()->setStatusText(
|
|
|
|
1000, "%s '%s' selected",
|
|
|
|
(site.layer()->isGroup() ? "Group": "Layer"),
|
|
|
|
site.layer()->name().c_str());
|
2014-03-17 08:56:18 +08:00
|
|
|
}
|
2016-06-11 02:23:45 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_offset;
|
2014-03-17 08:56:18 +08:00
|
|
|
};
|
|
|
|
|
2016-06-11 02:23:45 +08:00
|
|
|
class GotoPreviousLayerCommand : public GotoLayerCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
2016-06-11 02:23:45 +08:00
|
|
|
GotoPreviousLayerCommand()
|
|
|
|
: GotoLayerCommand(-1, "GotoPreviousLayer",
|
|
|
|
"Go to Previous Layer",
|
|
|
|
CmdUIOnlyFlag) {
|
|
|
|
}
|
|
|
|
Command* clone() const override {
|
|
|
|
return new GotoPreviousLayerCommand(*this);
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2016-06-11 02:23:45 +08:00
|
|
|
class GotoNextLayerCommand : public GotoLayerCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
2016-06-11 02:23:45 +08:00
|
|
|
GotoNextLayerCommand()
|
|
|
|
: GotoLayerCommand(+1, "GotoNextLayer",
|
|
|
|
"Go to Next Layer",
|
|
|
|
CmdUIOnlyFlag) {
|
|
|
|
}
|
|
|
|
Command* clone() const override {
|
|
|
|
return new GotoNextLayerCommand(*this);
|
|
|
|
}
|
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
|