2014-10-20 22:21:31 -03:00
|
|
|
// Aseprite Document Library
|
|
|
|
// Copyright (c) 2001-2014 David Capello
|
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifndef DOC_LAYER_H_INCLUDED
|
|
|
|
#define DOC_LAYER_H_INCLUDED
|
2014-03-29 19:40:17 -03:00
|
|
|
#pragma once
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
#include "doc/blend.h"
|
|
|
|
#include "doc/cel_list.h"
|
|
|
|
#include "doc/frame_number.h"
|
|
|
|
#include "doc/layer_list.h"
|
|
|
|
#include "doc/object.h"
|
2012-07-08 21:09:09 -03:00
|
|
|
|
|
|
|
#include <string>
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
namespace doc {
|
2008-03-23 02:08:06 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
class Cel;
|
|
|
|
class Image;
|
|
|
|
class Sprite;
|
|
|
|
class Layer;
|
|
|
|
class LayerImage;
|
|
|
|
class LayerFolder;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Layer class
|
2011-03-27 18:15:00 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
enum {
|
|
|
|
LAYER_IS_READABLE = 0x0001,
|
|
|
|
LAYER_IS_WRITABLE = 0x0002,
|
|
|
|
LAYER_IS_LOCKMOVE = 0x0004,
|
|
|
|
LAYER_IS_BACKGROUND = 0x0008,
|
|
|
|
};
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-11-09 19:59:05 -03:00
|
|
|
class Layer : public Object {
|
2013-08-05 21:20:19 -03:00
|
|
|
protected:
|
2013-11-09 19:59:05 -03:00
|
|
|
Layer(ObjectType type, Sprite* sprite);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
|
|
|
virtual ~Layer();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2014-11-16 21:32:18 -03:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-07-30 01:28:15 -03:00
|
|
|
std::string name() const { return m_name; }
|
2013-08-05 21:20:19 -03:00
|
|
|
void setName(const std::string& name) { m_name = name; }
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2014-07-30 01:28:15 -03:00
|
|
|
Sprite* sprite() const { return m_sprite; }
|
|
|
|
LayerFolder* parent() const { return m_parent; }
|
2013-08-05 21:20:19 -03:00
|
|
|
void setParent(LayerFolder* folder) { m_parent = folder; }
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
// Gets the previous sibling of this layer.
|
|
|
|
Layer* getPrevious() const;
|
|
|
|
Layer* getNext() const;
|
2013-01-11 12:43:25 -03:00
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
bool isImage() const { return type() == ObjectType::LayerImage; }
|
|
|
|
bool isFolder() const { return type() == ObjectType::LayerFolder; }
|
2013-08-05 21:20:19 -03:00
|
|
|
bool isBackground() const { return (m_flags & LAYER_IS_BACKGROUND) == LAYER_IS_BACKGROUND; }
|
|
|
|
bool isMoveable() const { return (m_flags & LAYER_IS_LOCKMOVE) == 0; }
|
|
|
|
bool isReadable() const { return (m_flags & LAYER_IS_READABLE) == LAYER_IS_READABLE; }
|
|
|
|
bool isWritable() const { return (m_flags & LAYER_IS_WRITABLE) == LAYER_IS_WRITABLE; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void setBackground(bool b) { if (b) m_flags |= LAYER_IS_BACKGROUND; else m_flags &= ~LAYER_IS_BACKGROUND; }
|
|
|
|
void setMoveable(bool b) { if (b) m_flags &= ~LAYER_IS_LOCKMOVE; else m_flags |= LAYER_IS_LOCKMOVE; }
|
|
|
|
void setReadable(bool b) { if (b) m_flags |= LAYER_IS_READABLE; else m_flags &= ~LAYER_IS_READABLE; }
|
|
|
|
void setWritable(bool b) { if (b) m_flags |= LAYER_IS_WRITABLE; else m_flags &= ~LAYER_IS_WRITABLE; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
uint32_t getFlags() const { return m_flags; }
|
|
|
|
void setFlags(uint32_t flags) { m_flags = flags; }
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2014-05-02 11:28:03 -03:00
|
|
|
virtual void getCels(CelList& cels) const = 0;
|
2011-03-22 21:11:25 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
std::string m_name; // layer name
|
|
|
|
Sprite* m_sprite; // owner of the layer
|
|
|
|
LayerFolder* m_parent; // parent layer
|
|
|
|
unsigned short m_flags;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
// Disable assigment
|
|
|
|
Layer& operator=(const Layer& other);
|
|
|
|
};
|
2008-10-01 01:27:51 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// LayerImage class
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
class LayerImage : public Layer {
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
|
|
|
explicit LayerImage(Sprite* sprite);
|
|
|
|
virtual ~LayerImage();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2014-11-16 21:32:18 -03:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
int getBlendMode() const { return BLEND_MODE_NORMAL; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void addCel(Cel *cel);
|
|
|
|
void removeCel(Cel *cel);
|
2014-04-09 21:56:06 -03:00
|
|
|
void moveCel(Cel *cel, FrameNumber frame);
|
2013-08-05 21:20:19 -03:00
|
|
|
const Cel* getCel(FrameNumber frame) const;
|
|
|
|
Cel* getCel(FrameNumber frame);
|
2014-08-14 23:07:47 -03:00
|
|
|
void getCels(CelList& cels) const override;
|
2014-08-12 07:57:40 -03:00
|
|
|
Cel* getLastCel() const;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void configureAsBackground();
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
CelIterator getCelBegin() { return m_cels.begin(); }
|
|
|
|
CelIterator getCelEnd() { return m_cels.end(); }
|
|
|
|
CelConstIterator getCelBegin() const { return m_cels.begin(); }
|
|
|
|
CelConstIterator getCelEnd() const { return m_cels.end(); }
|
|
|
|
int getCelsCount() const { return m_cels.size(); }
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
void destroyAllCels();
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
CelList m_cels; // List of all cels inside this layer used by frames.
|
|
|
|
};
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// LayerFolder class
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
class LayerFolder : public Layer {
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
|
|
|
explicit LayerFolder(Sprite* sprite);
|
|
|
|
virtual ~LayerFolder();
|
2010-10-03 15:51:03 -03:00
|
|
|
|
2014-11-16 21:32:18 -03:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
const LayerList& getLayersList() { return m_layers; }
|
|
|
|
LayerIterator getLayerBegin() { return m_layers.begin(); }
|
|
|
|
LayerIterator getLayerEnd() { return m_layers.end(); }
|
|
|
|
LayerConstIterator getLayerBegin() const { return m_layers.begin(); }
|
|
|
|
LayerConstIterator getLayerEnd() const { return m_layers.end(); }
|
|
|
|
int getLayersCount() const { return m_layers.size(); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
void addLayer(Layer* layer);
|
|
|
|
void removeLayer(Layer* layer);
|
|
|
|
void stackLayer(Layer* layer, Layer* after);
|
2013-03-11 20:29:45 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
Layer* getFirstLayer() { return (m_layers.empty() ? NULL: m_layers.front()); }
|
|
|
|
Layer* getLastLayer() { return (m_layers.empty() ? NULL: m_layers.back()); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-08-14 23:07:47 -03:00
|
|
|
void getCels(CelList& cels) const override;
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
private:
|
|
|
|
void destroyAllLayers();
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2013-08-05 21:20:19 -03:00
|
|
|
LayerList m_layers;
|
|
|
|
};
|
|
|
|
|
|
|
|
void layer_render(const Layer* layer, Image *image, int x, int y, FrameNumber frame);
|
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
} // namespace doc
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2009-08-17 21:38:00 +00:00
|
|
|
#endif
|