2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2017-12-01 01:51:13 +08:00
|
|
|
// Copyright (C) 2001-2017 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-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"
|
2016-11-29 23:14:33 +08:00
|
|
|
#include "app/context.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/document_api.h"
|
2016-11-29 23:14:33 +08:00
|
|
|
#include "app/pref/preferences.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
|
|
|
|
2015-09-23 03:33:49 +08:00
|
|
|
#include "frame_properties.xml.h"
|
2015-02-20 07:29:48 +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:
|
2017-12-01 01:51:13 +08:00
|
|
|
bool onNeedsParams() const override { return true; }
|
2015-03-12 02:40:22 +08:00
|
|
|
void onLoadParams(const Params& params) override;
|
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-12 02:40:22 +08:00
|
|
|
void FramePropertiesCommand::onLoadParams(const Params& params)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2015-03-12 02:40:22 +08:00
|
|
|
std::string frame = params.get("frame");
|
2012-01-06 06:45:03 +08:00
|
|
|
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;
|
2016-11-23 05:05:56 +08:00
|
|
|
m_frame = frame_t(base::convert_to<int>(frame));
|
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();
|
2016-11-23 05:05:56 +08:00
|
|
|
auto& docPref = Preferences::instance().document(context->activeDocument());
|
|
|
|
int base = docPref.timeline.firstFrame();
|
2015-02-20 07:29:48 +08:00
|
|
|
app::gen::FrameProperties window;
|
2016-06-15 00:08:17 +08:00
|
|
|
SelectedFrames selFrames;
|
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:
|
2016-06-15 00:08:17 +08:00
|
|
|
selFrames.insert(0, sprite->lastFrame());
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
|
2013-12-22 23:19:03 +08:00
|
|
|
case CURRENT_RANGE: {
|
2016-06-15 00:08:17 +08:00
|
|
|
Site site = context->activeSite();
|
|
|
|
if (site.inTimeline()) {
|
|
|
|
selFrames = site.selectedFrames();
|
2013-12-22 23:19:03 +08:00
|
|
|
}
|
|
|
|
else {
|
2016-06-15 00:08:17 +08:00
|
|
|
selFrames.insert(site.frame());
|
2013-12-22 23:19:03 +08:00
|
|
|
}
|
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:
|
2016-11-29 23:14:33 +08:00
|
|
|
selFrames.insert(m_frame-base);
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-15 00:08:17 +08:00
|
|
|
ASSERT(!selFrames.empty());
|
|
|
|
if (selFrames.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selFrames.size() == 1)
|
2016-11-29 23:14:33 +08:00
|
|
|
window.frame()->setTextf("%d", selFrames.firstFrame()+base);
|
2016-06-15 00:08:17 +08:00
|
|
|
else if (selFrames.ranges() == 1) {
|
|
|
|
window.frame()->setTextf("[%d...%d]",
|
2016-11-29 23:14:33 +08:00
|
|
|
selFrames.firstFrame()+base,
|
|
|
|
selFrames.lastFrame()+base);
|
2016-06-15 00:08:17 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2016-06-15 00:08:17 +08:00
|
|
|
window.frame()->setTextf("Multiple Frames");
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2016-06-15 00:08:17 +08:00
|
|
|
window.frlen()->setTextf(
|
|
|
|
"%d", sprite->frameDuration(selFrames.firstFrame()));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-02-20 07:29:48 +08:00
|
|
|
window.openWindowInForeground();
|
2015-12-05 01:54:15 +08:00
|
|
|
if (window.closer() == window.ok()) {
|
2016-06-15 00:08:17 +08:00
|
|
|
int newMsecs = window.frlen()->textInt();
|
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);
|
2016-06-15 00:08:17 +08:00
|
|
|
|
|
|
|
for (frame_t frame : selFrames)
|
|
|
|
api.setFrameDuration(writer.sprite(), frame, newMsecs);
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
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
|