aseprite/src/doc/layer.h

218 lines
7.0 KiB
C
Raw Normal View History

// Aseprite Document Library
2016-06-07 19:38:56 -03:00
// Copyright (c) 2001-2016 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
#include "doc/blend_mode.h"
#include "doc/cel_list.h"
#include "doc/frame.h"
#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
namespace doc {
2008-03-23 02:08:06 +00:00
class Cel;
class Image;
class Sprite;
class Layer;
class LayerImage;
2016-06-07 19:38:56 -03:00
class LayerGroup;
//////////////////////////////////////////////////////////////////////
// Layer class
2014-11-16 23:03:30 -03:00
enum class LayerFlags {
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
Continuous = 16, // Prefer to link cels when the user copy them
Collapsed = 32, // Prefer to show this group layer collapsed
Reference = 64, // Is a reference layer
BackgroundLayerFlags = LockMove | Background,
};
2015-12-10 18:34:25 -03:00
class Layer : public WithUserData {
protected:
Layer(ObjectType type, Sprite* sprite);
2007-09-18 23:57:02 +00:00
public:
virtual ~Layer();
virtual int getMemSize() const override;
std::string name() const { return m_name; }
void setName(const std::string& name) { m_name = name; }
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; }
// Gets the previous sibling of this layer.
Layer* getPrevious() const;
Layer* getNext() const;
Layer* getPreviousBrowsable() const;
Layer* getNextBrowsable() const;
2016-06-14 15:00:11 -03:00
Layer* getPreviousInWholeHierarchy() const;
Layer* getNextInWholeHierarchy() const;
bool isImage() const { return type() == ObjectType::LayerImage; }
2016-06-07 19:38:56 -03:00
bool isGroup() const { return type() == ObjectType::LayerGroup; }
virtual bool isBrowsable() const { return false; }
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); }
bool isReference() const { return hasFlags(LayerFlags::Reference); }
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); }
void setContinuous(bool state) { switchFlags(LayerFlags::Continuous, state); }
void setCollapsed (bool state) { switchFlags(LayerFlags::Collapsed, state); }
void setReference (bool state) { switchFlags(LayerFlags::Reference, 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));
}
virtual Cel* cel(frame_t frame) const;
virtual void getCels(CelList& cels) const = 0;
virtual void displaceFrames(frame_t fromThis, frame_t delta) = 0;
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
// Disable assigment
Layer& operator=(const Layer& other);
};
//////////////////////////////////////////////////////////////////////
// LayerImage class
class LayerImage : public Layer {
public:
explicit LayerImage(Sprite* sprite);
virtual ~LayerImage();
virtual int getMemSize() const override;
BlendMode blendMode() const { return m_blendmode; }
void setBlendMode(BlendMode blendmode) { m_blendmode = blendmode; }
2015-06-14 20:23:49 -03:00
int opacity() const { return m_opacity; }
void setOpacity(int opacity) { m_opacity = opacity; }
void addCel(Cel *cel);
void removeCel(Cel *cel);
void moveCel(Cel *cel, frame_t frame);
Cel* cel(frame_t frame) const override;
void getCels(CelList& cels) const override;
void displaceFrames(frame_t fromThis, frame_t delta) override;
Cel* getLastCel() const;
CelConstIterator findCelIterator(frame_t frame) const;
CelIterator findCelIterator(frame_t frame);
CelIterator findFirstCelIteratorAfter(frame_t firstAfterFrame);
void configureAsBackground();
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(); }
private:
void destroyAllCels();
BlendMode m_blendmode;
2015-06-14 20:23:49 -03:00
int m_opacity;
CelList m_cels; // List of all cels inside this layer used by frames.
};
//////////////////////////////////////////////////////////////////////
2016-06-07 19:38:56 -03:00
// LayerGroup class
2016-06-07 19:38:56 -03:00
class LayerGroup : public Layer {
public:
2016-06-07 19:38:56 -03:00
explicit LayerGroup(Sprite* sprite);
virtual ~LayerGroup();
virtual int getMemSize() const override;
const LayerList& layers() const { return m_layers; }
2016-06-07 19:38:56 -03:00
int layersCount() const { return (int)m_layers.size(); }
void addLayer(Layer* layer);
void removeLayer(Layer* layer);
void insertLayer(Layer* layer, Layer* after);
void stackLayer(Layer* layer, Layer* after);
2016-06-14 15:00:11 -03:00
Layer* firstLayer() const { return (m_layers.empty() ? nullptr: m_layers.front()); }
Layer* firstLayerInWholeHierarchy() const;
2016-06-14 15:00:11 -03:00
Layer* lastLayer() const { return (m_layers.empty() ? nullptr: m_layers.back()); }
void allLayers(LayerList& list) const;
layer_t allLayersCount() const;
void allVisibleLayers(LayerList& list) const;
void allVisibleReferenceLayers(LayerList& list) const;
void allBrowsableLayers(LayerList& list) const;
void getCels(CelList& cels) const override;
void displaceFrames(frame_t fromThis, frame_t delta) override;
bool isBrowsable() const override {
return isGroup() && isExpanded() && !m_layers.empty();
}
private:
void destroyAllLayers();
2007-09-18 23:57:02 +00:00
LayerList m_layers;
};
} // namespace doc
2007-09-18 23:57:02 +00:00
2009-08-17 21:38:00 +00:00
#endif