mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Add NewFrameTag command
This commit is contained in:
parent
d438fa09ed
commit
9e734b2e8c
@ -521,6 +521,7 @@
|
|||||||
<item command="NewFrame" text="New &Empty Frame">
|
<item command="NewFrame" text="New &Empty Frame">
|
||||||
<param name="content" value="empty" />
|
<param name="content" value="empty" />
|
||||||
</item>
|
</item>
|
||||||
|
<item command="NewFrameTag" text="New &Tag" />
|
||||||
<item command="RemoveFrame" text="&Remove Frame" />
|
<item command="RemoveFrame" text="&Remove Frame" />
|
||||||
<separator />
|
<separator />
|
||||||
<menu text="&Jump to">
|
<menu text="&Jump to">
|
||||||
@ -643,6 +644,7 @@
|
|||||||
<item command="NewFrame" text="&New Empty Frame">
|
<item command="NewFrame" text="&New Empty Frame">
|
||||||
<param name="content" value="empty" />
|
<param name="content" value="empty" />
|
||||||
</item>
|
</item>
|
||||||
|
<item command="NewFrameTag" text="New &Tag" />
|
||||||
<item command="RemoveFrame" text="&Remove" />
|
<item command="RemoveFrame" text="&Remove" />
|
||||||
</menu>
|
</menu>
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ add_library(app-lib
|
|||||||
cmd.cpp
|
cmd.cpp
|
||||||
cmd/add_cel.cpp
|
cmd/add_cel.cpp
|
||||||
cmd/add_frame.cpp
|
cmd/add_frame.cpp
|
||||||
|
cmd/add_frame_tag.cpp
|
||||||
cmd/add_layer.cpp
|
cmd/add_layer.cpp
|
||||||
cmd/add_palette.cpp
|
cmd/add_palette.cpp
|
||||||
cmd/background_from_layer.cpp
|
cmd/background_from_layer.cpp
|
||||||
@ -157,6 +158,7 @@ add_library(app-lib
|
|||||||
commands/cmd_move_mask.cpp
|
commands/cmd_move_mask.cpp
|
||||||
commands/cmd_new_file.cpp
|
commands/cmd_new_file.cpp
|
||||||
commands/cmd_new_frame.cpp
|
commands/cmd_new_frame.cpp
|
||||||
|
commands/cmd_new_frame_tag.cpp
|
||||||
commands/cmd_new_layer.cpp
|
commands/cmd_new_layer.cpp
|
||||||
commands/cmd_new_layer_set.cpp
|
commands/cmd_new_layer_set.cpp
|
||||||
commands/cmd_onionskin.cpp
|
commands/cmd_onionskin.cpp
|
||||||
|
66
src/app/cmd/add_frame_tag.cpp
Normal file
66
src/app/cmd/add_frame_tag.cpp
Normal 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
|
45
src/app/cmd/add_frame_tag.h
Normal file
45
src/app/cmd/add_frame_tag.h
Normal 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
|
84
src/app/commands/cmd_new_frame_tag.cpp
Normal file
84
src/app/commands/cmd_new_frame_tag.cpp
Normal 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
|
@ -67,6 +67,7 @@ FOR_EACH_COMMAND(MoveCel)
|
|||||||
FOR_EACH_COMMAND(MoveMask)
|
FOR_EACH_COMMAND(MoveMask)
|
||||||
FOR_EACH_COMMAND(NewFile)
|
FOR_EACH_COMMAND(NewFile)
|
||||||
FOR_EACH_COMMAND(NewFrame)
|
FOR_EACH_COMMAND(NewFrame)
|
||||||
|
FOR_EACH_COMMAND(NewFrameTag)
|
||||||
FOR_EACH_COMMAND(NewLayer)
|
FOR_EACH_COMMAND(NewLayer)
|
||||||
FOR_EACH_COMMAND(NewLayerSet)
|
FOR_EACH_COMMAND(NewLayerSet)
|
||||||
FOR_EACH_COMMAND(OpenFile)
|
FOR_EACH_COMMAND(OpenFile)
|
||||||
|
@ -25,19 +25,20 @@
|
|||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
|
#include "app/transaction.h"
|
||||||
#include "app/ui/configure_timeline_popup.h"
|
#include "app/ui/configure_timeline_popup.h"
|
||||||
#include "app/ui/document_view.h"
|
#include "app/ui/document_view.h"
|
||||||
#include "app/ui/editor/editor.h"
|
#include "app/ui/editor/editor.h"
|
||||||
#include "app/ui/skin/skin_theme.h"
|
#include "app/ui/skin/skin_theme.h"
|
||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
#include "app/transaction.h"
|
|
||||||
#include "app/util/clipboard.h"
|
#include "app/util/clipboard.h"
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
|
#include "doc/doc.h"
|
||||||
#include "doc/document_event.h"
|
#include "doc/document_event.h"
|
||||||
|
#include "doc/frame_tag.h"
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
#include "gfx/rect.h"
|
#include "gfx/rect.h"
|
||||||
#include "doc/doc.h"
|
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -871,6 +872,7 @@ void Timeline::onPaint(ui::PaintEvent& ev)
|
|||||||
|
|
||||||
drawPaddings(g);
|
drawPaddings(g);
|
||||||
drawLoopRange(g);
|
drawLoopRange(g);
|
||||||
|
drawFrameTags(g);
|
||||||
drawRangeOutline(g);
|
drawRangeOutline(g);
|
||||||
drawClipboardRange(g);
|
drawClipboardRange(g);
|
||||||
|
|
||||||
@ -1327,6 +1329,20 @@ void Timeline::drawLoopRange(ui::Graphics* g)
|
|||||||
drawPart(g, bounds, NULL, m_timelineLoopRangeStyle);
|
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)
|
void Timeline::drawRangeOutline(ui::Graphics* g)
|
||||||
{
|
{
|
||||||
gfx::Rect clipBounds;
|
gfx::Rect clipBounds;
|
||||||
|
@ -148,6 +148,7 @@ namespace app {
|
|||||||
void drawCelLinkDecorators(ui::Graphics* g, const gfx::Rect& bounds,
|
void drawCelLinkDecorators(ui::Graphics* g, const gfx::Rect& bounds,
|
||||||
Cel* cel, Cel* activeCel, frame_t frame, bool is_active, bool is_hover);
|
Cel* cel, Cel* activeCel, frame_t frame, bool is_active, bool is_hover);
|
||||||
void drawLoopRange(ui::Graphics* g);
|
void drawLoopRange(ui::Graphics* g);
|
||||||
|
void drawFrameTags(ui::Graphics* g);
|
||||||
void drawRangeOutline(ui::Graphics* g);
|
void drawRangeOutline(ui::Graphics* g);
|
||||||
void drawPaddings(ui::Graphics* g);
|
void drawPaddings(ui::Graphics* g);
|
||||||
bool drawPart(ui::Graphics* g, int part, LayerIndex layer, frame_t frame);
|
bool drawPart(ui::Graphics* g, int part, LayerIndex layer, frame_t frame);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user