2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2018-06-09 02:52:10 +08:00
|
|
|
// Copyright (C) 2001-2018 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"
|
2017-06-19 22:23:40 +08:00
|
|
|
#include "app/match_words.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"
|
2017-03-30 08:18:29 +08:00
|
|
|
#include "app/ui/editor/editor_customization_delegate.h"
|
2017-06-19 22:23:40 +08:00
|
|
|
#include "app/ui/search_entry.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"
|
2018-06-09 02:52:10 +08:00
|
|
|
#include "ui/combobox.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:
|
2017-12-01 10:41:45 +08:00
|
|
|
GotoCommand(const char* id)
|
|
|
|
: Command(id, 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()
|
2017-12-02 02:10:21 +08:00
|
|
|
: GotoCommand(CommandId::GotoFirstFrame()) { }
|
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
|
|
|
};
|
|
|
|
|
2018-10-26 21:26:11 +08:00
|
|
|
class GotoFirstFrameInTagCommand : public GotoCommand {
|
|
|
|
public:
|
|
|
|
GotoFirstFrameInTagCommand()
|
|
|
|
: GotoCommand(CommandId::GotoFirstFrameInTag()) { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
|
|
|
frame_t frame = editor->frame();
|
|
|
|
FrameTag* tag = editor
|
|
|
|
->getCustomizationDelegate()
|
|
|
|
->getFrameTagProvider()
|
|
|
|
->getFrameTagByFrame(frame, false);
|
|
|
|
return (tag ? tag->fromFrame(): 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoPreviousFrameCommand : public GotoCommand {
|
2013-03-12 07:29:45 +08:00
|
|
|
public:
|
|
|
|
GotoPreviousFrameCommand()
|
2017-12-02 02:10:21 +08:00
|
|
|
: GotoCommand(CommandId::GotoPreviousFrame()) { }
|
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:
|
2017-12-02 02:10:21 +08:00
|
|
|
GotoNextFrameCommand() : GotoCommand(CommandId::GotoNextFrame()) { }
|
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:
|
2017-12-02 02:10:21 +08:00
|
|
|
GotoNextFrameWithSameTagCommand() : GotoCommand(CommandId::GotoNextFrameWithSameTag()) { }
|
2015-12-05 18:10:24 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t frame = editor->frame();
|
2017-03-30 08:18:29 +08:00
|
|
|
FrameTag* tag = editor
|
|
|
|
->getCustomizationDelegate()
|
|
|
|
->getFrameTagProvider()
|
2018-06-20 01:35:00 +08:00
|
|
|
->getFrameTagByFrame(frame, false);
|
2015-12-06 02:42:12 +08:00
|
|
|
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:
|
2017-12-02 02:10:21 +08:00
|
|
|
GotoPreviousFrameWithSameTagCommand() : GotoCommand(CommandId::GotoPreviousFrameWithSameTag()) { }
|
2015-12-05 18:10:24 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2015-12-06 02:42:12 +08:00
|
|
|
frame_t frame = editor->frame();
|
2017-03-30 08:18:29 +08:00
|
|
|
FrameTag* tag = editor
|
|
|
|
->getCustomizationDelegate()
|
|
|
|
->getFrameTagProvider()
|
2018-06-20 01:35:00 +08:00
|
|
|
->getFrameTagByFrame(frame, false);
|
2015-12-06 02:42:12 +08:00
|
|
|
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:
|
2017-12-02 02:10:21 +08:00
|
|
|
GotoLastFrameCommand() : GotoCommand(CommandId::GotoLastFrame()) { }
|
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
|
|
|
};
|
|
|
|
|
2018-10-26 21:26:11 +08:00
|
|
|
class GotoLastFrameInTagCommand : public GotoCommand {
|
|
|
|
public:
|
|
|
|
GotoLastFrameInTagCommand()
|
|
|
|
: GotoCommand(CommandId::GotoLastFrameInTag()) { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
|
|
|
frame_t frame = editor->frame();
|
|
|
|
FrameTag* tag = editor
|
|
|
|
->getCustomizationDelegate()
|
|
|
|
->getFrameTagProvider()
|
|
|
|
->getFrameTagByFrame(frame, false);
|
|
|
|
return (tag ? tag->toFrame(): editor->sprite()->lastFrame());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-07 08:48:46 +08:00
|
|
|
class GotoFrameCommand : public GotoCommand {
|
2012-01-10 07:28:04 +08:00
|
|
|
public:
|
2017-12-02 02:10:21 +08:00
|
|
|
GotoFrameCommand() : GotoCommand(CommandId::GotoFrame())
|
2016-11-23 05:05:56 +08:00
|
|
|
, m_showUI(true) { }
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2017-06-19 22:23:40 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
// TODO this combobox is similar to FileSelector::CustomFileNameEntry
|
|
|
|
class TagsEntry : public ComboBox {
|
|
|
|
public:
|
|
|
|
TagsEntry(FrameTags& frameTags)
|
|
|
|
: m_frameTags(frameTags) {
|
|
|
|
setEditable(true);
|
|
|
|
getEntryWidget()->Change.connect(&TagsEntry::onEntryChange, this);
|
2017-06-24 02:15:17 +08:00
|
|
|
fill(true);
|
2017-06-19 22:23:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-06-24 02:15:17 +08:00
|
|
|
void fill(bool all) {
|
2017-06-19 22:23:40 +08:00
|
|
|
removeAllItems();
|
|
|
|
|
|
|
|
MatchWords match(getEntryWidget()->text());
|
2017-06-24 02:15:17 +08:00
|
|
|
|
|
|
|
bool matchAny = false;
|
|
|
|
for (const auto& frameTag : m_frameTags) {
|
|
|
|
if (match(frameTag->name())) {
|
|
|
|
matchAny = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-19 22:23:40 +08:00
|
|
|
for (const auto& frameTag : m_frameTags) {
|
2017-06-24 02:15:17 +08:00
|
|
|
if (all || !matchAny || match(frameTag->name()))
|
2017-06-19 22:23:40 +08:00
|
|
|
addItem(frameTag->name());
|
|
|
|
}
|
2017-06-24 02:15:17 +08:00
|
|
|
}
|
2017-06-19 22:23:40 +08:00
|
|
|
|
2017-06-24 02:15:17 +08:00
|
|
|
void onEntryChange() {
|
|
|
|
closeListBox();
|
|
|
|
fill(false);
|
2017-06-19 22:23:40 +08:00
|
|
|
if (getItemCount() > 0)
|
|
|
|
openListBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameTags& m_frameTags;
|
|
|
|
};
|
|
|
|
|
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;
|
2017-06-19 22:23:40 +08:00
|
|
|
TagsEntry combobox(editor->sprite()->frameTags());
|
|
|
|
|
|
|
|
window.framePlaceholder()->addChild(&combobox);
|
|
|
|
|
|
|
|
combobox.setFocusMagnet(true);
|
|
|
|
combobox.getEntryWidget()->setTextf(
|
2016-11-23 05:05:56 +08:00
|
|
|
"%d", editor->frame()+docPref.timeline.firstFrame());
|
2017-06-19 22:23:40 +08:00
|
|
|
|
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
|
|
|
|
2017-06-19 22:23:40 +08:00
|
|
|
std::string text = combobox.getEntryWidget()->text();
|
|
|
|
frame_t frameNum = base::convert_to<int>(text);
|
|
|
|
std::string textFromInt = base::convert_to<std::string>(frameNum);
|
|
|
|
if (text == textFromInt) {
|
|
|
|
m_frame = frameNum;
|
|
|
|
}
|
|
|
|
// Search a tag name
|
|
|
|
else {
|
|
|
|
MatchWords match(text);
|
|
|
|
for (const auto& frameTag : editor->sprite()->frameTags()) {
|
|
|
|
if (match(frameTag->name())) {
|
|
|
|
m_frame =
|
|
|
|
frameTag->fromFrame()+docPref.timeline.firstFrame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-26 21:26:11 +08:00
|
|
|
Command* CommandFactory::createGotoFirstFrameInTagCommand()
|
|
|
|
{
|
|
|
|
return new GotoFirstFrameInTagCommand;
|
|
|
|
}
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
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
|
|
|
|
2018-10-26 21:26:11 +08:00
|
|
|
Command* CommandFactory::createGotoLastFrameInTagCommand()
|
|
|
|
{
|
|
|
|
return new GotoLastFrameInTagCommand;
|
|
|
|
}
|
|
|
|
|
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
|