Add Frame Tags Properties dialog/command

This commit is contained in:
David Capello 2015-02-20 11:42:59 -03:00
parent b2ccf7a017
commit 2dac7f3869
16 changed files with 496 additions and 5 deletions

View File

@ -525,9 +525,12 @@
</item>
<item command="RemoveFrame" text="&amp;Remove Frame" />
<separator />
<item command="NewFrameTag" text="New &amp;Tag" />
<item command="RemoveFrameTag" text="Remove Ta&amp;g" />
<separator />
<menu text="&amp;Tags">
<item command="FrameTagProperties" text="Tag &amp;Properties..." />
<separator />
<item command="NewFrameTag" text="New &amp;Tag" />
<item command="RemoveFrameTag" text="&amp;Remove Tag" />
</menu>
<menu text="&amp;Jump to">
<item command="GotoFirstFrame" text="&amp;First Frame" />
<item command="GotoPreviousFrame" text="&amp;Previous Frame" />

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Aseprite -->
<!-- Copyright (C) 2015 by David Capello -->
<gui>
<window text="Frame Tag Properties" id="frame_tag_properties">
<grid columns="2">
<label text="Name:" />
<entry maxsize="256" id="name" />
<label text="From:" />
<entry maxsize="10" id="from" magnet="true" />
<label text="To:" />
<entry maxsize="10" id="to" />
<label text="Color:" />
<colorpicker id="color" />
<label text="Animation Direction:" />
<combobox id="anidir" />
<separator horizontal="true" cell_hspan="2" />
<box horizontal="true" homogeneous="true" cell_hspan="2" cell_align="right">
<button text="&amp;OK" closewindow="true" id="ok" magnet="true" minwidth="60" />
<button text="&amp;Cancel" closewindow="true" />
</box>
</grid>
</window>
</gui>

View File

