Add NewFrameTag command

This commit is contained in:
David Capello 2015-02-17 16:12:10 -03:00
parent d438fa09ed
commit 9e734b2e8c
8 changed files with 219 additions and 2 deletions

View File

@ -521,6 +521,7 @@
<item command="NewFrame" text="New &amp;Empty Frame">
<param name="content" value="empty" />
</item>
<item command="NewFrameTag" text="New &amp;Tag" />
<item command="RemoveFrame" text="&amp;Remove Frame" />
<separator />
<menu text="&amp;Jump to">
@ -643,6 +644,7 @@
<item command="NewFrame" text="&amp;New Empty Frame">
<param name="content" value="empty" />
</item>
<item command="NewFrameTag" text="New &amp;Tag" />
<item command="RemoveFrame" text="&amp;Remove" />
</menu>

View File

@ -56,6 +56,7 @@ add_library(app-lib
cmd.cpp
cmd/add_cel.cpp
cmd/add_frame.cpp
cmd/add_frame_tag.cpp
cmd/add_layer.cpp
cmd/add_palette.cpp
cmd/background_from_layer.cpp
@ -157,6 +158,7 @@ add_library(app-lib
commands/cmd_move_mask.cpp
commands/cmd_new_file.cpp
commands/cmd_new_frame.cpp
commands/cmd_new_frame_tag.cpp
commands/cmd_new_layer.cpp
commands/cmd_new_layer_set.cpp
commands/cmd_onionskin.cpp

View File

@ -0,0 +1,66 @@
// 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/add_frame_tag.h"
#include "doc/frame_tag.h"
#include "doc/frame_tag_io.h"
#include "doc/sprite.h"
namespace app {
namespace cmd {
using namespace doc;
AddFrameTag::AddFrameTag(Sprite* sprite, FrameTag* frameTag)
: WithSprite(sprite)
, m_frameTag(frameTag)
, m_frameTagId(0)
{
}
void AddFrameTag::onExecute()
{
Sprite* sprite = this->sprite();
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;
}
void AddFrameTag::onUndo()
{
Sprite* sprite = this->sprite();
FrameTag* frameTag = get<FrameTag>(m_frameTagId);
write_frame_tag(m_stream, frameTag);
sprite->frameTags().remove(frameTag);
delete frameTag;
}
size_t AddFrameTag::onMemSize() const
{
return sizeof(*this)
+ (m_frameTag ? m_frameTag->getMemSize(): 0)
+ (size_t)const_cast<std::stringstream*>(&m_stream)->tellp();
}
} // namespace cmd
} // namespace app

View File

@ -0,0 +1,45 @@
// 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_ADD_FRAME_TAG_H_INCLUDED
#define APP_CMD_ADD_FRAME_TAG_H_INCLUDED
#pragma once
#include "app/cmd.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:
AddFrameTag(Sprite* sprite, FrameTag* tag);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override;
private:
FrameTag* m_frameTag;
ObjectId m_frameTagId;
std::stringstream m_stream;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -0,0 +1,84 @@
// 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/add_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"
#include <stdexcept>
namespace app {
using namespace doc;
class NewFrameTagCommand : public Command {
public:
NewFrameTagCommand();
Command* clone() const override { return new NewFrameTagCommand(*this); }
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
NewFrameTagCommand::NewFrameTagCommand()
: Command("NewFrameTag",
"New Frame Tag",
CmdRecordableFlag)
{
}
bool NewFrameTagCommand::onEnabled(Context* context)
{
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::HasActiveSprite);
}
void NewFrameTagCommand::onExecute(Context* context)
{
ContextWriter writer(context);
Sprite* sprite(writer.sprite());
frame_t from = writer.frame();
frame_t to = writer.frame();
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled() &&
(range.type() == DocumentRange::kFrames ||
range.type() == DocumentRange::kCels)) {
from = range.frameBegin();
to = range.frameEnd();
}
{
Transaction transaction(writer.context(), "New Frames Tag");
FrameTag* frameTag = new FrameTag(from, to);
transaction.execute(new cmd::AddFrameTag(sprite, frameTag));
transaction.commit();
}
App::instance()->getMainWindow()->getTimeline()->invalidate();
}
Command* CommandFactory::createNewFrameTagCommand()
{
return new NewFrameTagCommand;
}
} // namespace app

View File

@ -67,6 +67,7 @@ FOR_EACH_COMMAND(MoveCel)
FOR_EACH_COMMAND(MoveMask)
FOR_EACH_COMMAND(NewFile)
FOR_EACH_COMMAND(NewFrame)
FOR_EACH_COMMAND(NewFrameTag)
FOR_EACH_COMMAND(NewLayer)
FOR_EACH_COMMAND(NewLayerSet)
FOR_EACH_COMMAND(OpenFile)

View File

@ -25,19 +25,20 @@
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/transaction.h"
#include "app/ui/configure_timeline_popup.h"
#include "app/ui/document_view.h"
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "app/transaction.h"
#include "app/util/clipboard.h"
#include "base/memory.h"
#include "doc/doc.h"
#include "doc/document_event.h"
#include "doc/frame_tag.h"
#include "gfx/point.h"
#include "gfx/rect.h"
#include "doc/doc.h"
#include "ui/ui.h"
#include <cstdio>
@ -871,6 +872,7 @@ void Timeline::onPaint(ui::PaintEvent& ev)
drawPaddings(g);
drawLoopRange(g);
drawFrameTags(g);
drawRangeOutline(g);
drawClipboardRange(g);
@ -1327,6 +1329,20 @@ void Timeline::drawLoopRange(ui::Graphics* g)
drawPart(g, bounds, NULL, m_timelineLoopRangeStyle);
}
void Timeline::drawFrameTags(ui::Graphics* g)
{
for (FrameTag* frameTag : m_sprite->frameTags()) {
gfx::Rect bounds1 = getPartBounds(A_PART_HEADER_FRAME, firstLayer(), frameTag->fromFrame());
gfx::Rect bounds2 = getPartBounds(A_PART_HEADER_FRAME, firstLayer(), frameTag->toFrame());
gfx::Rect bounds = bounds1.createUnion(bounds2);
IntersectClip clip(g, bounds);
if (clip) {
drawPart(g, bounds, NULL, m_timelineLoopRangeStyle);
}
}
}
void Timeline::drawRangeOutline(ui::Graphics* g)
{
gfx::Rect clipBounds;

View File

@ -148,6 +148,7 @@ namespace app {
void drawCelLinkDecorators(ui::Graphics* g, const gfx::Rect& bounds,
Cel* cel, Cel* activeCel, frame_t frame, bool is_active, bool is_hover);
void drawLoopRange(ui::Graphics* g);
void drawFrameTags(ui::Graphics* g);
void drawRangeOutline(ui::Graphics* g);
void drawPaddings(ui::Graphics* g);
bool drawPart(ui::Graphics* g, int part, LayerIndex layer, frame_t frame);