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
|
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"
|
2012-06-16 10:37:59 +08:00
|
|
|
#include "app/find_widget.h"
|
|
|
|
#include "app/load_widget.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"
|
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
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
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 {
|
|
|
|
return frame_t(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();
|
2013-03-12 07:29:45 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
if (frame > frame_t(0))
|
|
|
|
return frame-1;
|
2013-03-12 07:29:45 +08:00
|
|
|
else
|
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 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();
|
2014-07-30 12:28:15 +08:00
|
|
|
if (frame < editor->sprite()->lastFrame())
|
2014-12-29 07:39:11 +08:00
|
|
|
return frame+1;
|
2013-03-12 07:29:45 +08:00
|
|
|
else
|
2014-12-29 07:39:11 +08:00
|
|
|
return frame_t(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 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")
|
2013-03-12 07:29:45 +08:00
|
|
|
, m_frame(0) { }
|
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:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onLoadParams(Params* params) override
|
2013-03-12 07:29:45 +08:00
|
|
|
{
|
|
|
|
std::string frame = params->get("frame");
|
2014-09-21 22:59:39 +08:00
|
|
|
if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10);
|
2013-03-12 07:29:45 +08:00
|
|
|
else m_frame = 0;
|
|
|
|
}
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t onGetFrame(Editor* editor) override {
|
2013-03-12 07:29:45 +08:00
|
|
|
if (m_frame == 0) {
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Window> window(app::load_widget<Window>("goto_frame.xml", "goto_frame"));
|
2013-03-12 07:29:45 +08:00
|
|
|
Widget* frame = app::find_widget<Widget>(window, "frame");
|
|
|
|
Widget* ok = app::find_widget<Widget>(window, "ok");
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
frame->setTextf("%d", editor->frame()+1);
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
window->openWindowInForeground();
|
|
|
|
if (window->getKiller() != ok)
|
2014-07-30 12:28:15 +08:00
|
|
|
return editor->frame();
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2013-10-15 06:58:11 +08:00
|
|
|
m_frame = frame->getTextInt();
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
2012-01-10 07:28:04 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
return MID(0, m_frame-1, editor->sprite()->lastFrame());
|
2012-01-10 07:28:04 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
private:
|
|
|
|
// The frame to go. 0 is "show the UI dialog", another value is the
|
|
|
|
// frame (1 is the first name for the user).
|
|
|
|
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
|
|
|
|
|
|
|
Command* CommandFactory::createGotoFrameCommand()
|
|
|
|
{
|
|
|
|
return new GotoFrameCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|