2014-10-21 09:21:31 +08:00
|
|
|
// Aseprite Document Library
|
2016-06-08 06:38:56 +08:00
|
|
|
// Copyright (c) 2001-2016 David Capello
|
2014-10-21 09:21:31 +08: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-30 06:40:17 +08:00
|
|
|
#pragma once
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2015-06-14 08:29:16 +08:00
|
|
|
#include "doc/blend_mode.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel_list.h"
|
2014-12-29 07:39:11 +08:00
|
|
|
#include "doc/frame.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/layer_list.h"
|
|
|
|
#include "doc/object.h"
|
2015-12-11 05:34:25 +08:00
|
|
|
#include "doc/with_user_data.h"
|
2012-07-09 08:09:09 +08:00
|
|
|
|
|
|
|
#include <string>
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
namespace doc {
|
2008-03-23 10:08:06 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class Cel;
|
|
|
|
class Image;
|
|
|
|
class Sprite;
|
|
|
|
class Layer;
|
|
|
|
class LayerImage;
|
2016-06-08 06:38:56 +08:00
|
|
|
class LayerGroup;
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Layer class
|
2011-03-28 05:15:00 +08:00
|
|
|
|
2014-11-17 10:03:30 +08:00
|
|
|
enum class LayerFlags {
|
2016-06-15 23:00:31 +08:00
|
|
|
None = 0,
|
2014-11-17 10:03:30 +08: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 20:33:56 +08:00
|
|
|
Continuous = 16, // Prefer to link cels when the user copy them
|
2016-06-09 02:15:37 +08:00
|
|
|
Collapsed = 32, // Prefer to show this group layer collapsed
|
2015-01-19 09:05:33 +08:00
|
|
|
|
|
|
|
BackgroundLayerFlags = LockMove | Background,
|
2013-08-06 08:20:19 +08:00
|
|
|
};
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2015-12-11 05:34:25 +08:00
|
|
|
class Layer : public WithUserData {
|
2013-08-06 08:20:19 +08:00
|
|
|
protected:
|
2013-11-10 06:59:05 +08:00
|
|
|
Layer(ObjectType type, Sprite* sprite);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
public:
|
|
|
|
virtual ~Layer();
|
2010-10-04 02:51:03 +08:00
|
|
|
|
2014-11-17 08:32:18 +08:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
std::string name() const { return m_name; }
|
2013-08-06 08:20:19 +08:00
|
|
|
void setName(const std::string& name) { m_name = name; }
|
2013-01-11 23:43:25 +08:00
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
Sprite* sprite() const { return m_sprite; }
|
2016-06-08 06:38:56 +08:00
|
|
|
LayerGroup* parent() const { return m_parent; }
|
|
|
|
void setParent(LayerGroup* group) { m_parent = group; }
|
2013-01-11 23:43:25 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
// Gets the previous sibling of this layer.
|
|
|
|
Layer* getPrevious() const;
|
|
|
|
Layer* getNext() const;
|
2013-01-11 23:43:25 +08:00
|
|
|
|
2016-06-15 02:00:11 +08:00
|
|
|
Layer* getPreviousInWholeHierarchy() const;
|
|
|
|
Layer* getNextInWholeHierarchy() const;
|
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
bool isImage() const { return type() == ObjectType::LayerImage; }
|
2016-06-08 06:38:56 +08:00
|
|
|
bool isGroup() const { return type() == ObjectType::LayerGroup; }
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2016-06-09 02:15:37 +08: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 21:12:26 +08:00
|
|
|
|
2014-11-17 10:03:30 +08: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 20:33:56 +08:00
|
|
|
void setContinuous(bool state) { switchFlags(LayerFlags::Continuous, state); }
|
2016-06-09 02:15:37 +08:00
|
|
|
void setCollapsed (bool state) { switchFlags(LayerFlags::Collapsed, state); }
|
2014-11-17 10:03:30 +08: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 11:15:44 +08:00
|
|
|
|
2014-12-28 22:06:11 +08:00
|
|
|
virtual Cel* cel(frame_t frame) const;
|
2014-05-02 22:28:03 +08:00
|
|
|
virtual void getCels(CelList& cels) const = 0;
|
2015-01-19 09:05:33 +08:00
|
|
|
virtual void displaceFrames(frame_t fromThis, frame_t delta) = 0;
|
2011-03-23 08:11:25 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
private:
|
|
|
|
std::string m_name; // layer name
|
|
|
|
Sprite* m_sprite; // owner of the layer
|
2016-06-08 06:38:56 +08:00
|
|
|
LayerGroup* m_parent; // parent layer
|
2014-11-17 10:03:30 +08:00
|
|
|
LayerFlags m_flags; // stack order cannot be changed
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
// Disable assigment
|
|
|
|
Layer& operator=(const Layer& other);
|
|
|
|
};
|
2008-10-01 09:27:51 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// LayerImage class
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
class LayerImage : public Layer {
|
2013-08-06 08:20:19 +08:00
|
|
|
public:
|
|
|
|
explicit LayerImage(Sprite* sprite);
|
|
|
|
virtual ~LayerImage();
|
2010-10-04 02:51:03 +08:00
|
|
|
|
2014-11-17 08:32:18 +08:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2015-06-14 08:29:16 +08:00
|
|
|
BlendMode blendMode() const { return m_blendmode; }
|
|
|
|
void setBlendMode(BlendMode blendmode) { m_blendmode = blendmode; }
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2015-06-15 07:23:49 +08:00
|
|
|
int opacity() const { return m_opacity; }
|
|
|
|
void setOpacity(int opacity) { m_opacity = opacity; }
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
void addCel(Cel *cel);
|
|
|
|
void removeCel(Cel *cel);
|
2014-12-29 07:39:11 +08:00
|
|
|
void moveCel(Cel *cel, frame_t frame);
|
2015-09-15 19:18:52 +08:00
|
|
|
|
2014-12-28 22:06:11 +08:00
|
|
|
Cel* cel(frame_t frame) const override;
|
2014-08-15 10:07:47 +08:00
|
|
|
void getCels(CelList& cels) const override;
|
2015-01-19 09:05:33 +08:00
|
|
|
void displaceFrames(frame_t fromThis, frame_t delta) override;
|
2015-09-15 19:18:52 +08:00
|
|
|
|
2014-08-12 18:57:40 +08:00
|
|
|
Cel* getLastCel() const;
|
2015-09-15 19:18:52 +08:00
|
|
|
CelConstIterator findCelIterator(frame_t frame) const;
|
|
|
|
CelIterator findCelIterator(frame_t frame);
|
|
|
|
CelIterator findFirstCelIteratorAfter(frame_t firstAfterFrame);
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
void configureAsBackground();
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2013-08-06 08:20:19 +08: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-07 04:01:08 +08:00
|
|
|
int getCelsCount() const { return (int)m_cels.size(); }
|
2010-09-19 11:15:44 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
private:
|
|
|
|
void destroyAllCels();
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2015-06-14 08:29:16 +08:00
|
|
|
BlendMode m_blendmode;
|
2015-06-15 07:23:49 +08:00
|
|
|
int m_opacity;
|
2013-08-06 08:20:19 +08:00
|
|
|
CelList m_cels; // List of all cels inside this layer used by frames.
|
|
|
|
};
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2016-06-08 06:38:56 +08:00
|
|
|
// LayerGroup class
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2016-06-08 06:38:56 +08:00
|
|
|
class LayerGroup : public Layer {
|
2013-08-06 08:20:19 +08:00
|
|
|
public:
|
2016-06-08 06:38:56 +08:00
|
|
|
explicit LayerGroup(Sprite* sprite);
|
|
|
|
virtual ~LayerGroup();
|
2010-10-04 02:51:03 +08:00
|
|
|
|
2014-11-17 08:32:18 +08:00
|
|
|
virtual int getMemSize() const override;
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2016-06-09 03:46:15 +08:00
|
|
|
const LayerList& layers() const { return m_layers; }
|
2016-06-08 06:38:56 +08:00
|
|
|
int layersCount() const { return (int)m_layers.size(); }
|
2009-11-17 21:12:26 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
void addLayer(Layer* layer);
|
|
|
|
void removeLayer(Layer* layer);
|
|
|
|
void stackLayer(Layer* layer, Layer* after);
|
2013-03-12 07:29:45 +08:00
|
|
|
|
2016-06-15 02:00:11 +08: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 21:12:26 +08:00
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void getCels(CelList& cels) const override;
|
2015-01-19 09:05:33 +08:00
|
|
|
void displaceFrames(frame_t fromThis, frame_t delta) override;
|
2010-09-19 11:15:44 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
private:
|
|
|
|
void destroyAllLayers();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
LayerList m_layers;
|
|
|
|
};
|
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
} // namespace doc
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2009-08-18 05:38:00 +08:00
|
|
|
#endif
|