Add FrameTag(s) classes

This commit is contained in:
David Capello 2015-02-17 11:37:42 -03:00
parent 3da835899d
commit f4603b3be1
6 changed files with 123 additions and 1 deletions

View File

@ -24,6 +24,7 @@ add_library(doc-lib
documents.cpp
file/col_file.cpp
file/gpl_file.cpp
frame_tags.cpp
image.cpp
image_io.cpp
images_collector.cpp

45
src/doc/frame_tags.cpp Normal file
View File

@ -0,0 +1,45 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/frame_tags.h"
namespace doc {
FrameTag::FrameTag(frame_t from, frame_t to)
: Object(ObjectType::FrameTag)
, m_from(from)
, m_to(to)
, m_name("Tag")
, m_color(rgba(0, 0, 0, 255))
{
}
void FrameTag::setFrameRange(frame_t from, frame_t to)
{
m_from = from;
m_to = to;
}
void FrameTag::setName(const std::string& name)
{
m_name = name;
}
void FrameTag::setColor(color_t color)
{
m_color = color;
}
FrameTags::FrameTags(Sprite* sprite)
: m_sprite(sprite)
{
}
} // namespace doc

69
src/doc/frame_tags.h Normal file
View File

@ -0,0 +1,69 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_FRAME_TAGS_H_INCLUDED
#define DOC_FRAME_TAGS_H_INCLUDED
#pragma once
#include "base/disable_copying.h"
#include "doc/color.h"
#include "doc/frame.h"
#include "doc/object.h"
#include <string>
#include <vector>
namespace doc {
class Sprite;
class FrameTag : public Object {
public:
FrameTag(frame_t from, frame_t to);
frame_t fromFrame() const { return m_from; }
frame_t toFrame() const { return m_to; }
const std::string& name() const { return m_name; }
color_t color() const { return m_color; }
void setFrameRange(frame_t from, frame_t to);
void setName(const std::string& name);
void setColor(color_t color);
public:
frame_t m_from, m_to;
color_t m_color;
std::string m_name;
DISABLE_COPYING(FrameTag);
};
class FrameTags {
typedef std::vector<FrameTags> List;
public:
typedef List::iterator iterator;
FrameTags(Sprite* sprite);
Sprite* sprite() { return m_sprite; }
void add(FrameTag* tag);
void remove(FrameTag* tag);
iterator begin() { return m_tags.begin(); }
iterator end() { return m_tags.end(); }
private:
Sprite* m_sprite;
List m_tags;
DISABLE_COPYING(FrameTags);
};
} // namespace doc
#endif

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2001-2014 David Capello
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -23,6 +23,7 @@ namespace doc {
LayerFolder,
Sprite,
Document,
FrameTag,
};
} // namespace doc

View File

@ -36,6 +36,7 @@ Sprite::Sprite(PixelFormat format, int width, int height, int ncolors)
, m_width(width)
, m_height(height)
, m_frames(1)
, m_frameTags(this)
{
ASSERT(width > 0 && height > 0);

View File

@ -13,6 +13,7 @@
#include "doc/cel_list.h"
#include "doc/color.h"
#include "doc/frame.h"
#include "doc/frame_tags.h"
#include "doc/image_ref.h"
#include "doc/layer_index.h"
#include "doc/object.h"
@ -119,6 +120,8 @@ namespace doc {
void setFrameRangeDuration(frame_t from, frame_t to, int msecs);
void setDurationForAllFrames(int msecs);
FrameTags& frameTags() const;
////////////////////////////////////////
// Shared Images and CelData (for linked Cels)
@ -153,6 +156,8 @@ namespace doc {
// Transparent color used in indexed images
color_t m_transparentColor;
FrameTags m_frameTags;
// Disable default constructor and copying
Sprite();
DISABLE_COPYING(Sprite);