From f4603b3be1854e963224615829c00c3cca42cc80 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 17 Feb 2015 11:37:42 -0300 Subject: [PATCH] Add FrameTag(s) classes --- src/doc/CMakeLists.txt | 1 + src/doc/frame_tags.cpp | 45 +++++++++++++++++++++++++++ src/doc/frame_tags.h | 69 ++++++++++++++++++++++++++++++++++++++++++ src/doc/object_type.h | 3 +- src/doc/sprite.cpp | 1 + src/doc/sprite.h | 5 +++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/doc/frame_tags.cpp create mode 100644 src/doc/frame_tags.h diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt index 0761362e3..525451602 100644 --- a/src/doc/CMakeLists.txt +++ b/src/doc/CMakeLists.txt @@ -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 diff --git a/src/doc/frame_tags.cpp b/src/doc/frame_tags.cpp new file mode 100644 index 000000000..aaa422348 --- /dev/null +++ b/src/doc/frame_tags.cpp @@ -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 diff --git a/src/doc/frame_tags.h b/src/doc/frame_tags.h new file mode 100644 index 000000000..c4c8aa891 --- /dev/null +++ b/src/doc/frame_tags.h @@ -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 +#include + +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 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 diff --git a/src/doc/object_type.h b/src/doc/object_type.h index a343bb91c..cb7dcaf14 100644 --- a/src/doc/object_type.h +++ b/src/doc/object_type.h @@ -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 diff --git a/src/doc/sprite.cpp b/src/doc/sprite.cpp index 26067b62c..23468da4b 100644 --- a/src/doc/sprite.cpp +++ b/src/doc/sprite.cpp @@ -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); diff --git a/src/doc/sprite.h b/src/doc/sprite.h index 30ec130fe..da22df8ca 100644 --- a/src/doc/sprite.h +++ b/src/doc/sprite.h @@ -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);