@ -88,6 +88,10 @@ add_library(app-lib
cmd/set_cel_opacity.cpp
cmd/set_cel_position.cpp
cmd/set_frame_duration.cpp
cmd/set_frame_tag_anidir.cpp
cmd/set_frame_tag_color.cpp
cmd/set_frame_tag_name.cpp
cmd/set_frame_tag_range.cpp
cmd/set_layer_flags.cpp
cmd/set_layer_name.cpp
cmd/set_mask.cpp
@ -138,6 +142,7 @@ add_library(app-lib
commands/cmd_flatten_layers.cpp
commands/cmd_flip.cpp
commands/cmd_frame_properties.cpp
commands/cmd_frame_tag_properties.cpp
commands/cmd_fullscreen_preview.cpp
commands/cmd_goto_frame.cpp
commands/cmd_goto_layer.cpp

View File

@ -0,0 +1,37 @@
// 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/set_frame_tag_anidir.h"
#include "doc/frame_tag.h"
namespace app {
namespace cmd {
SetFrameTagAniDir::SetFrameTagAniDir(FrameTag* tag, doc::AniDir anidir)
: WithFrameTag(tag)
, m_oldAniDir(tag->aniDir())
, m_newAniDir(anidir)
{
}
void SetFrameTagAniDir::onExecute()
{
frameTag()->setAniDir(m_newAniDir);
}
void SetFrameTagAniDir::onUndo()
{
frameTag()->setAniDir(m_oldAniDir);
}
} // namespace cmd
} // namespace app

View 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.
#ifndef APP_CMD_SET_FRAME_TAG_ANIDIR_H_INCLUDED
#define APP_CMD_SET_FRAME_TAG_ANIDIR_H_INCLUDED
#pragma once
#include "app/cmd.h"
#include "app/cmd/with_frame_tag.h"
#include "doc/anidir.h"
namespace app {
namespace cmd {
using namespace doc;
class SetFrameTagAniDir : public Cmd
, public WithFrameTag {
public:
SetFrameTagAniDir(FrameTag* tag, doc::AniDir anidir);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override {
return sizeof(*this);
}
private:
doc::AniDir m_oldAniDir;
doc::AniDir m_newAniDir;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -0,0 +1,37 @@
// 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/set_frame_tag_color.h"
#include "doc/frame_tag.h"
namespace app {
namespace cmd {
SetFrameTagColor::SetFrameTagColor(FrameTag* tag, doc::color_t color)
: WithFrameTag(tag)
, m_oldColor(tag->color())
, m_newColor(color)
{
}
void SetFrameTagColor::onExecute()
{
frameTag()->setColor(m_newColor);
}
void SetFrameTagColor::onUndo()
{
frameTag()->setColor(m_oldColor);
}
} // namespace cmd
} // namespace app

View 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.
#ifndef APP_CMD_SET_FRAME_TAG_COLOR_H_INCLUDED
#define APP_CMD_SET_FRAME_TAG_COLOR_H_INCLUDED
#pragma once
#include "app/cmd.h"
#include "app/cmd/with_frame_tag.h"
#include "doc/color.h"
namespace app {
namespace cmd {
using namespace doc;
class SetFrameTagColor : public Cmd
, public WithFrameTag {
public:
SetFrameTagColor(FrameTag* tag, doc::color_t color);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override {
return sizeof(*this);
}
private:
doc::color_t m_oldColor;
doc::color_t m_newColor;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -0,0 +1,37 @@
// 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/set_frame_tag_name.h"
#include "doc/frame_tag.h"
namespace app {
namespace cmd {
SetFrameTagName::SetFrameTagName(FrameTag* tag, const std::string& name)
: WithFrameTag(tag)
, m_oldName(tag->name())
, m_newName(name)
{
}
void SetFrameTagName::onExecute()
{
frameTag()->setName(m_newName);
}
void SetFrameTagName::onUndo()
{
frameTag()->setName(m_oldName);
}
} // namespace cmd
} // namespace app

View File

@ -0,0 +1,41 @@
// 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_SET_FRAME_TAG_NAME_H_INCLUDED
#define APP_CMD_SET_FRAME_TAG_NAME_H_INCLUDED
#pragma once
#include "app/cmd.h"
#include "app/cmd/with_frame_tag.h"
#include <string>
namespace app {
namespace cmd {
using namespace doc;
class SetFrameTagName : public Cmd
, public WithFrameTag {
public:
SetFrameTagName(FrameTag* tag, const std::string& name);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override {
return sizeof(*this);
}
private:
std::string m_oldName;
std::string m_newName;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -0,0 +1,39 @@
// 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/set_frame_tag_range.h"
#include "doc/frame_tag.h"
namespace app {
namespace cmd {
SetFrameTagRange::SetFrameTagRange(FrameTag* tag, frame_t from, frame_t to)
: WithFrameTag(tag)
, m_oldFrom(tag->fromFrame())
, m_oldTo(tag->toFrame())
, m_newFrom(from)
, m_newTo(to)
{
}
void SetFrameTagRange::onExecute()
{
frameTag()->setFrameRange(m_newFrom, m_newTo);
}
void SetFrameTagRange::onUndo()
{
frameTag()->setFrameRange(m_oldFrom, m_oldTo);
}
} // namespace cmd
} // namespace app

View 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.
#ifndef APP_CMD_SET_FRAME_TAG_RANGE_H_INCLUDED
#define APP_CMD_SET_FRAME_TAG_RANGE_H_INCLUDED
#pragma once
#include "app/cmd.h"
#include "app/cmd/with_frame_tag.h"
#include "doc/frame.h"
namespace app {
namespace cmd {
using namespace doc;
class SetFrameTagRange : public Cmd
, public WithFrameTag {
public:
SetFrameTagRange(FrameTag* tag, frame_t from, frame_t to);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override {
return sizeof(*this);
}
private:
frame_t m_oldFrom, m_oldTo;
frame_t m_newFrom, m_newTo;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -0,0 +1,136 @@
// 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/set_frame_tag_anidir.h"
#include "app/cmd/set_frame_tag_color.h"
#include "app/cmd/set_frame_tag_name.h"
#include "app/cmd/set_frame_tag_range.h"
#include "app/color.h"
#include "app/commands/command.h"
#include "app/context_access.h"
#include "app/transaction.h"
#include "app/ui/color_button.h"
#include "doc/anidir.h"
#include "doc/frame_tag.h"
#include "doc/sprite.h"
#include "generated_frame_tag_properties.h"
namespace app {
using namespace ui;
class FrameTagPropertiesCommand : public Command {
public:
FrameTagPropertiesCommand();
Command* clone() const override { return new FrameTagPropertiesCommand(*this); }
protected:
bool onEnabled(Context* context);
void onExecute(Context* context);
private:
};
FrameTagPropertiesCommand::FrameTagPropertiesCommand()
: Command("FrameTagProperties",
"Frame Tag Properties",
CmdUIOnlyFlag)
{
}
bool FrameTagPropertiesCommand::onEnabled(Context* context)
{
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
}
void FrameTagPropertiesCommand::onExecute(Context* context)
{
const ContextReader reader(context);
const Sprite* sprite = reader.sprite();
frame_t frame = reader.frame();
const FrameTag* best = nullptr;
for (const 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;
app::gen::FrameTagProperties window;
window.name()->setText(best->name());
window.from()->setTextf("%d", best->fromFrame()+1);
window.to()->setTextf("%d", best->toFrame()+1);
window.color()->setColor(app::Color::fromRgb(
doc::rgba_getr(best->color()),
doc::rgba_getg(best->color()),
doc::rgba_getb(best->color())));
static_assert(
int(doc::AniDir::FORWARD) == 0 &&
int(doc::AniDir::REVERSE) == 1 &&
int(doc::AniDir::PING_PONG) == 2, "doc::AniDir has changed");
window.anidir()->addItem("Forward");
window.anidir()->addItem("Reverse");
window.anidir()->addItem("Ping-pong");
window.anidir()->setSelectedItemIndex(int(best->aniDir()));
window.openWindowInForeground();
if (window.getKiller() == window.ok()) {
std::string name = window.name()->getText();
frame_t first = 0;
frame_t last = sprite->lastFrame();
frame_t from = window.from()->getTextInt()-1;
frame_t to = window.to()->getTextInt()-1;
from = MID(first, from, last);
to = MID(from, to, last);
app::Color color = window.color()->getColor();
doc::color_t docColor = doc::rgba(
color.getRed(), color.getGreen(), color.getBlue(), 255);
doc::AniDir anidir = (doc::AniDir)window.anidir()->getSelectedItemIndex();
ContextWriter writer(reader);
Transaction transaction(writer.context(), "Change Frame Tag Properties");
FrameTag* tag = const_cast<FrameTag*>(best);
if (tag->name() != name)
transaction.execute(new cmd::SetFrameTagName(tag, name));
if (tag->fromFrame() != from ||
tag->toFrame() != to)
transaction.execute(new cmd::SetFrameTagRange(tag, from, to));
if (tag->color() != docColor)
transaction.execute(new cmd::SetFrameTagColor(tag, docColor));
if (tag->aniDir() != anidir)
transaction.execute(new cmd::SetFrameTagAniDir(tag, anidir));
transaction.commit();
}
}
Command* CommandFactory::createFrameTagPropertiesCommand()
{
return new FrameTagPropertiesCommand;
}
} // namespace app

View File

@ -37,6 +37,7 @@ FOR_EACH_COMMAND(Eyedropper)
FOR_EACH_COMMAND(FlattenLayers)
FOR_EACH_COMMAND(Flip)
FOR_EACH_COMMAND(FrameProperties)
FOR_EACH_COMMAND(FrameTagProperties)
FOR_EACH_COMMAND(FullscreenPreview)
FOR_EACH_COMMAND(GotoFirstFrame)
FOR_EACH_COMMAND(GotoFrame)

View File

@ -22,6 +22,7 @@ namespace doc {
public:
typedef List::iterator iterator;
typedef List::const_iterator const_iterator;
FrameTags(Sprite* sprite);
@ -32,8 +33,10 @@ namespace doc {
iterator begin() { return m_tags.begin(); }
iterator end() { return m_tags.end(); }
const_iterator begin() const { return m_tags.begin(); }
const_iterator end() const { return m_tags.end(); }
size_t size() { return m_tags.size(); }
size_t size() const { return m_tags.size(); }
private:
Sprite* m_sprite;

View File

@ -120,6 +120,7 @@ namespace doc {
void setFrameRangeDuration(frame_t from, frame_t to, int msecs);
void setDurationForAllFrames(int msecs);
const FrameTags& frameTags() const { return m_frameTags; }
FrameTags& frameTags() { return m_frameTags; }
////////////////////////////////////////

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2014 David Capello
// Copyright (c) 2014, 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -52,6 +52,7 @@ static std::string convert_type(const std::string& name)
if (name == "button") return "ui::Button";
if (name == "buttonset") return "app::ButtonSet";
if (name == "check") return "ui::CheckBox";
if (name == "colorpicker") return "app::ColorButton";
if (name == "combobox") return "ui::ComboBox";
if (name == "entry") return "ui::Entry";
if (name == "hbox") return "ui::HBox";