2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2016-11-23 05:05:56 +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
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/params.h"
|
2015-12-05 18:10:24 +08:00
|
|
|
#include "app/loop_tag.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
2015-12-05 18:10:24 +08:00
|
|
|
#include "doc/frame_tag.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2012-07-09 10:24:42 +08:00
|
|
|
#include "ui/window.h"
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2015-09-23 04:25:48 +08:00
|
|
|
#include "goto_frame.xml.h"
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
2015-12-05 18:10:24 +08:00
|
|
|
using namespace doc;
|
2012-06-18 09:02:54 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class GotoCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
protected:
|
2013-03-12 07:29:45 +08:00
|
|
|
GotoCommand(const char* short_name, const char* friendly_name)
|
|
|
|
: Command(short_name, friendly_name, CmdRecordableFlag) { }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
bool onEnabled(Context* context) override {
|
2013-03-12 07:29:45 +08:00
|
|
|
return (current_editor != NULL);
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void onExecute(Context* context) override {
|
2013-03-12 07:29:45 +08:00
|
|
|
ASSERT(current_editor != NULL);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
current_editor->setFrame(onGetFrame(current_editor));
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
virtual frame_t onGetFrame(Editor* editor) = 0;
|
2013-03-12 07:29:45 +08:00
|
|
|
};
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoFirstFrameCommand : public GotoCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
2013-03-12 07:29:45 +08:00
|
|
|
GotoFirstFrameCommand()
|
|
|
|
: GotoCommand("GotoFirstFrame",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to First Frame") { }
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoFirstFrameCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2015-12-06 02:42:12 +08:00
|
|
|
return 0;
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoPreviousFrameCommand : public GotoCommand {
|
2013-03-12 07:29:45 +08:00
|
|
|
public:
|
|
|
|
GotoPreviousFrameCommand()
|
|
|
|
: GotoCommand("GotoPreviousFrame",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Previous Frame") { }
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoPreviousFrameCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
protected:
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
|
|
|
frame_t frame = editor->frame();
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t last = editor->sprite()->lastFrame();
|
2013-03-12 07:29:45 +08:00
|
|
|
|
2015-12-06 02:42:12 +08:00
|
|
|
return (frame > 0 ? frame-1: last);
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
|
|
|
};
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoNextFrameCommand : public GotoCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
2013-03-12 07:29:45 +08:00
|
|
|
GotoNextFrameCommand() : GotoCommand("GotoNextFrame",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Next Frame") { }
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoNextFrameCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
|
|
|
frame_t frame = editor->frame();
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t last = editor->sprite()->lastFrame();
|
|
|
|
|
|
|
|
return (frame < last ? frame+1: 0);
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2015-12-05 18:10:24 +08:00
|
|
|
class GotoNextFrameWithSameTagCommand : public GotoCommand {
|
|
|
|
public:
|
|
|
|
GotoNextFrameWithSameTagCommand() : GotoCommand("GotoNextFrameWithSameTag",
|
|
|
|
"Go to Next Frame with same tag") { }
|
|
|
|
Command* clone() const override { return new GotoNextFrameWithSameTagCommand(*this); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t frame = editor->frame();
|
|
|
|
FrameTag* tag = get_animation_tag(editor->sprite(), frame);
|
|
|
|
frame_t first = (tag ? tag->fromFrame(): 0);
|
|
|
|
frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());
|
2015-12-05 18:10:24 +08:00
|
|
|
|
2015-12-06 02:42:12 +08:00
|
|
|
return (frame < last ? frame+1: first);
|
2015-12-05 18:10:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GotoPreviousFrameWithSameTagCommand : public GotoCommand {
|
|
|
|
public:
|
|
|
|
GotoPreviousFrameWithSameTagCommand() : GotoCommand("GotoPreviousFrameWithSameTag",
|
|
|
|
"Go to Previous Frame with same tag") { }
|
|
|
|
Command* clone() const override { return new GotoPreviousFrameWithSameTagCommand(*this); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t frame = editor->frame();
|
|
|
|
FrameTag* tag = get_animation_tag(editor->sprite(), frame);
|
|
|
|
frame_t first = (tag ? tag->fromFrame(): 0);
|
|
|
|
frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());
|
2015-12-05 18:10:24 +08:00
|
|
|
|
2015-12-06 02:42:12 +08:00
|
|
|
return (frame > first ? frame-1: last);
|
2015-12-05 18:10:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoLastFrameCommand : public GotoCommand {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
2013-03-12 07:29:45 +08:00
|
|
|
GotoLastFrameCommand() : GotoCommand("GotoLastFrame",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Last Frame") { }
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoLastFrameCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2014-07-30 12:28:15 +08:00
|
|
|
return editor->sprite()->lastFrame();
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoFrameCommand : public GotoCommand {
|
2012-01-10 07:28:04 +08:00
|
|
|
public:
|
2013-03-12 07:29:45 +08:00
|
|
|
GotoFrameCommand() : GotoCommand("GotoFrame",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Go to Frame")
|
2016-11-23 05:05:56 +08:00
|
|
|
, m_showUI(true) { }
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new GotoFrameCommand(*this); }
|
2012-01-10 07:28:04 +08:00
|
|
|
|
|
|
|
protected:
|
2015-12-06 02:42:12 +08:00
|
|
|
void onLoadParams(const Params& params) override {
|
2015-03-12 02:40:22 +08:00
|
|
|
std::string frame = params.get("frame");
|
2016-11-23 05:05:56 +08:00
|
|
|
if (!frame.empty()) {
|
|
|
|
m_frame = strtol(frame.c_str(), nullptr, 10);
|
|
|
|
m_showUI = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_showUI = true;
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2016-11-23 05:05:56 +08:00
|
|
|
auto& docPref = editor->docPref();
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2016-11-23 05:05:56 +08:00
|
|
|
if (m_showUI) {
|
|
|
|
app::gen::GotoFrame window;
|
|
|
|
window.frame()->setTextf(
|
|
|
|
"%d", editor->frame()+docPref.timeline.firstFrame());
|
2015-09-23 04:25:48 +08:00
|
|
|
window.openWindowInForeground();
|
2015-12-05 01:54:15 +08:00
|
|
|
if (window.closer() != window.ok())
|
2014-07-30 12:28:15 +08:00
|
|
|
return editor->frame();
|
2012-01-10 07:28:04 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
m_frame = window.frame()->textInt();
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2016-11-23 05:05:56 +08:00
|
|
|
return MID(0, m_frame-docPref.timeline.firstFrame(), editor->sprite()->lastFrame());
|
2012-01-10 07:28:04 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
private:
|
2016-11-23 05:05:56 +08:00
|
|
|
bool m_showUI;
|
2013-03-12 07:29:45 +08:00
|
|
|
int m_frame;
|
|
|
|
};
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
Command* CommandFactory::createGotoFirstFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoFirstFrameCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoPreviousFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoPreviousFrameCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoNextFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoNextFrameCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoLastFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoLastFrameCommand;
|
|
|
|
}
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2015-12-05 18:10:24 +08:00
|
|
|
Command* CommandFactory::createGotoNextFrameWithSameTagCommand()
|
|
|
|
{
|
|
|
|
return new GotoNextFrameWithSameTagCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createGotoPreviousFrameWithSameTagCommand()
|
|
|
|
{
|
|
|
|
return new GotoPreviousFrameWithSameTagCommand;
|
|
|
|
}
|
|
|
|
|
2012-01-10 07:28:04 +08:00
|
|
|
Command* CommandFactory::createGotoFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoFrameCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|