mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Add Remove Frame Tag command
This commit is contained in:
parent
9e67942235
commit
9f8505f490
@ -521,9 +521,11 @@
|
||||
<item command="NewFrame" text="New &Empty Frame">
|
||||
<param name="content" value="empty" />
|
||||
</item>
|
||||
<item command="NewFrameTag" text="New &Tag" />
|
||||
<item command="RemoveFrame" text="&Remove Frame" />
|
||||
<separator />
|
||||
<item command="NewFrameTag" text="New &Tag" />
|
||||
<item command="RemoveFrameTag" text="Remove Ta&g" />
|
||||
<separator />
|
||||
<menu text="&Jump to">
|
||||
<item command="GotoFirstFrame" text="&First Frame" />
|
||||
<item command="GotoPreviousFrame" text="&Previous Frame" />
|
||||
|
@ -78,6 +78,7 @@ add_library(app-lib
|
||||
cmd/move_layer.cpp
|
||||
cmd/remove_cel.cpp
|
||||
cmd/remove_frame.cpp
|
||||
cmd/remove_frame_tag.cpp
|
||||
cmd/remove_layer.cpp
|
||||
cmd/remove_palette.cpp
|
||||
cmd/replace_image.cpp
|
||||
@ -99,6 +100,7 @@ add_library(app-lib
|
||||
cmd/unlink_cel.cpp
|
||||
cmd/with_cel.cpp
|
||||
cmd/with_document.cpp
|
||||
cmd/with_frame_tag.cpp
|
||||
cmd/with_image.cpp
|
||||
cmd/with_layer.cpp
|
||||
cmd/with_palette.cpp
|
||||
@ -171,6 +173,7 @@ add_library(app-lib
|
||||
commands/cmd_play_animation.cpp
|
||||
commands/cmd_refresh.cpp
|
||||
commands/cmd_remove_frame.cpp
|
||||
commands/cmd_remove_frame_tag.cpp
|
||||
commands/cmd_remove_layer.cpp
|
||||
commands/cmd_repeat_last_export.cpp
|
||||
commands/cmd_reselect_mask.cpp
|
||||
|
@ -22,43 +22,41 @@ using namespace doc;
|
||||
|
||||
AddFrameTag::AddFrameTag(Sprite* sprite, FrameTag* frameTag)
|
||||
: WithSprite(sprite)
|
||||
, m_frameTag(frameTag)
|
||||
, m_frameTagId(0)
|
||||
, WithFrameTag(frameTag)
|
||||
{
|
||||
}
|
||||
|
||||
void AddFrameTag::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
FrameTag* frameTag = this->frameTag();
|
||||
|
||||
if (m_frameTag) {
|
||||
m_frameTagId = m_frameTag->id();
|
||||
}
|
||||
else {
|
||||
m_frameTag = read_frame_tag(m_stream);
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
sprite->frameTags().add(m_frameTag);
|
||||
m_frameTag = nullptr;
|
||||
sprite->frameTags().add(frameTag);
|
||||
}
|
||||
|
||||
void AddFrameTag::onUndo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
FrameTag* frameTag = get<FrameTag>(m_frameTagId);
|
||||
FrameTag* frameTag = this->frameTag();
|
||||
write_frame_tag(m_stream, frameTag);
|
||||
|
||||
sprite->frameTags().remove(frameTag);
|
||||
|
||||
delete frameTag;
|
||||
}
|
||||
|
||||
void AddFrameTag::onRedo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
FrameTag* frameTag = read_frame_tag(m_stream);
|
||||
sprite->frameTags().add(frameTag);
|
||||
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
size_t AddFrameTag::onMemSize() const
|
||||
{
|
||||
return sizeof(*this)
|
||||
+ (m_frameTag ? m_frameTag->getMemSize(): 0)
|
||||
+ (size_t)const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
}
|
||||
|
||||
|
@ -10,32 +10,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_frame_tag.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace doc {
|
||||
class FrameTag;
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class AddFrameTag : public Cmd
|
||||
, public WithSprite {
|
||||
, public WithSprite
|
||||
, public WithFrameTag {
|
||||
public:
|
||||
AddFrameTag(Sprite* sprite, FrameTag* tag);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override;
|
||||
|
||||
private:
|
||||
FrameTag* m_frameTag;
|
||||
ObjectId m_frameTagId;
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
|
40
src/app/cmd/remove_frame_tag.cpp
Normal file
40
src/app/cmd/remove_frame_tag.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/remove_frame_tag.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
RemoveFrameTag::RemoveFrameTag(Sprite* sprite, FrameTag* tag)
|
||||
: AddFrameTag(sprite, tag)
|
||||
{
|
||||
}
|
||||
|
||||
void RemoveFrameTag::onExecute()
|
||||
{
|
||||
AddFrameTag::onUndo();
|
||||
}
|
||||
|
||||
void RemoveFrameTag::onUndo()
|
||||
{
|
||||
AddFrameTag::onRedo();
|
||||
}
|
||||
|
||||
void RemoveFrameTag::onRedo()
|
||||
{
|
||||
AddFrameTag::onUndo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
31
src/app/cmd/remove_frame_tag.h
Normal file
31
src/app/cmd/remove_frame_tag.h
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
#ifndef APP_CMD_REMOVE_FRAME_TAG_H_INCLUDED
|
||||
#define APP_CMD_REMOVE_FRAME_TAG_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd/add_frame_tag.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class RemoveFrameTag : public AddFrameTag {
|
||||
public:
|
||||
RemoveFrameTag(Sprite* sprite, FrameTag* tag);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
32
src/app/cmd/with_frame_tag.cpp
Normal file
32
src/app/cmd/with_frame_tag.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/with_frame_tag.h"
|
||||
|
||||
#include "doc/frame_tag.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
WithFrameTag::WithFrameTag(FrameTag* frameTag)
|
||||
: m_frameTagId(frameTag->id())
|
||||
{
|
||||
}
|
||||
|
||||
FrameTag* WithFrameTag::frameTag()
|
||||
{
|
||||
return get<FrameTag>(m_frameTagId);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
34
src/app/cmd/with_frame_tag.h
Normal file
34
src/app/cmd/with_frame_tag.h
Normal file
@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
#ifndef APP_CMD_WITH_FRAME_TAG_H_INCLUDED
|
||||
#define APP_CMD_WITH_FRAME_TAG_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class FrameTag;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class WithFrameTag {
|
||||
public:
|
||||
WithFrameTag(FrameTag* tag);
|
||||
FrameTag* frameTag();
|
||||
|
||||
private:
|
||||
ObjectId m_frameTagId;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
80
src/app/commands/cmd_remove_frame_tag.cpp
Normal file
80
src/app/commands/cmd_remove_frame_tag.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/cmd/remove_frame_tag.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/timeline.h"
|
||||
#include "doc/frame_tag.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class RemoveFrameTagCommand : public Command {
|
||||
public:
|
||||
RemoveFrameTagCommand();
|
||||
Command* clone() const override { return new RemoveFrameTagCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
};
|
||||
|
||||
RemoveFrameTagCommand::RemoveFrameTagCommand()
|
||||
: Command("RemoveFrameTag",
|
||||
"Remove Frame Tag",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool RemoveFrameTagCommand::onEnabled(Context* context)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
||||
ContextFlags::HasActiveSprite);
|
||||
}
|
||||
|
||||
void RemoveFrameTagCommand::onExecute(Context* context)
|
||||
{
|
||||
ContextWriter writer(context);
|
||||
Document* document(writer.document());
|
||||
Sprite* sprite(writer.sprite());
|
||||
frame_t frame = writer.frame();
|
||||
|
||||
FrameTag* best = nullptr;
|
||||
for (FrameTag* tag : sprite->frameTags()) {
|
||||
if (frame >= tag->fromFrame() &&
|
||||
frame <= tag->toFrame()) {
|
||||
if (!best ||
|
||||
(tag->toFrame() - tag->fromFrame()) < (best->toFrame() - best->fromFrame())) {
|
||||
best = tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!best)
|
||||
return;
|
||||
|
||||
Transaction transaction(writer.context(), "Remove Frame Tag");
|
||||
transaction.execute(new cmd::RemoveFrameTag(sprite, best));
|
||||
transaction.commit();
|
||||
|
||||
App::instance()->getMainWindow()->getTimeline()->invalidate();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createRemoveFrameTagCommand()
|
||||
{
|
||||
return new RemoveFrameTagCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -80,6 +80,7 @@ FOR_EACH_COMMAND(PlayAnimation)
|
||||
FOR_EACH_COMMAND(Redo)
|
||||
FOR_EACH_COMMAND(Refresh)
|
||||
FOR_EACH_COMMAND(RemoveFrame)
|
||||
FOR_EACH_COMMAND(RemoveFrameTag)
|
||||
FOR_EACH_COMMAND(RemoveLayer)
|
||||
FOR_EACH_COMMAND(RepeatLastExport)
|
||||
FOR_EACH_COMMAND(ReplaceColor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user