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"
|
2014-12-28 20:39:11 -03:00
|
|
|
#include "doc/frame.h"
|
2014-10-20 22:21:31 -03:00
|
|
|
#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
|
|
|
|
2014-11-16 23:03:30 -03:00
|
|
|
enum class LayerFlags {
|
|
|
|
Visible = 1, // Can be read
|
|
|
|
Editable = 2, // Can be written
|
|
|
|
LockMove = 4, // Cannot be moved
|
|
|
|
Background = 8, // Stack order cannot be changed
|
2013-08-05 21:20:19 -03:00
|
|
|
};
|
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; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-11-16 23:03:30 -03:00
|
|
|
bool isBackground() const { return hasFlags(LayerFlags::Background); }
|
|
|
|
bool isVisible() const { return hasFlags(LayerFlags::Visible); }
|
|
|
|
bool isEditable() const { return hasFlags(LayerFlags::Editable); }
|
|
|
|
bool isMovable() const { return !hasFlags(LayerFlags::LockMove); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2014-11-16 23:03:30 -03:00
|
|
|
void setBackground(bool state) { switchFlags(LayerFlags::Background, state); }
|
|
|
|
void setVisible (bool state) { switchFlags(LayerFlags::Visible, state); }
|
|
|
|
void setEditable (bool state) { switchFlags(LayerFlags::Editable, state); }
|
|
|
|
void setMovable (bool state) { switchFlags(LayerFlags::LockMove, !state); }
|
|
|
|
|
|
|
|
LayerFlags flags() const {
|
|
|
|
return m_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasFlags(LayerFlags flags) const {
|
|
|
|
return (int(m_flags) & int(flags)) == int(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFlags(LayerFlags flags) {
|
|
|
|
m_flags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void switchFlags(LayerFlags flags, bool state) {
|
|
|
|
if (state)
|
|
|
|
m_flags = LayerFlags(int(m_flags) | int(flags));
|
|
|
|
else
|
|
|
|
m_flags = LayerFlags(int(m_flags) & ~int(flags));
|
|
|
|
}
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2014-12-28 11:06:11 -03:00
|
|
|
virtual Cel* cel(frame_t frame) const;
|
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
|
2014-11-16 23:03:30 -03:00
|
|
|
LayerFlags m_flags; // stack order cannot be changed
|
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-12-28 20:39:11 -03:00
|
|
|
void moveCel(Cel *cel, frame_t frame);
|
2014-12-28 11:06:11 -03:00
|
|
|
Cel* cel(frame_t frame) const override;
|
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;
|
|
|
|
};
|
|
|
|
|
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
|