Add undo info for FrameTags when frames are added/removed

Also we remove the entire FrameTag when all its frames are removed.
This commit is contained in:
David Capello 2015-03-12 15:05:20 -03:00
parent 9947d80b5e
commit e6dc94ddb2
2 changed files with 38 additions and 30 deletions

View File

@ -26,12 +26,14 @@
#include "app/cmd/move_layer.h"
#include "app/cmd/remove_cel.h"
#include "app/cmd/remove_frame.h"
#include "app/cmd/remove_frame_tag.h"
#include "app/cmd/remove_layer.h"
#include "app/cmd/replace_image.h"
#include "app/cmd/set_cel_frame.h"
#include "app/cmd/set_cel_opacity.h"
#include "app/cmd/set_cel_position.h"
#include "app/cmd/set_frame_duration.h"
#include "app/cmd/set_frame_tag_range.h"
#include "app/cmd/set_mask.h"
#include "app/cmd/set_mask_position.h"
#include "app/cmd/set_palette.h"
@ -50,12 +52,15 @@
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
#include "doc/context.h"
#include "doc/frame_tag.h"
#include "doc/frame_tags.h"
#include "doc/mask.h"
#include "render/quantization.h"
#include "render/render.h"
#include <set>
namespace app {
DocumentApi::DocumentApi(Document* document, Transaction& transaction)
@ -159,6 +164,21 @@ void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, Ditherin
void DocumentApi::addFrame(Sprite* sprite, frame_t newFrame)
{
copyFrame(sprite, newFrame-1, newFrame);
// As FrameTag::setFrameRange() changes m_frameTags, we need to use
// a copy of this collection
std::vector<FrameTag*> tags(sprite->frameTags().begin(), sprite->frameTags().end());
for (FrameTag* tag : tags) {
frame_t from = tag->fromFrame();
frame_t to = tag->toFrame();
if (newFrame <= from) { ++from; }
if (newFrame <= to+1) { ++to; }
if (from != tag->fromFrame() ||
to != tag->toFrame()) {
m_transaction.execute(new cmd::SetFrameTagRange(tag, from, to));
}
}
}
void DocumentApi::addEmptyFrame(Sprite* sprite, frame_t newFrame)
@ -182,6 +202,24 @@ void DocumentApi::removeFrame(Sprite* sprite, frame_t frame)
{
ASSERT(frame >= 0);
m_transaction.execute(new cmd::RemoveFrame(sprite, frame));
// As FrameTag::setFrameRange() changes m_frameTags, we need to use
// a copy of this collection
std::vector<FrameTag*> tags(sprite->frameTags().begin(), sprite->frameTags().end());
for (FrameTag* tag : tags) {
frame_t from = tag->fromFrame();
frame_t to = tag->toFrame();
if (frame < from) { --from; }
if (frame <= to) { --to; }
if (from != tag->fromFrame() ||
to != tag->toFrame()) {
if (from > to)
m_transaction.execute(new cmd::RemoveFrameTag(sprite, tag));
else
m_transaction.execute(new cmd::SetFrameTagRange(tag, from, to));
}
}
}
void DocumentApi::setTotalFrames(Sprite* sprite, frame_t frames)

View File

@ -358,21 +358,6 @@ void Sprite::addFrame(frame_t newFrame)
setFrameDuration(i, frameDuration(i-1));
folder()->displaceFrames(newFrame, +1);
// As FrameTag::setFrameRange() changes m_frameTags, we need to use
// a copy of this collection
std::vector<FrameTag*> tags(m_frameTags.begin(), m_frameTags.end());
for (FrameTag* tag : tags) {
frame_t from = tag->fromFrame();
frame_t to = tag->toFrame();
if (newFrame <= from) { ++from; }
if (newFrame <= to+1) { ++to; }
if (from != tag->fromFrame() ||
to != tag->toFrame()) {
tag->setFrameRange(from, to);
}
}
}
void Sprite::removeFrame(frame_t frame)
@ -383,21 +368,6 @@ void Sprite::removeFrame(frame_t frame)
for (frame_t i=frame; i<newTotal; ++i)
setFrameDuration(i, frameDuration(i+1));
setTotalFrames(newTotal);
// As FrameTag::setFrameRange() changes m_frameTags, we need to use
// a copy of this collection
std::vector<FrameTag*> tags(m_frameTags.begin(), m_frameTags.end());
for (FrameTag* tag : tags) {
frame_t from = tag->fromFrame();
frame_t to = tag->toFrame();
if (frame <= from) { --from; }
if (frame <= to+1) { --to; }
if (from != tag->fromFrame() ||
to != tag->toFrame()) {
tag->setFrameRange(from, to);
}
}
}
void Sprite::setTotalFrames(frame_t frames)