2014-10-20 22:21:31 -03:00
|
|
|
// Aseprite Document Library
|
2016-06-07 19:38:56 -03:00
|
|
|
// Copyright (c) 2001-2016 David Capello
|
2014-10-20 22:21:31 -03:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2015-06-13 21:29:16 -03:00
|
|
|
#include "doc/blend_mode.h"
|
2014-10-20 22:21:31 -03:00
|
|
|
#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"
|
2015-12-10 18:34:25 -03:00
|
|
|
#include "doc/with_user_data.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;
|
2016-06-07 19:38:56 -03:00
|
|
|
class LayerGroup;
|
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 {
|
2016-06-15 12:00:31 -03:00
|
|
|
None = 0,
|
2014-11-16 23:03:30 -03:00
|
|
|
Visible = 1, // Can be read
|
|
|
|
Editable = 2, // Can be written
|
|
|
|
LockMove = 4, // Cannot be moved
|
|
|
|
Background = 8, // Stack order cannot be changed
|
2015-01-20 09:33:56 -03:00
|
|
|
Continuous = 16, // Prefer to link cels when the user copy them
|
2016-06-08 15:15:37 -03:00
|
|
|
Collapsed = 32, // Prefer to show this group layer collapsed
|
2015-01-18 22:05:33 -03:00
|
|
|
|
|
|
|
BackgroundLayerFlags = LockMove | Background,
|
2013-08-05 21:20:19 -03:00
|
|
|
};
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2015-12-10 18:34:25 -03:00
|
|
|
class Layer : public WithUserData {
|
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; }
|
2016-06-07 19:38:56 -03:00
|
|
|
LayerGroup* parent() const { return m_parent; }
|
|
|
|
void setParent(LayerGroup* group) { m_parent = group; }
|
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
|
|
|
|
2016-06-14 15:00:11 -03:00
|
|
|
Layer* getPreviousInWholeHierarchy() const;
|
|
|
|
Layer* getNextInWholeHierarchy() const;
|
|
|
|
|
2014-10-20 22:21:31 -03:00
|
|
|
bool isImage() const { return type() == ObjectType::LayerImage; }
|
2016-06-07 19:38:56 -03:00
|
|
|
bool isGroup() const { return type() == ObjectType::LayerGroup; }
|
2016-06-20 21:15:35 -03:00
|
|
|
virtual bool isBrowsable() const { return false; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2016-06-08 15:15:37 -03:00
|
|
|
bool isBackground() const { return hasFlags(LayerFlags::Background); }
|
|
|
|
bool isTransparent() 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); }
|
|
|
|
bool isContinuous() const { return hasFlags(LayerFlags::Continuous); }
|
|
|
|
bool isCollapsed() const { return hasFlags(LayerFlags::Collapsed); }
|
|
|
|
bool isExpanded() const { return !hasFlags(LayerFlags::Collapsed); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2016-06-15 15:27:38 -03:00
|
|
|
bool isVisibleHierarchy() const;
|
|
|
|
bool isEditableHierarchy() const;
|
|
|
|
|
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); }
|
2015-01-20 09:33:56 -03:00
|
|
|
void setContinuous(bool state) { switchFlags(LayerFlags::Continuous, state); }
|
2016-06-08 15:15:37 -03:00
|
|
|
void setCollapsed (bool state) { switchFlags(LayerFlags::Collapsed, state); }
|
2014-11-16 23:03:30 -03:00
|
|
|
|
|
|
|
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;
|
2015-01-18 22:05:33 -03:00
|
|
|
virtual void displaceFrames(frame_t fromThis, frame_t delta) = 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
|
2016-06-07 19:38:56 -03:00
|
|
|
LayerGroup* 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
|
|
|
|
2015-06-13 21:29:16 -03:00
|
|
|
BlendMode blendMode() const { return m_blendmode; }
|
|
|
|
void setBlendMode(BlendMode blendmode) { m_blendmode = blendmode; }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2015-06-14 20:23:49 -03:00
|
|
|
int opacity() const { return m_opacity; }
|
|
|
|
void setOpacity(int opacity) { m_opacity = opacity; }
|
|
|
|
|
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);
|
2015-09-15 08:18:52 -03:00
|
|
|
|
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;
|
2015-01-18 22:05:33 -03:00
|
|
|
void displaceFrames(frame_t fromThis, frame_t delta) override;
|
2015-09-15 08:18:52 -03:00
|
|
|
|
2014-08-12 07:57:40 -03:00
|
|
|
Cel* getLastCel() const;
|
2015-09-15 08:18:52 -03:00
|
|
|
CelConstIterator findCelIterator(frame_t frame) const;
|
|
|
|
CelIterator findCelIterator(frame_t frame);
|
|
|
|
CelIterator findFirstCelIteratorAfter(frame_t firstAfterFrame);
|
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(); }
|
2015-03-06 17:01:08 -03:00
|
|
|
int getCelsCount() const { return (int)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
|
|
|
|
2015-06-13 21:29:16 -03:00
|
|
|
BlendMode m_blendmode;
|
2015-06-14 20:23:49 -03:00
|
|
|
int m_opacity;
|
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
|
|
|
//////////////////////////////////////////////////////////////////////
|
2016-06-07 19:38:56 -03:00
|
|
|
// LayerGroup class
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2016-06-07 19:38:56 -03:00
|
|
|
class LayerGroup : public Layer {
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
2016-06-07 19:38:56 -03:00
|
|
|
explicit LayerGroup(Sprite* sprite);
|
|
|
|
virtual ~LayerGroup();
|
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
|
|
|
|
2016-06-08 16:46:15 -03:00
|
|
|
const LayerList& layers() const { return m_layers; }
|
2016-06-07 19:38:56 -03:00
|
|
|
int layersCount() const { return (int)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);
|
2016-06-21 00:02:13 -03:00
|
|
|
void insertLayer(Layer* layer, Layer* after);
|
2013-08-05 21:20:19 -03:00
|
|
|
void stackLayer(Layer* layer, Layer* after);
|
2013-03-11 20:29:45 -03:00
|
|
|
|
2016-06-14 15:00:11 -03:00
|
|
|
Layer* firstLayer() const { return (m_layers.empty() ? nullptr: m_layers.front()); }
|
|
|
|
Layer* lastLayer() const { return (m_layers.empty() ? nullptr: m_layers.back()); }
|
2009-11-17 13:12:26 +00:00
|
|
|
|
2016-06-21 12:02:31 -03:00
|
|
|
void allLayers(LayerList& list) const;
|
2016-08-11 14:53:51 -03:00
|
|
|
layer_t allLayersCount() const;
|
2016-06-21 12:02:31 -03:00
|
|
|
void allVisibleLayers(LayerList& list) const;
|
|
|
|
void allBrowsableLayers(LayerList& list) const;
|
|
|
|
|
2014-08-14 23:07:47 -03:00
|
|
|
void getCels(CelList& cels) const override;
|
2015-01-18 22:05:33 -03:00
|
|
|
void displaceFrames(frame_t fromThis, frame_t delta) override;
|
2010-09-19 00:15:44 -03:00
|
|
|
|
2016-06-20 21:15:35 -03:00
|
|
|
bool isBrowsable() const override {
|
|
|
|
return isGroup() && isExpanded() && !m_layers.empty();
|
|
|
|
}
|
|
|
|
|
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
|