2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2012-01-06 06:45:03 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
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"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "raster/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
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
virtual FrameNumber onGetFrame(Editor* editor) = 0;
|
|
|
|
};
|
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",
|
|
|
|
"Goto 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-08-15 10:07:47 +08:00
|
|
|
FrameNumber onGetFrame(Editor* editor) override {
|
2013-03-12 07:29:45 +08:00
|
|
|
return FrameNumber(0);
|
|
|
|
}
|
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",
|
|
|
|
"Goto 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-08-15 10:07:47 +08:00
|
|
|
FrameNumber onGetFrame(Editor* editor) override {
|
2014-07-30 12:28:15 +08:00
|
|
|
FrameNumber frame = editor->frame();
|
2013-03-12 07:29:45 +08:00
|
|
|
|
|
|
|
if (frame > FrameNumber(0))
|
|
|
|
return frame.previous();
|
|
|
|
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",
|
|
|
|
"Goto 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-08-15 10:07:47 +08:00
|
|
|
FrameNumber onGetFrame(Editor* editor) override {
|
2014-07-30 12:28:15 +08:00
|
|
|
FrameNumber frame = editor->frame();
|
|
|
|
if (frame < editor->sprite()->lastFrame())
|
2013-03-12 07:29:45 +08:00
|
|
|
return frame.next();
|
|
|
|
else
|
|
|
|
return FrameNumber(0);
|
|
|
|
}
|
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",
|
|
|
|
"Goto 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-08-15 10:07:47 +08:00
|
|
|
FrameNumber 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",
|
|
|
|
"Goto Frame")
|
|
|
|
, 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-08-15 10:07:47 +08:00
|
|
|
FrameNumber 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-07-30 12:28:15 +08:00
|
|
|
return MID(FrameNumber(0), FrameNumber(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
|