2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2015-01-19 09:05:33 +08:00
|
|
|
* Copyright (C) 2001-2015 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-12-22 23:19:03 +08:00
|
|
|
#include "app/app.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/document_api.h"
|
2012-06-16 10:37:59 +08:00
|
|
|
#include "app/find_widget.h"
|
|
|
|
#include "app/load_widget.h"
|
2013-12-22 23:19:03 +08:00
|
|
|
#include "app/ui/main_window.h"
|
|
|
|
#include "app/ui/timeline.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "base/convert_to.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-06-18 09:02:54 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace ui;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class FramePropertiesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
FramePropertiesCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new FramePropertiesCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onLoadParams(Params* params);
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
|
|
|
|
private:
|
2012-07-09 08:09:09 +08:00
|
|
|
enum Target {
|
2012-01-06 06:45:03 +08:00
|
|
|
ALL_FRAMES = -1,
|
2013-12-22 23:19:03 +08:00
|
|
|
CURRENT_RANGE = 0,
|
2012-07-09 08:09:09 +08:00
|
|
|
SPECIFIC_FRAME = 1
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2013-12-22 23:19:03 +08:00
|
|
|
// Frame to be shown. It can be ALL_FRAMES, CURRENT_RANGE, or a
|
2012-01-06 06:45:03 +08:00
|
|
|
// number indicating a specific frame (1 is the first frame).
|
2012-07-09 08:09:09 +08:00
|
|
|
Target m_target;
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t m_frame;
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
FramePropertiesCommand::FramePropertiesCommand()
|
|
|
|
: Command("FrameProperties",
|
|
|
|
"Frame Properties",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramePropertiesCommand::onLoadParams(Params* params)
|
|
|
|
{
|
|
|
|
std::string frame = params->get("frame");
|
|
|
|
if (frame == "all") {
|
2012-07-09 08:09:09 +08:00
|
|
|
m_target = ALL_FRAMES;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
else if (frame == "current") {
|
2013-12-22 23:19:03 +08:00
|
|
|
m_target = CURRENT_RANGE;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-07-09 08:09:09 +08:00
|
|
|
m_target = SPECIFIC_FRAME;
|
2014-12-29 07:39:11 +08:00
|
|
|
m_frame = frame_t(base::convert_to<int>(frame)-1);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramePropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramePropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite = reader.sprite();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Window> window(app::load_widget<Window>("frame_duration.xml", "frame_duration"));
|
2012-06-16 10:37:59 +08:00
|
|
|
Widget* frame = app::find_widget<Widget>(window, "frame");
|
|
|
|
Widget* frlen = app::find_widget<Widget>(window, "frlen");
|
|
|
|
Widget* ok = app::find_widget<Widget>(window, "ok");
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t firstFrame(0);
|
|
|
|
frame_t lastFrame(0);
|
2013-12-22 23:19:03 +08:00
|
|
|
|
2012-07-09 08:09:09 +08:00
|
|
|
switch (m_target) {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
case ALL_FRAMES:
|
2014-07-30 12:28:15 +08:00
|
|
|
lastFrame = sprite->lastFrame();
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-22 23:19:03 +08:00
|
|
|
case CURRENT_RANGE: {
|
|
|
|
// TODO the range of selected frames should be in the DocumentLocation.
|
|
|
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
|
|
|
if (range.enabled()) {
|
|
|
|
firstFrame = range.frameBegin();
|
|
|
|
lastFrame = range.frameEnd();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
firstFrame = lastFrame = reader.frame();
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
2013-12-22 23:19:03 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-07-09 08:09:09 +08:00
|
|
|
case SPECIFIC_FRAME:
|
2013-12-22 23:19:03 +08:00
|
|
|
firstFrame = lastFrame = m_frame;
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-22 23:19:03 +08:00
|
|
|
if (firstFrame != lastFrame)
|
2015-02-06 23:47:52 +08:00
|
|
|
frame->setTextf("[%d...%d]", (int)firstFrame+1, (int)lastFrame+1);
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2013-12-22 23:19:03 +08:00
|
|
|
frame->setTextf("%d", (int)firstFrame+1);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-12-29 07:39:11 +08:00
|
|
|
frlen->setTextf("%d", sprite->frameDuration(firstFrame));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-07-09 10:24:42 +08:00
|
|
|
window->openWindowInForeground();
|
2013-01-11 23:43:25 +08:00
|
|
|
if (window->getKiller() == ok) {
|
2013-10-15 06:58:11 +08:00
|
|
|
int num = frlen->getTextInt();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-12-22 23:19:03 +08:00
|
|
|
ContextWriter writer(reader);
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Frame Duration");
|
|
|
|
DocumentApi api = writer.document()->getApi(transaction);
|
2013-12-22 23:19:03 +08:00
|
|
|
if (firstFrame != lastFrame)
|
2015-01-19 09:05:33 +08:00
|
|
|
api.setFrameRangeDuration(writer.sprite(), firstFrame, lastFrame, num);
|
2013-12-22 23:19:03 +08:00
|
|
|
else
|
2015-01-19 09:05:33 +08:00
|
|
|
api.setFrameDuration(writer.sprite(), firstFrame, num);
|
|
|
|
transaction.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createFramePropertiesCommand()
|
|
|
|
{
|
|
|
|
return new FramePropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|